From 2f2ffd16e23b20829998886797e91a478d283bd5 Mon Sep 17 00:00:00 2001 From: jayushi-canyon Date: Wed, 16 Oct 2024 20:59:09 +0530 Subject: [PATCH] [AIDAPP-307]: Introduce the ability to mark an article as "Featured" for display in the client portal (#281) * Set Feature toggle and tag for articles * chore: fix enforcement of copyright on all files * chore: fix code style * Change column name to is_featured * chore: fix code style --------- Co-authored-by: jayushi-canyon Co-authored-by: joelicatajr --- ...olumn_in_knowledge_base_articles_table.php | 55 +++++++++++++++++++ .../Pages/CreateKnowledgeBaseItem.php | 21 +++++-- .../Pages/EditKnowledgeBaseItemMetadata.php | 21 +++++-- .../src/Models/KnowledgeBaseItem.php | 2 + .../KnowledgeBaseArticleData.php | 1 + ...ledgeManagementPortalArticleController.php | 4 +- ...edgeManagementPortalCategoryController.php | 3 + app/Features/FeaturedArticle.php | 47 ++++++++++++++++ ...ctivate_featured_flag_featured_article.php | 50 +++++++++++++++++ .../src/Components/Article.vue | 2 +- .../src/Components/Tags.vue | 5 ++ .../src/Pages/ViewArticle.vue | 2 +- 12 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 app-modules/knowledge-base/database/migrations/2024_10_14_102603_add_featured_column_in_knowledge_base_articles_table.php create mode 100644 app/Features/FeaturedArticle.php create mode 100644 database/migrations/2024_10_14_102853_data_activate_featured_flag_featured_article.php diff --git a/app-modules/knowledge-base/database/migrations/2024_10_14_102603_add_featured_column_in_knowledge_base_articles_table.php b/app-modules/knowledge-base/database/migrations/2024_10_14_102603_add_featured_column_in_knowledge_base_articles_table.php new file mode 100644 index 000000000..ea63f4e3c --- /dev/null +++ b/app-modules/knowledge-base/database/migrations/2024_10_14_102603_add_featured_column_in_knowledge_base_articles_table.php @@ -0,0 +1,55 @@ + + + Copyright © 2016-2024, Canyon GBS LLC. All rights reserved. + + Aiding App™ is licensed under the Elastic License 2.0. For more details, + see + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Aiding App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + or contact us via email at legal@canyongbs.com. + + +*/ + +use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; + +return new class () extends Migration { + public function up(): void + { + Schema::table('knowledge_base_articles', function (Blueprint $table) { + $table->boolean('is_featured')->default(false); + }); + } + + public function down(): void + { + Schema::table('knowledge_base_articles', function (Blueprint $table) { + $table->dropColumn('is_featured'); + }); + } +}; diff --git a/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/CreateKnowledgeBaseItem.php b/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/CreateKnowledgeBaseItem.php index 133999d47..1503825df 100644 --- a/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/CreateKnowledgeBaseItem.php +++ b/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/CreateKnowledgeBaseItem.php @@ -37,7 +37,9 @@ namespace AidingApp\KnowledgeBase\Filament\Resources\KnowledgeBaseItemResource\Pages; use Filament\Forms\Form; +use App\Features\FeaturedArticle; use App\Models\Scopes\TagsForClass; +use Filament\Forms\Components\Grid; use Filament\Forms\Components\Select; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\Section; @@ -66,11 +68,20 @@ public function form(Form $form): Form ->label('Article Title') ->required() ->string(), - Toggle::make('public') - ->label('Public') - ->default(false) - ->onColor('success') - ->offColor('gray'), + Grid::make(2) + ->schema([ + Toggle::make('public') + ->label('Public') + ->default(false) + ->onColor('success') + ->offColor('gray'), + Toggle::make('is_featured') + ->label('Featured') + ->default(false) + ->onColor('success') + ->offColor('gray') + ->visible(FeaturedArticle::active()), + ]), Textarea::make('notes') ->label('Notes') ->string(), diff --git a/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/EditKnowledgeBaseItemMetadata.php b/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/EditKnowledgeBaseItemMetadata.php index 0c79eddff..aff00399a 100644 --- a/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/EditKnowledgeBaseItemMetadata.php +++ b/app-modules/knowledge-base/src/Filament/Resources/KnowledgeBaseItemResource/Pages/EditKnowledgeBaseItemMetadata.php @@ -36,7 +36,9 @@ namespace AidingApp\KnowledgeBase\Filament\Resources\KnowledgeBaseItemResource\Pages; +use App\Features\FeaturedArticle; use App\Models\Scopes\TagsForClass; +use Filament\Forms\Components\Grid; use Filament\Forms\Components\Select; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\Section; @@ -56,11 +58,20 @@ public function form(): array return [ Section::make() ->schema([ - Toggle::make('public') - ->label('Public') - ->default(false) - ->onColor('success') - ->offColor('gray'), + Grid::make(2) + ->schema([ + Toggle::make('public') + ->label('Public') + ->default(false) + ->onColor('success') + ->offColor('gray'), + Toggle::make('is_featured') + ->label('Featured') + ->default(false) + ->onColor('success') + ->offColor('gray') + ->visible(FeaturedArticle::active()), + ]), Textarea::make('notes') ->label('Notes') ->columnSpanFull() diff --git a/app-modules/knowledge-base/src/Models/KnowledgeBaseItem.php b/app-modules/knowledge-base/src/Models/KnowledgeBaseItem.php index daf73cddb..de7f9bc2e 100644 --- a/app-modules/knowledge-base/src/Models/KnowledgeBaseItem.php +++ b/app-modules/knowledge-base/src/Models/KnowledgeBaseItem.php @@ -64,6 +64,7 @@ class KnowledgeBaseItem extends BaseModel implements Auditable, HasMedia, HasTag protected $table = 'knowledge_base_articles'; protected $casts = [ + 'is_featured' => 'boolean', 'public' => 'boolean', 'article_details' => 'array', ]; @@ -76,6 +77,7 @@ class KnowledgeBaseItem extends BaseModel implements Auditable, HasMedia, HasTag 'quality_id', 'status_id', 'title', + 'is_featured', ]; public function quality(): BelongsTo diff --git a/app-modules/portal/src/DataTransferObjects/KnowledgeBaseArticleData.php b/app-modules/portal/src/DataTransferObjects/KnowledgeBaseArticleData.php index 91d800468..f38482e6d 100644 --- a/app-modules/portal/src/DataTransferObjects/KnowledgeBaseArticleData.php +++ b/app-modules/portal/src/DataTransferObjects/KnowledgeBaseArticleData.php @@ -47,5 +47,6 @@ public function __construct( public ?string $lastUpdated, public ?string $content, public ?array $tags, + public bool $featured, ) {} } diff --git a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalArticleController.php b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalArticleController.php index 4ebc2cf92..f8db18603 100644 --- a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalArticleController.php +++ b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalArticleController.php @@ -36,6 +36,7 @@ namespace AidingApp\Portal\Http\Controllers\KnowledgeManagementPortal; +use App\Features\FeaturedArticle; use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use AidingApp\KnowledgeBase\Models\KnowledgeBaseItem; @@ -60,7 +61,7 @@ public function show(KnowledgeBaseCategory $category, KnowledgeBaseItem $article 'categoryId' => $article->category_id, 'name' => $article->title, 'lastUpdated' => $article->updated_at->format('M d Y, h:m a'), - 'content' => tiptap_converter()->record($article, attribute: 'article_details')->asHTML($article->article_details), + 'content' => $article->article_details ? tiptap_converter()->record($article, attribute: 'article_details')->asHTML($article->article_details) : '', 'tags' => $article->tags() ->orderBy('name') ->select([ @@ -69,6 +70,7 @@ public function show(KnowledgeBaseCategory $category, KnowledgeBaseItem $article ]) ->get() ->toArray(), + 'featured' => FeaturedArticle::active() ? $article->is_featured : false, ]), 'portal_view_count' => $article->portal_view_count, ]); diff --git a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php index d0a20d976..561c2b80d 100644 --- a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php +++ b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php @@ -36,6 +36,7 @@ namespace AidingApp\Portal\Http\Controllers\KnowledgeManagementPortal; +use App\Features\FeaturedArticle; use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use AidingApp\KnowledgeBase\Models\KnowledgeBaseCategory; @@ -79,6 +80,8 @@ public function show(KnowledgeBaseCategory $category): JsonResponse $category->name = $category->title; $category->categoryId = $category->category_id; $category->id = $category->getKey(); + + $category->featured = FeaturedArticle::active() ? $category->is_featured : false; $category->tags = $category->tags() ->orderBy('name') ->select([ diff --git a/app/Features/FeaturedArticle.php b/app/Features/FeaturedArticle.php new file mode 100644 index 000000000..0b4a3bae4 --- /dev/null +++ b/app/Features/FeaturedArticle.php @@ -0,0 +1,47 @@ + + + Copyright © 2016-2024, Canyon GBS LLC. All rights reserved. + + Aiding App™ is licensed under the Elastic License 2.0. For more details, + see + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Aiding App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + or contact us via email at legal@canyongbs.com. + + +*/ + +namespace App\Features; + +use App\Support\AbstractFeatureFlag; + +class FeaturedArticle extends AbstractFeatureFlag +{ + public function resolve(mixed $scope): mixed + { + return false; + } +} diff --git a/database/migrations/2024_10_14_102853_data_activate_featured_flag_featured_article.php b/database/migrations/2024_10_14_102853_data_activate_featured_flag_featured_article.php new file mode 100644 index 000000000..f458baca2 --- /dev/null +++ b/database/migrations/2024_10_14_102853_data_activate_featured_flag_featured_article.php @@ -0,0 +1,50 @@ + + + Copyright © 2016-2024, Canyon GBS LLC. All rights reserved. + + Aiding App™ is licensed under the Elastic License 2.0. For more details, + see + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Aiding App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + or contact us via email at legal@canyongbs.com. + + +*/ + +use App\Features\FeaturedArticle; +use Illuminate\Database\Migrations\Migration; + +return new class () extends Migration { + public function up(): void + { + FeaturedArticle::activate(); + } + + public function down(): void + { + FeaturedArticle::deactivate(); + } +}; diff --git a/portals/knowledge-management/src/Components/Article.vue b/portals/knowledge-management/src/Components/Article.vue index bbd4cd009..72da8cfe9 100644 --- a/portals/knowledge-management/src/Components/Article.vue +++ b/portals/knowledge-management/src/Components/Article.vue @@ -60,7 +60,7 @@ class="opacity-0 h-5 w-5 text-primary-600 transition-all group-hover:translate-x-2 group-hover:opacity-100" /> - + diff --git a/portals/knowledge-management/src/Components/Tags.vue b/portals/knowledge-management/src/Components/Tags.vue index 998325320..58e6d2063 100644 --- a/portals/knowledge-management/src/Components/Tags.vue +++ b/portals/knowledge-management/src/Components/Tags.vue @@ -40,11 +40,16 @@ type: Array, required: true, }, + featured: { + type: Boolean, + default: false, + }, }); diff --git a/portals/knowledge-management/src/Pages/ViewArticle.vue b/portals/knowledge-management/src/Pages/ViewArticle.vue index 39a26e2cd..45f5159c2 100644 --- a/portals/knowledge-management/src/Pages/ViewArticle.vue +++ b/portals/knowledge-management/src/Pages/ViewArticle.vue @@ -120,7 +120,7 @@ Last updated: {{ article.lastUpdated }} - +