You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issues_helper.rb 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module IssuesHelper
  19. include ApplicationHelper
  20. include Redmine::Export::PDF::IssuesPdfHelper
  21. def issue_list(issues, &block)
  22. ancestors = []
  23. issues.each do |issue|
  24. while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
  25. ancestors.pop
  26. end
  27. yield issue, ancestors.size
  28. ancestors << issue unless issue.leaf?
  29. end
  30. end
  31. def grouped_issue_list(issues, query, &block)
  32. ancestors = []
  33. grouped_query_results(issues, query) do |issue, group_name, group_count, group_totals|
  34. while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
  35. ancestors.pop
  36. end
  37. yield issue, ancestors.size, group_name, group_count, group_totals
  38. ancestors << issue unless issue.leaf?
  39. end
  40. end
  41. # Renders a HTML/CSS tooltip
  42. #
  43. # To use, a trigger div is needed. This is a div with the class of "tooltip"
  44. # that contains this method wrapped in a span with the class of "tip"
  45. #
  46. # <div class="tooltip"><%= link_to_issue(issue) %>
  47. # <span class="tip"><%= render_issue_tooltip(issue) %></span>
  48. # </div>
  49. #
  50. def render_issue_tooltip(issue)
  51. @cached_label_status ||= l(:field_status)
  52. @cached_label_start_date ||= l(:field_start_date)
  53. @cached_label_due_date ||= l(:field_due_date)
  54. @cached_label_assigned_to ||= l(:field_assigned_to)
  55. @cached_label_priority ||= l(:field_priority)
  56. @cached_label_project ||= l(:field_project)
  57. link_to_issue(issue) + "<br /><br />".html_safe +
  58. "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
  59. "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name) + (" (#{format_date(issue.closed_on)})" if issue.closed?)}<br />".html_safe +
  60. "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
  61. "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
  62. "<strong>#{@cached_label_assigned_to}</strong>: #{avatar(issue.assigned_to, :size => "13", :title => l(:field_assigned_to)) if issue.assigned_to} #{h(issue.assigned_to)}<br />".html_safe +
  63. "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
  64. end
  65. def issue_heading(issue)
  66. h("#{issue.tracker} ##{issue.id}")
  67. end
  68. def render_issue_subject_with_tree(issue)
  69. s = +''
  70. ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
  71. ancestors.each do |ancestor|
  72. s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
  73. end
  74. s << '<div>'
  75. subject = h(issue.subject)
  76. if issue.is_private?
  77. subject = subject + ' ' + content_tag('span', l(:field_is_private), :class => 'badge badge-private private')
  78. end
  79. s << content_tag('h3', subject)
  80. s << '</div>' * (ancestors.size + 1)
  81. s.html_safe
  82. end
  83. def render_descendants_tree(issue)
  84. manage_relations = User.current.allowed_to?(:manage_subtasks, issue.project)
  85. s = +'<table class="list issues odd-even">'
  86. issue_list(issue.descendants.visible.preload(:status, :priority, :tracker, :assigned_to).sort_by(&:lft)) do |child, level|
  87. css = +"issue issue-#{child.id} hascontextmenu #{child.css_classes}"
  88. css << " idnt idnt-#{level}" if level > 0
  89. buttons = manage_relations ? link_to(l(:label_delete_link_to_subtask),
  90. issue_path({:id => child.id, :issue => {:parent_issue_id => ''}, :back_url => issue_path(issue.id), :no_flash => '1'}),
  91. :method => :put,
  92. :data => {:confirm => l(:text_are_you_sure)},
  93. :title => l(:label_delete_link_to_subtask),
  94. :class => 'icon-only icon-link-break'
  95. ) : "".html_safe
  96. buttons << link_to_context_menu
  97. s << content_tag('tr',
  98. content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
  99. content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
  100. content_tag('td', h(child.status), :class => 'status') +
  101. content_tag('td', link_to_user(child.assigned_to), :class => 'assigned_to') +
  102. content_tag('td', child.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(child.done_ratio), :class=> 'done_ratio') +
  103. content_tag('td', buttons, :class => 'buttons'),
  104. :class => css)
  105. end
  106. s << '</table>'
  107. s.html_safe
  108. end
  109. # Renders the list of related issues on the issue details view
  110. def render_issue_relations(issue, relations)
  111. manage_relations = User.current.allowed_to?(:manage_issue_relations, issue.project)
  112. s = ''.html_safe
  113. relations.each do |relation|
  114. other_issue = relation.other_issue(issue)
  115. css = "issue hascontextmenu #{other_issue.css_classes}"
  116. buttons = manage_relations ? link_to(l(:label_relation_delete),
  117. relation_path(relation),
  118. :remote => true,
  119. :method => :delete,
  120. :data => {:confirm => l(:text_are_you_sure)},
  121. :title => l(:label_relation_delete),
  122. :class => 'icon-only icon-link-break'
  123. ) :"".html_safe
  124. buttons << link_to_context_menu
  125. s << content_tag('tr',
  126. content_tag('td', check_box_tag("ids[]", other_issue.id, false, :id => nil), :class => 'checkbox') +
  127. content_tag('td', relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe, :class => 'subject', :style => 'width: 50%') +
  128. content_tag('td', other_issue.status, :class => 'status') +
  129. content_tag('td', format_date(other_issue.start_date), :class => 'start_date') +
  130. content_tag('td', format_date(other_issue.due_date), :class => 'due_date') +
  131. content_tag('td', other_issue.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(other_issue.done_ratio), :class=> 'done_ratio') +
  132. content_tag('td', buttons, :class => 'buttons'),
  133. :id => "relation-#{relation.id}",
  134. :class => css)
  135. end
  136. content_tag('table', s, :class => 'list issues odd-even')
  137. end
  138. def issue_estimated_hours_details(issue)
  139. if issue.total_estimated_hours.present?
  140. if issue.total_estimated_hours == issue.estimated_hours
  141. l_hours_short(issue.estimated_hours)
  142. else
  143. s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
  144. s += " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
  145. s.html_safe
  146. end
  147. end
  148. end
  149. def issue_spent_hours_details(issue)
  150. if issue.total_spent_hours > 0
  151. path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
  152. if issue.total_spent_hours == issue.spent_hours
  153. link_to(l_hours_short(issue.spent_hours), path)
  154. else
  155. s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
  156. s += " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
  157. s.html_safe
  158. end
  159. end
  160. end
  161. def issue_due_date_details(issue)
  162. return if issue&.due_date.nil?
  163. s = format_date(issue.due_date)
  164. s += " (#{due_date_distance_in_words(issue.due_date)})" unless issue.closed?
  165. s
  166. end
  167. # Returns a link for adding a new subtask to the given issue
  168. def link_to_new_subtask(issue)
  169. attrs = {
  170. :parent_issue_id => issue
  171. }
  172. attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
  173. link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs, :back_url => issue_path(issue)))
  174. end
  175. def trackers_options_for_select(issue)
  176. trackers = trackers_for_select(issue)
  177. trackers.collect {|t| [t.name, t.id]}
  178. end
  179. def trackers_for_select(issue)
  180. trackers = issue.allowed_target_trackers
  181. if issue.new_record? && issue.parent_issue_id.present?
  182. trackers = trackers.reject do |tracker|
  183. issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
  184. end
  185. end
  186. trackers
  187. end
  188. class IssueFieldsRows
  189. include ActionView::Helpers::TagHelper
  190. def initialize
  191. @left = []
  192. @right = []
  193. end
  194. def left(*args)
  195. args.any? ? @left << cells(*args) : @left
  196. end
  197. def right(*args)
  198. args.any? ? @right << cells(*args) : @right
  199. end
  200. def size
  201. @left.size > @right.size ? @left.size : @right.size
  202. end
  203. def to_html
  204. content =
  205. content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
  206. content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
  207. content_tag('div', content, :class => 'splitcontent')
  208. end
  209. def cells(label, text, options={})
  210. options[:class] = [options[:class] || "", 'attribute'].join(' ')
  211. content_tag 'div',
  212. content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
  213. options
  214. end
  215. end
  216. def issue_fields_rows
  217. r = IssueFieldsRows.new
  218. yield r
  219. r.to_html
  220. end
  221. def render_half_width_custom_fields_rows(issue)
  222. values = issue.visible_custom_field_values.reject {|value| value.custom_field.full_width_layout?}
  223. return if values.empty?
  224. half = (values.size / 2.0).ceil
  225. issue_fields_rows do |rows|
  226. values.each_with_index do |value, i|
  227. m = (i < half ? :left : :right)
  228. rows.send m, custom_field_name_tag(value.custom_field), custom_field_value_tag(value), :class => value.custom_field.css_classes
  229. end
  230. end
  231. end
  232. def render_full_width_custom_fields_rows(issue)
  233. values = issue.visible_custom_field_values.select {|value| value.custom_field.full_width_layout?}
  234. return if values.empty?
  235. s = ''.html_safe
  236. values.each_with_index do |value, i|
  237. attr_value_tag = custom_field_value_tag(value)
  238. next if attr_value_tag.blank?
  239. content =
  240. content_tag('hr') +
  241. content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) +
  242. content_tag('div', attr_value_tag, class: 'value')
  243. s << content_tag('div', content, class: "#{value.custom_field.css_classes} attribute")
  244. end
  245. s
  246. end
  247. # Returns the path for updating the issue form
  248. # with project as the current project
  249. def update_issue_form_path(project, issue)
  250. options = {:format => 'js'}
  251. if issue.new_record?
  252. if project
  253. new_project_issue_path(project, options)
  254. else
  255. new_issue_path(options)
  256. end
  257. else
  258. edit_issue_path(issue, options)
  259. end
  260. end
  261. # Returns the number of descendants for an array of issues
  262. def issues_descendant_count(issues)
  263. ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
  264. ids -= issues.map(&:id)
  265. ids.size
  266. end
  267. def issues_destroy_confirmation_message(issues)
  268. issues = [issues] unless issues.is_a?(Array)
  269. message = l(:text_issues_destroy_confirmation)
  270. descendant_count = issues_descendant_count(issues)
  271. if descendant_count > 0
  272. message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
  273. end
  274. message
  275. end
  276. # Returns an array of users that are proposed as watchers
  277. # on the new issue form
  278. def users_for_new_issue_watchers(issue)
  279. users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}
  280. if issue.project.users.count <= 20
  281. users = (users + issue.project.users.sort).uniq
  282. end
  283. users
  284. end
  285. def email_issue_attributes(issue, user, html)
  286. items = []
  287. %w(author status priority assigned_to category fixed_version start_date due_date).each do |attribute|
  288. if issue.disabled_core_fields.grep(/^#{attribute}(_id)?$/).empty?
  289. attr_value = (issue.send attribute).to_s
  290. next if attr_value.blank?
  291. if html
  292. items << content_tag('strong', "#{l("field_#{attribute}")}: ") + attr_value
  293. else
  294. items << "#{l("field_#{attribute}")}: #{attr_value}"
  295. end
  296. end
  297. end
  298. issue.visible_custom_field_values(user).each do |value|
  299. cf_value = show_value(value, false)
  300. next if cf_value.blank?
  301. if html
  302. items << content_tag('strong', "#{value.custom_field.name}: ") + cf_value
  303. else
  304. items << "#{value.custom_field.name}: #{cf_value}"
  305. end
  306. end
  307. items
  308. end
  309. def render_email_issue_attributes(issue, user, html=false)
  310. items = email_issue_attributes(issue, user, html)
  311. if html
  312. content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details")
  313. else
  314. items.map{|s| "* #{s}"}.join("\n")
  315. end
  316. end
  317. MultipleValuesDetail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
  318. # Returns the textual representation of a journal details
  319. # as an array of strings
  320. def details_to_strings(details, no_html=false, options={})
  321. options[:only_path] = (options[:only_path] == false ? false : true)
  322. strings = []
  323. values_by_field = {}
  324. details.each do |detail|
  325. if detail.property == 'cf'
  326. field = detail.custom_field
  327. if field && field.multiple?
  328. values_by_field[field] ||= {:added => [], :deleted => []}
  329. if detail.old_value
  330. values_by_field[field][:deleted] << detail.old_value
  331. end
  332. if detail.value
  333. values_by_field[field][:added] << detail.value
  334. end
  335. next
  336. end
  337. end
  338. strings << show_detail(detail, no_html, options)
  339. end
  340. if values_by_field.present?
  341. values_by_field.each do |field, changes|
  342. if changes[:added].any?
  343. detail = MultipleValuesDetail.new('cf', field.id.to_s, field)
  344. detail.value = changes[:added]
  345. strings << show_detail(detail, no_html, options)
  346. end
  347. if changes[:deleted].any?
  348. detail = MultipleValuesDetail.new('cf', field.id.to_s, field)
  349. detail.old_value = changes[:deleted]
  350. strings << show_detail(detail, no_html, options)
  351. end
  352. end
  353. end
  354. strings
  355. end
  356. # Returns the textual representation of a single journal detail
  357. def show_detail(detail, no_html=false, options={})
  358. multiple = false
  359. show_diff = false
  360. no_details = false
  361. case detail.property
  362. when 'attr'
  363. field = detail.prop_key.to_s.gsub(/\_id$/, "")
  364. label = l(("field_" + field).to_sym)
  365. case detail.prop_key
  366. when 'due_date', 'start_date'
  367. value = format_date(detail.value.to_date) if detail.value
  368. old_value = format_date(detail.old_value.to_date) if detail.old_value
  369. when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
  370. 'priority_id', 'category_id', 'fixed_version_id'
  371. value = find_name_by_reflection(field, detail.value)
  372. old_value = find_name_by_reflection(field, detail.old_value)
  373. when 'estimated_hours'
  374. value = l_hours_short(detail.value.to_f) unless detail.value.blank?
  375. old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
  376. when 'parent_id'
  377. label = l(:field_parent_issue)
  378. value = "##{detail.value}" unless detail.value.blank?
  379. old_value = "##{detail.old_value}" unless detail.old_value.blank?
  380. when 'is_private'
  381. value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
  382. old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
  383. when 'description'
  384. show_diff = true
  385. end
  386. when 'cf'
  387. custom_field = detail.custom_field
  388. if custom_field
  389. label = custom_field.name
  390. if custom_field.format.class.change_no_details
  391. no_details = true
  392. elsif custom_field.format.class.change_as_diff
  393. show_diff = true
  394. else
  395. multiple = custom_field.multiple?
  396. value = format_value(detail.value, custom_field) if detail.value
  397. old_value = format_value(detail.old_value, custom_field) if detail.old_value
  398. end
  399. end
  400. when 'attachment'
  401. label = l(:label_attachment)
  402. when 'relation'
  403. if detail.value && !detail.old_value
  404. rel_issue = Issue.visible.find_by_id(detail.value)
  405. value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
  406. (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
  407. elsif detail.old_value && !detail.value
  408. rel_issue = Issue.visible.find_by_id(detail.old_value)
  409. old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
  410. (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
  411. end
  412. relation_type = IssueRelation::TYPES[detail.prop_key]
  413. label = l(relation_type[:name]) if relation_type
  414. end
  415. call_hook(:helper_issues_show_detail_after_setting,
  416. {:detail => detail, :label => label, :value => value, :old_value => old_value })
  417. label ||= detail.prop_key
  418. value ||= detail.value
  419. old_value ||= detail.old_value
  420. unless no_html
  421. label = content_tag('strong', label)
  422. old_value = content_tag("i", h(old_value)) if detail.old_value
  423. if detail.old_value && detail.value.blank? && detail.property != 'relation'
  424. old_value = content_tag("del", old_value)
  425. end
  426. if detail.property == 'attachment' && value.present? &&
  427. atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
  428. # Link to the attachment if it has not been removed
  429. value = link_to_attachment(atta, only_path: options[:only_path])
  430. if options[:only_path] != false
  431. value += ' '
  432. value += link_to_attachment atta, class: 'icon-only icon-download', title: l(:button_download), download: true
  433. end
  434. else
  435. value = content_tag("i", h(value)) if value
  436. end
  437. end
  438. if no_details
  439. s = l(:text_journal_changed_no_detail, :label => label).html_safe
  440. elsif show_diff
  441. s = l(:text_journal_changed_no_detail, :label => label)
  442. unless no_html
  443. diff_link = link_to 'diff',
  444. diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
  445. :title => l(:label_view_diff)
  446. s << " (#{ diff_link })"
  447. end
  448. s.html_safe
  449. elsif detail.value.present?
  450. case detail.property
  451. when 'attr', 'cf'
  452. if detail.old_value.present?
  453. l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
  454. elsif multiple
  455. l(:text_journal_added, :label => label, :value => value).html_safe
  456. else
  457. l(:text_journal_set_to, :label => label, :value => value).html_safe
  458. end
  459. when 'attachment', 'relation'
  460. l(:text_journal_added, :label => label, :value => value).html_safe
  461. end
  462. else
  463. l(:text_journal_deleted, :label => label, :old => old_value).html_safe
  464. end
  465. end
  466. # Find the name of an associated record stored in the field attribute
  467. def find_name_by_reflection(field, id)
  468. unless id.present?
  469. return nil
  470. end
  471. @detail_value_name_by_reflection ||= Hash.new do |hash, key|
  472. association = Issue.reflect_on_association(key.first.to_sym)
  473. name = nil
  474. if association
  475. record = association.klass.find_by_id(key.last)
  476. if record
  477. name = record.name.force_encoding('UTF-8')
  478. end
  479. end
  480. hash[key] = name
  481. end
  482. @detail_value_name_by_reflection[[field, id]]
  483. end
  484. # Renders issue children recursively
  485. def render_api_issue_children(issue, api)
  486. return if issue.leaf?
  487. api.array :children do
  488. issue.children.each do |child|
  489. api.issue(:id => child.id) do
  490. api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
  491. api.subject child.subject
  492. render_api_issue_children(child, api)
  493. end
  494. end
  495. end
  496. end
  497. # Issue history tabs
  498. def issue_history_tabs
  499. tabs = []
  500. if @journals.present?
  501. journals_without_notes = @journals.select{|value| value.notes.blank?}
  502. journals_with_notes = @journals.reject{|value| value.notes.blank?}
  503. tabs << {:name => 'history', :label => :label_history, :onclick => 'showIssueHistory("history", this.href)', :partial => 'issues/tabs/history', :locals => {:issue => @issue, :journals => @journals}}
  504. tabs << {:name => 'notes', :label => :label_issue_history_notes, :onclick => 'showIssueHistory("notes", this.href)'} if journals_with_notes.any?
  505. tabs << {:name => 'properties', :label => :label_issue_history_properties, :onclick => 'showIssueHistory("properties", this.href)'} if journals_without_notes.any?
  506. end
  507. tabs << {:name => 'time_entries', :label => :label_time_entry_plural, :remote => true, :onclick => "getRemoteTab('time_entries', '#{tab_issue_path(@issue, :name => 'time_entries')}', '#{issue_path(@issue, :tab => 'time_entries')}')"} if User.current.allowed_to?(:view_time_entries, @project) && @issue.spent_hours > 0
  508. tabs << {:name => 'changesets', :label => :label_associated_revisions, :remote => true, :onclick => "getRemoteTab('changesets', '#{tab_issue_path(@issue, :name => 'changesets')}', '#{issue_path(@issue, :tab => 'changesets')}')"} if @has_changesets
  509. tabs
  510. end
  511. def issue_history_default_tab
  512. # tab params overrides user default tab preference
  513. return params[:tab] if params[:tab].present?
  514. user_default_tab = User.current.pref.history_default_tab
  515. case user_default_tab
  516. when 'last_tab_visited'
  517. cookies['history_last_tab'].presence || 'notes'
  518. when ''
  519. 'notes'
  520. else
  521. user_default_tab
  522. end
  523. end
  524. end