@@ -1,184 +1,187 | |||
|
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 | def sidebar_queries |
|
37 | 37 | unless @sidebar_queries |
|
38 | 38 | # User can see public queries and his own queries |
|
39 | 39 | visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)]) |
|
40 | 40 | # Project specific queries and global queries |
|
41 | 41 | visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) |
|
42 | 42 | @sidebar_queries = Query.find(:all, |
|
43 | 43 | :order => "name ASC", |
|
44 | 44 | :conditions => visible.conditions) |
|
45 | 45 | end |
|
46 | 46 | @sidebar_queries |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def show_detail(detail, no_html=false) |
|
50 | 50 | case detail.property |
|
51 | 51 | when 'attr' |
|
52 | 52 | label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym) |
|
53 | 53 | case detail.prop_key |
|
54 | 54 | when 'due_date', 'start_date' |
|
55 | 55 | value = format_date(detail.value.to_date) if detail.value |
|
56 | 56 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
57 | 57 | when 'project_id' |
|
58 | 58 | p = Project.find_by_id(detail.value) and value = p.name if detail.value |
|
59 | 59 | p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value |
|
60 | 60 | when 'status_id' |
|
61 | 61 | s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value |
|
62 | 62 | s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value |
|
63 | 63 | when 'tracker_id' |
|
64 | 64 | t = Tracker.find_by_id(detail.value) and value = t.name if detail.value |
|
65 | 65 | t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value |
|
66 | 66 | when 'assigned_to_id' |
|
67 | 67 | u = User.find_by_id(detail.value) and value = u.name if detail.value |
|
68 | 68 | u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value |
|
69 | 69 | when 'priority_id' |
|
70 | 70 | e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value |
|
71 | 71 | e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value |
|
72 | 72 | when 'category_id' |
|
73 | 73 | c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value |
|
74 | 74 | c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value |
|
75 | 75 | when 'fixed_version_id' |
|
76 | 76 | v = Version.find_by_id(detail.value) and value = v.name if detail.value |
|
77 | 77 | v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value |
|
78 | when 'estimated_hours' | |
|
79 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
|
80 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
|
78 | 81 | end |
|
79 | 82 | when 'cf' |
|
80 | 83 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
81 | 84 | if custom_field |
|
82 | 85 | label = custom_field.name |
|
83 | 86 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
84 | 87 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
85 | 88 | end |
|
86 | 89 | when 'attachment' |
|
87 | 90 | label = l(:label_attachment) |
|
88 | 91 | end |
|
89 | 92 | |
|
90 | 93 | label ||= detail.prop_key |
|
91 | 94 | value ||= detail.value |
|
92 | 95 | old_value ||= detail.old_value |
|
93 | 96 | |
|
94 | 97 | unless no_html |
|
95 | 98 | label = content_tag('strong', label) |
|
96 | 99 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
97 | 100 | old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?) |
|
98 | 101 | if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key) |
|
99 | 102 | # Link to the attachment if it has not been removed |
|
100 | 103 | value = link_to_attachment(a) |
|
101 | 104 | else |
|
102 | 105 | value = content_tag("i", h(value)) if value |
|
103 | 106 | end |
|
104 | 107 | end |
|
105 | 108 | |
|
106 | 109 | if !detail.value.blank? |
|
107 | 110 | case detail.property |
|
108 | 111 | when 'attr', 'cf' |
|
109 | 112 | if !detail.old_value.blank? |
|
110 | 113 | label + " " + l(:text_journal_changed, old_value, value) |
|
111 | 114 | else |
|
112 | 115 | label + " " + l(:text_journal_set_to, value) |
|
113 | 116 | end |
|
114 | 117 | when 'attachment' |
|
115 | 118 | "#{label} #{value} #{l(:label_added)}" |
|
116 | 119 | end |
|
117 | 120 | else |
|
118 | 121 | case detail.property |
|
119 | 122 | when 'attr', 'cf' |
|
120 | 123 | label + " " + l(:text_journal_deleted) + " (#{old_value})" |
|
121 | 124 | when 'attachment' |
|
122 | 125 | "#{label} #{old_value} #{l(:label_deleted)}" |
|
123 | 126 | end |
|
124 | 127 | end |
|
125 | 128 | end |
|
126 | 129 | |
|
127 | 130 | def issues_to_csv(issues, project = nil) |
|
128 | 131 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
129 | 132 | decimal_separator = l(:general_csv_decimal_separator) |
|
130 | 133 | export = StringIO.new |
|
131 | 134 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
132 | 135 | # csv header fields |
|
133 | 136 | headers = [ "#", |
|
134 | 137 | l(:field_status), |
|
135 | 138 | l(:field_project), |
|
136 | 139 | l(:field_tracker), |
|
137 | 140 | l(:field_priority), |
|
138 | 141 | l(:field_subject), |
|
139 | 142 | l(:field_assigned_to), |
|
140 | 143 | l(:field_category), |
|
141 | 144 | l(:field_fixed_version), |
|
142 | 145 | l(:field_author), |
|
143 | 146 | l(:field_start_date), |
|
144 | 147 | l(:field_due_date), |
|
145 | 148 | l(:field_done_ratio), |
|
146 | 149 | l(:field_estimated_hours), |
|
147 | 150 | l(:field_created_on), |
|
148 | 151 | l(:field_updated_on) |
|
149 | 152 | ] |
|
150 | 153 | # Export project custom fields if project is given |
|
151 | 154 | # otherwise export custom fields marked as "For all projects" |
|
152 | 155 | custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields |
|
153 | 156 | custom_fields.each {|f| headers << f.name} |
|
154 | 157 | # Description in the last column |
|
155 | 158 | headers << l(:field_description) |
|
156 | 159 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
157 | 160 | # csv lines |
|
158 | 161 | issues.each do |issue| |
|
159 | 162 | fields = [issue.id, |
|
160 | 163 | issue.status.name, |
|
161 | 164 | issue.project.name, |
|
162 | 165 | issue.tracker.name, |
|
163 | 166 | issue.priority.name, |
|
164 | 167 | issue.subject, |
|
165 | 168 | issue.assigned_to, |
|
166 | 169 | issue.category, |
|
167 | 170 | issue.fixed_version, |
|
168 | 171 | issue.author.name, |
|
169 | 172 | format_date(issue.start_date), |
|
170 | 173 | format_date(issue.due_date), |
|
171 | 174 | issue.done_ratio, |
|
172 | 175 | issue.estimated_hours.to_s.gsub('.', decimal_separator), |
|
173 | 176 | format_time(issue.created_on), |
|
174 | 177 | format_time(issue.updated_on) |
|
175 | 178 | ] |
|
176 | 179 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } |
|
177 | 180 | fields << issue.description |
|
178 | 181 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
179 | 182 | end |
|
180 | 183 | end |
|
181 | 184 | export.rewind |
|
182 | 185 | export |
|
183 | 186 | end |
|
184 | 187 | end |
General Comments 0
You need to be logged in to leave comments.
Login now