##// END OF EJS Templates
Preserve Issues/Gantt/Calendar tab when displaying a saved query (#7605)....
Jean-Philippe Lang -
r4789:a11e3a85d619
parent child
Show More
@@ -1,279 +1,282
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 issue_list(issues, &block)
22 22 ancestors = []
23 23 issues.each do |issue|
24 24 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
25 25 ancestors.pop
26 26 end
27 27 yield issue, ancestors.size
28 28 ancestors << issue unless issue.leaf?
29 29 end
30 30 end
31 31
32 32 # Renders a HTML/CSS tooltip
33 33 #
34 34 # To use, a trigger div is needed. This is a div with the class of "tooltip"
35 35 # that contains this method wrapped in a span with the class of "tip"
36 36 #
37 37 # <div class="tooltip"><%= link_to_issue(issue) %>
38 38 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
39 39 # </div>
40 40 #
41 41 def render_issue_tooltip(issue)
42 42 @cached_label_status ||= l(:field_status)
43 43 @cached_label_start_date ||= l(:field_start_date)
44 44 @cached_label_due_date ||= l(:field_due_date)
45 45 @cached_label_assigned_to ||= l(:field_assigned_to)
46 46 @cached_label_priority ||= l(:field_priority)
47 47 @cached_label_project ||= l(:field_project)
48 48
49 49 link_to_issue(issue) + "<br /><br />" +
50 50 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />" +
51 51 "<strong>#{@cached_label_status}</strong>: #{issue.status.name}<br />" +
52 52 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
53 53 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
54 54 "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
55 55 "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
56 56 end
57 57
58 58 def render_issue_subject_with_tree(issue)
59 59 s = ''
60 60 issue.ancestors.each do |ancestor|
61 61 s << '<div>' + content_tag('p', link_to_issue(ancestor))
62 62 end
63 63 s << '<div>' + content_tag('h3', h(issue.subject))
64 64 s << '</div>' * (issue.ancestors.size + 1)
65 65 s
66 66 end
67 67
68 68 def render_descendants_tree(issue)
69 69 s = '<form><table class="list issues">'
70 70 issue_list(issue.descendants.sort_by(&:lft)) do |child, level|
71 71 s << content_tag('tr',
72 72 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
73 73 content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') +
74 74 content_tag('td', h(child.status)) +
75 75 content_tag('td', link_to_user(child.assigned_to)) +
76 76 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
77 77 :class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}")
78 78 end
79 79 s << '</form></table>'
80 80 s
81 81 end
82 82
83 83 def render_custom_fields_rows(issue)
84 84 return if issue.custom_field_values.empty?
85 85 ordered_values = []
86 86 half = (issue.custom_field_values.size / 2.0).ceil
87 87 half.times do |i|
88 88 ordered_values << issue.custom_field_values[i]
89 89 ordered_values << issue.custom_field_values[i + half]
90 90 end
91 91 s = "<tr>\n"
92 92 n = 0
93 93 ordered_values.compact.each do |value|
94 94 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
95 95 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
96 96 n += 1
97 97 end
98 98 s << "</tr>\n"
99 99 s
100 100 end
101 101
102 102 def sidebar_queries
103 103 unless @sidebar_queries
104 104 # User can see public queries and his own queries
105 105 visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
106 106 # Project specific queries and global queries
107 107 visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
108 108 @sidebar_queries = Query.find(:all,
109 109 :select => 'id, name, is_public',
110 110 :order => "name ASC",
111 111 :conditions => visible.conditions)
112 112 end
113 113 @sidebar_queries
114 114 end
115 115
116 116 def query_links(title, queries)
117 # links to #index on issues/show
118 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
119
117 120 content_tag('h3', title) +
118 121 queries.collect {|query|
119 link_to(h(query.name), :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query)
122 link_to(h(query.name), url_params.merge(:query_id => query))
120 123 }.join('<br />')
121 124 end
122 125
123 126 def render_sidebar_queries
124 127 out = ''
125 128 queries = sidebar_queries.select {|q| !q.is_public?}
126 129 out << query_links(l(:label_my_queries), queries) if queries.any?
127 130 queries = sidebar_queries.select {|q| q.is_public?}
128 131 out << query_links(l(:label_query_plural), queries) if queries.any?
129 132 out
130 133 end
131 134
132 135 def show_detail(detail, no_html=false)
133 136 case detail.property
134 137 when 'attr'
135 138 field = detail.prop_key.to_s.gsub(/\_id$/, "")
136 139 label = l(("field_" + field).to_sym)
137 140 case
138 141 when ['due_date', 'start_date'].include?(detail.prop_key)
139 142 value = format_date(detail.value.to_date) if detail.value
140 143 old_value = format_date(detail.old_value.to_date) if detail.old_value
141 144
142 145 when ['project_id', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key)
143 146 value = find_name_by_reflection(field, detail.value)
144 147 old_value = find_name_by_reflection(field, detail.old_value)
145 148
146 149 when detail.prop_key == 'estimated_hours'
147 150 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
148 151 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
149 152
150 153 when detail.prop_key == 'parent_id'
151 154 label = l(:field_parent_issue)
152 155 value = "##{detail.value}" unless detail.value.blank?
153 156 old_value = "##{detail.old_value}" unless detail.old_value.blank?
154 157 end
155 158 when 'cf'
156 159 custom_field = CustomField.find_by_id(detail.prop_key)
157 160 if custom_field
158 161 label = custom_field.name
159 162 value = format_value(detail.value, custom_field.field_format) if detail.value
160 163 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
161 164 end
162 165 when 'attachment'
163 166 label = l(:label_attachment)
164 167 end
165 168 call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
166 169
167 170 label ||= detail.prop_key
168 171 value ||= detail.value
169 172 old_value ||= detail.old_value
170 173
171 174 unless no_html
172 175 label = content_tag('strong', label)
173 176 old_value = content_tag("i", h(old_value)) if detail.old_value
174 177 old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
175 178 if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key)
176 179 # Link to the attachment if it has not been removed
177 180 value = link_to_attachment(a)
178 181 else
179 182 value = content_tag("i", h(value)) if value
180 183 end
181 184 end
182 185
183 186 if !detail.value.blank?
184 187 case detail.property
185 188 when 'attr', 'cf'
186 189 if !detail.old_value.blank?
187 190 l(:text_journal_changed, :label => label, :old => old_value, :new => value)
188 191 else
189 192 l(:text_journal_set_to, :label => label, :value => value)
190 193 end
191 194 when 'attachment'
192 195 l(:text_journal_added, :label => label, :value => value)
193 196 end
194 197 else
195 198 l(:text_journal_deleted, :label => label, :old => old_value)
196 199 end
197 200 end
198 201
199 202 # Find the name of an associated record stored in the field attribute
200 203 def find_name_by_reflection(field, id)
201 204 association = Issue.reflect_on_association(field.to_sym)
202 205 if association
203 206 record = association.class_name.constantize.find_by_id(id)
204 207 return record.name if record
205 208 end
206 209 end
207 210
208 211 # Renders issue children recursively
209 212 def render_api_issue_children(issue, api)
210 213 return if issue.leaf?
211 214 api.array :children do
212 215 issue.children.each do |child|
213 216 api.issue(:id => child.id) do
214 217 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
215 218 api.subject child.subject
216 219 render_api_issue_children(child, api)
217 220 end
218 221 end
219 222 end
220 223 end
221 224
222 225 def issues_to_csv(issues, project = nil)
223 226 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
224 227 decimal_separator = l(:general_csv_decimal_separator)
225 228 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
226 229 # csv header fields
227 230 headers = [ "#",
228 231 l(:field_status),
229 232 l(:field_project),
230 233 l(:field_tracker),
231 234 l(:field_priority),
232 235 l(:field_subject),
233 236 l(:field_assigned_to),
234 237 l(:field_category),
235 238 l(:field_fixed_version),
236 239 l(:field_author),
237 240 l(:field_start_date),
238 241 l(:field_due_date),
239 242 l(:field_done_ratio),
240 243 l(:field_estimated_hours),
241 244 l(:field_parent_issue),
242 245 l(:field_created_on),
243 246 l(:field_updated_on)
244 247 ]
245 248 # Export project custom fields if project is given
246 249 # otherwise export custom fields marked as "For all projects"
247 250 custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields
248 251 custom_fields.each {|f| headers << f.name}
249 252 # Description in the last column
250 253 headers << l(:field_description)
251 254 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
252 255 # csv lines
253 256 issues.each do |issue|
254 257 fields = [issue.id,
255 258 issue.status.name,
256 259 issue.project.name,
257 260 issue.tracker.name,
258 261 issue.priority.name,
259 262 issue.subject,
260 263 issue.assigned_to,
261 264 issue.category,
262 265 issue.fixed_version,
263 266 issue.author.name,
264 267 format_date(issue.start_date),
265 268 format_date(issue.due_date),
266 269 issue.done_ratio,
267 270 issue.estimated_hours.to_s.gsub('.', decimal_separator),
268 271 issue.parent_id,
269 272 format_time(issue.created_on),
270 273 format_time(issue.updated_on)
271 274 ]
272 275 custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
273 276 fields << issue.description
274 277 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
275 278 end
276 279 end
277 280 export
278 281 end
279 282 end
General Comments 0
You need to be logged in to leave comments. Login now