show how many stories have been tagged with each on filters page
closes #93 closes #114
This commit is contained in:
parent
b0b6b72cf3
commit
20cf2bab65
|
@ -5,7 +5,7 @@ class FiltersController < ApplicationController
|
|||
@cur_url = "/filters"
|
||||
@title = "Filtered Tags"
|
||||
|
||||
@tags = Tag.order(:tag).accessible_to(@user)
|
||||
@tags = Tag.all_with_story_counts_for(@user)
|
||||
|
||||
if @user
|
||||
@filtered_tags = @user.tag_filter_tags.to_a
|
||||
|
|
|
@ -4,7 +4,7 @@ class Tag < ActiveRecord::Base
|
|||
has_many :stories,
|
||||
:through => :taggings
|
||||
|
||||
attr_accessor :filtered_count
|
||||
attr_accessor :filtered_count, :stories_count
|
||||
|
||||
scope :accessible_to, ->(user) do
|
||||
user && user.is_moderator?? all : where(:privileged => false)
|
||||
|
@ -23,6 +23,15 @@ class Tag < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def self.all_with_story_counts_for(user)
|
||||
counts = Tagging.group(:tag_id).count
|
||||
|
||||
Tag.order(:tag).accessible_to(user).map{|t|
|
||||
t.stories_count = counts[t.id].to_i
|
||||
t
|
||||
}
|
||||
end
|
||||
|
||||
def css_class
|
||||
"tag tag_#{self.tag}" << (self.is_media?? " tag_is_media" : "")
|
||||
end
|
||||
|
|
|
@ -20,17 +20,18 @@
|
|||
<table class="data zebra" cellspacing=0 width="75%">
|
||||
<tr>
|
||||
<th width="7%">Hide</th>
|
||||
<th width="15%">Tag</th>
|
||||
<th width="78%">Description</th>
|
||||
<th width="13%">Tag</th>
|
||||
<th width="65%">Description</th>
|
||||
<th width="5%" style="text-align: right; padding-right: 1em;">Stories</th>
|
||||
</tr>
|
||||
<% @tags.each do |tag| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= check_box_tag "tags[]", tag.tag, @filtered_tags.include?(tag) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to tag.tag, tag_path(tag), :class => tag.css_class %>
|
||||
<td><%= check_box_tag "tags[]", tag.tag,
|
||||
@filtered_tags.include?(tag) %></td>
|
||||
<td><%= link_to tag.tag, tag_path(tag), :class => tag.css_class %></td>
|
||||
<td><%= tag.description %></td>
|
||||
<td style="text-align: right; padding-right: 1em;"><%=
|
||||
tag.stories_count %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
|
Loading…
Reference in a new issue