add crud key_number

This commit is contained in:
Nicolas Demangeat 2024-03-29 16:19:12 +01:00
parent 439c227d10
commit 8b8f6963cf
5 changed files with 32 additions and 7 deletions

View file

@ -83,4 +83,15 @@ class KeyNumberPolicy
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
/**
* Determine whether the user can change the order of the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function changeOrder(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
}

View file

@ -2,7 +2,7 @@
@can('changeOrder', $model)
<div class="d-flex justify-content-center align-items-center">
<form @class(['invisible' => $loop->first and $models->onFirstPage()])
action="{{ route('bo.' . $routeName . '.change-order', [str($routeName)->singular() => $model, 'direction' => 'up']) }}"
action="{{ route('bo.' . $routeName . '.change-order', [str($routeName)->singular()->value => $model, 'direction' => 'up']) }}"
method="POST">
@csrf
@method('PATCH')
@ -17,7 +17,7 @@
'invisible' =>
$loop->last and $models->currentPage() === $models->lastPage(),
])
action="{{ route('bo.' . $routeName . '.change-order', [str($routeName)->singular() => $model, 'direction' => 'down']) }}"
action="{{ route('bo.' . $routeName . '.change-order', [str($routeName)->singular()->value => $model, 'direction' => 'down']) }}"
method="POST">
@csrf
@method('PATCH')

View file

@ -3,9 +3,10 @@
<thead>
@include('bo.modules.table-col-sorter', [
'cols' => [
'text' => str(__('validation.attributes.text'))->ucfirst(),
'picto' => str(__('validation.attributes.image'))->ucfirst(),
'published' => str(__('validation.custom.published'))->ucfirst(),
'text' => str(__('validation.attributes.text'))->ucfirst(),
'picto' => str(__('validation.attributes.image'))->ucfirst(),
'published' => str(__('validation.custom.published'))->ucfirst(),
'order' => str(__('validation.custom.order'))->ucfirst(),
'updated_at' => str(__('validation.attributes.updated_at'))->ucfirst(),
],
])
@ -20,8 +21,18 @@
</td>
@include('bo.modules.change-published-status', [
'routeName' => 'key_numbers',
'model' => $keyNumberModel,
'model' => $keyNumberModel,
])
@php
$routeName = request()->route()->getName();
@endphp
@if (empty(request()->search) && Session::get("$routeName.sort_col") === 'order')
@include('bo.modules.change-model-order', [
'routeName' => 'key_numbers',
'model' => $keyNumberModel,
'models' => $keyNumberModels,
])
@endif
<td class="text-center align-middle">
<span class="badge bg-secondary">{{ $keyNumberModel->updated_at->isoFormat('LLLL') }}</span>
</td>

View file

@ -61,7 +61,7 @@
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.source'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.source'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $keyNumberModel->source }}
</td>

View file

@ -62,6 +62,9 @@ Route::prefix('bo')
Route::patch('/key_numbers/{key_number}/change-published', [
KeyNumberController::class, 'changePublished'
])->name('key_numbers.change-published');
Route::patch('/key_numbers/{key_number}/change-order/{direction}', [
KeyNumberController::class, 'changeOrder'
])->where('direction', 'up|down')->name('key_numbers.change-order');
Route::get('/key_numbers/{key_number}/duplicate', [
KeyNumberController::class, 'duplicate'
])->name('key_numbers.duplicate');