##// END OF EJS Templates
Display time spent on the issue and the total time spent like estimated hours (#17550)....
Jean-Philippe Lang -
r13891:31bffaa053fc
parent child
Show More
@@ -1,500 +1,516
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module IssuesHelper
21 21 include ApplicationHelper
22 22 include Redmine::Export::PDF::IssuesPdfHelper
23 23
24 24 def issue_list(issues, &block)
25 25 ancestors = []
26 26 issues.each do |issue|
27 27 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
28 28 ancestors.pop
29 29 end
30 30 yield issue, ancestors.size
31 31 ancestors << issue unless issue.leaf?
32 32 end
33 33 end
34 34
35 35 def grouped_issue_list(issues, query, issue_count_by_group, &block)
36 36 previous_group, first = false, true
37 37 issue_list(issues) do |issue, level|
38 38 group_name = group_count = nil
39 39 if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first)
40 40 if group.blank? && group != false
41 41 group_name = "(#{l(:label_blank_value)})"
42 42 else
43 43 group_name = column_content(query.group_by_column, issue)
44 44 end
45 45 group_name ||= ""
46 46 group_count = issue_count_by_group[group]
47 47 end
48 48 yield issue, level, group_name, group_count
49 49 previous_group, first = group, false
50 50 end
51 51 end
52 52
53 53 # Renders a HTML/CSS tooltip
54 54 #
55 55 # To use, a trigger div is needed. This is a div with the class of "tooltip"
56 56 # that contains this method wrapped in a span with the class of "tip"
57 57 #
58 58 # <div class="tooltip"><%= link_to_issue(issue) %>
59 59 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
60 60 # </div>
61 61 #
62 62 def render_issue_tooltip(issue)
63 63 @cached_label_status ||= l(:field_status)
64 64 @cached_label_start_date ||= l(:field_start_date)
65 65 @cached_label_due_date ||= l(:field_due_date)
66 66 @cached_label_assigned_to ||= l(:field_assigned_to)
67 67 @cached_label_priority ||= l(:field_priority)
68 68 @cached_label_project ||= l(:field_project)
69 69
70 70 link_to_issue(issue) + "<br /><br />".html_safe +
71 71 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
72 72 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
73 73 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
74 74 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
75 75 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
76 76 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
77 77 end
78 78
79 79 def issue_heading(issue)
80 80 h("#{issue.tracker} ##{issue.id}")
81 81 end
82 82
83 83 def render_issue_subject_with_tree(issue)
84 84 s = ''
85 85 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
86 86 ancestors.each do |ancestor|
87 87 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
88 88 end
89 89 s << '<div>'
90 90 subject = h(issue.subject)
91 91 if issue.is_private?
92 92 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
93 93 end
94 94 s << content_tag('h3', subject)
95 95 s << '</div>' * (ancestors.size + 1)
96 96 s.html_safe
97 97 end
98 98
99 99 def render_descendants_tree(issue)
100 100 s = '<form><table class="list issues">'
101 101 issue_list(issue.descendants.visible.preload(:status, :priority, :tracker).sort_by(&:lft)) do |child, level|
102 102 css = "issue issue-#{child.id} hascontextmenu"
103 103 css << " idnt idnt-#{level}" if level > 0
104 104 s << content_tag('tr',
105 105 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
106 106 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
107 107 content_tag('td', h(child.status)) +
108 108 content_tag('td', link_to_user(child.assigned_to)) +
109 109 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
110 110 :class => css)
111 111 end
112 112 s << '</table></form>'
113 113 s.html_safe
114 114 end
115 115
116 116 def issue_estimated_hours_details(issue)
117 s = issue.estimated_hours.present? ? l_hours(issue.estimated_hours) : ""
118 unless issue.leaf? || issue.total_estimated_hours.nil?
119 s << " (#{l(:label_total)}: #{l_hours(issue.total_estimated_hours)})"
117 if issue.total_estimated_hours.present?
118 if issue.total_estimated_hours == issue.estimated_hours
119 l_hours_short(issue.estimated_hours)
120 else
121 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
122 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
123 s.html_safe
124 end
125 end
126 end
127
128 def issue_spent_hours_details(issue)
129 if issue.total_spent_hours > 0
130 if issue.total_spent_hours == issue.spent_hours
131 link_to(l_hours_short(issue.spent_hours), issue_time_entries_path(issue))
132 else
133 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
134 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), issue_time_entries_path(issue)})"
135 s.html_safe
136 end
120 137 end
121 s.html_safe
122 138 end
123 139
124 140 # Returns an array of error messages for bulk edited issues
125 141 def bulk_edit_error_messages(issues)
126 142 messages = {}
127 143 issues.each do |issue|
128 144 issue.errors.full_messages.each do |message|
129 145 messages[message] ||= []
130 146 messages[message] << issue
131 147 end
132 148 end
133 149 messages.map { |message, issues|
134 150 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
135 151 }
136 152 end
137 153
138 154 # Returns a link for adding a new subtask to the given issue
139 155 def link_to_new_subtask(issue)
140 156 attrs = {
141 157 :tracker_id => issue.tracker,
142 158 :parent_issue_id => issue
143 159 }
144 160 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
145 161 end
146 162
147 163 class IssueFieldsRows
148 164 include ActionView::Helpers::TagHelper
149 165
150 166 def initialize
151 167 @left = []
152 168 @right = []
153 169 end
154 170
155 171 def left(*args)
156 172 args.any? ? @left << cells(*args) : @left
157 173 end
158 174
159 175 def right(*args)
160 176 args.any? ? @right << cells(*args) : @right
161 177 end
162 178
163 179 def size
164 180 @left.size > @right.size ? @left.size : @right.size
165 181 end
166 182
167 183 def to_html
168 184 html = ''.html_safe
169 185 blank = content_tag('th', '') + content_tag('td', '')
170 186 size.times do |i|
171 187 left = @left[i] || blank
172 188 right = @right[i] || blank
173 189 html << content_tag('tr', left + right)
174 190 end
175 191 html
176 192 end
177 193
178 194 def cells(label, text, options={})
179 195 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
180 196 end
181 197 end
182 198
183 199 def issue_fields_rows
184 200 r = IssueFieldsRows.new
185 201 yield r
186 202 r.to_html
187 203 end
188 204
189 205 def render_custom_fields_rows(issue)
190 206 values = issue.visible_custom_field_values
191 207 return if values.empty?
192 208 ordered_values = []
193 209 half = (values.size / 2.0).ceil
194 210 half.times do |i|
195 211 ordered_values << values[i]
196 212 ordered_values << values[i + half]
197 213 end
198 214 s = "<tr>\n"
199 215 n = 0
200 216 ordered_values.compact.each do |value|
201 217 css = "cf_#{value.custom_field.id}"
202 218 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
203 219 s << "\t<th class=\"#{css}\">#{ custom_field_name_tag(value.custom_field) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n"
204 220 n += 1
205 221 end
206 222 s << "</tr>\n"
207 223 s.html_safe
208 224 end
209 225
210 226 # Returns the path for updating the issue form
211 227 # with project as the current project
212 228 def update_issue_form_path(project, issue)
213 229 options = {:format => 'js'}
214 230 if issue.new_record?
215 231 if project
216 232 new_project_issue_path(project, options)
217 233 else
218 234 new_issue_path(options)
219 235 end
220 236 else
221 237 edit_issue_path(issue, options)
222 238 end
223 239 end
224 240
225 241 # Returns the number of descendants for an array of issues
226 242 def issues_descendant_count(issues)
227 243 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
228 244 ids -= issues.map(&:id)
229 245 ids.size
230 246 end
231 247
232 248 def issues_destroy_confirmation_message(issues)
233 249 issues = [issues] unless issues.is_a?(Array)
234 250 message = l(:text_issues_destroy_confirmation)
235 251
236 252 descendant_count = issues_descendant_count(issues)
237 253 if descendant_count > 0
238 254 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
239 255 end
240 256 message
241 257 end
242 258
243 259 # Returns an array of users that are proposed as watchers
244 260 # on the new issue form
245 261 def users_for_new_issue_watchers(issue)
246 262 users = issue.watcher_users
247 263 if issue.project.users.count <= 20
248 264 users = (users + issue.project.users.sort).uniq
249 265 end
250 266 users
251 267 end
252 268
253 269 def sidebar_queries
254 270 unless @sidebar_queries
255 271 @sidebar_queries = IssueQuery.visible.
256 272 order("#{Query.table_name}.name ASC").
257 273 # Project specific queries and global queries
258 274 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
259 275 to_a
260 276 end
261 277 @sidebar_queries
262 278 end
263 279
264 280 def query_links(title, queries)
265 281 return '' if queries.empty?
266 282 # links to #index on issues/show
267 283 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
268 284
269 285 content_tag('h3', title) + "\n" +
270 286 content_tag('ul',
271 287 queries.collect {|query|
272 288 css = 'query'
273 289 css << ' selected' if query == @query
274 290 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
275 291 }.join("\n").html_safe,
276 292 :class => 'queries'
277 293 ) + "\n"
278 294 end
279 295
280 296 def render_sidebar_queries
281 297 out = ''.html_safe
282 298 out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?))
283 299 out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?))
284 300 out
285 301 end
286 302
287 303 def email_issue_attributes(issue, user)
288 304 items = []
289 305 %w(author status priority assigned_to category fixed_version).each do |attribute|
290 306 unless issue.disabled_core_fields.include?(attribute+"_id")
291 307 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
292 308 end
293 309 end
294 310 issue.visible_custom_field_values(user).each do |value|
295 311 items << "#{value.custom_field.name}: #{show_value(value, false)}"
296 312 end
297 313 items
298 314 end
299 315
300 316 def render_email_issue_attributes(issue, user, html=false)
301 317 items = email_issue_attributes(issue, user)
302 318 if html
303 319 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
304 320 else
305 321 items.map{|s| "* #{s}"}.join("\n")
306 322 end
307 323 end
308 324
309 325 # Returns the textual representation of a journal details
310 326 # as an array of strings
311 327 def details_to_strings(details, no_html=false, options={})
312 328 options[:only_path] = (options[:only_path] == false ? false : true)
313 329 strings = []
314 330 values_by_field = {}
315 331 details.each do |detail|
316 332 if detail.property == 'cf'
317 333 field = detail.custom_field
318 334 if field && field.multiple?
319 335 values_by_field[field] ||= {:added => [], :deleted => []}
320 336 if detail.old_value
321 337 values_by_field[field][:deleted] << detail.old_value
322 338 end
323 339 if detail.value
324 340 values_by_field[field][:added] << detail.value
325 341 end
326 342 next
327 343 end
328 344 end
329 345 strings << show_detail(detail, no_html, options)
330 346 end
331 347 if values_by_field.present?
332 348 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
333 349 values_by_field.each do |field, changes|
334 350 if changes[:added].any?
335 351 detail = multiple_values_detail.new('cf', field.id.to_s, field)
336 352 detail.value = changes[:added]
337 353 strings << show_detail(detail, no_html, options)
338 354 end
339 355 if changes[:deleted].any?
340 356 detail = multiple_values_detail.new('cf', field.id.to_s, field)
341 357 detail.old_value = changes[:deleted]
342 358 strings << show_detail(detail, no_html, options)
343 359 end
344 360 end
345 361 end
346 362 strings
347 363 end
348 364
349 365 # Returns the textual representation of a single journal detail
350 366 def show_detail(detail, no_html=false, options={})
351 367 multiple = false
352 368 show_diff = false
353 369
354 370 case detail.property
355 371 when 'attr'
356 372 field = detail.prop_key.to_s.gsub(/\_id$/, "")
357 373 label = l(("field_" + field).to_sym)
358 374 case detail.prop_key
359 375 when 'due_date', 'start_date'
360 376 value = format_date(detail.value.to_date) if detail.value
361 377 old_value = format_date(detail.old_value.to_date) if detail.old_value
362 378
363 379 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
364 380 'priority_id', 'category_id', 'fixed_version_id'
365 381 value = find_name_by_reflection(field, detail.value)
366 382 old_value = find_name_by_reflection(field, detail.old_value)
367 383
368 384 when 'estimated_hours'
369 385 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
370 386 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
371 387
372 388 when 'parent_id'
373 389 label = l(:field_parent_issue)
374 390 value = "##{detail.value}" unless detail.value.blank?
375 391 old_value = "##{detail.old_value}" unless detail.old_value.blank?
376 392
377 393 when 'is_private'
378 394 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
379 395 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
380 396
381 397 when 'description'
382 398 show_diff = true
383 399 end
384 400 when 'cf'
385 401 custom_field = detail.custom_field
386 402 if custom_field
387 403 label = custom_field.name
388 404 if custom_field.format.class.change_as_diff
389 405 show_diff = true
390 406 else
391 407 multiple = custom_field.multiple?
392 408 value = format_value(detail.value, custom_field) if detail.value
393 409 old_value = format_value(detail.old_value, custom_field) if detail.old_value
394 410 end
395 411 end
396 412 when 'attachment'
397 413 label = l(:label_attachment)
398 414 when 'relation'
399 415 if detail.value && !detail.old_value
400 416 rel_issue = Issue.visible.find_by_id(detail.value)
401 417 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
402 418 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
403 419 elsif detail.old_value && !detail.value
404 420 rel_issue = Issue.visible.find_by_id(detail.old_value)
405 421 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
406 422 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
407 423 end
408 424 relation_type = IssueRelation::TYPES[detail.prop_key]
409 425 label = l(relation_type[:name]) if relation_type
410 426 end
411 427 call_hook(:helper_issues_show_detail_after_setting,
412 428 {:detail => detail, :label => label, :value => value, :old_value => old_value })
413 429
414 430 label ||= detail.prop_key
415 431 value ||= detail.value
416 432 old_value ||= detail.old_value
417 433
418 434 unless no_html
419 435 label = content_tag('strong', label)
420 436 old_value = content_tag("i", h(old_value)) if detail.old_value
421 437 if detail.old_value && detail.value.blank? && detail.property != 'relation'
422 438 old_value = content_tag("del", old_value)
423 439 end
424 440 if detail.property == 'attachment' && value.present? &&
425 441 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
426 442 # Link to the attachment if it has not been removed
427 443 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
428 444 if options[:only_path] != false && atta.is_text?
429 445 value += link_to(
430 446 image_tag('magnifier.png'),
431 447 :controller => 'attachments', :action => 'show',
432 448 :id => atta, :filename => atta.filename
433 449 )
434 450 end
435 451 else
436 452 value = content_tag("i", h(value)) if value
437 453 end
438 454 end
439 455
440 456 if show_diff
441 457 s = l(:text_journal_changed_no_detail, :label => label)
442 458 unless no_html
443 459 diff_link = link_to 'diff',
444 460 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
445 461 :detail_id => detail.id, :only_path => options[:only_path]},
446 462 :title => l(:label_view_diff)
447 463 s << " (#{ diff_link })"
448 464 end
449 465 s.html_safe
450 466 elsif detail.value.present?
451 467 case detail.property
452 468 when 'attr', 'cf'
453 469 if detail.old_value.present?
454 470 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
455 471 elsif multiple
456 472 l(:text_journal_added, :label => label, :value => value).html_safe
457 473 else
458 474 l(:text_journal_set_to, :label => label, :value => value).html_safe
459 475 end
460 476 when 'attachment', 'relation'
461 477 l(:text_journal_added, :label => label, :value => value).html_safe
462 478 end
463 479 else
464 480 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
465 481 end
466 482 end
467 483
468 484 # Find the name of an associated record stored in the field attribute
469 485 def find_name_by_reflection(field, id)
470 486 unless id.present?
471 487 return nil
472 488 end
473 489 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
474 490 association = Issue.reflect_on_association(key.first.to_sym)
475 491 name = nil
476 492 if association
477 493 record = association.klass.find_by_id(key.last)
478 494 if record
479 495 name = record.name.force_encoding('UTF-8')
480 496 end
481 497 end
482 498 hash[key] = name
483 499 end
484 500 @detail_value_name_by_reflection[[field, id]]
485 501 end
486 502
487 503 # Renders issue children recursively
488 504 def render_api_issue_children(issue, api)
489 505 return if issue.leaf?
490 506 api.array :children do
491 507 issue.children.each do |child|
492 508 api.issue(:id => child.id) do
493 509 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
494 510 api.subject child.subject
495 511 render_api_issue_children(child, api)
496 512 end
497 513 end
498 514 end
499 515 end
500 516 end
@@ -1,160 +1,162
1 1 <%= render :partial => 'action_menu' %>
2 2
3 3 <h2><%= issue_heading(@issue) %></h2>
4 4
5 5 <div class="<%= @issue.css_classes %> details">
6 6 <% if @prev_issue_id || @next_issue_id %>
7 7 <div class="next-prev-links contextual">
8 8 <%= link_to_if @prev_issue_id,
9 9 "\xc2\xab #{l(:label_previous)}",
10 10 (@prev_issue_id ? issue_path(@prev_issue_id) : nil),
11 11 :title => "##{@prev_issue_id}",
12 12 :accesskey => accesskey(:previous) %> |
13 13 <% if @issue_position && @issue_count %>
14 14 <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> |
15 15 <% end %>
16 16 <%= link_to_if @next_issue_id,
17 17 "#{l(:label_next)} \xc2\xbb",
18 18 (@next_issue_id ? issue_path(@next_issue_id) : nil),
19 19 :title => "##{@next_issue_id}",
20 20 :accesskey => accesskey(:next) %>
21 21 </div>
22 22 <% end %>
23 23
24 24 <%= avatar(@issue.author, :size => "50") %>
25 25
26 26 <div class="subject">
27 27 <%= render_issue_subject_with_tree(@issue) %>
28 28 </div>
29 29 <p class="author">
30 30 <%= authoring @issue.created_on, @issue.author %>.
31 31 <% if @issue.created_on != @issue.updated_on %>
32 32 <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>.
33 33 <% end %>
34 34 </p>
35 35
36 36 <table class="attributes">
37 37 <%= issue_fields_rows do |rows|
38 38 rows.left l(:field_status), @issue.status.name, :class => 'status'
39 39 rows.left l(:field_priority), @issue.priority.name, :class => 'priority'
40 40
41 41 unless @issue.disabled_core_fields.include?('assigned_to_id')
42 42 rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to'
43 43 end
44 44 unless @issue.disabled_core_fields.include?('category_id')
45 45 rows.left l(:field_category), (@issue.category ? @issue.category.name : "-"), :class => 'category'
46 46 end
47 47 unless @issue.disabled_core_fields.include?('fixed_version_id')
48 48 rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version'
49 49 end
50 50
51 51 unless @issue.disabled_core_fields.include?('start_date')
52 52 rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date'
53 53 end
54 54 unless @issue.disabled_core_fields.include?('due_date')
55 55 rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date'
56 56 end
57 57 unless @issue.disabled_core_fields.include?('done_ratio')
58 58 rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress'
59 59 end
60 60 unless @issue.disabled_core_fields.include?('estimated_hours')
61 61 unless @issue.total_estimated_hours.nil?
62 62 rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), :class => 'estimated-hours'
63 63 end
64 64 end
65 65 if User.current.allowed_to?(:view_time_entries, @project)
66 rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), issue_time_entries_path(@issue)) : "-"), :class => 'spent-time'
66 if @issue.total_spent_hours > 0
67 rows.right l(:label_spent_time), issue_spent_hours_details(@issue), :class => 'spent-time'
68 end
67 69 end
68 70 end %>
69 71 <%= render_custom_fields_rows(@issue) %>
70 72 <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %>
71 73 </table>
72 74
73 75 <% if @issue.description? || @issue.attachments.any? -%>
74 76 <hr />
75 77 <% if @issue.description? %>
76 78 <div class="description">
77 79 <div class="contextual">
78 80 <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %>
79 81 </div>
80 82
81 83 <p><strong><%=l(:field_description)%></strong></p>
82 84 <div class="wiki">
83 85 <%= textilizable @issue, :description, :attachments => @issue.attachments %>
84 86 </div>
85 87 </div>
86 88 <% end %>
87 89 <%= link_to_attachments @issue, :thumbnails => true %>
88 90 <% end -%>
89 91
90 92 <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %>
91 93
92 94 <% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
93 95 <hr />
94 96 <div id="issue_tree">
95 97 <div class="contextual">
96 98 <%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %>
97 99 </div>
98 100 <p><strong><%=l(:label_subtask_plural)%></strong></p>
99 101 <%= render_descendants_tree(@issue) unless @issue.leaf? %>
100 102 </div>
101 103 <% end %>
102 104
103 105 <% if @relations.present? || User.current.allowed_to?(:manage_issue_relations, @project) %>
104 106 <hr />
105 107 <div id="relations">
106 108 <%= render :partial => 'relations' %>
107 109 </div>
108 110 <% end %>
109 111
110 112 </div>
111 113
112 114 <% if @changesets.present? %>
113 115 <div id="issue-changesets">
114 116 <h3><%=l(:label_associated_revisions)%></h3>
115 117 <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %>
116 118 </div>
117 119 <% end %>
118 120
119 121 <% if @journals.present? %>
120 122 <div id="history">
121 123 <h3><%=l(:label_history)%></h3>
122 124 <%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %>
123 125 </div>
124 126 <% end %>
125 127
126 128
127 129 <div style="clear: both;"></div>
128 130 <%= render :partial => 'action_menu' %>
129 131
130 132 <div style="clear: both;"></div>
131 133 <% if @issue.editable? %>
132 134 <div id="update" style="display:none;">
133 135 <h3><%= l(:button_edit) %></h3>
134 136 <%= render :partial => 'edit' %>
135 137 </div>
136 138 <% end %>
137 139
138 140 <% other_formats_links do |f| %>
139 141 <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
140 142 <%= f.link_to 'PDF' %>
141 143 <% end %>
142 144
143 145 <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %>
144 146
145 147 <% content_for :sidebar do %>
146 148 <%= render :partial => 'issues/sidebar' %>
147 149
148 150 <% if User.current.allowed_to?(:add_issue_watchers, @project) ||
149 151 (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %>
150 152 <div id="watchers">
151 153 <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %>
152 154 </div>
153 155 <% end %>
154 156 <% end %>
155 157
156 158 <% content_for :header_tags do %>
157 159 <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %>
158 160 <% end %>
159 161
160 162 <%= context_menu issues_context_menu_path %>
@@ -1,191 +1,195
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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 Redmine
19 19 module I18n
20 20 def self.included(base)
21 21 base.extend Redmine::I18n
22 22 end
23 23
24 24 def l(*args)
25 25 case args.size
26 26 when 1
27 27 ::I18n.t(*args)
28 28 when 2
29 29 if args.last.is_a?(Hash)
30 30 ::I18n.t(*args)
31 31 elsif args.last.is_a?(String)
32 32 ::I18n.t(args.first, :value => args.last)
33 33 else
34 34 ::I18n.t(args.first, :count => args.last)
35 35 end
36 36 else
37 37 raise "Translation string with multiple values: #{args.first}"
38 38 end
39 39 end
40 40
41 41 def l_or_humanize(s, options={})
42 42 k = "#{options[:prefix]}#{s}".to_sym
43 43 ::I18n.t(k, :default => s.to_s.humanize)
44 44 end
45 45
46 46 def l_hours(hours)
47 47 hours = hours.to_f
48 48 l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
49 49 end
50 50
51 def l_hours_short(hours)
52 "%.2f h" % hours.to_f
53 end
54
51 55 def ll(lang, str, value=nil)
52 56 ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" })
53 57 end
54 58
55 59 def format_date(date)
56 60 return nil unless date
57 61 options = {}
58 62 options[:format] = Setting.date_format unless Setting.date_format.blank?
59 63 ::I18n.l(date.to_date, options)
60 64 end
61 65
62 66 def format_time(time, include_date = true)
63 67 return nil unless time
64 68 options = {}
65 69 options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format)
66 70 time = time.to_time if time.is_a?(String)
67 71 zone = User.current.time_zone
68 72 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
69 73 (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
70 74 end
71 75
72 76 def day_name(day)
73 77 ::I18n.t('date.day_names')[day % 7]
74 78 end
75 79
76 80 def day_letter(day)
77 81 ::I18n.t('date.abbr_day_names')[day % 7].first
78 82 end
79 83
80 84 def month_name(month)
81 85 ::I18n.t('date.month_names')[month]
82 86 end
83 87
84 88 def valid_languages
85 89 ::I18n.available_locales
86 90 end
87 91
88 92 # Returns an array of languages names and code sorted by names, example:
89 93 # [["Deutsch", "de"], ["English", "en"] ...]
90 94 #
91 95 # The result is cached to prevent from loading all translations files
92 96 # unless :cache => false option is given
93 97 def languages_options(options={})
94 98 options = if options[:cache] == false
95 99 valid_languages.
96 100 select {|locale| ::I18n.exists?(:general_lang_name, locale)}.
97 101 map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.
98 102 sort {|x,y| x.first <=> y.first }
99 103 else
100 104 ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do
101 105 languages_options :cache => false
102 106 end
103 107 end
104 108 options.map {|name, lang| [name.force_encoding("UTF-8"), lang.force_encoding("UTF-8")]}
105 109 end
106 110
107 111 def find_language(lang)
108 112 @@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k }
109 113 @@languages_lookup[lang.to_s.downcase]
110 114 end
111 115
112 116 def set_language_if_valid(lang)
113 117 if l = find_language(lang)
114 118 ::I18n.locale = l
115 119 end
116 120 end
117 121
118 122 def current_language
119 123 ::I18n.locale
120 124 end
121 125
122 126 # Custom backend based on I18n::Backend::Simple with the following changes:
123 127 # * lazy loading of translation files
124 128 # * available_locales are determined by looking at translation file names
125 129 class Backend
126 130 (class << self; self; end).class_eval { public :include }
127 131
128 132 module Implementation
129 133 include ::I18n::Backend::Base
130 134
131 135 # Stores translations for the given locale in memory.
132 136 # This uses a deep merge for the translations hash, so existing
133 137 # translations will be overwritten by new ones only at the deepest
134 138 # level of the hash.
135 139 def store_translations(locale, data, options = {})
136 140 locale = locale.to_sym
137 141 translations[locale] ||= {}
138 142 data = data.deep_symbolize_keys
139 143 translations[locale].deep_merge!(data)
140 144 end
141 145
142 146 # Get available locales from the translations filenames
143 147 def available_locales
144 148 @available_locales ||= ::I18n.load_path.map {|path| File.basename(path, '.*')}.uniq.sort.map(&:to_sym)
145 149 end
146 150
147 151 # Clean up translations
148 152 def reload!
149 153 @translations = nil
150 154 @available_locales = nil
151 155 super
152 156 end
153 157
154 158 protected
155 159
156 160 def init_translations(locale)
157 161 locale = locale.to_s
158 162 paths = ::I18n.load_path.select {|path| File.basename(path, '.*') == locale}
159 163 load_translations(paths)
160 164 translations[locale] ||= {}
161 165 end
162 166
163 167 def translations
164 168 @translations ||= {}
165 169 end
166 170
167 171 # Looks up a translation from the translations hash. Returns nil if
168 172 # eiher key is nil, or locale, scope or key do not exist as a key in the
169 173 # nested translations hash. Splits keys or scopes containing dots
170 174 # into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as
171 175 # <tt>%w(currency format)</tt>.
172 176 def lookup(locale, key, scope = [], options = {})
173 177 init_translations(locale) unless translations.key?(locale)
174 178 keys = ::I18n.normalize_keys(locale, key, scope, options[:separator])
175 179
176 180 keys.inject(translations) do |result, _key|
177 181 _key = _key.to_sym
178 182 return nil unless result.is_a?(Hash) && result.has_key?(_key)
179 183 result = result[_key]
180 184 result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
181 185 result
182 186 end
183 187 end
184 188 end
185 189
186 190 include Implementation
187 191 # Adds fallback to default locale for untranslated strings
188 192 include ::I18n::Backend::Fallbacks
189 193 end
190 194 end
191 195 end
General Comments 0
You need to be logged in to leave comments. Login now