Skip to content

Commit

Permalink
Bookmarks as H1 and title
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed May 13, 2024
1 parent 738b2ea commit 04374b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,14 @@ 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->get('bookmark')) {
$bookmark = Bookmark::where('campaign_id', $campaign->id)->where('id', $request->get('bookmark'))->first();
$this->datagrid->bookmark($bookmark->id);
$data['titleKey'] = $bookmark->name;
}
}

if (method_exists($model, 'getParentKeyName')) {
$data['nestable'] = $nested;
}
Expand Down
10 changes: 9 additions & 1 deletion app/Renderers/DatagridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DatagridRenderer

protected string $hidden = ' hidden lg:table-cell';
protected array $columns = [];
protected null|int $bookmark = null;

protected LengthAwarePaginator|Collection|array $data = [];

Expand Down Expand Up @@ -59,6 +60,12 @@ public function options(array $options): self
return $this;
}

public function bookmark(int $bookmark): self
{
$this->bookmark = $bookmark;
return $this;
}

public function models(Collection|LengthAwarePaginator $models): self
{
$this->models = $models;
Expand Down Expand Up @@ -246,7 +253,8 @@ private function route(string $field = null, string $label = null)
$routeOptions = [
'campaign' => $this->campaign,
'order' => $field ,
'page' => request()->get('page')
'page' => request()->get('page'),
'bookmark' => $this->bookmark
];
if (request()->get('_from', false) == 'quicklink') {
$routeOptions['_from'] = 'quicklink';
Expand Down
10 changes: 5 additions & 5 deletions resources/views/layouts/datagrid/_togglers.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="dropdown-menu hidden" role="menu" id="toggler-submenu">
@foreach ($model->datagridSortableColumns() as $field => $translation)
@php
$options = [$campaign, 'order' => $field];
$options = [$campaign, 'order' => $field, 'bookmark' => request()->get('bookmark')];
$icon = null;
if (request()->get('order') === $field) {
if (request()->get('desc') === '1') {
Expand All @@ -29,12 +29,12 @@

@if (empty($forceMode))
@if (!isset($mode) || $mode === 'grid')
<a class="btn2 " href="{{ route($name . '.' . $route, [$campaign, 'm' => 'table']) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.table') }}">
<a class="btn2 " href="{{ route($name . '.' . $route, [$campaign, 'm' => 'table', 'bookmark' => request()->get('bookmark')]) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.table') }}">
<x-icon class="fa-solid fa-list-ul" />
<span class="sr-only">{{ __('datagrids.modes.table') }}</span>
</a>
@else
<a class="btn2" href="{{ route($name . '.' . $route, [$campaign, 'm' => 'grid']) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.grid') }}">
<a class="btn2" href="{{ route($name . '.' . $route, [$campaign, 'm' => 'grid', 'bookmark' => request()->get('bookmark')]) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.grid') }}">
<x-icon class="fa-solid fa-grid" />
<span class="sr-only">{{ __('datagrids.modes.grid') }}</span>
</a>
Expand All @@ -43,12 +43,12 @@

@if (isset($nestable) && empty($forceMode))
@if ($nestable)
<a class="btn2" href="{{ route($name . '.' . $route, [$campaign, 'n' => false]) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.flatten') }}">
<a class="btn2" href="{{ route($name . '.' . $route, [$campaign, 'n' => false, 'bookmark' => request()->get('bookmark')]) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.flatten') }}">
<x-icon class="fa-solid fa-boxes-stacked" />
<span class="sr-only">{{ __('datagrids.modes.flatten') }}</span>
</a>
@else
<a class="btn2" href="{{ route($name . '.' . $route, [$campaign, 'n' => true]) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.nested') }}">
<a class="btn2" href="{{ route($name . '.' . $route, [$campaign, 'n' => true, 'bookmark' => request()->get('bookmark')]) }}" data-toggle="tooltip" data-title="{{ __('datagrids.modes.nested') }}">
<x-icon class="fa-solid fa-layer-group" />
<span class="sr-only">{{ __('datagrids.modes.nested') }}</span>
</a>
Expand Down

0 comments on commit 04374b4

Please sign in to comment.