limits the number of members initially shown, adds ajax reloading for more

pull/6827/head
Jens Ulferts 12 years ago
parent 57f2cf0e44
commit 0af1678515
  1. 61
      app/controllers/my_projects_overviews_controller.rb
  2. 7
      app/views/my_projects_overviews/_members.html.erb
  3. 14
      app/views/my_projects_overviews/blocks/_members.rhtml
  4. 1
      app/views/my_projects_overviews/index.rhtml
  5. 1
      app/views/my_projects_overviews/page_layout.rhtml
  6. 22
      assets/javascripts/my_project_page.js
  7. 1
      config/routes.rb
  8. 3
      init.rb

@ -142,7 +142,16 @@ class MyProjectsOverviewsController < ApplicationController
render :partial => 'page_layout_attachments' render :partial => 'page_layout_attachments'
end end
def show_all_members
respond_to do |format|
format.js { render :partial => "members",
:locals => { :user_by_role => users_by_role(nil),
:count_users_by_role => count_users_by_role } }
end
end
helper_method :users_by_role, helper_method :users_by_role,
:count_users_by_role,
:childprojects, :childprojects,
:recent_news, :recent_news,
:trackers, :trackers,
@ -159,13 +168,6 @@ class MyProjectsOverviewsController < ApplicationController
:render_block, :render_block,
:object_callback :object_callback
def render_block name
end
def users_by_role
@users_by_role ||= project.users_by_role
end
def childprojects def childprojects
@childprojects ||= project.children.visible.all @childprojects ||= project.children.visible.all
end end
@ -202,6 +204,51 @@ class MyProjectsOverviewsController < ApplicationController
:order => "#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") :order => "#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC")
end end
def users_by_role(limit = 100)
@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
def count_users_by_role
@count_users_per_role ||= begin
sql_string = all_roles.map do |r|
%Q{ (Select COUNT(users.id) count, member_roles.role_id 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 } ) }
end.join(" UNION ALL ")
role_count = {}
ActiveRecord::Base.connection.execute(sql_string).each do |count, role_id|
role_count[all_roles.detect{ |r| r.id == role_id.to_i }] = count.to_i if count.to_i > 0
end
role_count
end
end
def all_roles
@all_roles = Role.all
end
def total_hours def total_hours
if User.current.allowed_to?(:view_time_entries, project) if User.current.allowed_to?(:view_time_entries, project)
@total_hours ||= TimeEntry.visible.sum(:hours, :include => :project, :conditions => subproject_condition).to_f @total_hours ||= TimeEntry.visible.sum(:hours, :include => :project, :conditions => subproject_condition).to_f

@ -0,0 +1,7 @@
<% users_by_role.keys.sort.each do |role| %>
<%=h role %>: <%= users_by_role[role].sort.collect{ |u| link_to_user u }.join("; ") %>
<% if users_by_role[role].count < count_users_by_role[role] %>
... (<%= count_users_by_role[role] - users_by_role[role].count %> more)
<% end %>
<br />
<% end %>

@ -1,11 +1,17 @@
<h2 class="page-layout-only"><%=l(:label_member_plural)%></h2> <h2 class="page-layout-only"><%=l(:label_member_plural)%></h2>
<h3><%=l(:label_member_plural)%></h3> <h3><%=l(:label_member_plural)%></h3>
<% if users_by_role.any? %> <% if users_by_role.any? %>
<div class="members overview"> <div class="members overview" id="users_per_role">
<p> <p>
<% users_by_role.keys.sort.each do |role| %> <%= render :partial => "members",
<%=h role %>: <%= users_by_role[role].sort.collect{ |u| link_to_user u }.join(", ") %><br /> :locals => { :users_by_role => users_by_role(50),
<% end %> :count_users_by_role => count_users_by_role } %>
</p>
<p>
<%= link_to("Show all", { :controller => 'my_projects_overviews',
:action => 'show_all_members',
:id => project.id },
:class => "all" ) %>
</p> </p>
</div> </div>
<% end %> <% end %>

