User display format is now configurable in administration settings.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1103 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-01-25 10:31:06 +00:00
parent 3d5d1a38e3
commit 79f92a675a
30 changed files with 65 additions and 6 deletions

View File

@ -35,7 +35,10 @@ class SettingsController < ApplicationController
end end
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'edit', :tab => params[:tab] redirect_to :action => 'edit', :tab => params[:tab]
return
end end
@options = {}
@options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
end end
def plugin def plugin

View File

@ -31,6 +31,10 @@ class Member < ActiveRecord::Base
self.user.name self.user.name
end end
def <=>(member)
role == member.role ? (user <=> member.user) : (role <=> member.role)
end
def before_destroy def before_destroy
# remove category based auto assignments for this member # 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] IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]

View File

@ -53,12 +53,13 @@ class Setting < ActiveRecord::Base
v = read_attribute(:value) v = read_attribute(:value)
# Unserialize serialized settings # Unserialize serialized settings
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String) 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 v
end end
def value=(v) def value=(v)
v = v.to_yaml if v && @@available_settings[name]['serialized'] v = v.to_yaml if v && @@available_settings[name]['serialized']
write_attribute(:value, v) write_attribute(:value, v.to_s)
end end
# Returns the value of the setting named name # Returns the value of the setting named name

View File

@ -24,6 +24,14 @@ class User < ActiveRecord::Base
STATUS_REGISTERED = 2 STATUS_REGISTERED = 2
STATUS_LOCKED = 3 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 :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 has_many :projects, :through => :memberships
has_many :custom_values, :dependent => :delete_all, :as => :customized has_many :custom_values, :dependent => :delete_all, :as => :customized
@ -107,8 +115,9 @@ class User < ActiveRecord::Base
end end
# Return user's full name for display # Return user's full name for display
def name def name(formatter = nil)
"#{firstname} #{lastname}" f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname]
eval '"' + f + '"'
end end
def active? def active?
@ -164,7 +173,13 @@ class User < ActiveRecord::Base
end end
def <=>(user) 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 end
def to_s def to_s

View File

@ -1,8 +1,8 @@
<%= error_messages_for 'member' %> <%= error_messages_for 'member' %>
<% roles = Role.find_all_givable %> <% 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 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? %> <% if members.any? %>
<table class="list"> <table class="list">

View File

@ -20,6 +20,9 @@
<p><label><%= l(:setting_time_format) %></label> <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> <%= 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> <p><label><%= l(:setting_attachment_max_size) %></label>
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p> <%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>

View File

@ -79,6 +79,9 @@ date_format:
default: '' default: ''
time_format: time_format:
default: '' default: ''
user_format:
default: :firstname_lastname
format: symbol
cross_project_issue_relations: cross_project_issue_relations:
default: 0 default: 0
notified_events: notified_events:

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -204,6 +204,7 @@ setting_repositories_encodings: Repositories encodings
setting_emails_footer: Emails footer setting_emails_footer: Emails footer
setting_protocol: Protocol setting_protocol: Protocol
setting_per_page_options: Objects per page options setting_per_page_options: Objects per page options
setting_user_format: Users display format
label_user: User label_user: User
label_user_plural: Users label_user_plural: Users

View File

@ -568,3 +568,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -569,3 +569,4 @@ enumeration_issue_priorities: Tapahtuman prioriteetit
enumeration_doc_categories: Dokumentin luokat enumeration_doc_categories: Dokumentin luokat
enumeration_activities: Aktiviteetit (ajan seuranta) enumeration_activities: Aktiviteetit (ajan seuranta)
label_associated_revisions: Liittyvät versiot label_associated_revisions: Liittyvät versiot
setting_user_format: Users display format

View File

@ -205,6 +205,7 @@ setting_repositories_encodings: Encodages des dépôts
setting_emails_footer: Pied-de-page des emails setting_emails_footer: Pied-de-page des emails
setting_protocol: Protocole setting_protocol: Protocole
setting_per_page_options: Options d'objets affichés par page setting_per_page_options: Options d'objets affichés par page
setting_user_format: Format d'affichage des utilisateurs
label_user: Utilisateur label_user: Utilisateur
label_user_plural: Utilisateurs label_user_plural: Utilisateurs

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: 속성 변경
label_general: 일반 label_general: 일반
label_repository_plural: 저장소들 label_repository_plural: 저장소들
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -566,3 +566,4 @@ text_no_configuration_data: "Roles, trackers, issue statuses and workflow have n
label_repository_plural: Repositories label_repository_plural: Repositories
error_can_t_load_default_data: "Default configuration could not be loaded: %s" error_can_t_load_default_data: "Default configuration could not be loaded: %s"
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Zmień właściwości
label_general: Ogólne label_general: Ogólne
label_repository_plural: Repozytoria label_repository_plural: Repozytoria
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -565,3 +565,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -567,3 +567,4 @@ enumeration_doc_categories: Категории документов
enumeration_activities: Действия (учет времени) enumeration_activities: Действия (учет времени)
error_can_t_load_default_data: "Конфигурация по умолчанию не была загружена: %s" error_can_t_load_default_data: "Конфигурация по умолчанию не была загружена: %s"
setting_user_format: Users display format

View File

@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -566,3 +566,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -566,3 +566,4 @@ enumeration_issue_priorities: 項目重要性
enumeration_doc_categories: 文件分類 enumeration_doc_categories: 文件分類
enumeration_activities: 活動 (time tracking) enumeration_activities: 活動 (time tracking)
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -568,3 +568,4 @@ label_change_properties: Change properties
label_general: General label_general: General
label_repository_plural: Repositories label_repository_plural: Repositories
label_associated_revisions: Associated revisions label_associated_revisions: Associated revisions
setting_user_format: Users display format

View File

@ -76,6 +76,14 @@ class UserTest < Test::Unit::TestCase
assert_equal User.hash_password("hello"), user.hashed_password assert_equal User.hash_password("hello"), user.hashed_password
end end
def test_name_format
assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)
Setting.user_format = :firstname_lastname
assert_equal 'John Smith', @jsmith.name
Setting.user_format = :username
assert_equal 'jsmith', @jsmith.name
end
def test_lock def test_lock
user = User.try_to_login("jsmith", "jsmith") user = User.try_to_login("jsmith", "jsmith")
assert_equal @jsmith, user assert_equal @jsmith, user