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