Fixed that Link custom fields are not displayed as links on the issue list (#16496).

git-svn-id: http://svn.redmine.org/redmine/trunk@13054 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-04-06 11:11:52 +00:00
parent 5b8a96472f
commit 22b2a1f699
3 changed files with 38 additions and 24 deletions

View File

@ -158,7 +158,10 @@ module ApplicationHelper
end end
# Helper that formats object for html or text rendering # Helper that formats object for html or text rendering
def format_object(object, html=true) def format_object(object, html=true, &block)
if block_given?
object = yield object
end
case object.class.name case object.class.name
when 'Array' when 'Array'
object.map {|o| format_object(o, html)}.join(', ').html_safe object.map {|o| format_object(o, html)}.join(', ').html_safe
@ -188,7 +191,7 @@ module ApplicationHelper
if f.nil? || f.is_a?(String) if f.nil? || f.is_a?(String)
f f
else else
format_object(f, html) format_object(f, html, &block)
end end
else else
object.value.to_s object.value.to_s

View File

@ -18,6 +18,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module QueriesHelper module QueriesHelper
include ApplicationHelper
def filters_options_for_select(query) def filters_options_for_select(query)
options_for_select(filters_options(query)) options_for_select(filters_options(query))
end end
@ -81,7 +83,7 @@ module QueriesHelper
end end
def column_content(column, issue) def column_content(column, issue)
value = column.value(issue) value = column.value_object(issue)
if value.is_a?(Array) if value.is_a?(Array)
value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
else else
@ -110,7 +112,7 @@ module QueriesHelper
end end
def csv_content(column, issue) def csv_content(column, issue)
value = column.value(issue) value = column.value_object(issue)
if value.is_a?(Array) if value.is_a?(Array)
value.collect {|v| csv_value(column, issue, v)}.compact.join(', ') value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
else else
@ -119,22 +121,16 @@ module QueriesHelper
end end
def csv_value(column, issue, value) def csv_value(column, issue, value)
case value.class.name format_object(value, false) do |value|
when 'Time' case value.class.name
format_time(value) when 'Float'
when 'Date' sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
format_date(value) when 'IssueRelation'
when 'Float' other = value.other_issue(issue)
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) l(value.label_for(issue)) + " ##{other.id}"
when 'IssueRelation' else
other = value.other_issue(issue) value
l(value.label_for(issue)) + " ##{other.id}" end
when 'TrueClass'
l(:general_text_Yes)
when 'FalseClass'
l(:general_text_No)
else
value.to_s
end end
end end

View File

@ -57,6 +57,10 @@ class QueryColumn
object.send name object.send name
end end
def value_object(object)
object.send name
end
def css_classes def css_classes
name name
end end
@ -80,10 +84,21 @@ class QueryCustomFieldColumn < QueryColumn
@cf @cf
end end
def value(object) def value_object(object)
if custom_field.visible_by?(object.project, User.current) if custom_field.visible_by?(object.project, User.current)
cv = object.custom_values.select {|v| v.custom_field_id == @cf.id}.collect {|v| @cf.cast_value(v.value)} cv = object.custom_values.select {|v| v.custom_field_id == @cf.id}
cv.size > 1 ? cv.sort {|a,b| a.to_s <=> b.to_s} : cv.first cv.size > 1 ? cv.sort {|a,b| a.value.to_s <=> b.value.to_s} : cv.first
else
nil
end
end
def value(object)
raw = value_object(object)
if raw.is_a?(Array)
raw.map {|r| @cf.cast_value(r.value)}
elsif raw
@cf.cast_value(raw.value)
else else
nil nil
end end
@ -105,7 +120,7 @@ class QueryAssociationCustomFieldColumn < QueryCustomFieldColumn
@association = association @association = association
end end
def value(object) def value_object(object)
if assoc = object.send(@association) if assoc = object.send(@association)
super(assoc) super(assoc)
end end