@@ -1,199 +1,199 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module IssuesHelper |
|
18 | module IssuesHelper | |
19 | include ApplicationHelper |
|
19 | include ApplicationHelper | |
20 |
|
20 | |||
21 | def render_issue_tooltip(issue) |
|
21 | def render_issue_tooltip(issue) | |
22 | @cached_label_start_date ||= l(:field_start_date) |
|
22 | @cached_label_start_date ||= l(:field_start_date) | |
23 | @cached_label_due_date ||= l(:field_due_date) |
|
23 | @cached_label_due_date ||= l(:field_due_date) | |
24 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
24 | @cached_label_assigned_to ||= l(:field_assigned_to) | |
25 | @cached_label_priority ||= l(:field_priority) |
|
25 | @cached_label_priority ||= l(:field_priority) | |
26 |
|
26 | |||
27 | link_to_issue(issue) + "<br /><br />" + |
|
27 | link_to_issue(issue) + "<br /><br />" + | |
28 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" + |
|
28 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" + | |
29 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" + |
|
29 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" + | |
30 | "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" + |
|
30 | "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" + | |
31 | "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}" |
|
31 | "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}" | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def render_custom_fields_rows(issue) |
|
34 | def render_custom_fields_rows(issue) | |
35 | return if issue.custom_field_values.empty? |
|
35 | return if issue.custom_field_values.empty? | |
36 | ordered_values = [] |
|
36 | ordered_values = [] | |
37 | half = (issue.custom_field_values.size / 2.0).ceil |
|
37 | half = (issue.custom_field_values.size / 2.0).ceil | |
38 | half.times do |i| |
|
38 | half.times do |i| | |
39 | ordered_values << issue.custom_field_values[i] |
|
39 | ordered_values << issue.custom_field_values[i] | |
40 | ordered_values << issue.custom_field_values[i + half] |
|
40 | ordered_values << issue.custom_field_values[i + half] | |
41 | end |
|
41 | end | |
42 | s = "<tr>\n" |
|
42 | s = "<tr>\n" | |
43 | n = 0 |
|
43 | n = 0 | |
44 | ordered_values.compact.each do |value| |
|
44 | ordered_values.compact.each do |value| | |
45 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
45 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 | |
46 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" |
|
46 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" | |
47 | n += 1 |
|
47 | n += 1 | |
48 | end |
|
48 | end | |
49 | s << "</tr>\n" |
|
49 | s << "</tr>\n" | |
50 | s |
|
50 | s | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def sidebar_queries |
|
53 | def sidebar_queries | |
54 | unless @sidebar_queries |
|
54 | unless @sidebar_queries | |
55 | # User can see public queries and his own queries |
|
55 | # User can see public queries and his own queries | |
56 | visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)]) |
|
56 | visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)]) | |
57 | # Project specific queries and global queries |
|
57 | # Project specific queries and global queries | |
58 | visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) |
|
58 | visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) | |
59 | @sidebar_queries = Query.find(:all, |
|
59 | @sidebar_queries = Query.find(:all, | |
60 | :select => 'id, name', |
|
60 | :select => 'id, name', | |
61 | :order => "name ASC", |
|
61 | :order => "name ASC", | |
62 | :conditions => visible.conditions) |
|
62 | :conditions => visible.conditions) | |
63 | end |
|
63 | end | |
64 | @sidebar_queries |
|
64 | @sidebar_queries | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def show_detail(detail, no_html=false) |
|
67 | def show_detail(detail, no_html=false) | |
68 | case detail.property |
|
68 | case detail.property | |
69 | when 'attr' |
|
69 | when 'attr' | |
70 | label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym) |
|
70 | label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym) | |
71 | case detail.prop_key |
|
71 | case detail.prop_key | |
72 | when 'due_date', 'start_date' |
|
72 | when 'due_date', 'start_date' | |
73 | value = format_date(detail.value.to_date) if detail.value |
|
73 | value = format_date(detail.value.to_date) if detail.value | |
74 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
74 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
75 | when 'project_id' |
|
75 | when 'project_id' | |
76 | p = Project.find_by_id(detail.value) and value = p.name if detail.value |
|
76 | p = Project.find_by_id(detail.value) and value = p.name if detail.value | |
77 | p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value |
|
77 | p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value | |
78 | when 'status_id' |
|
78 | when 'status_id' | |
79 | s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value |
|
79 | s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value | |
80 | s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value |
|
80 | s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value | |
81 | when 'tracker_id' |
|
81 | when 'tracker_id' | |
82 | t = Tracker.find_by_id(detail.value) and value = t.name if detail.value |
|
82 | t = Tracker.find_by_id(detail.value) and value = t.name if detail.value | |
83 | t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value |
|
83 | t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value | |
84 | when 'assigned_to_id' |
|
84 | when 'assigned_to_id' | |
85 | u = User.find_by_id(detail.value) and value = u.name if detail.value |
|
85 | u = User.find_by_id(detail.value) and value = u.name if detail.value | |
86 | u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value |
|
86 | u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value | |
87 | when 'priority_id' |
|
87 | when 'priority_id' | |
88 | e = IssuePriority.find_by_id(detail.value) and value = e.name if detail.value |
|
88 | e = IssuePriority.find_by_id(detail.value) and value = e.name if detail.value | |
89 | e = IssuePriority.find_by_id(detail.old_value) and old_value = e.name if detail.old_value |
|
89 | e = IssuePriority.find_by_id(detail.old_value) and old_value = e.name if detail.old_value | |
90 | when 'category_id' |
|
90 | when 'category_id' | |
91 | c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value |
|
91 | c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value | |
92 | c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value |
|
92 | c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value | |
93 | when 'fixed_version_id' |
|
93 | when 'fixed_version_id' | |
94 |
v = Version.find_by_id(detail.value) and value = |
|
94 | v = Version.find_by_id(detail.value) and value = v.name if detail.value | |
95 |
v = Version.find_by_id(detail.old_value) and old_value = |
|
95 | v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value | |
96 | when 'estimated_hours' |
|
96 | when 'estimated_hours' | |
97 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
97 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
98 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
98 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
99 | end |
|
99 | end | |
100 | when 'cf' |
|
100 | when 'cf' | |
101 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
101 | custom_field = CustomField.find_by_id(detail.prop_key) | |
102 | if custom_field |
|
102 | if custom_field | |
103 | label = custom_field.name |
|
103 | label = custom_field.name | |
104 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
104 | value = format_value(detail.value, custom_field.field_format) if detail.value | |
105 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
105 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value | |
106 | end |
|
106 | end | |
107 | when 'attachment' |
|
107 | when 'attachment' | |
108 | label = l(:label_attachment) |
|
108 | label = l(:label_attachment) | |
109 | end |
|
109 | end | |
110 | call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
110 | call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value }) | |
111 |
|
111 | |||
112 | label ||= detail.prop_key |
|
112 | label ||= detail.prop_key | |
113 | value ||= detail.value |
|
113 | value ||= detail.value | |
114 | old_value ||= detail.old_value |
|
114 | old_value ||= detail.old_value | |
115 |
|
115 | |||
116 | unless no_html |
|
116 | unless no_html | |
117 | label = content_tag('strong', label) |
|
117 | label = content_tag('strong', label) | |
118 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
118 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
119 | old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?) |
|
119 | old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?) | |
120 | if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key) |
|
120 | if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key) | |
121 | # Link to the attachment if it has not been removed |
|
121 | # Link to the attachment if it has not been removed | |
122 | value = link_to_attachment(a) |
|
122 | value = link_to_attachment(a) | |
123 | else |
|
123 | else | |
124 | value = content_tag("i", h(value)) if value |
|
124 | value = content_tag("i", h(value)) if value | |
125 | end |
|
125 | end | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | if !detail.value.blank? |
|
128 | if !detail.value.blank? | |
129 | case detail.property |
|
129 | case detail.property | |
130 | when 'attr', 'cf' |
|
130 | when 'attr', 'cf' | |
131 | if !detail.old_value.blank? |
|
131 | if !detail.old_value.blank? | |
132 | l(:text_journal_changed, :label => label, :old => old_value, :new => value) |
|
132 | l(:text_journal_changed, :label => label, :old => old_value, :new => value) | |
133 | else |
|
133 | else | |
134 | l(:text_journal_set_to, :label => label, :value => value) |
|
134 | l(:text_journal_set_to, :label => label, :value => value) | |
135 | end |
|
135 | end | |
136 | when 'attachment' |
|
136 | when 'attachment' | |
137 | l(:text_journal_added, :label => label, :value => value) |
|
137 | l(:text_journal_added, :label => label, :value => value) | |
138 | end |
|
138 | end | |
139 | else |
|
139 | else | |
140 | l(:text_journal_deleted, :label => label, :old => old_value) |
|
140 | l(:text_journal_deleted, :label => label, :old => old_value) | |
141 | end |
|
141 | end | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def issues_to_csv(issues, project = nil) |
|
144 | def issues_to_csv(issues, project = nil) | |
145 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
145 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
146 | decimal_separator = l(:general_csv_decimal_separator) |
|
146 | decimal_separator = l(:general_csv_decimal_separator) | |
147 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
147 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |
148 | # csv header fields |
|
148 | # csv header fields | |
149 | headers = [ "#", |
|
149 | headers = [ "#", | |
150 | l(:field_status), |
|
150 | l(:field_status), | |
151 | l(:field_project), |
|
151 | l(:field_project), | |
152 | l(:field_tracker), |
|
152 | l(:field_tracker), | |
153 | l(:field_priority), |
|
153 | l(:field_priority), | |
154 | l(:field_subject), |
|
154 | l(:field_subject), | |
155 | l(:field_assigned_to), |
|
155 | l(:field_assigned_to), | |
156 | l(:field_category), |
|
156 | l(:field_category), | |
157 | l(:field_fixed_version), |
|
157 | l(:field_fixed_version), | |
158 | l(:field_author), |
|
158 | l(:field_author), | |
159 | l(:field_start_date), |
|
159 | l(:field_start_date), | |
160 | l(:field_due_date), |
|
160 | l(:field_due_date), | |
161 | l(:field_done_ratio), |
|
161 | l(:field_done_ratio), | |
162 | l(:field_estimated_hours), |
|
162 | l(:field_estimated_hours), | |
163 | l(:field_created_on), |
|
163 | l(:field_created_on), | |
164 | l(:field_updated_on) |
|
164 | l(:field_updated_on) | |
165 | ] |
|
165 | ] | |
166 | # Export project custom fields if project is given |
|
166 | # Export project custom fields if project is given | |
167 | # otherwise export custom fields marked as "For all projects" |
|
167 | # otherwise export custom fields marked as "For all projects" | |
168 | custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields |
|
168 | custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields | |
169 | custom_fields.each {|f| headers << f.name} |
|
169 | custom_fields.each {|f| headers << f.name} | |
170 | # Description in the last column |
|
170 | # Description in the last column | |
171 | headers << l(:field_description) |
|
171 | headers << l(:field_description) | |
172 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
172 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
173 | # csv lines |
|
173 | # csv lines | |
174 | issues.each do |issue| |
|
174 | issues.each do |issue| | |
175 | fields = [issue.id, |
|
175 | fields = [issue.id, | |
176 | issue.status.name, |
|
176 | issue.status.name, | |
177 | issue.project.name, |
|
177 | issue.project.name, | |
178 | issue.tracker.name, |
|
178 | issue.tracker.name, | |
179 | issue.priority.name, |
|
179 | issue.priority.name, | |
180 | issue.subject, |
|
180 | issue.subject, | |
181 | issue.assigned_to, |
|
181 | issue.assigned_to, | |
182 | issue.category, |
|
182 | issue.category, | |
183 | issue.fixed_version, |
|
183 | issue.fixed_version, | |
184 | issue.author.name, |
|
184 | issue.author.name, | |
185 | format_date(issue.start_date), |
|
185 | format_date(issue.start_date), | |
186 | format_date(issue.due_date), |
|
186 | format_date(issue.due_date), | |
187 | issue.done_ratio, |
|
187 | issue.done_ratio, | |
188 | issue.estimated_hours.to_s.gsub('.', decimal_separator), |
|
188 | issue.estimated_hours.to_s.gsub('.', decimal_separator), | |
189 | format_time(issue.created_on), |
|
189 | format_time(issue.created_on), | |
190 | format_time(issue.updated_on) |
|
190 | format_time(issue.updated_on) | |
191 | ] |
|
191 | ] | |
192 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } |
|
192 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } | |
193 | fields << issue.description |
|
193 | fields << issue.description | |
194 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
194 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
195 | end |
|
195 | end | |
196 | end |
|
196 | end | |
197 | export |
|
197 | export | |
198 | end |
|
198 | end | |
199 | end |
|
199 | end |
General Comments 0
You need to be logged in to leave comments.
Login now