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.6KB

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