Skip to content

Commit

Permalink
[AIDAPP-307]: Introduce the ability to mark an article as "Featured" …
Browse files Browse the repository at this point in the history
…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 <jayushi-canyon@users.noreply.github.com>
Co-authored-by: joelicatajr <joelicatajr@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent f51ed2c commit 2f2ffd1
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
<COPYRIGHT>
Copyright © 2016-2024, Canyon GBS LLC. All rights reserved.
Aiding App™ is licensed under the Elastic License 2.0. For more details,
see <https://github.com/canyongbs/aidingapp/blob/main/LICENSE.>
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
<https://www.canyongbs.com> or contact us via email at legal@canyongbs.com.
</COPYRIGHT>
*/

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');
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions app-modules/knowledge-base/src/Models/KnowledgeBaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
Expand All @@ -76,6 +77,7 @@ class KnowledgeBaseItem extends BaseModel implements Auditable, HasMedia, HasTag
'quality_id',
'status_id',
'title',
'is_featured',
];

public function quality(): BelongsTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ public function __construct(
public ?string $lastUpdated,
public ?string $content,
public ?array $tags,
public bool $featured,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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([
Expand All @@ -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,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down
47 changes: 47 additions & 0 deletions app/Features/FeaturedArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
<COPYRIGHT>
Copyright © 2016-2024, Canyon GBS LLC. All rights reserved.
Aiding App™ is licensed under the Elastic License 2.0. For more details,
see <https://github.com/canyongbs/aidingapp/blob/main/LICENSE.>
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
<https://www.canyongbs.com> or contact us via email at legal@canyongbs.com.
</COPYRIGHT>
*/

namespace App\Features;

use App\Support\AbstractFeatureFlag;

class FeaturedArticle extends AbstractFeatureFlag
{
public function resolve(mixed $scope): mixed
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
<COPYRIGHT>
Copyright © 2016-2024, Canyon GBS LLC. All rights reserved.
Aiding App™ is licensed under the Elastic License 2.0. For more details,
see <https://github.com/canyongbs/aidingapp/blob/main/LICENSE.>
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
<https://www.canyongbs.com> or contact us via email at legal@canyongbs.com.
</COPYRIGHT>
*/

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();
}
};
2 changes: 1 addition & 1 deletion portals/knowledge-management/src/Components/Article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
</div>
<Tags :tags="article.tags" />
<Tags :tags="article.tags" :featured="article.featured" />
</router-link>
</template>

Expand Down
5 changes: 5 additions & 0 deletions portals/knowledge-management/src/Components/Tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@
type: Array,
required: true,
},
featured: {
type: Boolean,
default: false,
},
});
</script>

<template>
<div class="flex flex-wrap gap-2">
<Badge v-if="featured" value="Featured" />
<Badge v-for="tag in tags" :key="tag.id" :value="tag.name" />
</div>
</template>
2 changes: 1 addition & 1 deletion portals/knowledge-management/src/Pages/ViewArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<span class="text-xs">Last updated: {{ article.lastUpdated }}</span>
</div>
</div>
<Tags :tags="article.tags" />
<Tags :tags="article.tags" :featured="article.featured" />
<hr class="my-4" />
<div v-html="DOMPurify.sanitize(article.content)"></div>
</div>
Expand Down

0 comments on commit 2f2ffd1

Please sign in to comment.