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/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/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/ts/fo/base/common.ts b/resources/ts/fo/base/common.ts index 3a07c40..1e2a948 100644 --- a/resources/ts/fo/base/common.ts +++ b/resources/ts/fo/base/common.ts @@ -346,42 +346,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/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 }} -
+
+
@foreach ($carousel->media as $medias) @@ -18,6 +22,10 @@ class="position-relative swiper-pagination swiper-carousels-pagination swiper-pagination-clickable swiper-pagination-bullets swiper-pagination-horizontal d-flex justify-content-center align-items-center mt-5 flex-nowrap px-5">
+
@endif diff --git a/routes/web-bo.php b/routes/web-bo.php index 9604b7d..b616fea 100644 --- a/routes/web-bo.php +++ b/routes/web-bo.php @@ -210,6 +210,10 @@ Route::middleware(['admin-secure'])->prefix('bo') CarouselController::class, 'changePublished' ])->name('carousels.change-published'); + Route::patch('/carousels/{carousel}/change-order', [ + CarouselController::class, + 'changeCustomOrder' + ])->name('carousels.change-order'); // * BRANDS Route::resource('brands', BrandController::class)->except('show')