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

Bookmarks as H1 and title #874

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Expand Down
15 changes: 14 additions & 1 deletion app/Renderers/DatagridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@ class DatagridRenderer

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

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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
Expand Down
17 changes: 10 additions & 7 deletions resources/views/layouts/datagrid/_togglers.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
@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 = '<i class="fa-solid fa-arrow-down-a-z !mr-0" aria-hidden="true"></i>';
} else {
$options['desc'] = 1;
$icon = '<i class="fa-solid fa-arrow-up-a-z !mr-0" aria-hidden="true"></i>';
}
}
@endphp
<x-dropdowns.item :link="route($name . '.' . $route, $options)" :css="request()->get('order') === $field ? 'font-bold' : null">
<x-dropdowns.item :link="route($name . '.' . $route, $options)" :css="isset($order) && $order === $field ? 'font-bold' : null">
{!! $icon !!}
{{ $translation }}
</x-dropdowns.item>
Expand All @@ -29,12 +32,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' => isset($bookmark) ? $bookmark : null]) }}" 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' => isset($bookmark) ? $bookmark : null]) }}" 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 +46,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' => isset($bookmark) ? $bookmark : null]) }}" 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' => isset($bookmark) ? $bookmark : null]) }}" 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
Loading