From caca99a8230eb8f67c88b0547b2a260c20350c67 Mon Sep 17 00:00:00 2001 From: GitStart <1501599+gitstart@users.noreply.github.com> Date: Tue, 14 Feb 2023 01:27:17 +0300 Subject: [PATCH] fix : Help Center article view count (#6429) * fix: resolves issue with non updating article view count Co-authored-by: BikashSah999 <51731962+BikashSah999@users.noreply.github.com> * Update articles_controller.rb --------- Co-authored-by: BikashSah999 <51731962+BikashSah999@users.noreply.github.com> Co-authored-by: Pranav Raj S --- app/controllers/api/v1/accounts/articles_controller.rb | 3 ++- app/controllers/public/api/v1/portals/articles_controller.rb | 2 ++ .../routes/dashboard/helpcenter/components/ArticleItem.vue | 4 ++-- .../routes/dashboard/helpcenter/components/ArticleTable.vue | 2 +- .../helpcenter/components/stories/ArticleItem.stories.js | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/accounts/articles_controller.rb b/app/controllers/api/v1/accounts/articles_controller.rb index 847db90d0..b6e07be5f 100644 --- a/app/controllers/api/v1/accounts/articles_controller.rb +++ b/app/controllers/api/v1/accounts/articles_controller.rb @@ -55,7 +55,8 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController def article_params params.require(:article).permit( - :title, :slug, :content, :description, :position, :category_id, :author_id, :associated_article_id, :status, meta: [:title, :description, + :title, :slug, :content, :description, :position, :category_id, :author_id, :associated_article_id, :status, meta: [:title, + :description, { tags: [] }] ) end diff --git a/app/controllers/public/api/v1/portals/articles_controller.rb b/app/controllers/public/api/v1/portals/articles_controller.rb index ae0fb2b6a..bd490f240 100644 --- a/app/controllers/public/api/v1/portals/articles_controller.rb +++ b/app/controllers/public/api/v1/portals/articles_controller.rb @@ -16,6 +16,8 @@ class Public::Api::V1::Portals::ArticlesController < PublicController def set_article @article = @category.articles.find(params[:id]) + @article.views = @article.views ? @article.views + 1 : 1 + @article.save @parsed_content = render_article_content(@article.content) end diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue index 254302074..759389da6 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleItem.vue @@ -30,7 +30,7 @@ - {{ readCount }} + {{ views || 0 }} @@ -76,7 +76,7 @@ export default { type: Object, default: () => {}, }, - readCount: { + views: { type: Number, default: 0, }, diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleTable.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleTable.vue index 1f61f3bb7..515570195 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleTable.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/ArticleTable.vue @@ -21,7 +21,7 @@ :title="article.title" :author="article.author" :category="article.category" - :read-count="article.readCount" + :views="article.views" :status="article.status" :updated-at="article.updated_at" /> diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/stories/ArticleItem.stories.js b/app/javascript/dashboard/routes/dashboard/helpcenter/components/stories/ArticleItem.stories.js index 7f7c819e3..303a96cb6 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/stories/ArticleItem.stories.js +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/stories/ArticleItem.stories.js @@ -15,7 +15,7 @@ export default { type: 'text', }, }, - readCount: { + views: { defaultValue: 13, control: { type: 'number', @@ -57,7 +57,7 @@ ArticleItem.args = { name: 'John Doe', }, category: 'Getting started', - readCount: 12, + views: 12, status: 'published', updatedAt: 1657255863, };