@@ -1,160 +1,158 | |||||
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 | require 'csv' |
|
18 | require 'csv' | |
19 |
|
19 | |||
20 | module IssuesHelper |
|
20 | module IssuesHelper | |
21 |
|
21 | |||
22 | def render_issue_tooltip(issue) |
|
22 | def render_issue_tooltip(issue) | |
23 | @cached_label_start_date ||= l(:field_start_date) |
|
23 | @cached_label_start_date ||= l(:field_start_date) | |
24 | @cached_label_due_date ||= l(:field_due_date) |
|
24 | @cached_label_due_date ||= l(:field_due_date) | |
25 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
25 | @cached_label_assigned_to ||= l(:field_assigned_to) | |
26 | @cached_label_priority ||= l(:field_priority) |
|
26 | @cached_label_priority ||= l(:field_priority) | |
27 |
|
27 | |||
28 | link_to_issue(issue) + ": #{h(issue.subject)}<br /><br />" + |
|
28 | link_to_issue(issue) + ": #{h(issue.subject)}<br /><br />" + | |
29 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" + |
|
29 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" + | |
30 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" + |
|
30 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" + | |
31 | "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" + |
|
31 | "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" + | |
32 | "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}" |
|
32 | "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}" | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def show_detail(detail, no_html=false) |
|
35 | def show_detail(detail, no_html=false) | |
36 | case detail.property |
|
36 | case detail.property | |
37 | when 'attr' |
|
37 | when 'attr' | |
38 | label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym) |
|
38 | label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym) | |
39 | case detail.prop_key |
|
39 | case detail.prop_key | |
40 | when 'due_date', 'start_date' |
|
40 | when 'due_date', 'start_date' | |
41 | value = format_date(detail.value.to_date) if detail.value |
|
41 | value = format_date(detail.value.to_date) if detail.value | |
42 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
42 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
43 | when 'status_id' |
|
43 | when 'status_id' | |
44 | s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value |
|
44 | s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value | |
45 | s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value |
|
45 | s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value | |
46 | when 'assigned_to_id' |
|
46 | when 'assigned_to_id' | |
47 | u = User.find_by_id(detail.value) and value = u.name if detail.value |
|
47 | u = User.find_by_id(detail.value) and value = u.name if detail.value | |
48 | u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value |
|
48 | u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value | |
49 | when 'priority_id' |
|
49 | when 'priority_id' | |
50 | e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value |
|
50 | e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value | |
51 | e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value |
|
51 | e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value | |
52 | when 'category_id' |
|
52 | when 'category_id' | |
53 | c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value |
|
53 | c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value | |
54 | c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value |
|
54 | c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value | |
55 | when 'fixed_version_id' |
|
55 | when 'fixed_version_id' | |
56 | v = Version.find_by_id(detail.value) and value = v.name if detail.value |
|
56 | v = Version.find_by_id(detail.value) and value = v.name if detail.value | |
57 | v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value |
|
57 | v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value | |
58 | end |
|
58 | end | |
59 | when 'cf' |
|
59 | when 'cf' | |
60 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
60 | custom_field = CustomField.find_by_id(detail.prop_key) | |
61 | if custom_field |
|
61 | if custom_field | |
62 | label = custom_field.name |
|
62 | label = custom_field.name | |
63 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
63 | value = format_value(detail.value, custom_field.field_format) if detail.value | |
64 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
64 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value | |
65 | end |
|
65 | end | |
66 | when 'attachment' |
|
66 | when 'attachment' | |
67 | label = l(:label_attachment) |
|
67 | label = l(:label_attachment) | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | label ||= detail.prop_key |
|
70 | label ||= detail.prop_key | |
71 | value ||= detail.value |
|
71 | value ||= detail.value | |
72 | old_value ||= detail.old_value |
|
72 | old_value ||= detail.old_value | |
73 |
|
73 | |||
74 | unless no_html |
|
74 | unless no_html | |
75 | label = content_tag('strong', label) |
|
75 | label = content_tag('strong', label) | |
76 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
76 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
77 | old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?) |
|
77 | old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?) | |
78 | if detail.property == 'attachment' && !value.blank? && Attachment.find_by_id(detail.prop_key) |
|
78 | if detail.property == 'attachment' && !value.blank? && Attachment.find_by_id(detail.prop_key) | |
79 | # Link to the attachment if it has not been removed |
|
79 | # Link to the attachment if it has not been removed | |
80 | value = link_to(value, :controller => 'attachments', :action => 'download', :id => detail.prop_key) |
|
80 | value = link_to(value, :controller => 'attachments', :action => 'download', :id => detail.prop_key) | |
81 | else |
|
81 | else | |
82 | value = content_tag("i", h(value)) if value |
|
82 | value = content_tag("i", h(value)) if value | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | if !detail.value.blank? |
|
86 | if !detail.value.blank? | |
87 | case detail.property |
|
87 | case detail.property | |
88 | when 'attr', 'cf' |
|
88 | when 'attr', 'cf' | |
89 | if !detail.old_value.blank? |
|
89 | if !detail.old_value.blank? | |
90 | label + " " + l(:text_journal_changed, old_value, value) |
|
90 | label + " " + l(:text_journal_changed, old_value, value) | |
91 | else |
|
91 | else | |
92 | label + " " + l(:text_journal_set_to, value) |
|
92 | label + " " + l(:text_journal_set_to, value) | |
93 | end |
|
93 | end | |
94 | when 'attachment' |
|
94 | when 'attachment' | |
95 | "#{label} #{value} #{l(:label_added)}" |
|
95 | "#{label} #{value} #{l(:label_added)}" | |
96 | end |
|
96 | end | |
97 | else |
|
97 | else | |
98 | case detail.property |
|
98 | case detail.property | |
99 | when 'attr', 'cf' |
|
99 | when 'attr', 'cf' | |
100 | label + " " + l(:text_journal_deleted) + " (#{old_value})" |
|
100 | label + " " + l(:text_journal_deleted) + " (#{old_value})" | |
101 | when 'attachment' |
|
101 | when 'attachment' | |
102 | "#{label} #{old_value} #{l(:label_deleted)}" |
|
102 | "#{label} #{old_value} #{l(:label_deleted)}" | |
103 | end |
|
103 | end | |
104 | end |
|
104 | end | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def issues_to_csv(issues, project = nil) |
|
107 | def issues_to_csv(issues, project = nil) | |
108 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
108 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
109 | export = StringIO.new |
|
109 | export = StringIO.new | |
110 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
110 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
111 | # csv header fields |
|
111 | # csv header fields | |
112 | headers = [ "#", |
|
112 | headers = [ "#", | |
113 | l(:field_status), |
|
113 | l(:field_status), | |
114 | l(:field_project), |
|
114 | l(:field_project), | |
115 | l(:field_tracker), |
|
115 | l(:field_tracker), | |
116 | l(:field_priority), |
|
116 | l(:field_priority), | |
117 | l(:field_subject), |
|
117 | l(:field_subject), | |
118 | l(:field_assigned_to), |
|
118 | l(:field_assigned_to), | |
119 | l(:field_category), |
|
119 | l(:field_category), | |
120 | l(:field_fixed_version), |
|
120 | l(:field_fixed_version), | |
121 | l(:field_author), |
|
121 | l(:field_author), | |
122 | l(:field_start_date), |
|
122 | l(:field_start_date), | |
123 | l(:field_due_date), |
|
123 | l(:field_due_date), | |
124 | l(:field_done_ratio), |
|
124 | l(:field_done_ratio), | |
125 | l(:field_created_on), |
|
125 | l(:field_created_on), | |
126 | l(:field_updated_on) |
|
126 | l(:field_updated_on) | |
127 | ] |
|
127 | ] | |
128 |
# |
|
128 | # Export project custom fields if project is given | |
129 | for custom_field in project.all_custom_fields |
|
129 | # otherwise export custom fields marked as "For all projects" | |
130 | headers << custom_field.name |
|
130 | custom_fields = project.nil? ? IssueCustomField.for_all : project.all_custom_fields | |
131 | end if project |
|
131 | custom_fields.each {|f| headers << f.name} | |
132 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
132 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
133 | # csv lines |
|
133 | # csv lines | |
134 | issues.each do |issue| |
|
134 | issues.each do |issue| | |
135 | fields = [issue.id, |
|
135 | fields = [issue.id, | |
136 | issue.status.name, |
|
136 | issue.status.name, | |
137 | issue.project.name, |
|
137 | issue.project.name, | |
138 | issue.tracker.name, |
|
138 | issue.tracker.name, | |
139 | issue.priority.name, |
|
139 | issue.priority.name, | |
140 | issue.subject, |
|
140 | issue.subject, | |
141 | issue.assigned_to, |
|
141 | issue.assigned_to, | |
142 | issue.category, |
|
142 | issue.category, | |
143 | issue.fixed_version, |
|
143 | issue.fixed_version, | |
144 | issue.author.name, |
|
144 | issue.author.name, | |
145 | issue.start_date ? l_date(issue.start_date) : nil, |
|
145 | issue.start_date ? l_date(issue.start_date) : nil, | |
146 | issue.due_date ? l_date(issue.due_date) : nil, |
|
146 | issue.due_date ? l_date(issue.due_date) : nil, | |
147 | issue.done_ratio, |
|
147 | issue.done_ratio, | |
148 | l_datetime(issue.created_on), |
|
148 | l_datetime(issue.created_on), | |
149 | l_datetime(issue.updated_on) |
|
149 | l_datetime(issue.updated_on) | |
150 | ] |
|
150 | ] | |
151 | for custom_field in project.all_custom_fields |
|
151 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } | |
152 | fields << (show_value issue.custom_value_for(custom_field)) |
|
|||
153 | end if project |
|
|||
154 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
152 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
155 | end |
|
153 | end | |
156 | end |
|
154 | end | |
157 | export.rewind |
|
155 | export.rewind | |
158 | export |
|
156 | export | |
159 | end |
|
157 | end | |
160 | end |
|
158 | end |
General Comments 0
You need to be logged in to leave comments.
Login now