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.

versions_helper.rb 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 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 VersionsHelper
  19. def version_anchor(version)
  20. if @project == version.project
  21. anchor version.name
  22. else
  23. anchor "#{version.project.try(:identifier)}-#{version.name}"
  24. end
  25. end
  26. def version_filtered_issues_path(version, options = {})
  27. options = {:fixed_version_id => version, :set_filter => 1}.merge(options)
  28. project =
  29. case version.sharing
  30. when 'tree'
  31. if version.project && version.project.root.visible? && User.current.allowed_to?(:view_issues, version.project.root)
  32. version.project.root
  33. else
  34. nil
  35. end
  36. when 'system'
  37. nil
  38. else
  39. version.project
  40. end
  41. if project
  42. project_issues_path(project, options)
  43. else
  44. issues_path(options)
  45. end
  46. end
  47. STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category)
  48. def render_issue_status_by(version, criteria)
  49. criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria)
  50. h = Hash.new {|k, v| k[v] = [0, 0]}
  51. begin
  52. # Total issue count
  53. version.visible_fixed_issues.group(criteria).count.each {|c, s| h[c][0] = s}
  54. # Open issues count
  55. version.visible_fixed_issues.open.group(criteria).count.each {|c, s| h[c][1] = s}
  56. rescue ActiveRecord::RecordNotFound
  57. # When grouping by an association, Rails throws this exception if there's no result (bug)
  58. end
  59. # Sort with nil keys in last position
  60. sorted_keys =
  61. h.keys.sort do |a, b|
  62. if a.nil?
  63. 1
  64. else
  65. b.nil? ? -1 : a <=> b
  66. end
  67. end
  68. counts =
  69. sorted_keys.collect do |k|
  70. {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}
  71. end
  72. max = counts.collect {|c| c[:total]}.max
  73. render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
  74. end
  75. def status_by_options_for_select(value)
  76. options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
  77. end
  78. def link_to_new_issue(version, project)
  79. if version.open? && User.current.allowed_to?(:add_issues, project)
  80. trackers = Issue.allowed_target_trackers(project)
  81. unless trackers.empty?
  82. issue = Issue.new(:project => project)
  83. new_issue_tracker = trackers.detect do |tracker|
  84. issue.tracker = tracker
  85. issue.safe_attribute?('fixed_version_id')
  86. end
  87. end
  88. if new_issue_tracker
  89. attrs = {
  90. :tracker_id => new_issue_tracker,
  91. :fixed_version_id => version.id
  92. }
  93. link_to l(:label_issue_new), new_project_issue_path(project, :issue => attrs, :back_url => version_path(version)), :class => 'icon icon-add'
  94. end
  95. end
  96. end
  97. end