add news status column on index page - issue #32

This commit is contained in:
Alexis Gousseau 2023-08-30 12:25:37 +02:00
parent 295e4eb2e1
commit af56adc577
7 changed files with 89 additions and 82 deletions

View file

@ -34,14 +34,13 @@ class NewsController extends Controller
$request->search, $request->search,
null, null,
'seo_title', 'seo_title',
'name',
'title', 'title',
'subtitle', 'subtitle',
); );
} }
$this->sortQuery($news); $this->sortQuery($news);
$searchFields = trans('Name'); $searchFields = trans('SEO title, Title, subtitle');
$newsListModels = $news->paginate(10); $newsListModels = $news->paginate(10);

View file

@ -103,9 +103,6 @@ class News extends Model implements SeoInterface
$model->makeStatusSense(); $model->makeStatusSense();
self::setOrder($model); self::setOrder($model);
}); });
static::created(function (self $model) {
$model->flashMessages();
});
static::updating(function (self $model) { static::updating(function (self $model) {
// * ASSERTIONS // * ASSERTIONS
static::assertTitleIsUnique($model->title); static::assertTitleIsUnique($model->title);
@ -121,7 +118,6 @@ class News extends Model implements SeoInterface
$model->content, $model->content,
ToolboxHelper::getOriginal($model, 'content') ToolboxHelper::getOriginal($model, 'content')
); );
$model->flashMessages();
}); });
static::deleted(function (self $model) { static::deleted(function (self $model) {
FileStorageHelper::removeModelFilesOfHtml($model->content); FileStorageHelper::removeModelFilesOfHtml($model->content);
@ -217,44 +213,6 @@ class News extends Model implements SeoInterface
return false; return false;
} }
/**
* Flash boolean attributes modification messages
*
* @param boolean $old Ignore old attribute comparison.
* @return void
*/
public function flashMessages(bool $old = true)
{
$booleanChecks = [
'status' => [
'bo.info' => trans(':model est maintenant publié', [
'model' => Str::singular(trans('models.classes.products'))
]),
'bo.warning' => trans(':model est maintenant dépublié', [
'model' => Str::singular(trans('models.classes.products'))
])
]
];
$sessionMessages = [];
// * Merge messages
foreach ($booleanChecks as $attribute => $booleanCheck) {
if ($old and $this->getOriginal($attribute) == $this->{$attribute}) {
continue;
}
/** @var string $flashType */
$flashType = \array_keys($booleanCheck)[$this->{$attribute} ? 0 : 1];
if (!\array_key_exists($flashType, $sessionMessages)) {
$sessionMessages[$flashType] = [];
}
$sessionMessages[$flashType][] = $booleanCheck[$flashType];
}
foreach ($sessionMessages as $flashType => $messages) {
session()->flash($flashType, collect($messages)->implode("\n"));
}
}
/** /**
* Set the slug. * Set the slug.
* *

View file

@ -24,7 +24,7 @@
</p> </p>
<p class="card-text"> <p class="card-text">
{{ __('For any problems or desired evolutions, please contact us via our tool : ') }} {{ __('For any problems or desired evolutions, please contact us via our tool : ') }}
<a href="https://supportweb.ldc.fr" target="blank">supportweb.ldc.fr</a> <a href="https://support.uwil.fr" target="blank">support.uwil.fr</a>
</p> </p>
</div> </div>
</div> </div>

View file

@ -1,50 +1,79 @@
<div class="table-responsive"> <div class="table-responsive">
<table class="table fix-action m-0"> <table class="table fix-action m-0">
<thead> <thead>
@php @include('bo.modules.table-col-sorter', [
$cols = [ 'cols' => [
'title' => __('validation.attributes.title'), 'title' => __('validation.attributes.title'),
'subtitle' => __('validation.attributes.subtitle'), 'subtitle' => __('validation.attributes.subtitle'),
'order' => __('validation.attributes.order'), 'status' => __('validation.attributes.visibility'),
'updated_at' => __('validation.attributes.updated_at')]; 'order' => __('validation.attributes.order'),
@endphp 'updated_at' => __('validation.attributes.updated_at')
@include('bo.modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => ['status']]) ],
'mobileHide' => ['status']
])
</thead> </thead>
<tbody> <tbody>
@if($newsListModels->count()) @if($newsListModels->count())
@foreach ($newsListModels as $newsModels) @foreach ($newsListModels as $newsModel)
<tr> <tr>
<td class="align-middle">{{ $newsModels->title }}</td> <td class="align-middle">{{ $newsModel->title }}</td>
<td class="align-middle">{{ $newsModels->subtitle }}</td> <td class="align-middle">{{ $newsModel->subtitle }}</td>
<td class="d-none d-lg-table-cell text-center align-middle">
<form action="{{ route('bo.news.change-published', $newsModel->id) }}" method="POST">
@csrf
<button type="submit"
class="btn btn-sm"
title="{{ __($newsModel->status ? __('crud.helpers.unpublish') : __('crud.helpers.publish')) }}"
data-bs-toggle="tooltip">
@if($newsModel->status)
<i class="fs-6 text-success fa-solid fa-circle-check"></i>
@else
<i class="fs-6 text-danger fa-regular fa-circle-xmark"></i>
@endif
</button>
</form>
</td>
@php $routeName = request()->route()->getName(); @endphp @php $routeName = request()->route()->getName(); @endphp
@if(empty(request()->search) and empty($noOrder) and Session::get("$routeName.sort_col") === 'order') @if(empty(request()->search) and empty($noOrder) and Session::get("$routeName.sort_col") === 'order')
<td class="d-flex"> <td class="d-flex">
<form action="{{ route('bo.news.change-order', ['news' => $newsModels, 'action' => 'up']) }}" method="POST" class="text-center @if($loop->first and $newsListModels->onFirstPage()) invisible @endif"> <form action="{{ route('bo.news.change-order', ['news' => $newsModel, 'action' => 'up']) }}"
method="POST"
class="text-center @if($loop->first and $newsListModels->onFirstPage()) invisible @endif">
@csrf @csrf
<button type="submit" class="btn btn-sm @if(($loop->first and $newsListModels->onFirstPage())) disabled @endif" title="{{ __('Change the order of appearance upwards') }}" data-bs-toggle="tooltip"> <button type="submit" class="btn btn-sm @if(($loop->first and $newsListModels->onFirstPage())) disabled @endif"
title="{{ __('Change the order of appearance upwards') }}" data-bs-toggle="tooltip">
<i class="fas fa-arrow-alt-circle-up"></i> <i class="fas fa-arrow-alt-circle-up"></i>
</button> </button>
</form> </form>
<form action="{{ route('bo.news.change-order', ['news' => $newsModels, 'action' => 'down']) }}" method="POST" class="text-center @if($loop->last and $newsListModels->currentPage() === $newsListModels->lastPage()) invisible @endif"> <form action="{{ route('bo.news.change-order', ['news' => $newsModel, 'action' => 'down']) }}"
method="POST"
class="text-center @if($loop->last and $newsListModels->currentPage() === $newsListModels->lastPage()) invisible @endif">
@csrf @csrf
<button type="submit" class="btn btn-sm @if($loop->last and $newsListModels->currentPage() === $newsListModels->lastPage()) disabled @endif" title="{{ __('Change the order of appearance downwards') }}" data-bs-toggle="tooltip"> <button type="submit"
class="btn btn-sm @if($loop->last and $newsListModels->currentPage() === $newsListModels->lastPage()) disabled @endif"
title="{{ __('Change the order of appearance downwards') }}"
data-bs-toggle="tooltip">
<i class="fas fa-arrow-alt-circle-down"></i> <i class="fas fa-arrow-alt-circle-down"></i>
</button> </button>
</form> </form>
</td> </td>
@endif @endif
<td class="align-middle"> <td class="align-middle">
<span class="badge bg-warning text-dark text-wrap">{{ $newsModels->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}</span> <span class="badge bg-warning text-dark text-wrap">{{ $newsModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}</span>
</td> </td>
<td class="align-middle"> <td class="align-middle">
<form action="{{ route('bo.news.destroy', $newsModels->id) }}" method="POST" class="btn-group confirmDeleteJS" novalidate> <form action="{{ route('bo.news.destroy', $newsModel->id) }}" method="POST" class="btn-group confirmDeleteJS" novalidate>
<a class="btn btn-sm btn-primary" href="{{ route('bo.news.edit', $newsModels->id) }}" title="{{ __('crud.helpers.update_model', ['model' => Str::singular(__('models.classes.news'))]) }}" data-bs-toggle="tooltip"> <a class="btn btn-sm btn-primary" href="{{ route('bo.news.edit', $newsModel->id) }}"
title="{{ __('crud.helpers.update_model', ['model' => Str::singular(__('models.classes.news'))]) }}"
data-bs-toggle="tooltip">
<i class="fa-solid fa-pencil"></i> <i class="fa-solid fa-pencil"></i>
</a> </a>
@method('DELETE') @method('DELETE')
@csrf @csrf
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button class="btn btn-sm btn-danger" title="{{ __('crud.helpers.delete_model', ['model' => Str::singular(__('models.classes.news'))]) }}" data-bs-toggle="tooltip"> <button class="btn btn-sm btn-danger"
title="{{ __('crud.helpers.delete_model', ['model' => Str::singular(__('models.classes.news'))]) }}"
data-bs-toggle="tooltip">
<i class="fa-solid fa-trash"></i> <i class="fa-solid fa-trash"></i>
</button> </button>
</div> </div>

View file

@ -1,14 +1,15 @@
<div class="table-responsive"> <div class="table-responsive">
<table class="table fix-action m-0"> <table class="table fix-action m-0">
<thead> <thead>
@php @include('bo.modules.table-col-sorter', [
$cols = [ 'cols' => [
'label' => __('validation.attributes.label'), 'label' => __('validation.attributes.label'),
'status' => __('validation.attributes.visibility'), 'status' => __('validation.attributes.visibility'),
'order' => __('validation.attributes.order'), 'order' => __('validation.attributes.order'),
'updated_at' => __('validation.attributes.updated_at')]; 'updated_at' => __('validation.attributes.updated_at')
@endphp ],
@include('bo.modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => ['status']]) 'mobileHide' => ['status']
])
</thead> </thead>
<tbody> <tbody>
@if($productModels->count()) @if($productModels->count())
@ -18,7 +19,10 @@
<td class="d-none d-lg-table-cell text-center align-middle"> <td class="d-none d-lg-table-cell text-center align-middle">
<form action="{{ route('bo.products.change-published', $productModel->id) }}" method="POST"> <form action="{{ route('bo.products.change-published', $productModel->id) }}" method="POST">
@csrf @csrf
<button type="submit" class="btn btn-sm" title="{{ __($productModel->status ? __('crud.helpers.unpublish') : __('crud.helpers.publish')) }}" data-bs-toggle="tooltip"> <button type="submit"
class="btn btn-sm"
title="{{ __($productModel->status ? __('crud.helpers.unpublish') : __('crud.helpers.publish')) }}"
data-bs-toggle="tooltip">
@if($productModel->status) @if($productModel->status)
<i class="fs-6 text-success fa-solid fa-circle-check"></i> <i class="fs-6 text-success fa-solid fa-circle-check"></i>
@else @else
@ -30,15 +34,25 @@
@php $routeName = request()->route()->getName(); @endphp @php $routeName = request()->route()->getName(); @endphp
@if(empty(request()->search) and empty($noOrder) and Session::get("$routeName.sort_col") === 'order') @if(empty(request()->search) and empty($noOrder) and Session::get("$routeName.sort_col") === 'order')
<td class="d-flex"> <td class="d-flex">
<form action="{{ route('bo.products.change-order', ['product' => $productModel, 'action' => 'up']) }}" method="POST" class="text-center @if($loop->first and $productModels->onFirstPage()) invisible @endif"> <form action="{{ route('bo.products.change-order', ['product' => $productModel, 'action' => 'up']) }}"
method="POST"
class="text-center @if($loop->first and $productModels->onFirstPage()) invisible @endif">
@csrf @csrf
<button type="submit" class="btn btn-sm @if(($loop->first and $productModels->onFirstPage())) disabled @endif" title="{{ __('Change the order of appearance upwards') }}" data-bs-toggle="tooltip"> <button type="submit"
class="btn btn-sm @if(($loop->first and $productModels->onFirstPage())) disabled @endif"
title="{{ __('Change the order of appearance upwards') }}"
data-bs-toggle="tooltip">
<i class="fas fa-arrow-alt-circle-up"></i> <i class="fas fa-arrow-alt-circle-up"></i>
</button> </button>
</form> </form>
<form action="{{ route('bo.products.change-order', ['product' => $productModel, 'action' => 'down']) }}" method="POST" class="text-center @if($loop->last and $productModels->currentPage() === $productModels->lastPage()) invisible @endif"> <form action="{{ route('bo.products.change-order', ['product' => $productModel, 'action' => 'down']) }}"
method="POST"
class="text-center @if($loop->last and $productModels->currentPage() === $productModels->lastPage()) invisible @endif">
@csrf @csrf
<button type="submit" class="btn btn-sm @if($loop->last and $productModels->currentPage() === $productModels->lastPage()) disabled @endif" title="{{ __('Change the order of appearance downwards') }}" data-bs-toggle="tooltip"> <button type="submit"
class="btn btn-sm @if($loop->last and $productModels->currentPage() === $productModels->lastPage()) disabled @endif"
title="{{ __('Change the order of appearance downwards') }}"
data-bs-toggle="tooltip">
<i class="fas fa-arrow-alt-circle-down"></i> <i class="fas fa-arrow-alt-circle-down"></i>
</button> </button>
</form> </form>
@ -48,14 +62,19 @@
<span class="badge bg-warning text-dark text-wrap">{{ $productModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}</span> <span class="badge bg-warning text-dark text-wrap">{{ $productModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}</span>
</td> </td>
<td class="align-middle"> <td class="align-middle">
<form action="{{ route('bo.products.destroy', $productModel->id) }}" method="POST" class="btn-group confirmDeleteJS" novalidate> <form action="{{ route('bo.products.destroy', $productModel->id) }}"
<a class="btn btn-sm btn-primary" href="{{ route('bo.products.edit', $productModel->id) }}" title="{{ __('crud.helpers.update_model', ['model' => Str::singular(__('models.classes.products'))]) }}" data-bs-toggle="tooltip"> method="POST" class="btn-group confirmDeleteJS" novalidate>
<a class="btn btn-sm btn-primary" href="{{ route('bo.products.edit', $productModel->id) }}"
title="{{ __('crud.helpers.update_model', ['model' => Str::singular(__('models.classes.products'))]) }}"
data-bs-toggle="tooltip">
<i class="fa-solid fa-pencil"></i> <i class="fa-solid fa-pencil"></i>
</a> </a>
@method('DELETE') @method('DELETE')
@csrf @csrf
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button class="btn btn-sm btn-danger" title="{{ __('crud.helpers.delete_model', ['model' => Str::singular(__('models.classes.products'))]) }}" data-bs-toggle="tooltip"> <button class="btn btn-sm btn-danger"
title="{{ __('crud.helpers.delete_model', ['model' => Str::singular(__('models.classes.products'))]) }}"
data-bs-toggle="tooltip">
<i class="fa-solid fa-trash"></i> <i class="fa-solid fa-trash"></i>
</button> </button>
</div> </div>

View file

@ -33,7 +33,7 @@
@if ($errors->any()) @if ($errors->any())
<div class="alert alert-danger alert-dismissible fade show" role="alert"> <div class="alert alert-danger alert-dismissible fade show" role="alert">
@if ($errors->any()) @if ($errors->any())
<ul class="list-unstyled"> <ul class="list-unstyled m-0">
@foreach ($errors->all() as $error) @foreach ($errors->all() as $error)
<li>{{ $error }}</li> <li>{{ $error }}</li>
@endforeach @endforeach

View file

@ -61,6 +61,8 @@ Route::prefix('bo')
->middleware(['htmlsanitize:content']); ->middleware(['htmlsanitize:content']);
Route::post('/news/{news}/change-order', [NewsController::class, 'changeOrder']) Route::post('/news/{news}/change-order', [NewsController::class, 'changeOrder'])
->name('news.change-order'); ->name('news.change-order');
Route::post('/news/{news}/change-published', [NewsController::class, 'changePublished'])
->name('news.change-published');
// * CONCEPTS // * CONCEPTS
Route::resource('concepts', ConceptController::class)->except(['show']) Route::resource('concepts', ConceptController::class)->except(['show'])
@ -119,7 +121,7 @@ Route::prefix('bo')
->withoutMiddleware('htmlsanitize') ->withoutMiddleware('htmlsanitize')
->middleware(['htmlsanitize:description']); ->middleware(['htmlsanitize:description']);
Route::post('/sliders/{slider}/change-order', [SliderController::class, 'changeOrder']) Route::post('/sliders/{slider}/change-order', [SliderController::class, 'changeOrder'])
->name('sliders.change-order'); ->name('sliders.change-order');
}); });
} }
); );