ldc-boutique-cnc-sable/resources/views/bo/modules/change-order.blade.php
Jérémy Munsch c52b13cc51
feat(order): implement soft delete handling in order changes
Added support for soft-deleted models in ChangeModelOrder and ChangeModelOrderPosition actions.
This allows for proper order adjustments even when models are soft-deleted.
2026-10-29 19:04:46 +01:00

96 lines
3.8 KiB
PHP

@php
/** @var string $route */
/** @var \Illuminate\Database\Eloquent\Model $model */
/** @var bool $first */
/** @var bool $last */
/** @var bool $isFirstPage */
/** @var bool $isLastPage */
if (!isset($first) || !is_bool($first)) {
throw new \InvalidArgumentException('The $first variable must be set and must be a boolean.');
}
if (!isset($last) || !is_bool($last)) {
throw new \InvalidArgumentException('The $last variable must be set and must be a boolean.');
}
if (!isset($isFirstPage) || !is_bool($isFirstPage)) {
throw new \InvalidArgumentException('The $isFirstPage variable must be set and must be a boolean.');
}
if (!isset($isLastPage) || !is_bool($isLastPage)) {
throw new \InvalidArgumentException('The $isLastPage variable must be set and must be a boolean.');
}
// * 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;
$isFirst = $first && $isFirstPage;
$isLast = $last && $isLastPage;
@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 (!$isFirst)
<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 (!$isLast)
<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