Commit 3aee2dd6 authored by jplang's avatar jplang

Sort members on the DB side.

git-svn-id: https://svn.redmine.org/redmine/trunk@16040 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent c9bd95a7
......@@ -31,6 +31,13 @@ class Member < ActiveRecord::Base
scope :active, lambda { joins(:principal).where(:users => {:status => Principal::STATUS_ACTIVE})}
# Sort by first role and principal
scope :sorted, lambda {
includes(:member_roles, :roles, :principal).
reorder("#{Role.table_name}.position").
order(Principal.fields_for_order_statement)
}
alias :base_reload :reload
def reload(*args)
@managed_roles = nil
......
<% roles = Role.find_all_givable
members = @project.memberships.active.includes(:member_roles, :roles, :principal).to_a.sort %>
members = @project.memberships.active.sorted.to_a %>
<p><%= link_to l(:label_member_new), new_project_membership_path(@project), :remote => true, :class => "icon icon-add" %></p>
......
......@@ -38,6 +38,12 @@ class MemberTest < ActiveSupport::TestCase
@jsmith = Member.find(1)
end
def test_sorted_scope_on_project_members
members = Project.find(1).members.sorted.to_a
roles = members.map {|m| m.roles.sort.first}
assert_equal roles, roles.sort
end
def test_create
member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
assert member.save
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment