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 24KB

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