Skip to content

Commit

Permalink
topic card count fixes for publiclab#7965 (publiclab#8249)
Browse files Browse the repository at this point in the history
* fixes for publiclab#7965

* count fixes
  • Loading branch information
jywarren authored and manchere committed Feb 13, 2021
1 parent 92d269d commit 075decb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
10 changes: 4 additions & 6 deletions app/models/node_tag.rb
Expand Up @@ -8,13 +8,11 @@ class NodeTag < ApplicationRecord
has_many :tag_selections, foreign_key: 'tid'
accepts_nested_attributes_for :tag

after_create :increment_count
after_create :update_count
after_destroy :update_count

def increment_count
tag = self.tag
tag.count = 0 if tag.count.nil?
tag.count += 1
tag.save
def update_count
tag.run_count # update count of tag usage
end

def user
Expand Down
8 changes: 0 additions & 8 deletions app/models/tag.rb
Expand Up @@ -115,14 +115,6 @@ def self.find_nodes_by_type(tagnames, type = 'note', limit = 10)
.order(order)
end

def self.counter(tagname)
Node.where(type: %w(note page))
.where('term_data.name = ?', tagname)
.includes(:node_tag, :tag)
.references(:term_data)
.count
end

# just like find_nodes_by_type, but searches wiki pages, places, and tools
def self.find_pages(tagnames, limit = 10)
find_nodes_by_type(tagnames, %w(page place tool), limit)
Expand Down
2 changes: 1 addition & 1 deletion app/views/tag/_topicCard.html.erb
Expand Up @@ -32,7 +32,7 @@
</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/<%= tag.name %>"><%= Tag.counter(tag.name)-shown_nids.count - Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).where.not(nid: shown_nids).count %> <%= translation('tag.index.more_posts') %> &raquo;</a>
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= tag.name %>"><%= Tag.count %> <%= translation('tag.index.posts') %> &raquo;</a>
<div id="follow-unfollow-column-<%=tag.tid%>" style="float:right;margin:10px 0 10px 10px;">
<% if current_user %>
<% if !current_user.following(tag.name) %>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Expand Up @@ -369,7 +369,7 @@ en:
number_of_subscriptions: "# of people"
subscriptions: "Your subscriptions"
sort_by: "Sort By"
more_posts: "more posts"
posts: "posts"
follow: "Follow"
unfollow: "Unfollow"
notes:
Expand Down

0 comments on commit 075decb

Please sign in to comment.