Skip to content

Commit a53ec52

Browse files
committed
add move function
1 parent 54c73c7 commit a53ec52

File tree

8 files changed

+226
-4
lines changed

8 files changed

+226
-4
lines changed

public/js/script.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function toggleActions() {
202202
$('[data-action=use]').toggleClass('d-none', !(many_selected && only_file))
203203
$('[data-action=rename]').toggleClass('d-none', !one_selected)
204204
$('[data-action=preview]').toggleClass('d-none', !(many_selected && only_file))
205-
$('[data-action=move]').toggleClass('d-none', !(many_selected && only_file))
205+
$('[data-action=move]').toggleClass('d-none', !many_selected)
206206
$('[data-action=download]').toggleClass('d-none', !(one_selected && only_file))
207207
$('[data-action=resize]').toggleClass('d-none', !(one_selected && only_image))
208208
$('[data-action=crop]').toggleClass('d-none', !(one_selected && only_image))
@@ -438,8 +438,11 @@ function preview(items) {
438438
notify(carousel);
439439
}
440440

441-
function move(item) {
442-
notImp();
441+
function move(items) {
442+
performLfmRequest('move', {
443+
items: items.map(function (item) { return item.name; })
444+
})
445+
.done(refreshFoldersAndItems);
443446
}
444447

445448
function getUrlParam(paramName) {

src/Events/FileIsMoving.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Events;
4+
5+
class FileIsMoving
6+
{
7+
private $old_path;
8+
private $new_path;
9+
10+
public function __construct($old_path, $new_path)
11+
{
12+
$this->old_path = $old_path;
13+
$this->new_path = $new_path;
14+
}
15+
16+
/**
17+
* @return string
18+
*/
19+
public function oldPath()
20+
{
21+
return $this->old_path;
22+
}
23+
24+
public function newPath()
25+
{
26+
return $this->new_path;
27+
}
28+
}

src/Events/FileWasMoving.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Events;
4+
5+
class FileWasMoving
6+
{
7+
private $old_path;
8+
private $new_path;
9+
10+
public function __construct($old_path, $new_path)
11+
{
12+
$this->old_path = $old_path;
13+
$this->new_path = $new_path;
14+
}
15+
16+
/**
17+
* @return string
18+
*/
19+
public function oldPath()
20+
{
21+
return $this->old_path;
22+
}
23+
24+
public function newPath()
25+
{
26+
return $this->new_path;
27+
}
28+
}

src/Events/FolderIsMoving.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Events;
4+
5+
class FolderIsMoving
6+
{
7+
private $old_path;
8+
private $new_path;
9+
10+
public function __construct($old_path, $new_path)
11+
{
12+
$this->old_path = $old_path;
13+
$this->new_path = $new_path;
14+
}
15+
16+
/**
17+
* @return string
18+
*/
19+
public function oldPath()
20+
{
21+
return $this->old_path;
22+
}
23+
24+
public function newPath()
25+
{
26+
return $this->new_path;
27+
}
28+
}

src/Events/FolderWasMoving.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Events;
4+
5+
class FolderWasMoving
6+
{
7+
private $old_path;
8+
private $new_path;
9+
10+
public function __construct($old_path, $new_path)
11+
{
12+
$this->old_path = $old_path;
13+
$this->new_path = $new_path;
14+
}
15+
16+
/**
17+
* @return string
18+
*/
19+
public function oldPath()
20+
{
21+
return $this->old_path;
22+
}
23+
24+
public function newPath()
25+
{
26+
return $this->new_path;
27+
}
28+
}

src/Lfm.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ public static function routes()
270270
'as' => 'getItems',
271271
]);
272272

273+
Route::get('/move', [
274+
'uses' => $namespace . 'ItemsController@move',
275+
'as' => 'move',
276+
]);
277+
278+
Route::get('/domove',[
279+
'uses' => $namespace . 'ItemsController@domove',
280+
'as' => 'domove'
281+
]);
282+
273283
// folders
274284
Route::get('/newfolder', [
275285
'uses' => $namespace . 'FolderController@getAddfolder',

src/controllers/ItemsController.php

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?php
22

3-
namespace UniSharp\LaravelFilemanager\Controllers;
3+
namespace UniSharp\LaravelFilemanager\controllers;
4+
5+
use UniSharp\LaravelFilemanager\Events\FileIsMoving;
6+
use UniSharp\LaravelFilemanager\Events\FileWasMoving;
7+
use UniSharp\LaravelFilemanager\Events\FolderIsMoving;
8+
use UniSharp\LaravelFilemanager\Events\FolderWasMoving;
49

510
class ItemsController extends LfmController
611
{
@@ -19,4 +24,56 @@ public function getItems()
1924
'working_dir' => $this->lfm->path('working_dir'),
2025
];
2126
}
27+
28+
public function move()
29+
{
30+
$items = request('items');
31+
$folder_types = array_filter(['user', 'share'], function ($type) {
32+
return $this->helper->allowFolderType($type);
33+
});
34+
return view('laravel-filemanager::move')
35+
->with([
36+
'root_folders' => array_map(function ($type) use ($folder_types) {
37+
$path = $this->lfm->dir($this->helper->getRootFolder($type));
38+
39+
return (object) [
40+
'name' => trans('laravel-filemanager::lfm.title-' . $type),
41+
'url' => $path->path('working_dir'),
42+
'children' => $path->folders(),
43+
'has_next' => ! ($type == end($folder_types)),
44+
];
45+
}, $folder_types),
46+
])
47+
->with('items', $items);
48+
}
49+
50+
public function domove()
51+
{
52+
$target = $this->helper->input('goToFolder');
53+
$items = $this->helper->input('items');
54+
55+
foreach ($items as $item ) {
56+
$old_file = $this->lfm->pretty($item);
57+
$is_directory = $old_file->isDirectory();
58+
59+
if ($old_file->hasThumb()) {
60+
$new_file = $this->lfm->setName($item)->thumb()->dir($target);
61+
if ($is_directory) {
62+
event(new FolderIsMoving($old_file->path(), $new_file->path()));
63+
} else {
64+
event(new FileIsMoving($old_file->path(), $new_file->path()));
65+
}
66+
$this->lfm->setName($item)->thumb()->move($new_file);
67+
}
68+
$new_file = $this->lfm->setName($item)->dir($target);
69+
$this->lfm->setName($item)->move($new_file);
70+
if ($is_directory) {
71+
event(new FolderWasMoving($old_file->path(), $new_file->path()));
72+
} else {
73+
event(new FileWasMoving($old_file->path(), $new_file->path()));
74+
}
75+
};
76+
77+
return parent::$success_response;
78+
}
2279
}

src/views/move.blade.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<ul class="nav nav-pills flex-column">
2+
@foreach($root_folders as $root_folder)
3+
<li class="nav-item">
4+
<a class="nav-link" href="#" data-type="0" onclick="moveToNewFolder(`{{$root_folder->url}}`)">
5+
<i class="fa fa-folder fa-fw"></i> {{ $root_folder->name }}
6+
<input type="hidden" id="goToFolder" name="goToFolder" value="{{ $root_folder->url }}">
7+
<div id="items">
8+
@foreach($items as $i)
9+
<input type="hidden" id="{{ $i }}" name="items[]" value="{{ $i }}">
10+
@endforeach
11+
</div>
12+
</a>
13+
</li>
14+
@foreach($root_folder->children as $directory)
15+
<li class="nav-item sub-item">
16+
<a class="nav-link" href="#" data-type="0" onclick="moveToNewFolder(`{{$directory->url}}`)">
17+
<i class="fa fa-folder fa-fw"></i> {{ $directory->name }}
18+
<input type="hidden" id="goToFolder" name="goToFolder" value="{{ $directory->url }}">
19+
<div id="items">
20+
@foreach($items as $i)
21+
<input type="hidden" id="{{ $i }}" name="items[]" value="{{ $i }}">
22+
@endforeach
23+
</div>
24+
</a>
25+
</li>
26+
@endforeach
27+
@endforeach
28+
</ul>
29+
30+
<script>
31+
function moveToNewFolder($folder) {
32+
$("#notify").modal('hide');
33+
var items =[];
34+
$("#items").find("input").each(function() {items.push(this.id)});
35+
performLfmRequest('domove', {
36+
items: items,
37+
goToFolder: $folder
38+
}).done(refreshFoldersAndItems);
39+
}
40+
</script>

0 commit comments

Comments
 (0)