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