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,
null,
'seo_title',
'name',
'title',
'subtitle',
);
}
$this->sortQuery($news);
$searchFields = trans('Name');
$searchFields = trans('SEO title, Title, subtitle');
$newsListModels = $news->paginate(10);

View file

@ -103,9 +103,6 @@ class News extends Model implements SeoInterface
$model->makeStatusSense();
self::setOrder($model);
});
static::created(function (self $model) {
$model->flashMessages();
});
static::updating(function (self $model) {
// * ASSERTIONS
static::assertTitleIsUnique($model->title);
@ -121,7 +118,6 @@ class News extends Model implements SeoInterface
$model->content,
ToolboxHelper::getOriginal($model, 'content')
);
$model->flashMessages();
});
static::deleted(function (self $model) {
FileStorageHelper::removeModelFilesOfHtml($model->content);
@ -217,44 +213,6 @@ class News extends Model implements SeoInterface
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.
*

View file

@ -24,7 +24,7 @@
</p>
<p class="card-text">
{{ __('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>
</div>
</div>

View file

@ -1,50 +1,79 @@
<div class="table-responsive">
<table class="table fix-action m-0">
<thead>
@php
$cols = [
'title' => __('validation.attributes.title'),
'subtitle' => __('validation.attributes.subtitle'),
'order' => __('validation.attributes.order'),
'updated_at' => __('validation.attributes.updated_at')];
@endphp
@include('bo.modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => ['status']])
@include('bo.modules.table-col-sorter', [
'cols' => [
'title' => __('validation.attributes.title'),
'subtitle' => __('validation.attributes.subtitle'),
'status' => __('validation.attributes.visibility'),
'order' => __('validation.attributes.order'),
'updated_at' => __('validation.attributes.updated_at')
],
'mobileHide' => ['status']
])
</thead>
<tbody>
@if($newsListModels->count())
@foreach ($newsListModels as $newsModels)
@foreach ($newsListModels as $newsModel)
<tr>
<td class="align-middle">{{ $newsModels->title }}</td>
<td class="align-middle">{{ $newsModels->subtitle }}</td>
<td class="align-middle">{{ $newsModel->title }}</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
@if(empty(request()->search) and empty($noOrder) and Session::get("$routeName.sort_col") === 'order')
<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
<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>
</button>
</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
<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>
</button>
</form>
</td>
@endif
<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 class="align-middle">
<form action="{{ route('bo.news.destroy', $newsModels->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">
<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', $newsModel->id) }}"
title="{{ __('crud.helpers.update_model', ['model' => Str::singular(__('models.classes.news'))]) }}"
data-bs-toggle="tooltip">
<i class="fa-solid fa-pencil"></i>
</a>
@method('DELETE')
@csrf
<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>
</button>
</div>

View file

@ -1,14 +1,15 @@
<div class="table-responsive">
<table class="table fix-action m-0">
<thead>
@php
$cols = [
'label' => __('validation.attributes.label'),
'status' => __('validation.attributes.visibility'),
'order' => __('validation.attributes.order'),
'updated_at' => __('validation.attributes.updated_at')];
@endphp
@include('bo.modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => ['status']])
@include('bo.modules.table-col-sorter', [
'cols' => [
'label' => __('validation.attributes.label'),
'status' => __('validation.attributes.visibility'),
'order' => __('validation.attributes.order'),
'updated_at' => __('validation.attributes.updated_at')
],
'mobileHide' => ['status']
])
</thead>
<tbody>
@if($productModels->count())
@ -18,7 +19,10 @@
<td class="d-none d-lg-table-cell text-center align-middle">
<form action="{{ route('bo.products.change-published', $productModel->id) }}" method="POST">
@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)
<i class="fs-6 text-success fa-solid fa-circle-check"></i>
@else
@ -30,15 +34,25 @@
@php $routeName = request()->route()->getName(); @endphp
@if(empty(request()->search) and empty($noOrder) and Session::get("$routeName.sort_col") === 'order')
<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
<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>
</button>
</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
<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>
</button>
</form>
@ -48,14 +62,19 @@
<span class="badge bg-warning text-dark text-wrap">{{ $productModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}</span>
</td>
<td class="align-middle">
<form action="{{ route('bo.products.destroy', $productModel->id) }}" 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">
<form action="{{ route('bo.products.destroy', $productModel->id) }}"
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>
</a>
@method('DELETE')
@csrf
<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>
</button>
</div>

View file

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

View file

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