@ -58,6 +58,7 @@
<% end %> <% end %>
<% content_for :header_tags do %> <% content_for :header_tags do %>
<%= javascript_include_tag "my_project_page", :plugin => 'chiliproject_my_project_page' %>
<%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :key => User.current.rss_key}) %> <%= auto_discovery_link_tag(:atom, {:controller => 'activities', :action => 'index', :id => @project, :format => 'atom', :key => User.current.rss_key}) %>
<%= stylesheet_link_tag "my_projects_overview.css", :plugin => "chiliproject_my_project_page", :media => 'all' %> <%= stylesheet_link_tag "my_projects_overview.css", :plugin => "chiliproject_my_project_page", :media => 'all' %>
<% end %> <% end %>

@ -155,6 +155,7 @@ function addBlock() {
<%= javascript_tag "updateSelect()" %> <%= javascript_tag "updateSelect()" %>
<% content_for :header_tags do %> <% content_for :header_tags do %>
<%= javascript_include_tag "my_project_page", :plugin => 'chiliproject_my_project_page' %>
<%= stylesheet_link_tag "my_projects_overview.css", :plugin => "chiliproject_my_project_page", :media => 'all' %> <%= stylesheet_link_tag "my_projects_overview.css", :plugin => "chiliproject_my_project_page", :media => 'all' %>
<% heads_for_wiki_formatter %> <% heads_for_wiki_formatter %>
<% end %> <% end %>

@ -0,0 +1,22 @@
/*globals jQuery, I18n*/
var MyProjectPage = (function ($) {
var init;
init = function () {
$('#users_per_role .all').click(function () {
$('#users_per_role').html('');
});
$.ajaxAppend({
trigger: '.all',
indicator_class: 'ajax-indicator',
load_target: '#users_per_role',
loading_text: I18n.t("js.ajax.loading"),
loading_class: 'box loading'
});
};
$('document').ready(init);
}(jQuery));

@ -17,5 +17,6 @@ ActionController::Routing::Routes.draw do |map|
my.connect 'my_projects_overview/:id/page_layout/order_blocks', :action => 'order_blocks' my.connect 'my_projects_overview/:id/page_layout/order_blocks', :action => 'order_blocks'
my.connect 'my_projects_overview/:id/page_layout/update_custom_element', :action => 'update_custom_element' my.connect 'my_projects_overview/:id/page_layout/update_custom_element', :action => 'update_custom_element'
my.connect 'my_projects_overview/:id/page_layout/destroy_attachment', :action => 'destroy_attachment', :conditions => {:method => :post} my.connect 'my_projects_overview/:id/page_layout/destroy_attachment', :action => 'destroy_attachment', :conditions => {:method => :post}
my.connect 'my_projects_overview/:id/page_layout/show_all_members', :action => 'show_all_members'
end end
end end

@ -7,7 +7,8 @@ Redmine::Plugin.register :chiliproject_my_project_page do
description 'This plugin replaces the old overview page for projects with something similar to the "My Page"' description 'This plugin replaces the old overview page for projects with something similar to the "My Page"'
version MyProjectPage::Version.full version MyProjectPage::Version.full
Redmine::AccessControl.permission(:view_project).actions << "my_projects_overviews/index" Redmine::AccessControl.permission(:view_project).actions << "my_projects_overviews/index" <<
"my_projects_overviews/show_all_members"
Redmine::AccessControl.permission(:edit_project).actions << "my_projects_overviews/page_layout" << Redmine::AccessControl.permission(:edit_project).actions << "my_projects_overviews/page_layout" <<
"my_projects_overviews/add_block" << "my_projects_overviews/add_block" <<
"my_projects_overviews/remove_block" << "my_projects_overviews/remove_block" <<

Loading…
Cancel
Save