Chris@909: # encoding: utf-8 Chris@909: # Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: module VersionsHelper Chris@909: Chris@909: STATUS_BY_CRITERIAS = %w(category tracker status priority author assigned_to) Chris@909: Chris@909: def render_issue_status_by(version, criteria) Chris@909: criteria = 'category' unless STATUS_BY_CRITERIAS.include?(criteria) Chris@909: Chris@909: h = Hash.new {|k,v| k[v] = [0, 0]} Chris@909: begin Chris@909: # Total issue count Chris@909: Issue.count(:group => criteria, Chris@909: :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s} Chris@909: # Open issues count Chris@909: Issue.count(:group => criteria, Chris@909: :include => :status, Chris@909: :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s} Chris@909: rescue ActiveRecord::RecordNotFound Chris@909: # When grouping by an association, Rails throws this exception if there's no result (bug) Chris@909: end Chris@909: counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}} Chris@909: max = counts.collect {|c| c[:total]}.max Chris@909: Chris@909: render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} Chris@909: end Chris@909: Chris@909: def status_by_options_for_select(value) Chris@909: options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value) Chris@909: end Chris@909: end