Skip to content

Commit

Permalink
Merge branch 'main' of github.com:canyongbs/aidingapp into Operationa…
Browse files Browse the repository at this point in the history
…l-Excellence/AIDAPP-327
  • Loading branch information
kandarp-canyon committed Oct 28, 2024
2 parents 47a9847 + 244b065 commit 3e3ab9f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public function show(KnowledgeBaseCategory $category, KnowledgeBaseItem $article
$voterType = session()->has('guest_id') ? (new PortalGuest())->getMorphClass() : (new Contact())->getMorphClass();
$voterId = session()->has('guest_id') ? session('guest_id') : auth('contact')->user()?->getKey();

$totalVotes = $article->votes->count();
$helpfulVotes = $article->votes->where('is_helpful', true)->count();

$helpfulVotePercentage = 0;

if (ArticleWasHelpful::active() && $totalVotes > 0) {

Check failure on line 65 in app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalArticleController.php

View workflow job for this annotation

GitHub Actions / Code Checks / lint

Call to static method active() on an unknown class AidingApp\Portal\Http\Controllers\KnowledgeManagementPortal\ArticleWasHelpful.
$helpfulVotePercentage = round(($helpfulVotes / $totalVotes) * 100, 0);
}

if (! $article->public) {
return response()->json([], 401);
}
Expand Down Expand Up @@ -94,6 +103,7 @@ public function show(KnowledgeBaseCategory $category, KnowledgeBaseItem $article
'featured' => $article->is_featured,
]),
'portal_view_count' => $article->portal_view_count,
'helpful_vote_percentage' => $helpfulVotePercentage,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use AidingApp\Portal\Models\PortalGuest;
use AidingApp\KnowledgeBase\Models\KnowledgeBaseItem;
use AidingApp\Portal\Models\KnowledgeBaseArticleVote;
use AidingApp\Portal\Http\Requests\StoreKnowledgeBaseArticleVoteRequest;

Expand Down Expand Up @@ -72,6 +73,20 @@ public function __invoke(StoreKnowledgeBaseArticleVoteRequest $request): JsonRes
$voter->knowledgeBaseArticleVotes()->where('article_id', $request->article_id)->delete();
}
}
$helpfulVoteData = KnowledgeBaseItem::withCount([
'votes',
'votes as helpful_votes_count' => function ($query) {
$query->where('is_helpful', true);
},
])->find($request->article_id);

$helpfulVotePercentage = 0;

if ($helpfulVoteData->votes_count > 0) {
$helpfulVotePercentage = round(($helpfulVoteData->helpful_votes_count / $helpfulVoteData->votes_count) * 100, 0);
}

$articleVote['helpful_vote_percentage'] = $helpfulVotePercentage;

return response()->json($articleVote, 200);
}
Expand Down
17 changes: 13 additions & 4 deletions portals/knowledge-management/src/Pages/ViewArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
const portalViewCount = ref(0);
const portalViewCountFlag = ref(false);
const feedback = ref(null);
const helpfulVotePercentage = ref(0);
watch(
route,
Expand All @@ -94,6 +95,7 @@
article.value = response.data.article;
portalViewCount.value = response.data.portal_view_count;
feedback.value = response.data.article.vote ? response.data.article.vote.is_helpful : null;
helpfulVotePercentage.value = response.data.helpful_vote_percentage;
}
loading.value = false;
Expand All @@ -112,11 +114,15 @@
article_id: route.params.articleId,
})
.then((response) => {
if (response.status === 200 && !response.data) {
feedback.value = null;
} else if (response.status === 200) {
feedback.value = response.data.is_helpful;
if (response.status === 200) {
if (response.data.hasOwnProperty('is_helpful') && response.data.is_helpful !== null) {
feedback.value = response.data.is_helpful;
} else {
feedback.value = null;
}
}
helpfulVotePercentage.value = response.data.helpful_vote_percentage;
})
.catch((error) => {
console.error('Error submitting feedback:', error);
Expand Down Expand Up @@ -192,6 +198,9 @@
<span class="text-sm">No</span>
</button>
</div>
<p class="text-lg font-semibold ml-4" v-if="helpfulVotePercentage">
{{ helpfulVotePercentage }}% of visitors found this helpful.
</p>
</div>
</div>
<div class="flex items-center justify-center min-h-screen bg-gray-100" v-else>
Expand Down

0 comments on commit 3e3ab9f

Please sign in to comment.