From 40999debbf39541d1ed42285b126db5516915d44 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 25 Sep 2012 13:50:28 +0400 Subject: [PATCH] #648: updated projects_helper --- app/helpers/projects_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 8f9278523..a04f1c531 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -1,6 +1,10 @@ # -*- encoding : utf-8 -*- module ProjectsHelper def options_for_filters(all_projects, groups, owners) + projects_count_by_groups = all_projects.where(:owner_id => groups, :owner_type => 'Group'). + group(:owner_id).count + projects_count_by_owners = all_projects.where(:owner_id => owners, :owner_type => 'User'). + group(:owner_id).count (groups + owners).map do |o| class_name = o.class.name { @@ -11,7 +15,7 @@ module ProjectsHelper :check_box_value => o.id, :name => content_tag(:div, content_tag(:span, o.uname, :class => class_name.downcase)), :uname => o.uname, # only for sorting - :count => all_projects.where(:owner_id => o, :owner_type => class_name).count + :count => o.is_a?(User) ? projects_count_by_owners[o.id] : projects_count_by_groups[o.id] } end.sort_by{ |f| f[:uname] } end