##// END OF EJS Templates
Adds parent issue id to the issues CSV export....
Jean-Philippe Lang -
r3503:06d2c3fd4e4a
parent child
Show More
@@ -1,226 +1,228
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 module IssuesHelper
19 19 include ApplicationHelper
20 20
21 21 def render_issue_tooltip(issue)
22 22 @cached_label_start_date ||= l(:field_start_date)
23 23 @cached_label_due_date ||= l(:field_due_date)
24 24 @cached_label_assigned_to ||= l(:field_assigned_to)
25 25 @cached_label_priority ||= l(:field_priority)
26 26
27 27 link_to_issue(issue) + "<br /><br />" +
28 28 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
29 29 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
30 30 "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
31 31 "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
32 32 end
33 33
34 34 def render_issue_subject_with_tree(issue)
35 35 s = ''
36 36 issue.ancestors.each do |ancestor|
37 37 s << '<div>' + content_tag('p', link_to_issue(ancestor))
38 38 end
39 39 s << '<div>' + content_tag('h3', h(issue.subject))
40 40 s << '</div>' * (issue.ancestors.size + 1)
41 41 s
42 42 end
43 43
44 44 def render_descendants_tree(issue)
45 45 s = '<form><table class="list issues">'
46 46 ancestors = []
47 47 issue.descendants.sort_by(&:lft).each do |child|
48 48 level = child.level - issue.level - 1
49 49 s << content_tag('tr',
50 50 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
51 51 content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject',
52 52 :style => "padding-left: #{level * 20}px") +
53 53 content_tag('td', h(child.status)) +
54 54 content_tag('td', link_to_user(child.assigned_to)) +
55 55 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
56 56 :class => "issue-#{child.id} hascontextmenu")
57 57 end
58 58 s << '</form></table>'
59 59 s
60 60 end
61 61
62 62 def render_custom_fields_rows(issue)
63 63 return if issue.custom_field_values.empty?
64 64 ordered_values = []
65 65 half = (issue.custom_field_values.size / 2.0).ceil
66 66 half.times do |i|
67 67 ordered_values << issue.custom_field_values[i]
68 68 ordered_values << issue.custom_field_values[i + half]
69 69 end
70 70 s = "<tr>\n"
71 71 n = 0
72 72 ordered_values.compact.each do |value|
73 73 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
74 74 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
75 75 n += 1
76 76 end
77 77 s << "</tr>\n"
78 78 s
79 79 end
80 80
81 81 def sidebar_queries
82 82 unless @sidebar_queries
83 83 # User can see public queries and his own queries
84 84 visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
85 85 # Project specific queries and global queries
86 86 visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
87 87 @sidebar_queries = Query.find(:all,
88 88 :select => 'id, name',
89 89 :order => "name ASC",
90 90 :conditions => visible.conditions)
91 91 end
92 92 @sidebar_queries
93 93 end
94 94
95 95 def show_detail(detail, no_html=false)
96 96 case detail.property
97 97 when 'attr'
98 98 field = detail.prop_key.to_s.gsub(/\_id$/, "")
99 99 label = l(("field_" + field).to_sym)
100 100 case
101 101 when ['due_date', 'start_date'].include?(detail.prop_key)
102 102 value = format_date(detail.value.to_date) if detail.value
103 103 old_value = format_date(detail.old_value.to_date) if detail.old_value
104 104
105 105 when ['project_id', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key)
106 106 value = find_name_by_reflection(field, detail.value)
107 107 old_value = find_name_by_reflection(field, detail.old_value)
108 108
109 109 when detail.prop_key == 'estimated_hours'
110 110 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
111 111 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
112 112
113 113 when detail.prop_key == 'parent_id'
114 114 label = l(:field_parent_issue)
115 115 value = "##{detail.value}" unless detail.value.blank?
116 116 old_value = "##{detail.old_value}" unless detail.old_value.blank?
117 117 end
118 118 when 'cf'
119 119 custom_field = CustomField.find_by_id(detail.prop_key)
120 120 if custom_field
121 121 label = custom_field.name
122 122 value = format_value(detail.value, custom_field.field_format) if detail.value
123 123 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
124 124 end
125 125 when 'attachment'
126 126 label = l(:label_attachment)
127 127 end
128 128 call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
129 129
130 130 label ||= detail.prop_key
131 131 value ||= detail.value
132 132 old_value ||= detail.old_value
133 133
134 134 unless no_html
135 135 label = content_tag('strong', label)
136 136 old_value = content_tag("i", h(old_value)) if detail.old_value
137 137 old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
138 138 if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key)
139 139 # Link to the attachment if it has not been removed
140 140 value = link_to_attachment(a)
141 141 else
142 142 value = content_tag("i", h(value)) if value
143 143 end
144 144 end
145 145
146 146 if !detail.value.blank?
147 147 case detail.property
148 148 when 'attr', 'cf'
149 149 if !detail.old_value.blank?
150 150 l(:text_journal_changed, :label => label, :old => old_value, :new => value)
151 151 else
152 152 l(:text_journal_set_to, :label => label, :value => value)
153 153 end
154 154 when 'attachment'
155 155 l(:text_journal_added, :label => label, :value => value)
156 156 end
157 157 else
158 158 l(:text_journal_deleted, :label => label, :old => old_value)
159 159 end
160 160 end
161 161
162 162 # Find the name of an associated record stored in the field attribute
163 163 def find_name_by_reflection(field, id)
164 164 association = Issue.reflect_on_association(field.to_sym)
165 165 if association
166 166 record = association.class_name.constantize.find_by_id(id)
167 167 return record.name if record
168 168 end
169 169 end
170 170
171 171 def issues_to_csv(issues, project = nil)
172 172 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
173 173 decimal_separator = l(:general_csv_decimal_separator)
174 174 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
175 175 # csv header fields
176 176 headers = [ "#",
177 177 l(:field_status),
178 178 l(:field_project),
179 179 l(:field_tracker),
180 180 l(:field_priority),
181 181 l(:field_subject),
182 182 l(:field_assigned_to),
183 183 l(:field_category),
184 184 l(:field_fixed_version),
185 185 l(:field_author),
186 186 l(:field_start_date),
187 187 l(:field_due_date),
188 188 l(:field_done_ratio),
189 189 l(:field_estimated_hours),
190 l(:field_parent_issue),
190 191 l(:field_created_on),
191 192 l(:field_updated_on)
192 193 ]
193 194 # Export project custom fields if project is given
194 195 # otherwise export custom fields marked as "For all projects"
195 196 custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields
196 197 custom_fields.each {|f| headers << f.name}
197 198 # Description in the last column
198 199 headers << l(:field_description)
199 200 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
200 201 # csv lines
201 202 issues.each do |issue|
202 203 fields = [issue.id,
203 204 issue.status.name,
204 205 issue.project.name,
205 206 issue.tracker.name,
206 207 issue.priority.name,
207 208 issue.subject,
208 209 issue.assigned_to,
209 210 issue.category,
210 211 issue.fixed_version,
211 212 issue.author.name,
212 213 format_date(issue.start_date),
213 214 format_date(issue.due_date),
214 215 issue.done_ratio,
215 216 issue.estimated_hours.to_s.gsub('.', decimal_separator),
217 issue.parent_id,
216 218 format_time(issue.created_on),
217 219 format_time(issue.updated_on)
218 220 ]
219 221 custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
220 222 fields << issue.description
221 223 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
222 224 end
223 225 end
224 226 export
225 227 end
226 228 end
General Comments 0
You need to be logged in to leave comments. Login now