Skip to content

Commit

Permalink
Small mediapicker fixes (#3980)
Browse files Browse the repository at this point in the history
* Small mediapicker fixes

* Shw only filename for selected files

* Hide crop modal after cropping

* Add condition

* Improve condition

* Improve multi/single decision
  • Loading branch information
emptynick authored Mar 5, 2019
1 parent 047b2eb commit 104aafd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
16 changes: 10 additions & 6 deletions resources/views/media/manager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
<div class="details">
<div class="folder">
<h4>@{{ file }}</h4>
<h4>@{{ getFileName(file) }}</h4>
</div>
</div>
<i class="voyager-x dd-nodrag" v-on:click="removeFileFromInput(file)"></i>
Expand Down Expand Up @@ -295,7 +295,7 @@
<h4>{{ __('voyager::media.destination_folder') }}</h4>
<select class="form-control">
<option v-if="current_folder != basePath && showFolders" value="/../">../</option>
<option v-for="file in files" v-if="file.type == 'folder' && !selected_files.includes(file)" :value="file.name">@{{ file.name }}</option>
<option v-for="file in files" v-if="file.type == 'folder' && !selected_files.includes(file)" :value="current_folder+'/'+file.name">@{{ file.name }}</option>
</select>
</div>

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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') }}");
}
Expand All @@ -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%;';
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Http/Controllers/VoyagerMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 104aafd

Please sign in to comment.