Added default sorting by date in descending order for order queries. Updated related views and tests to reflect this change.
94 lines
3.3 KiB
PHP
94 lines
3.3 KiB
PHP
@php
|
|
// * Route vars
|
|
$routeName = request()->route()?->getName() ?? 'noroute';
|
|
|
|
// * Default sort vars
|
|
$defaultSortCol = $defaultSortCol ?? 'order';
|
|
$defaultSortWay = $defaultSortWay ?? 'asc';
|
|
$defaultSortWayStr = $defaultSortWay instanceof \SortDirection
|
|
? ($defaultSortWay === \SortDirection::Descending ? 'desc' : 'asc')
|
|
: (string) $defaultSortWay;
|
|
|
|
// * Request vars
|
|
$currentSortCol = session()->get("{$routeName}.sort_col", $defaultSortCol);
|
|
$currentSortWay = session()->get("{$routeName}.sort_way", $defaultSortWayStr);
|
|
|
|
$searchQuery = request()->input('search');
|
|
|
|
// * Vue vars
|
|
$noOrder = $noOrder ?? false;
|
|
$ignore = isset($ignore) && is_array($ignore) ? $ignore : [];
|
|
|
|
// * Hide order column
|
|
$sortColIsOrder = $currentSortCol === 'order';
|
|
$noOrder = $noOrder || (!$sortColIsOrder && $currentSortCol) || !empty($searchQuery);
|
|
View::share('noOrder', $noOrder);
|
|
|
|
// * Reset button
|
|
$hasCustomSort = ($currentSortCol && $currentSortCol !== $defaultSortCol) || ($currentSortCol === $defaultSortCol && $currentSortWay !== $defaultSortWayStr);
|
|
$showReset = !empty($searchQuery) || $hasCustomSort;
|
|
@endphp
|
|
|
|
<tr>
|
|
@foreach ($cols as $col => $colname)
|
|
@php
|
|
$iArgs = ['sort_col' => $col];
|
|
if ($searchQuery) {
|
|
$iArgs['search'] = $searchQuery;
|
|
}
|
|
|
|
$isCurrentCol = $currentSortCol === $col;
|
|
$mobileHiddenClass =
|
|
isset($mobileHide) && is_array($mobileHide) && in_array($col, $mobileHide) ? 'd-none d-md-table-cell text-center' : '';
|
|
@endphp
|
|
|
|
{{-- NO Sort for order column & ignored columns --}}
|
|
@if ($col === 'order' || in_array($col, $ignore))
|
|
@if ($noOrder && $col === 'order')
|
|
@continue
|
|
@endif
|
|
<th class="{{ $mobileHiddenClass }}" scope="col">
|
|
<span class="text-nowrap">{{ $colname }}</span>
|
|
</th>
|
|
@continue
|
|
@endif
|
|
|
|
{{-- Sortable Columns --}}
|
|
<th class="{{ $mobileHiddenClass }}" scope="col">
|
|
<span class="text-nowrap">
|
|
{{ $colname }}
|
|
|
|
@if (!$isCurrentCol || $currentSortWay === 'desc')
|
|
<a class="col_sort text-info small asc" data-bs-toggle="tooltip"
|
|
href="{{ request()->fullUrlWithQuery(array_merge($iArgs, ['sort_way' => 'asc', 'rst' => null])) }}"
|
|
title="{{ __('Sort :name in ascending order', ['name' => Str::lower($colname)]) }}">
|
|
↓
|
|
</a>
|
|
@endif
|
|
|
|
@if (!$isCurrentCol || $currentSortWay === 'asc')
|
|
<a class="col_sort text-info small desc" data-bs-toggle="tooltip"
|
|
href="{{ request()->fullUrlWithQuery(array_merge($iArgs, ['sort_way' => 'desc', 'rst' => null])) }}"
|
|
title="{{ __('Sort :name in descending order', ['name' => Str::lower($colname)]) }}">
|
|
↑
|
|
</a>
|
|
@endif
|
|
</span>
|
|
</th>
|
|
@endforeach
|
|
|
|
{{-- Buttons Col --}}
|
|
<th scope="col">
|
|
@if ($showReset)
|
|
<a class="btn btn-sm btn-danger" data-bs-toggle="tooltip"
|
|
href="{{ request()->fullUrlWithQuery(['sort_col' => null, 'sort_way' => null, 'rst' => true, 'search' => null]) }}"
|
|
title="{{ __('Clear sorting') }}">
|
|
<i class="fa fa-eraser"></i>
|
|
</a>
|
|
@else
|
|
<span data-bs-toggle="tooltip" data-bs-placement="top" title="{{ __('Here, the arrows are used to sort and not to filter') }}">
|
|
<i class="fas fa-question-circle"></i>
|
|
</span>
|
|
@endif
|
|
</th>
|
|
</tr>
|