summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-01-25 10:31:06 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-01-25 10:31:06 +0000
commit79f92a675af528ecbe5abcc15b9c98805c9c7315 (patch)
treec5c2f04a5b16bfc2d98fe03495bc83f902188ee0 /app
parent3d5d1a38e3d48e1fda7eee751563cbf8c3b0f00b (diff)
downloadredmine-79f92a675af528ecbe5abcc15b9c98805c9c7315.tar.gz
redmine-79f92a675af528ecbe5abcc15b9c98805c9c7315.zip
User display format is now configurable in administration settings.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1103 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/settings_controller.rb3
-rw-r--r--app/models/member.rb4
-rw-r--r--app/models/setting.rb3
-rw-r--r--app/models/user.rb21
-rw-r--r--app/views/projects/settings/_members.rhtml4
-rw-r--r--app/views/settings/_general.rhtml3
6 files changed, 32 insertions, 6 deletions
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index c5fae2a16..c7c8751dd 100644
--- a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -35,7 +35,10 @@ class SettingsController < ApplicationController
end
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'edit', :tab => params[:tab]
+ return
end
+ @options = {}
+ @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
end
def plugin
diff --git a/app/models/member.rb b/app/models/member.rb
index 0d0540690..b4617c229 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -31,6 +31,10 @@ class Member < ActiveRecord::Base
self.user.name
end
+ def <=>(member)
+ role == member.role ? (user <=> member.user) : (role <=> member.role)
+ end
+
def before_destroy
# remove category based auto assignments for this member
IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 46b6d76ce..185991d9b 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -53,12 +53,13 @@ class Setting < ActiveRecord::Base
v = read_attribute(:value)
# Unserialize serialized settings
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
+ v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
v
end
def value=(v)
v = v.to_yaml if v && @@available_settings[name]['serialized']
- write_attribute(:value, v)
+ write_attribute(:value, v.to_s)
end
# Returns the value of the setting named name
diff --git a/app/models/user.rb b/app/models/user.rb
index 906420ed4..22d66539d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,6 +23,14 @@ class User < ActiveRecord::Base
STATUS_ACTIVE = 1
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
+
+ USER_FORMATS = {
+ :firstname_lastname => '#{firstname} #{lastname}',
+ :firstname => '#{firstname}',
+ :lastname_firstname => '#{lastname} #{firstname}',
+ :lastname_coma_firstname => '#{lastname}, #{firstname}',
+ :username => '#{login}'
+ }
has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all
has_many :projects, :through => :memberships
@@ -107,8 +115,9 @@ class User < ActiveRecord::Base
end
# Return user's full name for display
- def name
- "#{firstname} #{lastname}"
+ def name(formatter = nil)
+ f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]
+ eval '"' + f + '"'
end
def active?
@@ -164,7 +173,13 @@ class User < ActiveRecord::Base
end
def <=>(user)
- user.nil? ? -1 : (lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname)
+ if user.nil?
+ -1
+ elsif lastname.to_s.downcase == user.lastname.to_s.downcase
+ firstname.to_s.downcase <=> user.firstname.to_s.downcase
+ else
+ lastname.to_s.downcase <=> user.lastname.to_s.downcase
+ end
end
def to_s
diff --git a/app/views/projects/settings/_members.rhtml b/app/views/projects/settings/_members.rhtml
index 55dfde1ac..ab22ac602 100644
--- a/app/views/projects/settings/_members.rhtml
+++ b/app/views/projects/settings/_members.rhtml
@@ -1,8 +1,8 @@
<%= error_messages_for 'member' %>
<% roles = Role.find_all_givable %>
-<% users = User.find_active(:all) - @project.users %>
+<% users = User.find_active(:all).sort - @project.users %>
<% # members sorted by role position
- members = @project.members.find(:all, :include => [:role, :user]).sort{|x,y| x.role.position <=> y.role.position} %>
+ members = @project.members.find(:all, :include => [:role, :user]).sort %>
<% if members.any? %>
<table class="list">
diff --git a/app/views/settings/_general.rhtml b/app/views/settings/_general.rhtml
index 514e62b59..548ebbfac 100644
--- a/app/views/settings/_general.rhtml
+++ b/app/views/settings/_general.rhtml
@@ -20,6 +20,9 @@
<p><label><%= l(:setting_time_format) %></label>
<%= select_tag 'settings[time_format]', options_for_select( [[l(:label_language_based), '']] + Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, Setting.time_format) %></p>
+<p><label><%= l(:setting_user_format) %></label>
+<%= select_tag 'settings[user_format]', options_for_select( @options[:user_format], Setting.user_format.to_s ) %></p>
+
<p><label><%= l(:setting_attachment_max_size) %></label>
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>