comparison app/helpers/versions_helper.rb @ 1338:25603efa57b5

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:14 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
1209:1b1138f6f55e 1338:25603efa57b5
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 # 5 #
6 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
17 # along with this program; if not, write to the Free Software 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. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 module VersionsHelper 20 module VersionsHelper
21 21
22 STATUS_BY_CRITERIAS = %w(category tracker status priority author assigned_to) 22 def version_anchor(version)
23 if @project == version.project
24 anchor version.name
25 else
26 anchor "#{version.project.try(:identifier)}-#{version.name}"
27 end
28 end
29
30 STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category)
23 31
24 def render_issue_status_by(version, criteria) 32 def render_issue_status_by(version, criteria)
25 criteria = 'category' unless STATUS_BY_CRITERIAS.include?(criteria) 33 criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria)
26 34
27 h = Hash.new {|k,v| k[v] = [0, 0]} 35 h = Hash.new {|k,v| k[v] = [0, 0]}
28 begin 36 begin
29 # Total issue count 37 # Total issue count
30 Issue.count(:group => criteria, 38 Issue.count(:group => criteria,
34 :include => :status, 42 :include => :status,
35 :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s} 43 :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s}
36 rescue ActiveRecord::RecordNotFound 44 rescue ActiveRecord::RecordNotFound
37 # When grouping by an association, Rails throws this exception if there's no result (bug) 45 # When grouping by an association, Rails throws this exception if there's no result (bug)
38 end 46 end
39 counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}} 47 # Sort with nil keys in last position
48 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])}}
40 max = counts.collect {|c| c[:total]}.max 49 max = counts.collect {|c| c[:total]}.max
41 50
42 render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} 51 render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
43 end 52 end
44 53