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:
parent
3d5d1a38e3
commit
79f92a675a
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -79,6 +79,9 @@ date_format:
|
|||
default: ''
|
||||
time_format:
|
||||
default: ''
|
||||
user_format:
|
||||
default: :firstname_lastname
|
||||
format: symbol
|
||||
cross_project_issue_relations:
|
||||
default: 0
|
||||
notified_events:
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -204,6 +204,7 @@ setting_repositories_encodings: Repositories encodings
|
|||
setting_emails_footer: Emails footer
|
||||
setting_protocol: Protocol
|
||||
setting_per_page_options: Objects per page options
|
||||
setting_user_format: Users display format
|
||||
|
||||
label_user: User
|
||||
label_user_plural: Users
|
||||
|
|
|
@ -568,3 +568,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -569,3 +569,4 @@ enumeration_issue_priorities: Tapahtuman prioriteetit
|
|||
enumeration_doc_categories: Dokumentin luokat
|
||||
enumeration_activities: Aktiviteetit (ajan seuranta)
|
||||
label_associated_revisions: Liittyvät versiot
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -205,6 +205,7 @@ setting_repositories_encodings: Encodages des dépôts
|
|||
setting_emails_footer: Pied-de-page des emails
|
||||
setting_protocol: Protocole
|
||||
setting_per_page_options: Options d'objets affichés par page
|
||||
setting_user_format: Format d'affichage des utilisateurs
|
||||
|
||||
label_user: Utilisateur
|
||||
label_user_plural: Utilisateurs
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -566,3 +566,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: 속성 변경
|
|||
label_general: 일반
|
||||
label_repository_plural: 저장소들
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -566,3 +566,4 @@ text_no_configuration_data: "Roles, trackers, issue statuses and workflow have n
|
|||
label_repository_plural: Repositories
|
||||
error_can_t_load_default_data: "Default configuration could not be loaded: %s"
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -566,3 +566,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Zmień właściwości
|
|||
label_general: Ogólne
|
||||
label_repository_plural: Repozytoria
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -565,3 +565,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -567,3 +567,4 @@ enumeration_doc_categories: Категории документов
|
|||
enumeration_activities: Действия (учет времени)
|
||||
|
||||
error_can_t_load_default_data: "Конфигурация по умолчанию не была загружена: %s"
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -566,3 +566,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -566,3 +566,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -566,3 +566,4 @@ enumeration_issue_priorities: 項目重要性
|
|||
enumeration_doc_categories: 文件分類
|
||||
enumeration_activities: 活動 (time tracking)
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -568,3 +568,4 @@ label_change_properties: Change properties
|
|||
label_general: General
|
||||
label_repository_plural: Repositories
|
||||
label_associated_revisions: Associated revisions
|
||||
setting_user_format: Users display format
|
||||
|
|
|
@ -76,6 +76,14 @@ class UserTest < Test::Unit::TestCase
|
|||
assert_equal User.hash_password("hello"), user.hashed_password
|
||||
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
|
||||
user = User.try_to_login("jsmith", "jsmith")
|
||||
assert_equal @jsmith, user
|
||||
|
|
Loading…
Reference in New Issue