Skip to content

Commit

Permalink
Autoselect uploaded asset in selector (#3604)
Browse files Browse the repository at this point in the history
* Autoselect uploaded asset in selector

* Sort only when requested
  • Loading branch information
arthurperton authored Apr 28, 2021
1 parent be5cf66 commit e8d1696
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
15 changes: 12 additions & 3 deletions resources/js/components/assets/Browser/Browser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ export default {
selectedAssets: Array,
maxFiles: Number,
initialEditingAssetId: String,
autoselectUploads: Boolean,
},
data() {
return {
columns: [
{ label: __('File'), field: 'basename', visible: true },
{ label: __('Size'), field: 'size', value: 'size_formatted', visible: true },
{ label: __('Last Modified'), field: 'last_modified', value: 'last_modified_relative', visible: true },
{ label: __('File'), field: 'basename', visible: true, sortable: true },
{ label: __('Size'), field: 'size', value: 'size_formatted', visible: true, sortable: true },
{ label: __('Last Modified'), field: 'last_modified', value: 'last_modified_relative', visible: true, sortable: true },
],
containers: [],
container: {},
Expand Down Expand Up @@ -523,6 +524,14 @@ export default {
},
uploadCompleted(asset) {
if (this.autoselectUploads) {
this.sortColumn = 'last_modified';
this.sortDirection = 'desc';
this.selectedAssets.push(asset.id);
this.$emit('selections-updated', this.selectedAssets);
}
this.loadAssets();
this.$toast.success(__(':file uploaded', { file: asset.basename }));
},
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/assets/Selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:restrict-container-navigation="restrictContainerNavigation"
:restrict-folder-navigation="restrictFolderNavigation"
:max-files="maxFiles"
:autoselect-uploads="true"
@selections-updated="selectionsUpdated"
@asset-doubleclicked="select">

Expand Down
8 changes: 7 additions & 1 deletion src/Http/Controllers/CP/Assets/BrowserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ public function folder(Request $request, $container, $path = '/')

$folder = $container->assetFolder($path);

$assets = $folder->queryAssets()->paginate(30);
$query = $folder->queryAssets();

if ($request->sort) {
$query->orderBy($request->sort, $request->order ?? 'asc');
}

$assets = $query->paginate(30);

return (new FolderAssetsCollection($assets))->folder($folder);
}
Expand Down

0 comments on commit e8d1696

Please sign in to comment.