@@ -158,7 +158,10 module ApplicationHelper | |||
|
158 | 158 | end |
|
159 | 159 | |
|
160 | 160 | # Helper that formats object for html or text rendering |
|
161 | def format_object(object, html=true) | |
|
161 | def format_object(object, html=true, &block) | |
|
162 | if block_given? | |
|
163 | object = yield object | |
|
164 | end | |
|
162 | 165 | case object.class.name |
|
163 | 166 | when 'Array' |
|
164 | 167 | object.map {|o| format_object(o, html)}.join(', ').html_safe |
@@ -188,7 +191,7 module ApplicationHelper | |||
|
188 | 191 | if f.nil? || f.is_a?(String) |
|
189 | 192 | f |
|
190 | 193 | else |
|
191 | format_object(f, html) | |
|
194 | format_object(f, html, &block) | |
|
192 | 195 | end |
|
193 | 196 | else |
|
194 | 197 | object.value.to_s |
@@ -18,6 +18,8 | |||
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | module QueriesHelper |
|
21 | include ApplicationHelper | |
|
22 | ||
|
21 | 23 | def filters_options_for_select(query) |
|
22 | 24 | options_for_select(filters_options(query)) |
|
23 | 25 | end |
@@ -81,7 +83,7 module QueriesHelper | |||
|
81 | 83 | end |
|
82 | 84 | |
|
83 | 85 | def column_content(column, issue) |
|
84 | value = column.value(issue) | |
|
86 | value = column.value_object(issue) | |
|
85 | 87 | if value.is_a?(Array) |
|
86 | 88 | value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe |
|
87 | 89 | else |
@@ -110,7 +112,7 module QueriesHelper | |||
|
110 | 112 | end |
|
111 | 113 | |
|
112 | 114 | def csv_content(column, issue) |
|
113 | value = column.value(issue) | |
|
115 | value = column.value_object(issue) | |
|
114 | 116 | if value.is_a?(Array) |
|
115 | 117 | value.collect {|v| csv_value(column, issue, v)}.compact.join(', ') |
|
116 | 118 | else |
@@ -119,22 +121,16 module QueriesHelper | |||
|
119 | 121 | end |
|
120 | 122 | |
|
121 | 123 | def csv_value(column, issue, value) |
|
122 | case value.class.name | |
|
123 | when 'Time' | |
|
124 | format_time(value) | |
|
125 | when 'Date' | |
|
126 | format_date(value) | |
|
127 | when 'Float' | |
|
128 | sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) | |
|
129 | when 'IssueRelation' | |
|
130 | other = value.other_issue(issue) | |
|
131 | l(value.label_for(issue)) + " ##{other.id}" | |
|
132 | when 'TrueClass' | |
|
133 | l(:general_text_Yes) | |
|
134 | when 'FalseClass' | |
|
135 | l(:general_text_No) | |
|
136 | else | |
|
137 | value.to_s | |
|
124 | format_object(value, false) do |value| | |
|
125 | case value.class.name | |
|
126 | when 'Float' | |
|
127 | sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) | |
|
128 | when 'IssueRelation' | |
|
129 | other = value.other_issue(issue) | |
|
130 | l(value.label_for(issue)) + " ##{other.id}" | |
|
131 | else | |
|
132 | value | |
|
133 | end | |
|
138 | 134 | end |
|
139 | 135 | end |
|
140 | 136 |
@@ -57,6 +57,10 class QueryColumn | |||
|
57 | 57 | object.send name |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | def value_object(object) | |
|
61 | object.send name | |
|
62 | end | |
|
63 | ||
|
60 | 64 | def css_classes |
|
61 | 65 | name |
|
62 | 66 | end |
@@ -80,10 +84,21 class QueryCustomFieldColumn < QueryColumn | |||
|
80 | 84 | @cf |
|
81 | 85 | end |
|
82 | 86 | |
|
83 | def value(object) | |
|
87 | def value_object(object) | |
|
84 | 88 | if custom_field.visible_by?(object.project, User.current) |
|
85 |
cv = object.custom_values.select {|v| v.custom_field_id == @cf.id} |
|
|
86 | cv.size > 1 ? cv.sort {|a,b| a.to_s <=> b.to_s} : cv.first | |
|
89 | cv = object.custom_values.select {|v| v.custom_field_id == @cf.id} | |
|
90 | cv.size > 1 ? cv.sort {|a,b| a.value.to_s <=> b.value.to_s} : cv.first | |
|
91 | else | |
|
92 | nil | |
|
93 | end | |
|
94 | end | |
|
95 | ||
|
96 | def value(object) | |
|
97 | raw = value_object(object) | |
|
98 | if raw.is_a?(Array) | |
|
99 | raw.map {|r| @cf.cast_value(r.value)} | |
|
100 | elsif raw | |
|
101 | @cf.cast_value(raw.value) | |
|
87 | 102 | else |
|
88 | 103 | nil |
|
89 | 104 | end |
@@ -105,7 +120,7 class QueryAssociationCustomFieldColumn < QueryCustomFieldColumn | |||
|
105 | 120 | @association = association |
|
106 | 121 | end |
|
107 | 122 | |
|
108 | def value(object) | |
|
123 | def value_object(object) | |
|
109 | 124 | if assoc = object.send(@association) |
|
110 | 125 | super(assoc) |
|
111 | 126 | end |
General Comments 0
You need to be logged in to leave comments.
Login now