Skip to content

Commit

Permalink
add number of wikis to topic card (publiclab#9054)
Browse files Browse the repository at this point in the history
  • Loading branch information
RuthNjeri authored and billymoroney1 committed Dec 28, 2021
1 parent 8f495b5 commit d9f515e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module HomeHelper
def post_count(tag_name, type)
Tag.tagged_node_count(tag_name, type)
end
end
4 changes: 2 additions & 2 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def self.tagged_nodes_by_author(tagname, user_id)
end
end

def self.tagged_node_count(tag_name)
Node.where(status: 1, type: 'note')
def self.tagged_node_count(tag_name, type = 'note')
Node.where(status: 1, type: type)
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', tag_name)
Expand Down
5 changes: 4 additions & 1 deletion app/views/dashboard_v2/_topicCard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
</div>
<div class="card-footer" style="background-color: inherit; border:none;">
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= subscription.tag.name %>"><%= Tag.tagged_node_count(subscription.tag.name) %> <%= translation('tag.index.posts') %> &raquo;</a>
<% note_count = post_count(subscription.tag.name, 'note') %>
<% wiki_count = post_count(subscription.tag.name, 'page') %>
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= subscription.tag.name %>"><%= note_count %> <% if note_count > 1 %> <%= translation('tag.index.post').pluralize %> <% else %> <%= translation('tag.index.post') %> <% end %></a> |
<a style="text-decoration:underline;color:#808080;display:inline-block;" href="/wiki/<%= subscription.tag.name %>"><%= wiki_count %><% if wiki_count > 1 %> <%= translation('tag.index.wiki').pluralize %> <% else %> <%= translation('tag.index.wiki') %> <% end %></a>
<div id="new-post" style="float:right;margin:10px 0 10px 10px;">
<% if current_user %>
<a rel="tooltip" title="<%= translation('sidebar._post_button.share_your_work') %>" data-placement="bottom" href="/post?tags=<%= subscription.tag.name %>" class="btn btn-primary btn-sm requireLogin"><%= translation('tag.show.new_post') %> <i class="fa fa-plus fa-white"></i></a>
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ en:
number_of_subscriptions: "# of people"
subscriptions: "Your subscriptions"
sort_by: "Sort By"
posts: "posts"
post: "post"
wiki: "wiki"
follow: "Follow"
unfollow: "Unfollow"
notes:
Expand Down
9 changes: 9 additions & 0 deletions test/unit/tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,13 @@ def setup
assert_equal last_week_subscriptions, graph.values.sum
assert_equal Hash, graph.class
end

test 'tagged_node_count' do
tag = tags(:test)
note_count = Tag.tagged_node_count(tag.name)
wiki_count = Tag.tagged_node_count(tag.name, 'page')

assert_equal 2 , note_count
assert_equal 0 , wiki_count
end
end

0 comments on commit d9f515e

Please sign in to comment.