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