diff --git a/app/Http/Controllers/Bo/CarouselController.php b/app/Http/Controllers/Bo/CarouselController.php index 90c8d98..0eeb469 100644 --- a/app/Http/Controllers/Bo/CarouselController.php +++ b/app/Http/Controllers/Bo/CarouselController.php @@ -8,6 +8,8 @@ use App\Http\Requests\Bo\Carousels\UpdateCarouselRequest; use App\Lib\Helpers\FileStorageHelper; use App\Models\Carousel; use App\Models\Section; +use App\Traits\Controllers\UpdateModelOrder; +use App\Traits\Controllers\UpdateModelPublished; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; @@ -15,6 +17,9 @@ use Illuminate\Support\Str; class CarouselController extends Controller { + use UpdateModelOrder; + use UpdateModelPublished; + /** * Create the controller instance. */ diff --git a/app/Http/Controllers/Fo/StaticPageController.php b/app/Http/Controllers/Fo/StaticPageController.php index 07bcc21..fd496bf 100644 --- a/app/Http/Controllers/Fo/StaticPageController.php +++ b/app/Http/Controllers/Fo/StaticPageController.php @@ -278,7 +278,7 @@ class StaticPageController extends Controller $testimonialSection = $sectionModels->where('section', PageSectionEnum::hire_grow)->first(); $paritySection = $sectionModels->where('section', PageSectionEnum::hire_parity)->first(); $findSection = $sectionModels->where('section', PageSectionEnum::hire_find)->first(); - $carouselSectionParity = Carousel::query()->where('section_id', PageSectionEnum::hire_parity)->where('published', true)->get(); + $carouselSectionParity = Carousel::query()->where('section_id', PageSectionEnum::hire_parity)->where('published', true)->orderBy('order')->get(); $navLinks = Sticky::query()->where('type', StaticPageType::we_hire)->get(); return view('fo.pages.hire', \compact( diff --git a/app/Models/Aisle.php b/app/Models/Aisle.php index 17d0287..46b7b35 100644 --- a/app/Models/Aisle.php +++ b/app/Models/Aisle.php @@ -94,9 +94,11 @@ class Aisle extends Model private static function assertLimitPublishedModels(self $model, bool $isDeletion = false) { $count = self::query()->where('published', true)->where('network_id', $model->network_id)->count(); + $updatePublished = !$isDeletion && $model->published && !$model->getOriginal('published'); + if ( (!$model->published && $count <= 1) || - ($model->published && $count >= 4) || + ($updatePublished && $count >= 4) || ($isDeletion && $count === 1) ) { throw ValidationException::withMessages([ diff --git a/app/Models/Brand.php b/app/Models/Brand.php index 90baf1a..d583ef0 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -89,11 +89,13 @@ class Brand extends Model */ private static function assertLimitPublishedModels(self $model, bool $isDeletion = false) { - $count = self::query()->where('published', true)->count(); + $count = self::query()->where('published', true)->where('aisle_id', $model->aisle_id)->count(); + $updatePublished = !$isDeletion && $model->published && !$model->getOriginal('published'); + if ( $count !== 0 && ((!$model->published && $count <= 1) || - ($model->published && $count >= 5) || + ($updatePublished && $count >= 5) || ($isDeletion && $count === 1)) ) { throw ValidationException::withMessages([ diff --git a/app/Models/Carousel.php b/app/Models/Carousel.php index 7f91e08..28decd4 100644 --- a/app/Models/Carousel.php +++ b/app/Models/Carousel.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Lib\Helpers\FileStorageHelper; use App\Lib\Helpers\ToolboxHelper; use App\Traits\Models\ActivityLog; +use App\Traits\Models\Orderable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -21,6 +22,7 @@ class Carousel extends Model { use ActivityLog; use HasFactory; + use Orderable; /** * The attributes that are mass assignable. @@ -78,28 +80,14 @@ class Carousel extends Model // * METHODS - /** - * Set order after the last element of the list. + * Group ordering by section_id. * - * @param self $model - * @param boolean $isDeletion - * @return void + * @return string */ - private static function setOrder(self $model, bool $isDeletion = false): void + public function getOrderGroupField(): string { - $maxOrder = \intval(self::query()->where('section_id', $model->section_id)->max('order')); - - if ($isDeletion) { - $request = Carousel::query() - ->where('section_id', $model->section_id) - ->whereNot('id', $model->id) - ->whereBetween('order', [$model->order, $maxOrder]); - $request->decrement('order', 1); - return; - } - - $model->order = $maxOrder + 1; + return 'section_id'; } diff --git a/app/Models/Network.php b/app/Models/Network.php index e4d9397..0d1535f 100644 --- a/app/Models/Network.php +++ b/app/Models/Network.php @@ -138,9 +138,11 @@ class Network extends Model private static function assertLimitPublishedModels(self $model, bool $isDeletion = false) { $count = self::query()->where('published', true)->count(); + $updatePublished = !$isDeletion && $model->published && !$model->getOriginal('published'); + if ( (!$model->published && $count <= 1) || - ($model->published && $count >= 5) || + ($updatePublished && $count >= 5) || ($isDeletion && $count === 1) ) { throw ValidationException::withMessages([ diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 4cfd0e0..0c133f4 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -5,6 +5,7 @@ namespace App\Providers; use App\Http\Middleware\VerifyCsrfToken; use App\Models\Aisle; use App\Models\Brand; +use App\Models\Carousel; use App\Models\Network; use App\Models\News; use App\Models\Strip; @@ -53,6 +54,7 @@ class RouteServiceProvider extends ServiceProvider Route::model('network', Network::class); Route::model('aisle', Aisle::class); Route::model('brand', Brand::class); + Route::model('carousel', Carousel::class); Route::bind('publishedNews', function ($value) { return News::where(function ($q) use ($value) { $q->where('slug', $value); diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index dfb5e68..962a5a5 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -303,6 +303,7 @@ return [ 'link' => 'lien de l\'ancre', ], 'media' => 'média', - 'anchor' => 'ancre' + 'anchor' => 'ancre', + 'link' => 'lien', ], ]; diff --git a/resources/sass/fo/pages/_unveil.scss b/resources/sass/fo/pages/_unveil.scss index 36269fc..52f91cc 100644 --- a/resources/sass/fo/pages/_unveil.scss +++ b/resources/sass/fo/pages/_unveil.scss @@ -16,6 +16,18 @@ } } + .swiper-button-prev-custom { + top: 10%; + left: 1rem; + transform: translateY(-50%) rotate(180deg); + } + + .swiper-button-next-custom { + top: 10%; + right: 1rem; + transform: translateY(-50%); + } + .history { #historical-milestone-carousel { .carousel-container { diff --git a/resources/ts/fo/base/common.ts b/resources/ts/fo/base/common.ts index 3a07c40..53f27f0 100644 --- a/resources/ts/fo/base/common.ts +++ b/resources/ts/fo/base/common.ts @@ -159,11 +159,15 @@ document.addEventListener("DOMContentLoaded", function () { }, }, "swiper-year": { - modules: [Keyboard], + modules: [Keyboard, Navigation], grabCursor: true, slidesPerView: 1.5, centeredSlides: true, slideToClickedSlide: true, + navigation: { + nextEl: ".year-next", + prevEl: ".year-prev", + }, keyboard: { enabled: true, }, @@ -346,42 +350,6 @@ document.addEventListener("DOMContentLoaded", function () { }, }, }, - "swiper-carousels": { - modules: [Pagination], - grabCursor: true, - slidesPerView: 1, - spaceBetween: 15, - centeredSlides: true, - initialSlide: 0, - speed: 750, - pagination: { - el: ".swiper-carousels-pagination", - clickable: true, - renderBullet: function (index: number, className: string) { - return ""; - }, - }, - breakpoints: { - 576: { - slidesPerView: 1.5, - }, - 768: { - slidesPerView: 2, - }, - 992: { - slidesPerView: 2.5, - }, - }, - on: { - beforeInit(swiper: Swiper) { - const slideCount = swiper.el.querySelectorAll(".swiper-slide").length; - - if (slideCount !== 2) { - swiper.params.initialSlide = Math.floor(slideCount / 2); - } - } - } - }, }; const swiperVol = document.getElementsByClassName("swiper") as HTMLCollectionOf; diff --git a/resources/ts/fo/fo.ts b/resources/ts/fo/fo.ts index c1c5da6..4969d97 100644 --- a/resources/ts/fo/fo.ts +++ b/resources/ts/fo/fo.ts @@ -22,4 +22,5 @@ import "./base/sticky"; // PAGES import "./pages/unveil"; import "./pages/site"; +import "./pages/hire"; diff --git a/resources/ts/fo/pages/hire.ts b/resources/ts/fo/pages/hire.ts new file mode 100644 index 0000000..1f39d0b --- /dev/null +++ b/resources/ts/fo/pages/hire.ts @@ -0,0 +1,63 @@ +import Swiper from "swiper"; +import { Navigation, Pagination } from "swiper/modules"; + +document.addEventListener("DOMContentLoaded", function () { + const hire = document.querySelector("section.we-hire"); + if (hire === null) { + return; + } + + const swiperContainers = document.querySelectorAll(".swiper-container"); + + swiperContainers.forEach((container, index) => { + const carousel = container.querySelector(".swiper-carousels") as HTMLElement, + btnPrev = container.querySelector(".carousel-prev") as HTMLElement, + btnNext = container.querySelector(".carousel-next") as HTMLElement, + pagination = carousel?.querySelector(".swiper-carousels-pagination") as HTMLElement; + + carousel.classList.add(`swiper-${index}`); + pagination.classList.add(`swiper-pagination-${index}`); + btnPrev.classList.add(`prev-${index}`); + btnNext.classList.add(`next-${index}`); + + new Swiper(carousel, { + modules: [Pagination, Navigation], + grabCursor: true, + slidesPerView: 1, + spaceBetween: 15, + centeredSlides: true, + initialSlide: 0, + speed: 750, + pagination: { + el: `.swiper-pagination-${index}`, + clickable: true, + renderBullet: function (idx, className) { + return ``; + }, + }, + navigation: { + prevEl: `.prev-${index}`, + nextEl: `.next-${index}`, + }, + on: { + beforeInit(swiper: Swiper) { + const slideCount = swiper.el.querySelectorAll(".swiper-slide").length; + if (slideCount !== 2) { + swiper.params.initialSlide = Math.floor(slideCount / 2); + } + }, + }, + breakpoints: { + 576: { + slidesPerView: 1.5 + }, + 768: { + slidesPerView: 2 + }, + 992: { + slidesPerView: 2.5 + }, + }, + }); + }); +}); diff --git a/resources/views/bo/modules/change-model-order-select.blade.php b/resources/views/bo/modules/change-model-order-select.blade.php index 313e09c..ffb643f 100644 --- a/resources/views/bo/modules/change-model-order-select.blade.php +++ b/resources/views/bo/modules/change-model-order-select.blade.php @@ -12,7 +12,7 @@ @method('PATCH')
- +
diff --git a/resources/views/bo/pages/brands/form.blade.php b/resources/views/bo/pages/brands/form.blade.php index ed73c4c..fe868ed 100644 --- a/resources/views/bo/pages/brands/form.blade.php +++ b/resources/views/bo/pages/brands/form.blade.php @@ -34,13 +34,13 @@ {{-- LINK --}}
- {{ Str::ucfirst(__('validation.attributes.link')) }} + {{ Str::ucfirst(__('validation.custom.link')) }}
@include('bo.partials.inputs.varchar', [ 'id' => 'brandLink', 'label' => __(':field :inter:model', [ - 'field' => Str::ucfirst(__('validation.attributes.link')), + 'field' => Str::ucfirst(__('validation.custom.link')), 'inter' => __('validation.custom.of_the.female'), 'model' => trans_choice('models.classes.brand', 1), ]), @@ -50,7 +50,7 @@ 'model' => $brandModel ?? null, 'helper' => __('validation.between.string', [ 'attribute' => __(':field :inter:model', [ - 'field' => __('validation.attributes.link'), + 'field' => __('validation.custom.link'), 'inter' => __('validation.custom.of_the.female'), 'model' => trans_choice('models.classes.brand', 1), ]), diff --git a/resources/views/bo/pages/carousels/index-list.blade.php b/resources/views/bo/pages/carousels/index-list.blade.php index f53cd83..712575a 100644 --- a/resources/views/bo/pages/carousels/index-list.blade.php +++ b/resources/views/bo/pages/carousels/index-list.blade.php @@ -1,18 +1,39 @@ @if (count($carouselModels) > 0) - @include('bo.modules.table-col-sorter', [ - 'cols' => [ + @php + $cols = []; + + if (request()->section) { + $cols = array_merge($cols, [ + 'order' => Str::ucfirst(__('validation.custom.order')), + ]); + } + + $cols = array_merge($cols, [ 'title' => Str::ucfirst(__('validation.attributes.title')), 'section_id' => Str::ucfirst(trans_choice('models.classes.section', 1)), 'published' => Str::ucfirst(__('validation.custom.activated')), 'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')), - ], + ]); + @endphp + + @include('bo.modules.table-col-sorter', [ + $cols ]) @foreach ($carouselModels as $carouselModel) + @php + $routeName = request()->route()->getName(); + @endphp + @if (request()->section && empty(request()->search) && Session::get("$routeName.sort_col") === 'order') + @include('bo.modules.change-model-order-select', [ + 'routeName' => 'carousels', + 'model' => $carouselModel, + ]) + @endif
{{ $carouselModel->title }} @endforeach +
+
+