Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset browser pagination size changer #3957

Merged
merged 10 commits into from
Jul 6, 2021
10 changes: 9 additions & 1 deletion resources/js/components/assets/Browser/Browser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
class="mt-3"
:resource-meta="meta"
@page-selected="page = $event"
@per-page-changed="changePerPage"
:per-page="perPage"
/>

</div>
Expand Down Expand Up @@ -297,7 +299,7 @@ export default {
creatingFolder: false,
uploads: [],
page: 1,
perPage: 30, // TODO: Should come from the controller, or a config.
perPage: localStorage.getItem('assets-per-page') ?? 25,
meta: {},
sortColumn: 'basename',
sortDirection: 'asc',
Expand Down Expand Up @@ -505,6 +507,12 @@ export default {
this.editedAssetId = id;
},

changePerPage(size) {
localStorage.setItem('assets-per-page', size)
this.perPage = parseInt(size);
this.loadAssets();
},

closeAssetEditor() {
this.editedAssetId = null;
},
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/data-list/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default {

perPageOptions() {
let defaultPaginationSize = Statamic.$config.get('paginationSize');
let defaultOptions = [10, 25, 50, 100].filter(size => size !== defaultPaginationSize);
let defaultOptions = [10, 25, 50, 100, 500].filter(size => size !== defaultPaginationSize);
let options = this.normalizeInputOptions(defaultOptions);

options.push({
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/CP/Assets/BrowserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function folder(Request $request, $container, $path = '/')
$query->orderBy($request->sort, $request->order ?? 'asc');
}

$assets = $query->paginate(30);
$assets = $query->paginate(request('perPage', config('statamic.cp.pagination_size')));
jackmcdade marked this conversation as resolved.
Show resolved Hide resolved

return (new FolderAssetsCollection($assets))->folder($folder);
}
Expand All @@ -90,7 +90,7 @@ public function search(Request $request, $container)
? $container->searchIndex()->ensureExists()->search($request->search)
: $container->queryAssets()->where('path', 'like', '%'.$request->search.'%');

$assets = $query->paginate(30);
$assets = $query->paginate(request('perPage', config('statamic.cp.pagination_size')));
jackmcdade marked this conversation as resolved.
Show resolved Hide resolved

return new SearchedAssetsCollection($assets);
}
Expand Down