Using new folder mover and improving response message in case of some failures

parent 9ff63d42
...@@ -54,8 +54,10 @@ ...@@ -54,8 +54,10 @@
.then((response) => { .then((response) => {
console.log(response); console.log(response);
this.loading = false; this.loading = false;
const type = response.errors === true ? 'warning' : 'success';
this.$message({ this.$message({
type: 'success', type,
message: response.message, message: response.message,
}); });
this.dialogFormVisible = false; this.dialogFormVisible = false;
......
...@@ -7,6 +7,7 @@ use Modules\Media\Entities\File; ...@@ -7,6 +7,7 @@ use Modules\Media\Entities\File;
use Modules\Media\Http\Requests\MoveMediaRequest; use Modules\Media\Http\Requests\MoveMediaRequest;
use Modules\Media\Repositories\FileRepository; use Modules\Media\Repositories\FileRepository;
use Modules\Media\Repositories\FolderRepository; use Modules\Media\Repositories\FolderRepository;
use Modules\Media\Services\FolderMover;
class MoveMediaController extends Controller class MoveMediaController extends Controller
{ {
...@@ -18,11 +19,16 @@ class MoveMediaController extends Controller ...@@ -18,11 +19,16 @@ class MoveMediaController extends Controller
* @var FolderRepository * @var FolderRepository
*/ */
private $folder; 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->file = $file;
$this->folder = $folder; $this->folder = $folder;
$this->folderMover = $folderMover;
} }
public function __invoke(MoveMediaRequest $request) public function __invoke(MoveMediaRequest $request)
...@@ -32,6 +38,7 @@ class MoveMediaController extends Controller ...@@ -32,6 +38,7 @@ class MoveMediaController extends Controller
$destination = $this->makeRootFolder(); $destination = $this->makeRootFolder();
} }
$failedMoves = 0;
foreach ($request->get('files') as $file) { foreach ($request->get('files') as $file) {
$file = $this->file->find($file['id']); $file = $this->file->find($file['id']);
...@@ -39,13 +46,15 @@ class MoveMediaController extends Controller ...@@ -39,13 +46,15 @@ class MoveMediaController extends Controller
$this->file->move($file, $destination); $this->file->move($file, $destination);
} }
if ($file->is_folder === true) { if ($file->is_folder === true) {
$this->folder->move($file, $destination); if ($this->folderMover->move($file, $destination) === false) {
$failedMoves++;
}
} }
} }
return response()->json([ return response()->json([
'errors' => false, 'errors' => $failedMoves > 0,
'message' => 'Files moved successfully', 'message' => $failedMoves > 0 ? 'Some files were not moved' : 'Files moved successfully',
'folder_id' => $destination->id, 'folder_id' => $destination->id,
]); ]);
} }
......
...@@ -104227,8 +104227,10 @@ exports.default = { ...@@ -104227,8 +104227,10 @@ exports.default = {
this.form.post(route('api.media.media.move')).then(function (response) { this.form.post(route('api.media.media.move')).then(function (response) {
console.log(response); console.log(response);
_this.loading = false; _this.loading = false;
var type = response.errors === true ? 'warning' : 'success';
_this.$message({ _this.$message({
type: 'success', type: type,
message: response.message message: response.message
}); });
_this.dialogFormVisible = false; _this.dialogFormVisible = false;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment