Adds User and Version custom field format that can be used to reference a project member or version in custom fields (#2096).
These new field formats are available for project, issue, version and time entry custom fields. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5272 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
122ba564b9
commit
1cd6a2aa84
10 files changed
+229
-28
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006 Jean-Philippe Lang
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -48,6 +48,33 @@ class CustomField < ActiveRecord::Base
|
||||
errors.add(:default_value, :invalid) unless v.valid?
|
||||
end
|
||||
|
||||
def possible_values_options(obj=nil)
|
||||
case field_format
|
||||
when 'user', 'version'
|
||||
if obj.respond_to?(:project)
|
||||
case field_format
|
||||
when 'user'
|
||||
obj.project.users.sort.collect {|u| [u.to_s, u.id.to_s]}
|
||||
when 'version'
|
||||
obj.project.versions.sort.collect {|u| [u.to_s, u.id.to_s]}
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
else
|
||||
read_attribute :possible_values
|
||||
end
|
||||
end
|
||||
|
||||
def possible_values(obj=nil)
|
||||
case field_format
|
||||
when 'user'
|
||||
possible_values_options(obj).collect(&:last)
|
||||
else
|
||||
read_attribute :possible_values
|
||||
end
|
||||
end
|
||||
|
||||
# Makes possible_values accept a multiline string
|
||||
def possible_values=(arg)
|
||||
if arg.is_a?(Array)
|
||||
@@ -71,6 +98,8 @@ class CustomField < ActiveRecord::Base
|
||||
casted = value.to_i
|
||||
when 'float'
|
||||
casted = value.to_f
|
||||
when 'user', 'version'
|
||||
casted = (value.blank? ? nil : field_format.classify.constantize.find_by_id(value.to_i))
|
||||
end
|
||||
end
|
||||
casted
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@@ -636,6 +636,9 @@ class Query < ActiveRecord::Base
|
||||
options = { :type => :date, :order => 20 }
|
||||
when "bool"
|
||||
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
||||
when "user", "version"
|
||||
next unless project
|
||||
options = { :type => :list_optional, :values => field.possible_values_options(project), :order => 20}
|
||||
else
|
||||
options = { :type => :string, :order => 20 }
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user