Add functionality to change the order of models in the product list. This includes new actions, requests, and UI components for user interaction.
75 lines
3.1 KiB
PHP
75 lines
3.1 KiB
PHP
@php
|
|
/** @var string $route */
|
|
/** @var \Illuminate\Database\Eloquent\Model $model */
|
|
/** @var bool $first */
|
|
/** @var bool $last */
|
|
|
|
// * Route vars
|
|
$routeName = request()->route()?->getName() ?? 'noroute';
|
|
|
|
// * Request vars
|
|
$currentSortCol = session()->get("{$routeName}.sort_col");
|
|
$currentSortWay = session()->get("{$routeName}.sort_way");
|
|
|
|
$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 !== 'order') || ($currentSortCol === 'order' && $currentSortWay === 'desc');
|
|
$showReset = !empty($searchQuery) || $hasCustomSort;
|
|
@endphp
|
|
@if (!$noOrder)
|
|
<td class="text-nowrap align-middle">
|
|
<div class="d-flex align-items-center justify-content-center mb-2 gap-1">
|
|
<span class="fw-bold text-muted small me-1">#{{ $model->order }}</span>
|
|
@if (isset($selectRoute))
|
|
<div class="dropdown d-inline-block ms-1">
|
|
<button class="btn btn-sm btn-outline-secondary px-1 py-0" data-bs-toggle="dropdown" type="button"
|
|
title="{{ __('Choose position') }}" aria-expanded="false">
|
|
<i class="fa-solid fa-list-ol"></i>
|
|
</button>
|
|
<div class="dropdown-menu dropdown-menu-end p-3 shadow" style="min-width: 180px;">
|
|
<form action="{{ route($selectRoute, $model) }}" method="POST">
|
|
@csrf
|
|
@method('PATCH')
|
|
<div class="mb-2">
|
|
<label class="form-label small fw-bold mb-1" for="order-pos-{{ $model->id }}">{{ __('New position') }}</label>
|
|
<input class="form-control form-control-sm" id="order-pos-{{ $model->id }}" name="order" type="number"
|
|
value="{{ $model->order }}" min="1" required>
|
|
</div>
|
|
<button class="btn btn-sm btn-primary w-100" type="submit">{{ __('Move') }}</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
<div class="d-flex align-items-center justify-content-center gap-1">
|
|
<form class="d-inline" method="POST">
|
|
@csrf
|
|
@method('PATCH')
|
|
<input name="action" type="hidden" value="down">
|
|
@if (!$first)
|
|
<button class="btn btn-link text-decoration-none p-0" formaction="{{ route($route, [$model, 'action' => 'up']) }}" type="submit"
|
|
title="{{ __('Move up') }}">
|
|
<i class="icon-size fas fa-arrow-alt-circle-up fa-2x" name="down_up"></i>
|
|
</button>
|
|
@endif
|
|
@if (!$last)
|
|
<button class="btn btn-link text-decoration-none p-0" formaction="{{ route($route, [$model, 'action' => 'down']) }}"
|
|
type="submit" title="{{ __('Move down') }}">
|
|
<i class="icon-size fas fa-arrow-alt-circle-down fa-2x" name="down_arrow"></i>
|
|
</button>
|
|
@endif
|
|
</form>
|
|
|
|
</div>
|
|
</td>
|
|
@endif
|