Fixed: "None" category issue count is empty while grouping by category (#4308).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3112 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2009-12-02 18:57:17 +00:00
parent 8b8c24e61f
commit 346c569f98
8 changed files with 115 additions and 49 deletions
+19
View File
@@ -67,6 +67,25 @@ class CustomField < ActiveRecord::Base
end
end
def cast_value(value)
casted = nil
unless value.blank?
case field_format
when 'string', 'text', 'list'
casted = value
when 'date'
casted = begin; value.to_date; rescue; nil end
when 'bool'
casted = (value == '1' ? true : false)
when 'int'
casted = value.to_i
when 'float'
casted = value.to_f
end
end
casted
end
# Returns a ORDER BY clause that can used to sort customized
# objects by their value of the custom field.
# Returns false, if the custom field can not be used for sorting.
+17 -4
View File
@@ -37,6 +37,10 @@ class QueryColumn
def sortable?
!sortable.nil?
end
def value(issue)
issue.send name
end
end
class QueryCustomFieldColumn < QueryColumn
@@ -58,6 +62,11 @@ class QueryCustomFieldColumn < QueryColumn
def custom_field
@cf
end
def value(issue)
cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
cv && @cf.cast_value(cv.value)
end
end
class Query < ActiveRecord::Base
@@ -407,16 +416,20 @@ class Query < ActiveRecord::Base
# Returns the issue count by group or nil if query is not grouped
def issue_count_by_group
r = nil
if grouped?
begin
# Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
Issue.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement)
r = Issue.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement)
rescue ActiveRecord::RecordNotFound
{nil => issue_count}
r = {nil => issue_count}
end
c = group_by_column
if c.is_a?(QueryCustomFieldColumn)
r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
end
else
nil
end
r
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end