show how many users are filtering each tag

This commit is contained in:
joshua stein 2012-09-19 12:25:11 -05:00
parent b2315a5728
commit 0663ea0fed
4 changed files with 30 additions and 4 deletions

View File

@ -493,7 +493,7 @@
if (i === 0 && placeholder !== undefined && text === "") return true;
if (query.matcher(term, text)) {
data.results.push({id: e.attr("value"), text: text});
data.results.push({id: e.attr("value"), text: (e.attr("data-html") == undefined ? text : e.attr("data-html")) });
}
});
query.callback(data);

View File

@ -1109,3 +1109,10 @@ div.modal_confirm_content div.modal_confirm_buttonbar input.default_button {
-o-box-shadow : none;
box-shadow : none;
}
.select2-container .select2-results li em {
background: none;
color: #aaa;
font-style: italic;
padding-left: 0.5em;
}

View File

@ -1,2 +1,16 @@
class Tag < ActiveRecord::Base
attr_accessor :filtered_count
def self.all_with_filtered_counts
counts = TagFilter.count(:group => "tag_id")
Tag.order(:tag).all.map{|t|
t.filtered_count = counts[t.id].to_i
t
}
end
def filtered_count
@filtered_count ||= TagFilter.where(:tag_id => self.id).count
end
end

View File

@ -23,9 +23,14 @@
<div class="boxline" style="margin-bottom: 2px;">
<%= f.label :tags_a, "Tags:", :class => "required",
:style => "line-height: 2.3em;" %>
<%= f.select "tags_a", Tag.order(:tag).map{|t|
[ "#{t.tag} - #{t.description}", t.tag ] }, {},
{ :multiple => true } %>
<%= f.select "tags_a", options_for_select(
Tag.all_with_filtered_counts.map{|t|
[ "#{t.tag} - #{t.description}", t.tag, { "data-html" => raw("<strong>") +
t.tag + raw("</strong> - ") + t.description.to_s +
(t.filtered_count == 0 ? "" :
raw(" <em>") + "#{t.filtered_count} user" +
(t.filtered_count == 1 ? "" : "s") + " filtering" +
raw("</em>")) } ]}), {}, { :multiple => true } %>
</div>
<div class="boxline">