diff --git a/app/Http/Controllers/CrudController.php b/app/Http/Controllers/CrudController.php index 49ae5c0773..6f7b37a3d8 100644 --- a/app/Http/Controllers/CrudController.php +++ b/app/Http/Controllers/CrudController.php @@ -251,7 +251,22 @@ public function crudIndex(Request $request) if (empty($data['titleKey'])) { $data['titleKey'] = Module::plural($entityTypeId, __('entities.' . $langKey)); } + // If its a bookmark, override everything else + if ($request->has('bookmark')) { + $bookmark = Bookmark::where('id', $request->get('bookmark'))->first(); + if ($bookmark) { + $this->datagrid->bookmark($bookmark); + $data['bookmark'] = $bookmark; + $data['titleKey'] = $bookmark->name; + } + } + + if ($request->has('order')) { + $data['order'] = $request->get('order'); + $data['desc'] = $request->get('desc'); + } } + if (method_exists($model, 'getParentKeyName')) { $data['nestable'] = $nested; } diff --git a/app/Renderers/DatagridRenderer.php b/app/Renderers/DatagridRenderer.php index 0ed39509cc..003324fecd 100644 --- a/app/Renderers/DatagridRenderer.php +++ b/app/Renderers/DatagridRenderer.php @@ -5,6 +5,7 @@ use App\Facades\Avatar; use App\Facades\Module; use App\Facades\UserCache; +use App\Models\Bookmark; use App\Models\Entity; use App\Models\Journal; use App\Models\Location; @@ -25,6 +26,7 @@ class DatagridRenderer protected string $hidden = ' hidden lg:table-cell'; protected array $columns = []; + protected Bookmark $bookmark; protected LengthAwarePaginator|Collection|array $data = []; @@ -59,6 +61,12 @@ public function options(array $options): self return $this; } + public function bookmark(Bookmark $bookmark): self + { + $this->bookmark = $bookmark; + return $this; + } + public function models(Collection|LengthAwarePaginator $models): self { $this->models = $models; @@ -246,8 +254,13 @@ private function route(string $field = null, string $label = null) $routeOptions = [ 'campaign' => $this->campaign, 'order' => $field , - 'page' => request()->get('page') + 'page' => request()->get('page'), ]; + + if (isset($this->bookmark)) { + $routeOptions['bookmark'] = $this->bookmark; + } + if (request()->get('_from', false) == 'quicklink') { $routeOptions['_from'] = 'quicklink'; } diff --git a/resources/views/layouts/datagrid/_togglers.blade.php b/resources/views/layouts/datagrid/_togglers.blade.php index d2e844cd89..90259b9f01 100644 --- a/resources/views/layouts/datagrid/_togglers.blade.php +++ b/resources/views/layouts/datagrid/_togglers.blade.php @@ -8,9 +8,12 @@ @foreach ($model->datagridSortableColumns() as $field => $translation) @php $options = [$campaign, 'order' => $field]; + if (isset($bookmark)) { + $options['bookmark'] = $bookmark; + } $icon = null; - if (request()->get('order') === $field) { - if (request()->get('desc') === '1') { + if (isset($order) && $order === $field) { + if (isset($desc) && $desc === 1) { $icon = ''; } else { $options['desc'] = 1; @@ -18,7 +21,7 @@ } } @endphp - + {!! $icon !!} {{ $translation }} @@ -29,12 +32,12 @@ @if (empty($forceMode)) @if (!isset($mode) || $mode === 'grid') - + {{ __('datagrids.modes.table') }} @else - + {{ __('datagrids.modes.grid') }} @@ -43,12 +46,12 @@ @if (isset($nestable) && empty($forceMode)) @if ($nestable) - + {{ __('datagrids.modes.flatten') }} @else - + {{ __('datagrids.modes.nested') }}