summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-26 17:37:20 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-26 17:37:20 +0000
commit5a1fcf826ffe4c4d6e0f839138d442725cae2ab5 (patch)
tree82b6f8d8f638d2798315cc82abd352c77c45cd28 /app
parent0293ba7e9f4f82788363ef699327887005db7b3e (diff)
downloadredmine-5a1fcf826ffe4c4d6e0f839138d442725cae2ab5.tar.gz
redmine-5a1fcf826ffe4c4d6e0f839138d442725cae2ab5.zip
Sort the issue list by author/assignee according to user display format (#9669).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7938 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/query.rb10
-rw-r--r--app/models/user.rb33
2 files changed, 32 insertions, 11 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 55ac3d6a4..f3b83d0f4 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -36,7 +36,11 @@ class QueryColumn
# Returns true if the column is sortable, otherwise false
def sortable?
- !sortable.nil?
+ !@sortable.nil?
+ end
+
+ def sortable
+ @sortable.is_a?(Proc) ? @sortable.call : @sortable
end
def value(issue)
@@ -136,8 +140,8 @@ class Query < ActiveRecord::Base
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
- QueryColumn.new(:author, :sortable => ["authors.lastname", "authors.firstname", "authors.id"], :groupable => true),
- QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
+ QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement("authors")}, :groupable => true),
+ QueryColumn.new(:assigned_to, :sortable => lambda {User.fields_for_order_statement}, :groupable => true),
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true),
diff --git a/app/models/user.rb b/app/models/user.rb
index 0ac0dcb74..8268d752e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -26,12 +26,13 @@ class User < Principal
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
+ # Different ways of displaying/sorting users
USER_FORMATS = {
- :firstname_lastname => '#{firstname} #{lastname}',
- :firstname => '#{firstname}',
- :lastname_firstname => '#{lastname} #{firstname}',
- :lastname_coma_firstname => '#{lastname}, #{firstname}',
- :username => '#{login}'
+ :firstname_lastname => {:string => '#{firstname} #{lastname}', :order => %w(firstname lastname id)},
+ :firstname => {:string => '#{firstname}', :order => %w(firstname id)},
+ :lastname_firstname => {:string => '#{lastname} #{firstname}', :order => %w(lastname firstname id)},
+ :lastname_coma_firstname => {:string => '#{lastname}, #{firstname}', :order => %w(lastname firstname id)},
+ :username => {:string => '#{login}', :order => %w(login id)},
}
MAIL_NOTIFICATION_OPTIONS = [
@@ -168,13 +169,29 @@ class User < Principal
end
end
end
-
+
+ def self.name_formatter(formatter = nil)
+ USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]
+ end
+
+ # Returns an array of fields names than can be used to make an order statement for users
+ # according to how user names are displayed
+ # Examples:
+ #
+ # User.fields_for_order_statement => ['users.login', 'users.id']
+ # User.fields_for_order_statement('authors') => ['authors.login', 'authors.id']
+ def self.fields_for_order_statement(table=nil)
+ table ||= table_name
+ name_formatter[:order].map {|field| "#{table}.#{field}"}
+ end
+
# Return user's full name for display
def name(formatter = nil)
+ f = self.class.name_formatter(formatter)
if formatter
- eval('"' + (USER_FORMATS[formatter] || USER_FORMATS[:firstname_lastname]) + '"')
+ eval('"' + f[:string] + '"')
else
- @name ||= eval('"' + (USER_FORMATS[Setting.user_format] || USER_FORMATS[:firstname_lastname]) + '"')
+ @name ||= eval('"' + f[:string] + '"')
end
end