]> source.dussan.org Git - redmine.git/commitdiff
Sort user memberships by project.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Jan 2017 10:28:59 +0000 (10:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Jan 2017 10:28:59 +0000 (10:28 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16150 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/member.rb
app/views/principal_memberships/_index.html.erb

index 0b73def6c5763c6f2d63832d98bba7f44fc8966d..06b90bf5506b3c75a27aadb5483b6dd36e55bbdb 100644 (file)
@@ -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)
index b451f536b9e81c71b2b39e1f1ab3bf5680e03546..e434190727cd43325e71c5d82873c72ab3519d5e 100644 (file)
@@ -1,6 +1,8 @@
+<% memberships = principal.memberships.preload(:member_roles => :role).sorted_by_project.to_a %>
+
 <p><%= link_to l(:label_add_projects), new_principal_membership_path(principal), :remote => true, :class => "icon icon-add" %></p>
 
-<% if principal.memberships.any? %>
+<% if memberships.any? %>
 <table class="list memberships">
   <thead><tr>
     <th><%= l(:label_project) %></th>
@@ -9,7 +11,7 @@
       <%= call_table_header_hook principal %>
   </tr></thead>
   <tbody>
-  <% principal.memberships.preload(:member_roles => :role).each do |membership| %>
+  <% memberships.each do |membership| %>
   <% next if membership.new_record? %>
   <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class">
   <td class="project name">