From 104aafd0787bb28b24363b1efec05b997da02dae Mon Sep 17 00:00:00 2001 From: Christoph Schweppe Date: Tue, 5 Mar 2019 17:34:53 +0100 Subject: [PATCH] Small mediapicker fixes (#3980) * Small mediapicker fixes * Shw only filename for selected files * Hide crop modal after cropping * Add condition * Improve condition * Improve multi/single decision --- resources/views/media/manager.blade.php | 16 ++++++++++------ src/Http/Controllers/Controller.php | 10 +++++----- src/Http/Controllers/VoyagerMediaController.php | 1 - 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/resources/views/media/manager.blade.php b/resources/views/media/manager.blade.php index 9e9778cba9..9bad6760a1 100644 --- a/resources/views/media/manager.blade.php +++ b/resources/views/media/manager.blade.php @@ -26,7 +26,7 @@
-

@{{ file }}

+

@{{ getFileName(file) }}

@@ -295,7 +295,7 @@

{{ __('voyager::media.destination_folder') }}

@@ -554,7 +554,7 @@ }, addFileToInput: function(file) { if (file.type != 'folder') { - if (this.maxSelectedFiles == 1) { + if (!this.allowMultiSelect) { this.hidden_element.value = file.relative_path; } else { var content = JSON.parse(this.hidden_element.value); @@ -577,7 +577,7 @@ } }, removeFileFromInput: function(path) { - if (this.maxSelectedFiles > 1) { + if (this.allowMultiSelect) { var content = JSON.parse(this.hidden_element.value); if (content.indexOf(path) !== -1) { content.splice(content.indexOf(path), 1); @@ -589,7 +589,7 @@ } }, getSelectedFiles: function() { - if (this.maxSelectedFiles == 1) { + if (!this.allowMultiSelect) { var content = []; if (this.hidden_element.value != '') { content.push(this.hidden_element.value); @@ -698,7 +698,7 @@ if (data.success) { toastr.success(data.message); vm.getFiles(); - $('#crop_modal').modal('hide'); + $('#crop_modal_'+vm._uid).modal('hide'); } else { toastr.error(data.error, "{{ __('voyager::generic.whoopsie') }}"); } @@ -710,6 +710,10 @@ var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; }, + getFileName: function(name) { + var name = name.split('/'); + return name[name.length -1]; + }, imgIcon: function(path) { path = path.replace(/\\/g,"/"); return 'background-size: cover; background-image: url("' + path + '"); background-repeat:no-repeat; background-position:center center;display:inline-block; width:100%; height:100%;'; diff --git a/src/Http/Controllers/Controller.php b/src/Http/Controllers/Controller.php index 0deee24bed..368afdb796 100644 --- a/src/Http/Controllers/Controller.php +++ b/src/Http/Controllers/Controller.php @@ -141,11 +141,11 @@ public function insertUpdateData($request, $slug, $rows, $data) $data->{$row->field} = str_replace($uuid, $data->getKey(), $data->{$row->field}); }); $data->save(); - - Storage::disk(config('voyager.storage.disk'))->move($old_path, $new_path); - Storage::disk(config('voyager.storage.disk'))->deleteDirectory($folder_path); - - $request->session()->forget([$slug.'_path', $slug.'_uuid']); + if ($old_path != $new_path && !Storage::disk(config('voyager.storage.disk'))->exists($new_path)) { + $request->session()->forget([$slug.'_path', $slug.'_uuid']); + Storage::disk(config('voyager.storage.disk'))->move($old_path, $new_path); + Storage::disk(config('voyager.storage.disk'))->deleteDirectory($folder_path); + } } return $data; diff --git a/src/Http/Controllers/VoyagerMediaController.php b/src/Http/Controllers/VoyagerMediaController.php index d52221e41d..35fcbfd543 100644 --- a/src/Http/Controllers/VoyagerMediaController.php +++ b/src/Http/Controllers/VoyagerMediaController.php @@ -217,7 +217,6 @@ public function upload(Request $request) return Str::random($random[1]); }, $name); } - $name .= '.'.$extension; } $file = $request->file->storeAs($request->upload_path, $name.'.'.$extension, $this->filesystem);