reduces size of initially displayed members to 50

pull/6827/head
Jens Ulferts 12 years ago
parent 18b122f9e8
commit 98b0873b93
  1. 40
      app/controllers/my_projects_overviews_controller.rb
  2. 5
      app/views/my_projects_overviews/blocks/_members.rhtml

@ -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

@ -1,6 +1,7 @@
<h2 class="page-layout-only"><%=l(:label_member_plural)%></h2>
<h3><%=l(:label_member_plural)%></h3>
<% if users_by_role.any? %>
<% if users_by_role(50).any? %>
<div class="members overview" id="users_per_role">
<p>
<%= render :partial => "members",
@ -8,10 +9,12 @@
:count_users_by_role => count_users_by_role } %>
</p>
<p>
<% 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 %>
</p>
</div>
<% end %>

Loading…
Cancel
Save