From: Jean-Philippe Lang Date: Sat, 7 Jan 2017 10:28:59 +0000 (+0000) Subject: Sort user memberships by project. X-Git-Tag: 3.4.0~456 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c005719aeeb73a8a6ac02aa99eee5426c558294;p=redmine.git Sort user memberships by project. git-svn-id: http://svn.redmine.org/redmine/trunk@16150 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/member.rb b/app/models/member.rb index 0b73def6c..06b90bf55 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -37,6 +37,10 @@ class Member < ActiveRecord::Base reorder("#{Role.table_name}.position"). order(Principal.fields_for_order_statement) } + scope :sorted_by_project, lambda { + includes(:project). + reorder("#{Project.table_name}.lft") + } alias :base_reload :reload def reload(*args) diff --git a/app/views/principal_memberships/_index.html.erb b/app/views/principal_memberships/_index.html.erb index b451f536b..e43419072 100644 --- a/app/views/principal_memberships/_index.html.erb +++ b/app/views/principal_memberships/_index.html.erb @@ -1,6 +1,8 @@ +<% memberships = principal.memberships.preload(:member_roles => :role).sorted_by_project.to_a %> +

<%= link_to l(:label_add_projects), new_principal_membership_path(principal), :remote => true, :class => "icon icon-add" %>

-<% if principal.memberships.any? %> +<% if memberships.any? %> @@ -9,7 +11,7 @@ <%= call_table_header_hook principal %> - <% principal.memberships.preload(:member_roles => :role).each do |membership| %> + <% memberships.each do |membership| %> <% next if membership.new_record? %>
<%= l(:label_project) %>