From e93cb4e41f0bcad99b88c27cf7978e4a4ee7b486 Mon Sep 17 00:00:00 2001 From: Nicolas Demangeat Date: Wed, 12 Mar 2025 09:46:06 +0100 Subject: [PATCH] feat: :sparkles: add static pages crud for rgpd content --- app/Enums/GeneralConfigType.php | 4 - app/Enums/StaticPageType.php | 23 +++ .../Controllers/Bo/StaticPageController.php | 102 +++++++++++++ app/Http/Controllers/Fo/HomeController.php | 8 +- .../StaticPages/UpdateStaticPageRequest.php | 59 ++++++++ app/Models/StaticPage.php | 143 ++++++++++++++++++ app/Models/User.php | 1 - app/Policies/StaticPagePolicy.php | 47 ++++++ app/Rules/WysiwygLength.php | 83 ++++++++++ database/factories/UserFactory.php | 15 -- .../2025_03_07_150955_create_static_pages.php | 40 +++++ database/seeders/DatabaseSeeder.php | 3 +- database/seeders/StaticPageSeeder.php | 33 ++++ resources/lang/fr/crud.php | 3 - resources/lang/fr/models.php | 1 + resources/lang/fr/validation.php | 2 +- resources/views/bo/layouts/nav-list.blade.php | 38 +++-- .../bo/pages/static_pages/edit.blade.php | 45 ++++++ .../bo/pages/static_pages/form.blade.php | 51 +++++++ resources/views/fo/partials/charte.blade.php | 32 +--- .../views/fo/partials/mentions.blade.php | 18 +-- routes/breadcrumbs-bo.php | 17 +++ routes/web-bo.php | 14 ++ 23 files changed, 689 insertions(+), 93 deletions(-) create mode 100644 app/Enums/StaticPageType.php create mode 100644 app/Http/Controllers/Bo/StaticPageController.php create mode 100644 app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php create mode 100644 app/Models/StaticPage.php create mode 100644 app/Policies/StaticPagePolicy.php create mode 100644 app/Rules/WysiwygLength.php create mode 100644 database/migrations/2025_03_07_150955_create_static_pages.php create mode 100644 database/seeders/StaticPageSeeder.php create mode 100644 resources/views/bo/pages/static_pages/edit.blade.php create mode 100644 resources/views/bo/pages/static_pages/form.blade.php diff --git a/app/Enums/GeneralConfigType.php b/app/Enums/GeneralConfigType.php index 3df59b26..db02af91 100644 --- a/app/Enums/GeneralConfigType.php +++ b/app/Enums/GeneralConfigType.php @@ -13,8 +13,6 @@ enum GeneralConfigType: int case demarche = 3; case engagement = 4; case elevage = 5; - case mention = 6; - case charte = 7; /** * Optionnal labels definition. @@ -27,7 +25,5 @@ enum GeneralConfigType: int self::demarche->name => 'Demarche', self::engagement->name => 'Engagement', self::elevage->name => 'Elevage', - self::mention->name => 'Mention légales', - self::charte->name => 'Charte', ]; } diff --git a/app/Enums/StaticPageType.php b/app/Enums/StaticPageType.php new file mode 100644 index 00000000..f33ea1a5 --- /dev/null +++ b/app/Enums/StaticPageType.php @@ -0,0 +1,23 @@ +name => 'Charte de Confidentialité', + self::legals->name => 'Mentions légales et CGU', + ]; +} diff --git a/app/Http/Controllers/Bo/StaticPageController.php b/app/Http/Controllers/Bo/StaticPageController.php new file mode 100644 index 00000000..24609558 --- /dev/null +++ b/app/Http/Controllers/Bo/StaticPageController.php @@ -0,0 +1,102 @@ +authorizeResource(StaticPage::class); + } + + /** + * Display a listing of the resource. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Contracts\View\View + */ + public function index(Request $request): \Illuminate\Contracts\View\View + { + /** @var \Illuminate\Database\Eloquent\Builder $query */ + $query = StaticPage::query(); + + /** @var string $search Search field */ + $search = $request->search; + if ($search) { + $this->searchQuery( + $query, + $search, + null, + 'title', + ); + } + $searchFields = \implode(', ', [ + trans('validation.attributes.title'), + ]); + + /** Sort columns with a query */ + $this->sortQuery($query); + + /** Custom pagination */ + $staticPageModelList = $this->paginate($query); + + return view('bo.pages.static_pages.index', compact('staticPageModelList', 'search', 'searchFields')); + } + + /** + * Show a specific resource. + * + * @param \App\Models\StaticPage $static_page + * @return \Illuminate\Contracts\View\View + */ + public function show(StaticPage $static_page): \Illuminate\Contracts\View\View + { + return view('bo.pages.static_pages.show', ['staticPageModel' => $static_page]); + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Models\StaticPage $static_page + * @return \Illuminate\Contracts\View\View + */ + public function edit(StaticPage $static_page): \Illuminate\Contracts\View\View + { + return view('bo.pages.static_pages.edit', ['staticPageModel' => $static_page]); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest $request + * @param \App\Models\StaticPage $static_page + * @return \Illuminate\Http\RedirectResponse + */ + public function update(UpdateStaticPageRequest $request, StaticPage $static_page): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request, $static_page) { + $static_page->fill($request->validated()); + + if ($static_page->saveOrFail()) { + return redirect()->route('bo.static_pages.edit', $static_page) + ->with('success', __('crud.messages.has_been_updated', [ + 'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1)) + ])); + } + return redirect()->route('bo.static_pages.edit', $static_page) + ->with('error', __('crud.messages.cannot_be_updated', [ + 'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1)) + ])); + }); + } +} diff --git a/app/Http/Controllers/Fo/HomeController.php b/app/Http/Controllers/Fo/HomeController.php index 3f3c7d71..cdcfafac 100644 --- a/app/Http/Controllers/Fo/HomeController.php +++ b/app/Http/Controllers/Fo/HomeController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers\Fo; +use App\Enums\StaticPageType; use App\Http\Controllers\Controller; use App\Models\GeneralConfig; +use App\Models\StaticPage; class HomeController extends Controller { @@ -14,9 +16,11 @@ class HomeController extends Controller */ public function index(): \Illuminate\Contracts\View\View { - $configList = GeneralConfig::all()->keyBy(function (GeneralConfig $item) { + $configList = GeneralConfig::all()->keyBy(function (GeneralConfig $item) { return $item->type->value(); }); - return view('fo.pages.home', compact('configList')); + $legalsStaticPageModel = StaticPage::query()->where('type', StaticPageType::legals)->first(); + $confidStaticPageModel = StaticPage::query()->where('type', StaticPageType::confidentiality)->first(); + return view('fo.pages.home', compact('configList', 'legalsStaticPageModel', 'confidStaticPageModel')); } } diff --git a/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php b/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php new file mode 100644 index 00000000..c426f58a --- /dev/null +++ b/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php @@ -0,0 +1,59 @@ +route('static_page')); + } + + /** + * Prepare the data for validation. + * + * @return void + */ + public function prepareForValidation(): void + { + $this->merge([ + 'content' => Str::of($this->input('content'))->value() + ]); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'title' => 'required|min:3|max:255', + 'content' => ['required', 'string', new WysiwygLength(15)], + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes(): array + { + return [ + 'title' => trans('validation.attributes.title'), + 'content' => trans('validation.attributes.content'), + ]; + } +} diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php new file mode 100644 index 00000000..11fb3fa5 --- /dev/null +++ b/app/Models/StaticPage.php @@ -0,0 +1,143 @@ + + */ + protected $fillable = [ + 'type', + 'title', + 'subtitle', + 'content', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'type' => StaticPageType::class, + 'data' => 'object', + ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::creating(function () { + throw new \RuntimeException("Creating a new page is not authorized"); + }); + static::updating(function (self $model) { + self::assertTitleIsUnique($model->title, $model->getKey()); + $model->slug = Str::slug($model->title); + }); + static::updated(function (self $model) { + self::resetCache($model->type); + }); + static::deleted(function () { + throw new \RuntimeException('Deleting a page is not authorized'); + }); + } + + // * ROUTABLE + + /** + * Get the value of the model's route key. + * + * @return mixed + */ + public function getRouteKey(): mixed + { + /** @var \App\Enums\StaticPageType */ + $enum = $this->getAttribute($this->getRouteKeyName()); + return $enum->value(); + } + + /** + * Get the route key for the model. + * + * ! Type is the routable parameter + * + * @return string + */ + public function getRouteKeyName(): string + { + return 'type'; + } + + // * METHODS + + /** + * Asserts using validation that the title is unique + * + * @param string $title + * @param integer|null $id + * @return void + * @throws \Illuminate\Validation\ValidationException If an actu title already exists. + */ + private static function assertTitleIsUnique(string $title, ?int $id = null): void + { + $table = (new self())->getTable(); + ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id); + ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id); + } + + /** + * Reset all cache elements related to this model. + * + * @param \App\Enums\StaticPageType $type + * @return void + */ + private static function resetCache(StaticPageType $type): void + { + Cache::forget(sprintf('%sStaticPage', $type->name)); + self::getCachedStaticPage($type); + + // Breeding pages. + Cache::forget('breedingStaticPages'); + } + + /** + * Get cached static page associated to a given type. + * + * @param \App\Enums\StaticPageType $type + * @return \App\Models\StaticPage + */ + public static function getCachedStaticPage(StaticPageType $type): \App\Models\StaticPage + { + return Cache::rememberForever( + sprintf('%sStaticPage', $type->name), + fn() => self::query()->where('type', $type)->first() + ); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 772cd2da..8ebafb07 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -55,7 +55,6 @@ class User extends Authenticatable */ protected $casts = [ 'role' => RoleEnum::class, - 'email_verified_at' => 'datetime', 'published' => 'boolean', 'published_at' => 'datetime', ]; diff --git a/app/Policies/StaticPagePolicy.php b/app/Policies/StaticPagePolicy.php new file mode 100644 index 00000000..b15e0ba0 --- /dev/null +++ b/app/Policies/StaticPagePolicy.php @@ -0,0 +1,47 @@ +max) and !($length >= $this->min && $length <= $this->max)) { + $fail(trans('validation.between.string', [ + 'attribute' => $translatedAttribute, + 'min' => $this->min, + 'max' => $this->max + ])); + return; + } + if ($length < $this->min) { + $fail(trans('validation.min.string', [ + 'attribute' => $translatedAttribute, + 'min' => $this->min + ])); + } + } + + /** + * Get the correct translation for the given attrribute. + * + * @param string $attribute + * @return string + */ + private static function getTranslatedAttribute(string $attribute): string + { + /** @var \Illuminate\Translation\Translator $trans */ + $trans = trans(); + if ($trans->has('validation.attributes.' . $attribute)) { + return trans('validation.attributes.' . $attribute); + } + if ($trans->has('validation.custom.' . $attribute)) { + return trans('validation.custom.' . $attribute); + } + return $attribute; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index e478bb4a..131d1846 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -20,25 +20,10 @@ class UserFactory extends Factory 'first_name' => fake()->firstname(), 'last_name' => fake()->lastname(), 'email' => fake()->unique()->safeEmail(), - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'remember_token' => Str::random(10), 'role' => \collect(RoleEnum::toArray())->random()->value, 'published' => $published, 'published_at' => ($published) ? now() : null, ]; } - - /** - * Indicate that the model's email address should be unverified. - * - * @return static - */ - public function unverified(): static - { - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass - return $this->state(fn() => [ - 'email_verified_at' => null, - ]); - } } diff --git a/database/migrations/2025_03_07_150955_create_static_pages.php b/database/migrations/2025_03_07_150955_create_static_pages.php new file mode 100644 index 00000000..008abc6b --- /dev/null +++ b/database/migrations/2025_03_07_150955_create_static_pages.php @@ -0,0 +1,40 @@ +id(); + $table->unsignedTinyInteger('type')->unique()->comment('Type of the page.'); + $table->string('title')->comment('Title of the page.'); + $table->string('slug')->unique()->comment('Unique slug from the title of the page.'); + $table->text('content')->comment('Text content of the page.'); + $table->timestamps(); + }); + + // Remove old enum values. + GeneralConfig::query()->whereKey(6)->delete(); + GeneralConfig::query()->whereKey(7)->delete(); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('static_pages'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 9af3d6ab..805b951d 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,7 +14,8 @@ class DatabaseSeeder extends Seeder public function run() { $this->call([ - UserSeeder::class + UserSeeder::class, + StaticPageSeeder::class ]); } } diff --git a/database/seeders/StaticPageSeeder.php b/database/seeders/StaticPageSeeder.php new file mode 100644 index 00000000..f765d8e3 --- /dev/null +++ b/database/seeders/StaticPageSeeder.php @@ -0,0 +1,33 @@ +slug = Str::slug(StaticPageType::legals->label()); + $staticPageModel->type = StaticPageType::legals; + $staticPageModel->title = StaticPageType::legals->label(); + $staticPageModel->content = \clean(\fake()->randomHtml(6, 7)); + $staticPageModel->saveQuietly(); + + $staticPageModel = new StaticPage(); + $staticPageModel->slug = Str::slug(StaticPageType::confidentiality->label()); + $staticPageModel->type = StaticPageType::confidentiality; + $staticPageModel->title = StaticPageType::confidentiality->label(); + $staticPageModel->content = \clean(\fake()->randomHtml(6, 7)); + $staticPageModel->saveQuietly(); + } +} diff --git a/resources/lang/fr/crud.php b/resources/lang/fr/crud.php index 8aa5dc71..f3a3e275 100644 --- a/resources/lang/fr/crud.php +++ b/resources/lang/fr/crud.php @@ -25,9 +25,6 @@ return [ 'no_results' => 'Aucun résultat pour :model', 'publish' => 'Publié', 'unpublish' => 'Dépublié', - 'seo_title' => 'Doit décrire précisément la page, recommandation pour un positionnement - optimal dans les moteurs de recherche (balise ).', - 'seo_description' => 'Doit décrire précisément le contenu de la page (balise <meta> description).', ], 'libs' => [ diff --git a/resources/lang/fr/models.php b/resources/lang/fr/models.php index 30d0c4a9..a4ab8347 100644 --- a/resources/lang/fr/models.php +++ b/resources/lang/fr/models.php @@ -5,5 +5,6 @@ return [ 'user' => 'utilisateur', 'activity_log' => 'journal d\'activité|journaux d\'activité', 'section' => 'section', + 'static_page' => 'page statique|pages statiques', ] ]; diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index bb22f65a..445d4b28 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -214,7 +214,7 @@ return [ 'username' => 'nom d\'utilisateur', 'year' => 'année', ], - 'custom' => [ + 'custom' => [ 'of_the' => [ 'male' => 'du ', 'female' => 'de la ', diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php index fd3ddc79..fc0c5c5c 100644 --- a/resources/views/bo/layouts/nav-list.blade.php +++ b/resources/views/bo/layouts/nav-list.blade.php @@ -1,13 +1,14 @@ @auth('backend') <ul class="navbar-nav border-top border-lg-0 mt-lg-0 me-auto mt-2"> <li class="nav-item"> - <a class="nav-link @if (request()->routeIs('bo.dashboard')) active @endif" data-bs-toggle="tooltip" href="{{ route('bo.dashboard') }}" - title="{{ __('Revenir à l\'accueil') }}"> + <a class="nav-link @if (request()->routeIs('bo.dashboard')) active @endif" data-bs-toggle="tooltip" + href="{{ route('bo.dashboard') }}" title="{{ __('Revenir à l\'accueil') }}"> {{ __('Accueil') }} </a> </li> <li class="nav-item"> - <a class="nav-link @if (request()->routeIs('bo.general_configs.edit') and request()->general_config->type->value == \App\Enums\GeneralConfigType::menu->value) active @endif" data-bs-toggle="tooltip" + <a class="nav-link @if (request()->routeIs('bo.general_configs.edit') and + request()->general_config->type->value == \App\Enums\GeneralConfigType::menu->value) active @endif" data-bs-toggle="tooltip" href="{{ route('bo.general_configs.edit', ['general_config' => \App\Enums\GeneralConfigType::menu]) }}" title="{{ __('Administrer :model', ['model' => \App\Enums\GeneralConfigType::menu->label()]) }}"> {{ \App\Enums\GeneralConfigType::menu->label() }} @@ -46,34 +47,31 @@ </a> </li> <li class="nav-item dropdown"> - <a class="nav-link dropdown-toggle @if (request()->routeIs('bo.general_configs.edit') and - request()->general_config->type->value == \App\Enums\GeneralConfigType::mention->value || - request()->general_config->type->value == \App\Enums\GeneralConfigType::charte->value) active @endif" id="rgpdDropdown" data-bs-toggle="dropdown" - role="button" aria-expanded="false"> + <a class="nav-link dropdown-toggle @if (request()->routeIs('bo.static_pages.edit')) active @endif" id="rgpdDropdown" + data-bs-toggle="dropdown" role="button" aria-expanded="false"> {{ __('RGPD') }} </a> <div class="dropdown-menu dropdown-menu-end" aria-labelledby="rgpdDropdown"> - <a class="nav-link @if (request()->routeIs('bo.general_configs.edit') and - request()->general_config->type->value == \App\Enums\GeneralConfigType::mention->value) active @endif py-1 text-center" data-bs-toggle="tooltip" - data-bs-placement="right" - href="{{ route('bo.general_configs.edit', ['general_config' => \App\Enums\GeneralConfigType::mention->value]) }}" - title="{{ __('Administrer :model', ['model' => \App\Enums\GeneralConfigType::mention->label()]) }}"> - {{ \App\Enums\GeneralConfigType::mention->label() }} + <a class="nav-link @if (request()->routeIs('bo.static_pages.edit') && request()->static_page->type->equals(\App\Enums\StaticPageType::legals)) active @endif py-1 text-center" + data-bs-toggle="tooltip" data-bs-placement="right" + href="{{ route('bo.static_pages.edit', ['static_page' => \App\Enums\StaticPageType::legals->value]) }}" + title="{{ __('Administrer :model', ['model' => \App\Enums\StaticPageType::legals->label()]) }}"> + {{ \App\Enums\StaticPageType::legals->label() }} </a> <hr class="dropdown-divider"> - <a class="nav-link @if (request()->routeIs('bo.general_configs.edit') and request()->general_config->type->value == \App\Enums\GeneralConfigType::charte->value) active @endif py-1 text-center" data-bs-toggle="tooltip" - data-bs-placement="right" - href="{{ route('bo.general_configs.edit', ['general_config' => \App\Enums\GeneralConfigType::charte->value]) }}" - title="{{ __('Administrer :model', ['model' => \App\Enums\GeneralConfigType::charte->label()]) }}"> - {{ \App\Enums\GeneralConfigType::charte->label() }} + <a class="nav-link @if (request()->routeIs('bo.static_pages.edit') && request()->static_page->type->equals(\App\Enums\StaticPageType::confidentiality)) active @endif py-1 text-center" + data-bs-toggle="tooltip" data-bs-placement="right" + href="{{ route('bo.static_pages.edit', ['static_page' => \App\Enums\StaticPageType::confidentiality->value]) }}" + title="{{ __('Administrer :model', ['model' => \App\Enums\StaticPageType::confidentiality->label()]) }}"> + {{ \App\Enums\StaticPageType::confidentiality->label() }} </a> </div> </li> @canAny(['isConceptor', 'viewAny'], \App\Models\User::class) <li class="nav-item"> <div class="dropdown"> - <a class="nav-link @if (request()->routeIs('bo.users.*') || request()->routeIs('bo.activity_logs.*')) active @endif dropdown-toggle" data-bs-toggle="dropdown" type="button" - aria-expanded="false"> + <a class="nav-link @if (request()->routeIs('bo.users.*') || request()->routeIs('bo.activity_logs.*')) active @endif dropdown-toggle" + data-bs-toggle="dropdown" type="button" aria-expanded="false"> {{ __('Avancé') }} </a> <ol class="dropdown-menu"> diff --git a/resources/views/bo/pages/static_pages/edit.blade.php b/resources/views/bo/pages/static_pages/edit.blade.php new file mode 100644 index 00000000..b90b2032 --- /dev/null +++ b/resources/views/bo/pages/static_pages/edit.blade.php @@ -0,0 +1,45 @@ +@extends('bo.layout', ['brParam' => $staticPageModel]) + +@section('title', __('Édition d\'une :model', ['model' => trans_choice('models.classes.static_page', 1)])) +@section('description', __('Édition d\'une :model déjà existante', ['model' => trans_choice('models.classes.static_page', 1)])) +@section('breadcrumb', request()->route()->getName()) + +@section('content') + <div class="row pb-3"> + <div class="col-12 d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap"> + <div class="d-flex align-items-start flex-row"> + @include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $staticPageModel]) + </div> + <div class="mb-md-0 mb-2"> + <div class="btn-group"> + <button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit" + title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.static_page')]) }}"> + {{ Str::ucfirst(__('crud.actions.save')) }} + </button> + </div> + </div> + </div> + <div class="col-12 overflow-hidden mt-3"> + <div class="bg-body-tertiary rounded-3 p-3"> + <p class="m-0"> + {{ str(__('validation.attributes.updated_at'))->ucFirst() }} + <span class="fw-bold">{{ $staticPageModel->updated_at->isoFormat('LLLL') }}</span> + </p> + </div> + </div> + </div> + <form action="{{ route('bo.static_pages.update', $staticPageModel) }}" method="POST" enctype="multipart/form-data"> + @csrf + @method('PUT') + @include('bo.pages.static_pages.form') + @include('bo.partials.script-button-clone') + <div class="row"> + <div class="col text-center"> + <button class="btn btn-primary" id="formSubmit" data-bs-toggle="tooltip" type="submit" + title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.static_page')]) }}"> + {{ str(__('crud.actions.save'))->ucfirst() }} + </button> + </div> + </div> + </form> +@endsection diff --git a/resources/views/bo/pages/static_pages/form.blade.php b/resources/views/bo/pages/static_pages/form.blade.php new file mode 100644 index 00000000..8e10ba5e --- /dev/null +++ b/resources/views/bo/pages/static_pages/form.blade.php @@ -0,0 +1,51 @@ +<div class="row"> + {{-- TITLE --}} + <div class="col-12 col-md-6 mb-3"> + <fieldset class="h-100 border p-3"> + <legend>{{ str(__('validation.attributes.title'))->ucfirst() }}</legend> + <div class="row"> + <div class="col-12"> + @include('bo.partials.inputs.varchar', [ + 'id' => 'userFirstname', + 'label' => __('Titre de la :model', ['model' => trans_choice('models.classes.static_page', 1)]), + 'hasWordCounter' => true, + 'name' => 'title', + 'required' => true, + 'model' => $staticPageModel ?? null, + 'helper' => __('validation.between.string', [ + 'attribute' => __('titre de la :model', ['model' => trans_choice('models.classes.static_page', 1)]), + 'min' => 3, + 'max' => 255, + ]), + 'placeholder' => __('Un titre clair et concis'), + ]) + </div> + </div> + </fieldset> + </div> + {{-- CONTENT --}} + <div class="col-12 mb-3"> + <fieldset class="border p-3"> + <legend>{{ str(__('validation.attributes.content'))->ucfirst() }}</legend> + <div class="row mb-3"> + <div class="col-12"> + @include('bo.partials.inputs.text-html', [ + 'id' => 'articleContent', + 'label' => __(':field :inter:model', [ + 'field' => str(__('validation.attributes.content'))->ucfirst(), + 'inter' => __('validation.custom.of_the.female'), + 'model' => trans_choice('models.classes.static_page', 1), + ]), + 'name' => 'content', + 'model' => $staticPageModel ?? null, + 'required' => true, + 'helper' => __('crud.minicrud.text_warning'), + ]) + </div> + </div> + </fieldset> + </div> + <div class="col-12 text-center"> + <p><b>{{ __('* Champs obligatoires') }}</b></p> + </div> +</div> diff --git a/resources/views/fo/partials/charte.blade.php b/resources/views/fo/partials/charte.blade.php index 55da93d2..4c770eb1 100644 --- a/resources/views/fo/partials/charte.blade.php +++ b/resources/views/fo/partials/charte.blade.php @@ -1,34 +1,6 @@ -@php - $configCharte = $configList->get(App\Enums\GeneralConfigType::charte->value()); -@endphp <template id="popin-politique"> <swal-html> - <h2 class="title text-brown mb1">{{ $configCharte->data['charte_title']['value'] }}</h2> - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_1']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_1']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_2']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_2']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_3']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_3']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_4']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_4']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_5']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_5']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_6']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_6']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_7']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_7']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_8']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_8']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_9']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_9']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_10']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_10']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_11']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_11']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_12']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_12']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configCharte->data['charte_subtitle_13']['value'] }}</h3> - {!! clean($configCharte->data['charte_text_13']['value']) !!} + <h3>{{ $confidStaticPageModel->title }}</h3> + {!! clean($confidStaticPageModel->content) !!} </swal-html> </template> diff --git a/resources/views/fo/partials/mentions.blade.php b/resources/views/fo/partials/mentions.blade.php index 722a1839..bd132691 100644 --- a/resources/views/fo/partials/mentions.blade.php +++ b/resources/views/fo/partials/mentions.blade.php @@ -1,20 +1,6 @@ -@php - $configMention = $configList->get(App\Enums\GeneralConfigType::mention->value()); -@endphp <template id="popin-mention"> <swal-html> - <h2 class="title text-brown mb1">{{ $configMention->data['mention_title']['value'] }}</h2> - <h3 class="subtitle text-yellow ck-content">{{ $configMention->data['mention_subtitle_1']['value'] }}</h3> - {!! clean($configMention->data['mention_text_1']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configMention->data['mention_subtitle_2']['value'] }}</h3> - {!! clean($configMention->data['mention_text_2']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configMention->data['mention_subtitle_3']['value'] }}</h3> - {!! clean($configMention->data['mention_text_3']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configMention->data['mention_subtitle_4']['value'] }}</h3> - {!! clean($configMention->data['mention_text_4']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configMention->data['mention_subtitle_5']['value'] }}</h3> - {!! clean($configMention->data['mention_text_5']['value']) !!} - <h3 class="subtitle text-yellow ck-content">{{ $configMention->data['mention_subtitle_6']['value'] }}</h3> - {!! clean($configMention->data['mention_text_6']['value']) !!} + <h3>{{ $legalsStaticPageModel->title }}</h3> + {!! clean($legalsStaticPageModel->content) !!} </swal-html> </template> diff --git a/routes/breadcrumbs-bo.php b/routes/breadcrumbs-bo.php index 6326d5ca..2bc63068 100644 --- a/routes/breadcrumbs-bo.php +++ b/routes/breadcrumbs-bo.php @@ -2,6 +2,7 @@ use App\Models\ActivityLog; use App\Models\GeneralConfig; +use App\Models\StaticPage; use App\Models\User; use Diglactic\Breadcrumbs\Breadcrumbs; use Diglactic\Breadcrumbs\Generator; @@ -43,3 +44,19 @@ Breadcrumbs::for('bo.activity_logs.show', function (Generator $trail, ActivityLo $trail->parent('bo.activity_logs.index'); $trail->push(Str::ucfirst(trans('crud.actions.view')), route('bo.activity_logs.show', $activityLogModel)); }); + +// * STATIC PAGES +Breadcrumbs::for('bo.static_pages.index', function (Generator $trail) { + $trail->push( + Str::of(trans_choice('models.classes.static_page', 2))->ucfirst(), + ); +}); +Breadcrumbs::for('bo.static_pages.show', function (Generator $trail, StaticPage $static_page) { + $trail->parent('bo.static_pages.index'); + $trail->push(Str::ucfirst(trans('crud.actions.show')), route('bo.static_pages.show', $static_page)); +}); + +Breadcrumbs::for('bo.static_pages.edit', function (Generator $trail, StaticPage $static_page) { + $trail->parent('bo.static_pages.index'); + $trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.static_pages.edit', $static_page)); +}); diff --git a/routes/web-bo.php b/routes/web-bo.php index 29736fb3..027c575f 100644 --- a/routes/web-bo.php +++ b/routes/web-bo.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Bo\ActivityLogController; use App\Http\Controllers\Bo\DashboardController; use App\Http\Controllers\Bo\GeneralConfigController; use App\Http\Controllers\Bo\UserController; +use App\Http\Controllers\Bo\StaticPageController; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; @@ -49,6 +50,19 @@ Route::prefix('bo') 'duplicate' ])->name('users.duplicate'); + + // * StaticPages + Route::resource('pages', StaticPageController::class) + ->names([ + 'index' => 'static_pages.index', + 'show' => 'static_pages.show', + 'edit' => 'static_pages.edit', + 'update' => 'static_pages.update', + ])->parameters(['pages' => 'static_page']) + ->only(['index', 'show', 'edit', 'update']) + ->withoutMiddleware('htmlsanitize') + ->middleware(['htmlsanitize:content']); + Route::middleware('can:isConceptor')->group(function () { // * ACTIVITY LOGS. Route::resource('activity_logs', ActivityLogController::class)->only(['index', 'show']);