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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2016 Jean-Philippe Lang
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. module VersionsHelper
  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 = case version.sharing
  30. when 'hierarchy', 'tree'
  31. if version.project && version.project.root.visible?
  32. version.project.root
  33. else
  34. version.project
  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.fixed_issues.group(criteria).count.each {|c,s| h[c][0] = s}
  54. # Open issues count
  55. version.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. 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])}}
  61. max = counts.collect {|c| c[:total]}.max
  62. render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
  63. end
  64. def status_by_options_for_select(value)
  65. options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
  66. end
  67. end