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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 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 = case version.sharing
  29. when 'hierarchy', 'tree'
  30. if version.project && version.project.root.visible?
  31. version.project.root
  32. else
  33. version.project
  34. end
  35. when 'system'
  36. nil
  37. else
  38. version.project
  39. end
  40. if project
  41. project_issues_path(project, options)
  42. else
  43. issues_path(options)
  44. end
  45. end
  46. STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category)
  47. def render_issue_status_by(version, criteria)
  48. criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria)
  49. h = Hash.new {|k,v| k[v] = [0, 0]}
  50. begin
  51. # Total issue count
  52. version.visible_fixed_issues.group(criteria).count.each {|c,s| h[c][0] = s}
  53. # Open issues count
  54. version.visible_fixed_issues.open.group(criteria).count.each {|c,s| h[c][1] = s}
  55. rescue ActiveRecord::RecordNotFound
  56. # When grouping by an association, Rails throws this exception if there's no result (bug)
  57. end
  58. # Sort with nil keys in last position
  59. counts = h.keys.sort {|a,b| a.nil? ? 1 : (b.nil? ? -1 : a <=> b)}.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}}
  60. max = counts.collect {|c| c[:total]}.max
  61. render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
  62. end
  63. def status_by_options_for_select(value)
  64. options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
  65. end
  66. end