Skip to content

Commit

Permalink
Using new folder mover and improving response message in case of some…
Browse files Browse the repository at this point in the history
… failures
  • Loading branch information
nWidart committed Oct 10, 2017
1 parent 9ff63d4 commit 5e16955
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Modules/Media/Assets/js/components/MoveMediaDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
.then((response) => {
console.log(response);
this.loading = false;
const type = response.errors === true ? 'warning' : 'success';
this.$message({
type: 'success',
type,
message: response.message,
});
this.dialogFormVisible = false;
Expand Down
17 changes: 13 additions & 4 deletions Modules/Media/Http/Controllers/Api/MoveMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Modules\Media\Http\Requests\MoveMediaRequest;
use Modules\Media\Repositories\FileRepository;
use Modules\Media\Repositories\FolderRepository;
use Modules\Media\Services\FolderMover;

class MoveMediaController extends Controller
{
Expand All @@ -18,11 +19,16 @@ class MoveMediaController extends Controller
* @var FolderRepository
*/
private $folder;
/**
* @var FolderMover
*/
private $folderMover;

public function __construct(FileRepository $file, FolderRepository $folder)
public function __construct(FileRepository $file, FolderRepository $folder, FolderMover $folderMover)
{
$this->file = $file;
$this->folder = $folder;
$this->folderMover = $folderMover;
}

public function __invoke(MoveMediaRequest $request)
Expand All @@ -32,20 +38,23 @@ public function __invoke(MoveMediaRequest $request)
$destination = $this->makeRootFolder();
}

$failedMoves = 0;
foreach ($request->get('files') as $file) {
$file = $this->file->find($file['id']);

if ($file->is_folder === false) {
$this->file->move($file, $destination);
}
if ($file->is_folder === true) {
$this->folder->move($file, $destination);
if ($this->folderMover->move($file, $destination) === false) {
$failedMoves++;
}
}
}

return response()->json([
'errors' => false,
'message' => 'Files moved successfully',
'errors' => $failedMoves > 0,
'message' => $failedMoves > 0 ? 'Some files were not moved' : 'Files moved successfully',
'folder_id' => $destination->id,
]);
}
Expand Down
4 changes: 3 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -104227,8 +104227,10 @@ exports.default = {
this.form.post(route('api.media.media.move')).then(function (response) {
console.log(response);
_this.loading = false;
var type = response.errors === true ? 'warning' : 'success';

_this.$message({
type: 'success',
type: type,
message: response.message
});
_this.dialogFormVisible = false;
Expand Down

0 comments on commit 5e16955

Please sign in to comment.