diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index 11e6a62f98..af9b7b38ec 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -145,7 +145,7 @@ class MyProjectsOverviewsController < ApplicationController def show_all_members respond_to do |format| format.js { render :partial => "members", - :locals => { :user_by_role => users_by_role(nil), + :locals => { :users_by_role => users_by_role(0), :count_users_by_role => count_users_by_role } } end end @@ -205,25 +205,29 @@ class MyProjectsOverviewsController < ApplicationController end def users_by_role(limit = 100) + @users_by_role = Hash.new do |h, size| + h[size] = if size > 0 + sql_string = all_roles.map do |r| + %Q{ (Select users.*, member_roles.role_id from users + JOIN members on users.id = members.user_id + JOIN member_roles on member_roles.member_id = members.id + WHERE members.project_id = #{ project.id } AND member_roles.role_id = #{ r.id } + LIMIT #{ size } ) } + end.join(" UNION ALL ") + + User.find_by_sql(sql_string).group_by(&:role_id).inject({}) do |hash, (role_id, users)| + hash[all_roles.detect{ |r| r.id == role_id.to_i }] = users + hash + end + else + + project.users_by_role + + end - @users_by_role ||= if limit - sql_string = all_roles.map do |r| - %Q{ (Select users.*, member_roles.role_id from users - JOIN members on users.id = members.user_id - JOIN member_roles on member_roles.member_id = members.id - WHERE members.project_id = #{ project.id } AND member_roles.role_id = #{ r.id } - LIMIT #{ limit } ) } - end.join(" UNION ALL ") - - User.find_by_sql(sql_string).group_by(&:role_id).inject({}) do |hash, (role_id, users)| - hash[all_roles.detect{ |r| r.id == role_id.to_i }] = users - hash - end - else - - project.users_by_role + end - end + @users_by_role[limit] end def count_users_by_role diff --git a/app/views/my_projects_overviews/blocks/_members.rhtml b/app/views/my_projects_overviews/blocks/_members.rhtml index bb0607d46b..38c96d8221 100644 --- a/app/views/my_projects_overviews/blocks/_members.rhtml +++ b/app/views/my_projects_overviews/blocks/_members.rhtml @@ -1,6 +1,7 @@

<%=l(:label_member_plural)%>

<%=l(:label_member_plural)%>

-<% if users_by_role.any? %> + +<% if users_by_role(50).any? %>

<%= render :partial => "members", @@ -8,10 +9,12 @@ :count_users_by_role => count_users_by_role } %>

+ <% if users_by_role(50).any?{ |role, users| users.count < count_users_by_role[role] } %> <%= link_to(l(:'project_page.all'), { :controller => 'my_projects_overviews', :action => 'show_all_members', :id => project.id }, :class => "all" ) %> + <% end %>

<% end %>