From 9f564c61ed98a80483f3698ba0dd86149c88e7f8 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 28 May 2026 11:54:19 +0200 Subject: [PATCH] feat: :sparkles: Added color column to sticky model + keep sticky displayed on mobile --- app/Enums/StickiesColorEnum.php | 31 +++++ .../Controllers/Fo/StaticPageController.php | 14 +++ .../Bo/Stickies/StoreStickyRequest.php | 6 + app/Models/Sticky.php | 4 + ...2026_05_28_102226_alter_stickies_table.php | 35 ++++++ database/seeders/Mandatory/StickySeeder.php | 119 ++++++++++++++++-- resources/lang/fr/validation.php | 1 + resources/ts/fo/base/layout.ts | 18 +-- .../views/bo/pages/stickies/form.blade.php | 21 ++++ resources/views/fo/layouts/header.blade.php | 34 +++-- .../views/fo/pages/commitments.blade.php | 22 ++-- resources/views/fo/pages/hire.blade.php | 27 +--- resources/views/fo/pages/site.blade.php | 3 +- resources/views/fo/pages/unveil.blade.php | 27 +--- 14 files changed, 261 insertions(+), 101 deletions(-) create mode 100644 app/Enums/StickiesColorEnum.php create mode 100644 database/migrations/2026_05_28_102226_alter_stickies_table.php diff --git a/app/Enums/StickiesColorEnum.php b/app/Enums/StickiesColorEnum.php new file mode 100644 index 0000000..51e5d73 --- /dev/null +++ b/app/Enums/StickiesColorEnum.php @@ -0,0 +1,31 @@ +name => 'Primary', + self::secondary->name => 'Secondary', + self::tertiary->name => 'Tertiary', + self::quad->name => 'Quad', + self::quint->name => 'Quint', + self::sixt->name => 'Sixt', + ]; +} diff --git a/app/Http/Controllers/Fo/StaticPageController.php b/app/Http/Controllers/Fo/StaticPageController.php index df4ec12..2371b81 100644 --- a/app/Http/Controllers/Fo/StaticPageController.php +++ b/app/Http/Controllers/Fo/StaticPageController.php @@ -6,6 +6,7 @@ use App\Enums\Listen\ObjectEnum; use App\Enums\Sections\PageSectionEnum; use App\Enums\Slides\SliderTypeEnum; use App\Enums\StaticPageType; +use App\Enums\StickiesColorEnum; use App\Enums\Testimonials\TypeEnum; use App\Http\Controllers\Controller; use App\Http\Requests\Fo\ListenFormRequest; @@ -150,6 +151,8 @@ class StaticPageController extends Controller $feedSection = $sectionModels->where('section', PageSectionEnum::commit_feed)->first(); $testimonialsSection = $sectionModels->where('section', PageSectionEnum::commit_commitments)->first(); + $navLinks = Sticky::query()->where('type', StaticPageType::we_commit)->get(); + return view('fo.pages.commitments', compact( 'staticPageModel', 'sectionModels', @@ -162,6 +165,7 @@ class StaticPageController extends Controller 'earthSection', 'feedSection', 'testimonialsSection', + 'navLinks', )); } @@ -326,12 +330,22 @@ class StaticPageController extends Controller ]; $initialZoom = 10; + // Create datas similar to Sticky model. + $navLinks = collect([ + (object) [ + 'title' => $site->sticky_title, + 'anchor' => $site->sticky_link, + 'color' => StickiesColorEnum::quad, + ], + ]); + return view('fo.pages.site', [ 'siteModelList' => $siteModelList, 'siteModel' => $site, 'nextSiteModel' => $nextSiteModel, 'viewBox' => $viewBox, 'initialZoom' => $initialZoom, + 'navLinks' => $navLinks, ]); } } diff --git a/app/Http/Requests/Bo/Stickies/StoreStickyRequest.php b/app/Http/Requests/Bo/Stickies/StoreStickyRequest.php index a5dbe86..a93592b 100644 --- a/app/Http/Requests/Bo/Stickies/StoreStickyRequest.php +++ b/app/Http/Requests/Bo/Stickies/StoreStickyRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Bo\Stickies; use App\Enums\StaticPageType; +use App\Enums\StickiesColorEnum; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Enum; @@ -37,6 +38,10 @@ class StoreStickyRequest extends FormRequest 'string', 'between:3,255' ], + 'color' => [ + Rule::requiredIf($this->user()->can('create', $this->sticky)), + new Enum(StickiesColorEnum::class) + ], ]; } @@ -51,6 +56,7 @@ class StoreStickyRequest extends FormRequest 'type' => trans('validation.custom.type'), 'title' => trans('validation.attributes.title'), 'anchor' => trans('validation.custom.anchor'), + 'color' => trans('validation.custom.color'), ]; } } diff --git a/app/Models/Sticky.php b/app/Models/Sticky.php index b5cc570..9836ede 100644 --- a/app/Models/Sticky.php +++ b/app/Models/Sticky.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\StaticPageType; +use App\Enums\StickiesColorEnum; use App\Enums\Users\RoleEnum; use App\Traits\Models\ActivityLog; use Illuminate\Auth\Access\AuthorizationException; @@ -13,6 +14,7 @@ use Illuminate\Database\Eloquent\Model; * @property \App\Enums\StaticPageType $type Page type (StaticPageEnum). * @property string $title Title for the sticky. * @property string $anchor Anchor for the sticky. + * @property \App\Enums\StickiesColorEnum $color Color of the button (StickiesColorEnum). * @property-read \Illuminate\Support\Carbon $created_at Created date. * @property-read \Illuminate\Support\Carbon $updated_at Updated date. * @@ -31,6 +33,7 @@ class Sticky extends Model 'type', 'title', 'anchor', + 'color', ]; /** @@ -40,6 +43,7 @@ class Sticky extends Model */ protected $casts = [ 'type' => StaticPageType::class, + 'color' => StickiesColorEnum::class, ]; /** diff --git a/database/migrations/2026_05_28_102226_alter_stickies_table.php b/database/migrations/2026_05_28_102226_alter_stickies_table.php new file mode 100644 index 0000000..eda2676 --- /dev/null +++ b/database/migrations/2026_05_28_102226_alter_stickies_table.php @@ -0,0 +1,35 @@ +unsignedSmallInteger('color')->comment('Color of the button (StickyColorEnum) based on bootstrap colots')->after('anchor'); + }); + + // Update existing stickies + Add commitments stickies (actually hard-written). + Artisan::call('db:seed', [ + 'class' => StickySeeder::class + ]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('stickies', function (Blueprint $table) { + $table->removeColumn('color'); + }); + } +}; diff --git a/database/seeders/Mandatory/StickySeeder.php b/database/seeders/Mandatory/StickySeeder.php index 0f580ba..1aacb4d 100644 --- a/database/seeders/Mandatory/StickySeeder.php +++ b/database/seeders/Mandatory/StickySeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders\Mandatory; use App\Enums\StaticPageType; +use App\Enums\StickiesColorEnum; use App\Models\Sticky; use Illuminate\Database\Seeder; @@ -14,73 +15,171 @@ class StickySeeder extends Seeder public function run(): void { Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_hire, + 'anchor' => 'company-life', + ], [ 'type' => StaticPageType::we_hire, 'title' => 'La vie d\'entreprise', - 'anchor' => 'company-life' + 'anchor' => 'company-life', + 'color' => StickiesColorEnum::primary, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_hire, + 'anchor' => 'formation', + ], [ 'type' => StaticPageType::we_hire, 'title' => 'L\'alternance et la formation', - 'anchor' => 'formation' + 'anchor' => 'formation', + 'color' => StickiesColorEnum::secondary, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_hire, + 'anchor' => 'we-testimonials', + ], [ 'type' => StaticPageType::we_hire, 'title' => 'Nos collaborateurs témoignent', - 'anchor' => 'we-testimonials' + 'anchor' => 'we-testimonials', + 'color' => StickiesColorEnum::quad, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_hire, + 'anchor' => 'parity', + ], [ 'type' => StaticPageType::we_hire, 'title' => 'La parité', - 'anchor' => 'parity' + 'anchor' => 'parity', + 'color' => StickiesColorEnum::quint, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_hire, + 'anchor' => 'on-se-retrouve', + ], [ 'type' => StaticPageType::we_hire, 'title' => 'En savoir plus', - 'anchor' => 'on-se-retrouve' + 'anchor' => 'on-se-retrouve', + 'color' => StickiesColorEnum::sixt, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::unveil, + 'anchor' => 'key-numbers', + ], [ 'type' => StaticPageType::unveil, 'title' => 'VOLENA', - 'anchor' => 'key-numbers' + 'anchor' => 'key-numbers', + 'color' => StickiesColorEnum::primary, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::unveil, + 'anchor' => 'missions', + ], [ 'type' => StaticPageType::unveil, 'title' => 'Notre mission', - 'anchor' => 'missions' + 'anchor' => 'missions', + 'color' => StickiesColorEnum::secondary, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::unveil, + 'anchor' => 'local', + ], [ 'type' => StaticPageType::unveil, 'title' => 'Filière 100% française', - 'anchor' => 'local' + 'anchor' => 'local', + 'color' => StickiesColorEnum::quad, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::unveil, + 'anchor' => 'sites', + ], [ 'type' => StaticPageType::unveil, 'title' => 'Nos sites', - 'anchor' => 'sites' + 'anchor' => 'sites', + 'color' => StickiesColorEnum::quint, ], ); Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::unveil, + 'anchor' => 'history', + ], [ 'type' => StaticPageType::unveil, 'title' => 'Notre histoire', - 'anchor' => 'history' + 'anchor' => 'history', + 'color' => StickiesColorEnum::sixt, + ], + ); + Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_commit, + 'anchor' => 'breeding', + ], + [ + 'type' => StaticPageType::we_commit, + 'title' => 'Élever durablement', + 'anchor' => 'breeding', + 'color' => StickiesColorEnum::tertiary, + ], + ); + Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_commit, + 'anchor' => 'life', + ], + [ + 'type' => StaticPageType::we_commit, + 'title' => 'Mieux vivre', + 'anchor' => 'life', + 'color' => StickiesColorEnum::quad, + ], + ); + Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_commit, + 'anchor' => 'earth', + ], + [ + 'type' => StaticPageType::we_commit, + 'title' => 'Respecter la terre', + 'anchor' => 'earth', + 'color' => StickiesColorEnum::quint, + ], + ); + Sticky::query()->updateOrCreate( + [ + 'type' => StaticPageType::we_commit, + 'anchor' => 'feed', + ], + [ + 'type' => StaticPageType::we_commit, + 'title' => 'Bien nourrir', + 'anchor' => 'feed', + 'color' => StickiesColorEnum::sixt, ], ); } diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index 962a5a5..d50c705 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -305,5 +305,6 @@ return [ 'media' => 'média', 'anchor' => 'ancre', 'link' => 'lien', + 'color' => 'couleur', ], ]; diff --git a/resources/ts/fo/base/layout.ts b/resources/ts/fo/base/layout.ts index 43fba4a..88e6ac9 100644 --- a/resources/ts/fo/base/layout.ts +++ b/resources/ts/fo/base/layout.ts @@ -32,21 +32,21 @@ document.addEventListener("DOMContentLoaded", function () { } }); -// * Commit Buttons +// * Stickies on mobile. document.addEventListener("DOMContentLoaded", function () { - const commitDiv = document.getElementById("commit-blocks") as HTMLDivElement; - if (commitDiv) { - commitDiv.style.display = "none"; + const stickyDiv = document.getElementById("sticky-blocks") as HTMLDivElement; + if (stickyDiv) { + stickyDiv.style.display = "none"; document.onscroll = function () { - const introCommitDiv = document.getElementById("introduction") as HTMLDivElement; + const stickyDisplayerDiv = document.getElementById("sticky-displayer") as HTMLDivElement; - if (introCommitDiv) { + if (stickyDisplayerDiv) { const scrollTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop; - if (scrollTop < introCommitDiv.offsetTop - 100) { - commitDiv.style.display = "none"; + if (scrollTop < stickyDisplayerDiv.offsetTop - 100) { + stickyDiv.style.display = "none"; } else { - commitDiv.style.display = "block"; + stickyDiv.style.display = "block"; } } }; diff --git a/resources/views/bo/pages/stickies/form.blade.php b/resources/views/bo/pages/stickies/form.blade.php index 42d5af4..aca78f3 100644 --- a/resources/views/bo/pages/stickies/form.blade.php +++ b/resources/views/bo/pages/stickies/form.blade.php @@ -86,6 +86,27 @@ @endcan + {{-- TYPE --}} + @can('create', \App\Models\Sticky::class) +
+
+ {{ Str::ucfirst(__('validation.custom.color')) }} +
+
+ @include('bo.partials.inputs.tinyint-enum', [ + 'id' => 'stickyColor', + 'label' => __('Associer une couleur'), + 'name' => 'color', + 'model' => $stickyModel ?? null, + 'required' => true, + 'associatedModels' => \App\Enums\StickiesColorEnum::toArray(), + 'helper' => __('Sélectionnez une couleur dans la liste déroulante.'), + ]) +
+
+
+
+ @endcan

{{ __('validation.custom.required_fields') }}

diff --git a/resources/views/fo/layouts/header.blade.php b/resources/views/fo/layouts/header.blade.php index 4f789fc..71768bd 100644 --- a/resources/views/fo/layouts/header.blade.php +++ b/resources/views/fo/layouts/header.blade.php @@ -7,27 +7,21 @@ @include('fo.layouts.search') --}} - @if (request()->routeIs('fo.commit.show')) -
-
-
- {{-- blade-formatter-disable --}} - @php - $commitNav = [ - ['label' => __('Élever durablement'), 'link' => '#breeding', 'color' => 'tertiary'], - ['label' => __('Mieux vivre'), 'link' => '#life', 'color' => 'quad'], - ['label' => __('Respecter la terre'), 'link' => '#earth', 'color' => 'quint'], - ['label' => __('Bien nourrir'), 'link' => '#feed', 'color' => 'sixt']]; - @endphp - {{-- blade-formatter-enable --}} - @foreach ($commitNav as $key => $value) + + @if (isset($navLinks)) +
+