From 13c45b80d20ab38ca2c50ad1163b076a72f1e2b7 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Thu, 3 Apr 2025 15:11:04 +0500 Subject: [PATCH] Added changes to search by Vicon structure. Added fix for Page view for settings column. --- app/Http/Controllers/SearchController.php | 7 +- .../Controllers/StaticSearchController.php | 5 +- .../AdditionalEducationSearchResource.php | 6 +- app/Http/Resources/EventSearchResource.php | 8 +- app/Http/Resources/FacultySearchResource.php | 6 +- app/Http/Resources/UserSearchResource.php | 6 +- .../Services/HtmlContentExtractorService.php | 26 +++++++ .../Filament/Services/StaticFileSearch.php | 39 +++++++--- public/logos/ntspi.svg | 78 +++++++++++++++++++ public/logos/ntspi_white.svg | 78 +++++++++++++++++++ resources/js/Navbars/MainPageNavbar.vue | 6 +- resources/js/Pages/Page.vue | 6 +- .../Items/ResultAdditionalEducationItem.vue | 26 +++---- .../components/Items/ResultEventItem.vue | 30 +++---- .../components/Items/ResultPostItem.vue | 5 +- .../search/components/StaticSearch.vue | 28 ++----- resources/js/mixins/Helpers.js | 4 +- 17 files changed, 288 insertions(+), 76 deletions(-) create mode 100644 app/Services/Filament/Services/HtmlContentExtractorService.php create mode 100644 public/logos/ntspi.svg create mode 100644 public/logos/ntspi_white.svg diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 861d672..b2e2655 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -9,7 +9,6 @@ use App\Http\Resources\EventSearchResource; use App\Http\Resources\FacultySearchResource; use App\Http\Resources\PageSearchResource; use App\Http\Resources\PostSearchResource; -use App\Http\Resources\StaticPageSearchResource; use App\Http\Resources\UserSearchResource; use App\Models\AdditionalEducation; use App\Models\EducationalGroup; @@ -35,9 +34,9 @@ class SearchController extends Controller EducationalGroup::class => EducationGroupSearchResource::class, EducationalProgram::class => EducationalProgramSearchResource::class, Event::class => EventSearchResource::class, - AdditionalEducation::class => AdditionalEducationSearchResource::class, - User::class => UserSearchResource::class, - Faculty::class => FacultySearchResource::class, + AdditionalEducation::class => AdditionalEducationSearchResource::class, //?? + User::class => UserSearchResource::class, //?? + Faculty::class => FacultySearchResource::class, //?? ]; public function index(Request $request) { diff --git a/app/Http/Controllers/StaticSearchController.php b/app/Http/Controllers/StaticSearchController.php index 8848b9c..7398a6a 100644 --- a/app/Http/Controllers/StaticSearchController.php +++ b/app/Http/Controllers/StaticSearchController.php @@ -12,10 +12,7 @@ class StaticSearchController extends Controller public function search(Request $request) { return app(StaticFileSearch::class) - ->search( - $request->input('search'), - $request->input('page', 1) - ); + ->search($request); } public function getCategories() diff --git a/app/Http/Resources/AdditionalEducationSearchResource.php b/app/Http/Resources/AdditionalEducationSearchResource.php index af8cdaf..b5c26a0 100644 --- a/app/Http/Resources/AdditionalEducationSearchResource.php +++ b/app/Http/Resources/AdditionalEducationSearchResource.php @@ -14,6 +14,10 @@ class AdditionalEducationSearchResource extends JsonResource */ public function toArray(Request $request): array { - return parent::toArray($request); + return [ + 'id' => $this->id, + 'title' => $this->title, + 'slug' => $this->slug, + ]; } } diff --git a/app/Http/Resources/EventSearchResource.php b/app/Http/Resources/EventSearchResource.php index 8ea9663..8fece5d 100644 --- a/app/Http/Resources/EventSearchResource.php +++ b/app/Http/Resources/EventSearchResource.php @@ -14,6 +14,12 @@ class EventSearchResource extends JsonResource */ public function toArray(Request $request): array { - return parent::toArray($request); + return [ + 'id' => $this->id, + 'title' => $this->title, + 'slug' => $this->slug, + 'event_date_start' => $this->event_date_start, + 'event_time_start' => $this->event_time_start + ]; } } diff --git a/app/Http/Resources/FacultySearchResource.php b/app/Http/Resources/FacultySearchResource.php index a394f9c..eccc9ff 100644 --- a/app/Http/Resources/FacultySearchResource.php +++ b/app/Http/Resources/FacultySearchResource.php @@ -14,6 +14,10 @@ class FacultySearchResource extends JsonResource */ public function toArray(Request $request): array { - return parent::toArray($request); + return [ + 'id' => $this->id, + 'title' => $this->title, + 'slug' => $this->slug, + ]; } } diff --git a/app/Http/Resources/UserSearchResource.php b/app/Http/Resources/UserSearchResource.php index 3cd9da9..325b065 100644 --- a/app/Http/Resources/UserSearchResource.php +++ b/app/Http/Resources/UserSearchResource.php @@ -14,6 +14,10 @@ class UserSearchResource extends JsonResource */ public function toArray(Request $request): array { - return parent::toArray($request); + return [ + 'id' => $this->id, + 'name' => $this->name, + 'slug' => $this->slug, + ]; } } diff --git a/app/Services/Filament/Services/HtmlContentExtractorService.php b/app/Services/Filament/Services/HtmlContentExtractorService.php new file mode 100644 index 0000000..954876f --- /dev/null +++ b/app/Services/Filament/Services/HtmlContentExtractorService.php @@ -0,0 +1,26 @@ +first('.vikon-content'); + $breadcrumb = $content->first('.row'); + $content->firstInDocument('.row')->remove(); + + return [$content->html(), $breadcrumb->html()] ?? null; + } + + +} \ No newline at end of file diff --git a/app/Services/Filament/Services/StaticFileSearch.php b/app/Services/Filament/Services/StaticFileSearch.php index 58fdb0b..0b0cdad 100644 --- a/app/Services/Filament/Services/StaticFileSearch.php +++ b/app/Services/Filament/Services/StaticFileSearch.php @@ -2,7 +2,7 @@ namespace App\Services\Filament\Services; -use Illuminate\Http\Client\Request; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; @@ -17,14 +17,19 @@ class StaticFileSearch const CACHE_TTL = 86400; // 24 часа const PER_PAGE = 10; // Количество результатов на страницу - public function search(string $query): array + public function search(Request $request): array { + $query = $request->input('search'); + $category = $request->input('category'); + $page = request()->input('page', 1); + + if ($query === null) { return [ - 'data' => null + 'data' => [] ]; } - $page = request()->input('page', 1); + try { $index = $this->getIndex(); $results = []; @@ -40,7 +45,21 @@ class StaticFileSearch ]; } } - return $this->paginateResults($results, $page); + + $categories = array_values(array_unique(array_filter(array_column($results, 'category')))); + + + if ($category !== null) { + $results = array_filter($results, function($item) use ($category) { + return $item['category'] === $category; + }); + + // Переиндексировать массив + $results = array_values($results); + } + + + return $this->paginateResults($results, $page, $categories); } catch (\Exception $e) { Log::error('Search error: ' . $e->getMessage()); return [ @@ -55,7 +74,7 @@ class StaticFileSearch } } - protected function paginateResults(array $results, int $page): array + protected function paginateResults(array $results, int $page, ?array $categories): array { $total = count($results); $lastPage = max(1, ceil($total / self::PER_PAGE)); @@ -71,7 +90,8 @@ class StaticFileSearch 'total' => $total, 'per_page' => self::PER_PAGE, 'last_page' => $lastPage - ] + ], + 'categories' => $categories ]; } @@ -94,9 +114,10 @@ class StaticFileSearch foreach ($iterator as $file) { if ($file->isFile() && $this->isHtmlFile($file)) { - $content = file_get_contents($file->getPathname()); + $html = file_get_contents($file->getPathname()); + [$content, $breadcrumb] = app(HtmlContentExtractorService::class)->getContent($html); if ($content !== false) { - $breadcrumb = app(BreadcrumbFinderService::class)->isSameCategory($content); + $breadcrumb = app(BreadcrumbFinderService::class)->isSameCategory($breadcrumb); $text = $this->normalizeText(strip_tags($content)); $index[$file->getPathname()] = [ 'title' => $this->getFirstH1Content($content), diff --git a/public/logos/ntspi.svg b/public/logos/ntspi.svg new file mode 100644 index 0000000..336dbdd --- /dev/null +++ b/public/logos/ntspi.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/logos/ntspi_white.svg b/public/logos/ntspi_white.svg new file mode 100644 index 0000000..de9db77 --- /dev/null +++ b/public/logos/ntspi_white.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/js/Navbars/MainPageNavbar.vue b/resources/js/Navbars/MainPageNavbar.vue index b524d8a..ce37127 100644 --- a/resources/js/Navbars/MainPageNavbar.vue +++ b/resources/js/Navbars/MainPageNavbar.vue @@ -96,8 +96,8 @@ export default { headerFilter: false, underSliderHeader: true, logos: { - default: '/logos/white_ntspi_logo.svg', - alternate: '/logos/ntspi-logo.svg', + default: '/logos/ntspi_white.svg', + alternate: '/logos/ntspi.svg', }, } }, @@ -113,7 +113,7 @@ export default { } } - this.headerFilter = this.scrollPosition > 50; + this.headerFilter = this.scrollPosition > 5; }, }, watch: { diff --git a/resources/js/Pages/Page.vue b/resources/js/Pages/Page.vue index 87cdcb9..a506de6 100644 --- a/resources/js/Pages/Page.vue +++ b/resources/js/Pages/Page.vue @@ -6,11 +6,11 @@
- - + +
- +
diff --git a/resources/js/componentss/features/search/components/Items/ResultAdditionalEducationItem.vue b/resources/js/componentss/features/search/components/Items/ResultAdditionalEducationItem.vue index 2e7e9f9..9e99967 100644 --- a/resources/js/componentss/features/search/components/Items/ResultAdditionalEducationItem.vue +++ b/resources/js/componentss/features/search/components/Items/ResultAdditionalEducationItem.vue @@ -1,5 +1,5 @@ diff --git a/resources/js/componentss/features/search/components/Items/ResultEventItem.vue b/resources/js/componentss/features/search/components/Items/ResultEventItem.vue index c4aa2c6..d55a884 100644 --- a/resources/js/componentss/features/search/components/Items/ResultEventItem.vue +++ b/resources/js/componentss/features/search/components/Items/ResultEventItem.vue @@ -4,20 +4,22 @@ - {{ item.data.title }} - -
- -
+
+ {{ item.data.title }} + Начало {{ item.data.event_date_start }} в {{ item.data.event_time_start }} +
+ + + + + + + + + + + + diff --git a/resources/js/componentss/features/search/components/Items/ResultPostItem.vue b/resources/js/componentss/features/search/components/Items/ResultPostItem.vue index c4f8de5..afe5350 100644 --- a/resources/js/componentss/features/search/components/Items/ResultPostItem.vue +++ b/resources/js/componentss/features/search/components/Items/ResultPostItem.vue @@ -3,7 +3,10 @@ - {{ item.data.title }} +
+ {{ item.data.title }} + {{ item.data.created_post }} +
diff --git a/resources/js/componentss/features/search/components/StaticSearch.vue b/resources/js/componentss/features/search/components/StaticSearch.vue index 0e26a53..5eee26a 100644 --- a/resources/js/componentss/features/search/components/StaticSearch.vue +++ b/resources/js/componentss/features/search/components/StaticSearch.vue @@ -28,7 +28,7 @@ name="hs-as-table-product-review-search" class="py-1 placeholder-[#8F8F8F] font-light px-2 block flex-1 w-full border-none text-lg focus:z-10 border-transparent focus:border-transparent focus:ring-0" placeholder="Поиск по сведениям об образовательной организации"> -
- - + @@ -76,8 +75,10 @@ import {debounce} from "lodash"; import {Link} from "@inertiajs/vue3"; import {ruCategories} from "@/assets/data/ruCategories.js"; import ResultList from "@/componentss/features/search/components/ResultList.vue"; +import {helpers} from "@/mixins/Helpers.js"; export default { - name: "GlobalSearch", + mixins: [helpers], + name: "GlobalSearch", data() { return { searchInput: "", @@ -107,9 +108,6 @@ export default { }, search() { - if (!this.categories) { - this.getCategories() - } this.toggleLoadingState(true); this.debouncedSearch(this.searchInput.toLowerCase()); }, @@ -144,9 +142,6 @@ export default { async executeCategory(params) { try { - if (params.category === null) { - return null; - } const response = await axios.get(route('client.search.static'), { params: { search: this.searchInput.toLowerCase(), @@ -179,17 +174,9 @@ export default { updateResults(response) { this.paginate = response.data.meta; this.result = response.data.data; - // this.categories = response.data.result_type; + this.categories = response.data.categories; }, - async getCategories() { - try { - const response = await axios.get(route('client.categories.static')); - this.categories = response.data; - } catch (error) { - console.error('Ошибка при загрузке категорий:', error); - } - }, toggleLoadingState(state) { this.loading = state @@ -204,8 +191,9 @@ export default { return text }, - clearSearch() { + clearFilters() { this.searchInput = "" + this.selectedCategory = null this.search() } }, diff --git a/resources/js/mixins/Helpers.js b/resources/js/mixins/Helpers.js index 93b7c07..9145760 100644 --- a/resources/js/mixins/Helpers.js +++ b/resources/js/mixins/Helpers.js @@ -36,6 +36,8 @@ export const helpers = { locale: 'ru' }); }, - + GET_BASE_URL() { + return window.location.origin + '/'; + } }, }; \ No newline at end of file