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