diff --git a/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php b/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php index b6c7057..f4baaa1 100644 --- a/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php +++ b/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php @@ -2,6 +2,7 @@ namespace App\Containers\Schedule\UI\WEB\Controllers; +use App\Containers\InstituteStructure\Models\Faculty; use App\Containers\Schedule\Models\EducationalGroup; use App\Containers\Schedule\UI\WEB\Transformers\EducationalGroupResource; use App\Ship\Contracts\SeoServiceInterface; @@ -25,7 +26,11 @@ class ClientScheduleController extends Controller }) ->when(request()->input('form'), function ($query, $form) { $query->where('education_form_id', FormEducation::fromName($form)->value); - + }) + ->when(request()->input('faculty'), function ($query, $facultySlug) { + $query->whereHas('faculty', function ($q) use ($facultySlug) { + $q->where('slug', $facultySlug); + }); }) ->with('schedules') ->with('faculty') @@ -49,12 +54,19 @@ class ClientScheduleController extends Controller $forms_education[$case->name] = $case->getLabel(); } + $faculties = Faculty::query()->where('is_active', true)->get(); + $filters = [ 'form_education_filter' => [ 'type' => 'form', 'value' => request()->input('form'), 'param' => 'form' ], + 'faculty_filter' => [ + 'type' => 'faculty', + 'value' => request()->input('faculty'), + 'param' => 'faculty' + ], 'search_filter' => [ 'type' => 'search', 'value' => $request->input('search'), @@ -77,6 +89,7 @@ class ClientScheduleController extends Controller 'schedulesByFaculty' => inertia()->deepMerge(fn() => $schedulesByFaculty), 'schedules_paginator' => $schedulesPaginate, 'seo' => $seo, + 'faculties' => $faculties, ] ); diff --git a/resources/js/Pages/Client/Schedules/Index.vue b/resources/js/Pages/Client/Schedules/Index.vue index a1582e8..764c2f8 100644 --- a/resources/js/Pages/Client/Schedules/Index.vue +++ b/resources/js/Pages/Client/Schedules/Index.vue @@ -12,21 +12,25 @@ import FormEducationalFilter from "@/componentss/shared/filter/filters/FormEduca import MetaTags from "@/componentss/shared/SEO/MetaTags.vue"; import BreadcrumbsItem from "@/componentss/shared/Breadcrumbs/BreadcrumbsItem.vue"; import BaseBreadcrumbs from "@/componentss/shared/Breadcrumbs/BaseBreadcrumbs.vue"; +import FavoriteFilter from "@/componentss/features/schedules/components/FavoriteFilter.vue"; +import FacultyFilter from "@/componentss/features/schedules/components/FacultyFilter.vue"; +import SearchFilter from "@/componentss/features/schedules/components/SearchFilter.vue"; export default { name: "Index", data() { return { - searchInput: this.filters.search_filter.value, favoriteGroups: JSON.parse(localStorage.getItem('favoriteGroups')), showFavorites: false, loading: false, currentPageLoaded: this.schedules_paginator.current_page, - }; }, components: { + SearchFilter, + FacultyFilter, + FavoriteFilter, BaseBreadcrumbs, BreadcrumbsItem, WhenVisible, MetaTags, @@ -57,34 +61,12 @@ export default { }, breadcrumbs: { type: Object - } + }, + faculties: { + type: Object + }, }, methods: { - search: debounce(function () { - if(this.searchInput === "") { - let url = new URL(window.location.href); - url.searchParams.delete('search'); - let newUrl = url.toString(); - this.$inertia.visit(newUrl,{ - method: 'get', - preserveState: true, - replace: true, - }); - } else { - let url = new URL(window.location.href); - url.searchParams.delete('page'); - let newUrl = url.toString(); - this.$inertia.visit(newUrl,{ - method: 'get', - data: { - search: this.searchInput, - }, - preserveState: true, - replace: true, - }) - } - }, 500), - toggleFavorite(group) { if (!this.favoriteGroups) { this.favoriteGroups = []; @@ -107,66 +89,6 @@ export default { } return this.favoriteGroups.some(g => g === group); }, - toggleShowFavorites() { - this.loading = true; // Включаем состояние загрузки - - if (this.filters.favorite_filter.value === null) { - this.filterFavorite(() => { - this.loading = false; // Выключаем состояние загрузки после завершения - }); - } else { - this.clearFilterFavorite(() => { - this.loading = false; // Выключаем состояние загрузки после завершения - }); - } - }, - - filterFavorite: debounce(function (callback) { - let url = new URL(window.location.href); - // Создаем массив для хранения всех ключей, которые нужно удалить - const keysToDelete = []; - - // Перебираем все параметры и добавляем ключи, начинающиеся с 'category', в массив - for (const [key] of url.searchParams) { - if (key.startsWith('favorite')) { - keysToDelete.push(key); - } - } - // Удаляем все ключи из массива - keysToDelete.forEach(key => url.searchParams.delete(key)); - let newUrl = url.toString(); - this.$inertia.visit(newUrl, { - method: 'get', - preserveState: true, - data: { - favorite: (this.favoriteGroups?.length !== 0) ? this.favoriteGroups : "", - }, - onFinish: callback, // Вызываем колбэк после завершения запроса - }); - }, 500), - clearFilterFavorite(callback) { - let url = new URL(window.location.href); - // Создаем массив для хранения всех ключей, которые нужно удалить - const keysToDelete = []; - - // Перебираем все параметры и добавляем ключи, начинающиеся с 'category', в массив - for (const [key] of url.searchParams) { - if (key.startsWith('favorite')) { - keysToDelete.push(key); - } - } - // Удаляем все ключи из массива - keysToDelete.forEach(key => url.searchParams.delete(key)); - let newUrl = url.toString(); - this.$inertia.visit(newUrl, { - method: 'get', - preserveState: true, - onFinish: callback, // Вызываем колбэк после завершения запроса - - }); - }, - }, - computed: { }, }; @@ -186,47 +108,14 @@ export default { bottom-text="Просто введите название группы" header="Расписание занятий" />