From 96d035581011cb3229254df9a5f707cebcd0b893 Mon Sep 17 00:00:00 2001 From: amit-canyon Date: Mon, 28 Oct 2024 06:20:13 +0000 Subject: [PATCH 1/4] Enhance the display of articles by all articles, featured articles, and most viewed articles --- ...edgeManagementPortalCategoryController.php | 6 ++ ...wledgeManagementPortalSearchController.php | 6 ++ .../src/Components/FilterComponent.vue | 55 ++++++++++++++++ .../src/Components/SearchResults.vue | 13 +++- .../knowledge-management/src/Pages/Home.vue | 9 +++ .../src/Pages/ViewCategory.vue | 64 ++++++++++++------- 6 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 portals/knowledge-management/src/Components/FilterComponent.vue diff --git a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php index ad66977ad..99f3cd48c 100644 --- a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php +++ b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php @@ -74,6 +74,12 @@ public function show(KnowledgeBaseCategory $category): JsonResponse 'articles' => $category->knowledgeBaseItems() ->with('tags') ->public() + ->when(request()->get('filter') === 'featured', function ($q) { + $q->where('is_featured', true); + }) + ->when(request()->get('filter') === 'most-viewed', function ($q) { + $q->orderBy('portal_view_count', 'desc'); + }) ->paginate(5) ->through(function ($category) { $category->name = $category->title; diff --git a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php index 3c8963400..35268c4b5 100644 --- a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php +++ b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php @@ -69,6 +69,12 @@ public function get(Request $request): KnowledgeManagementSearchData ->with('tags') ->when($search->isNotEmpty(), fn (Builder $query) => $query->tap(new SearchBy('title', $search))) ->when($tags->isNotEmpty(), fn (Builder $query) => $query->whereHas('tags', fn (Builder $query) => $query->whereIn('id', $tags))) + ->when($request->get('filter') === 'featured', function ($q) { + $q->where('is_featured', true); + }) + ->when($request->get('filter') === 'most-viewed', function ($q) { + $q->orderBy('portal_view_count', 'desc'); + }) ->get() ->map(function (KnowledgeBaseItem $article) { return [ diff --git a/portals/knowledge-management/src/Components/FilterComponent.vue b/portals/knowledge-management/src/Components/FilterComponent.vue new file mode 100644 index 000000000..cd17a2103 --- /dev/null +++ b/portals/knowledge-management/src/Components/FilterComponent.vue @@ -0,0 +1,55 @@ + + diff --git a/portals/knowledge-management/src/Components/SearchResults.vue b/portals/knowledge-management/src/Components/SearchResults.vue index 42baf2b8d..be8ee937c 100644 --- a/portals/knowledge-management/src/Components/SearchResults.vue +++ b/portals/knowledge-management/src/Components/SearchResults.vue @@ -37,6 +37,7 @@ import { ChevronRightIcon, XMarkIcon } from '@heroicons/vue/20/solid'; import Tags from './Tags.vue'; import Article from './Article.vue'; + import FilterComponent from './FilterComponent.vue'; defineProps({ searchQuery: { @@ -51,7 +52,17 @@ type: Boolean, required: true, }, + selectedFilter: { + type: String, + default: '', + }, }); + + const emit = defineEmits(['change-filter']); + + const updateFilter = (value) => { + emit('change-filter', value); + };