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:
parent
8b8c24e61f
commit
346c569f98
@ -27,44 +27,38 @@ module QueriesHelper
|
|||||||
content_tag('th', column.caption)
|
content_tag('th', column.caption)
|
||||||
end
|
end
|
||||||
|
|
||||||
def column_value(column, issue)
|
|
||||||
if column.is_a?(QueryCustomFieldColumn)
|
|
||||||
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
|
||||||
show_value(cv)
|
|
||||||
else
|
|
||||||
value = issue.send(column.name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def column_content(column, issue)
|
def column_content(column, issue)
|
||||||
if column.is_a?(QueryCustomFieldColumn)
|
value = column.value(issue)
|
||||||
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
|
||||||
show_value(cv)
|
case value.class.name
|
||||||
else
|
when 'String'
|
||||||
value = issue.send(column.name)
|
if column.name == :subject
|
||||||
if value.is_a?(Date)
|
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
||||||
format_date(value)
|
|
||||||
elsif value.is_a?(Time)
|
|
||||||
format_time(value)
|
|
||||||
else
|
else
|
||||||
case column.name
|
h(value)
|
||||||
when :subject
|
|
||||||
h((!@project.nil? && @project != issue.project) ? "#{issue.project.name} - " : '') +
|
|
||||||
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
|
||||||
when :project
|
|
||||||
link_to(h(value), :controller => 'projects', :action => 'show', :id => value)
|
|
||||||
when :assigned_to
|
|
||||||
link_to_user value
|
|
||||||
when :author
|
|
||||||
link_to_user value
|
|
||||||
when :done_ratio
|
|
||||||
progress_bar(value, :width => '80px')
|
|
||||||
when :fixed_version
|
|
||||||
link_to(h(value), { :controller => 'versions', :action => 'show', :id => issue.fixed_version_id })
|
|
||||||
else
|
|
||||||
h(value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
when 'Time'
|
||||||
|
format_time(value)
|
||||||
|
when 'Date'
|
||||||
|
format_date(value)
|
||||||
|
when 'Fixnum', 'Float'
|
||||||
|
if column.name == :done_ratio
|
||||||
|
progress_bar(value, :width => '80px')
|
||||||
|
else
|
||||||
|
value.to_s
|
||||||
|
end
|
||||||
|
when 'User'
|
||||||
|
link_to_user value
|
||||||
|
when 'Project'
|
||||||
|
link_to(h(value), :controller => 'projects', :action => 'show', :id => value)
|
||||||
|
when 'Version'
|
||||||
|
link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
|
||||||
|
when 'TrueClass'
|
||||||
|
l(:general_text_Yes)
|
||||||
|
when 'FalseClass'
|
||||||
|
l(:general_text_No)
|
||||||
|
else
|
||||||
|
h(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,6 +67,25 @@ class CustomField < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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
|
# Returns a ORDER BY clause that can used to sort customized
|
||||||
# objects by their value of the custom field.
|
# objects by their value of the custom field.
|
||||||
# Returns false, if the custom field can not be used for sorting.
|
# Returns false, if the custom field can not be used for sorting.
|
||||||
|
@ -37,6 +37,10 @@ class QueryColumn
|
|||||||
def sortable?
|
def sortable?
|
||||||
!sortable.nil?
|
!sortable.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value(issue)
|
||||||
|
issue.send name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class QueryCustomFieldColumn < QueryColumn
|
class QueryCustomFieldColumn < QueryColumn
|
||||||
@ -58,6 +62,11 @@ class QueryCustomFieldColumn < QueryColumn
|
|||||||
def custom_field
|
def custom_field
|
||||||
@cf
|
@cf
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value(issue)
|
||||||
|
cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
|
||||||
|
cv && @cf.cast_value(cv.value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Query < ActiveRecord::Base
|
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
|
# Returns the issue count by group or nil if query is not grouped
|
||||||
def issue_count_by_group
|
def issue_count_by_group
|
||||||
|
r = nil
|
||||||
if grouped?
|
if grouped?
|
||||||
begin
|
begin
|
||||||
# Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
|
# 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
|
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
|
end
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
r
|
||||||
rescue ::ActiveRecord::StatementInvalid => e
|
rescue ::ActiveRecord::StatementInvalid => e
|
||||||
raise StatementInvalid.new(e.message)
|
raise StatementInvalid.new(e.message)
|
||||||
end
|
end
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
<% previous_group = false %>
|
<% previous_group = false %>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% issues.each do |issue| -%>
|
<% issues.each do |issue| -%>
|
||||||
<% if @query.grouped? && (group = column_value(@query.group_by_column, issue) || '') != previous_group %>
|
<% if @query.grouped? && (group = @query.group_by_column.value(issue)) != previous_group %>
|
||||||
<% reset_cycle %>
|
<% reset_cycle %>
|
||||||
<tr class="group open">
|
<tr class="group open">
|
||||||
<td colspan="<%= query.columns.size + 2 %>">
|
<td colspan="<%= query.columns.size + 2 %>">
|
||||||
<span class="expander" onclick="toggleRowGroup(this); return false;"> </span>
|
<span class="expander" onclick="toggleRowGroup(this); return false;"> </span>
|
||||||
<%= group.blank? ? 'None' : group %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
|
<%= group.blank? ? 'None' : column_content(@query.group_by_column, issue) %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% previous_group = group %>
|
<% previous_group = group %>
|
||||||
|
14
test/fixtures/custom_fields.yml
vendored
14
test/fixtures/custom_fields.yml
vendored
@ -101,3 +101,17 @@ custom_fields_007:
|
|||||||
field_format: bool
|
field_format: bool
|
||||||
default_value: ""
|
default_value: ""
|
||||||
editable: true
|
editable: true
|
||||||
|
custom_fields_008:
|
||||||
|
name: Custom date
|
||||||
|
min_length: 0
|
||||||
|
regexp: ""
|
||||||
|
is_for_all: true
|
||||||
|
is_filter: false
|
||||||
|
type: IssueCustomField
|
||||||
|
max_length: 0
|
||||||
|
possible_values: ""
|
||||||
|
id: 8
|
||||||
|
is_required: false
|
||||||
|
field_format: date
|
||||||
|
default_value: ""
|
||||||
|
editable: true
|
||||||
|
6
test/fixtures/custom_values.yml
vendored
6
test/fixtures/custom_values.yml
vendored
@ -95,3 +95,9 @@ custom_values_016:
|
|||||||
customized_id: 11
|
customized_id: 11
|
||||||
id: 16
|
id: 16
|
||||||
value: '1'
|
value: '1'
|
||||||
|
custom_values_017:
|
||||||
|
customized_type: Issue
|
||||||
|
custom_field_id: 8
|
||||||
|
customized_id: 1
|
||||||
|
id: 17
|
||||||
|
value: '2009-12-01'
|
||||||
|
@ -177,10 +177,7 @@ class IssuesControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'index.rhtml'
|
assert_template 'index.rhtml'
|
||||||
assert_not_nil assigns(:issues)
|
assert_not_nil assigns(:issues)
|
||||||
count_by_group = assigns(:issue_count_by_group)
|
assert_not_nil assigns(:issue_count_by_group)
|
||||||
assert_kind_of Hash, count_by_group
|
|
||||||
assert_kind_of Tracker, count_by_group.keys.first
|
|
||||||
assert_not_nil count_by_group[Tracker.find(1)]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_with_query_grouped_by_list_custom_field
|
def test_index_with_query_grouped_by_list_custom_field
|
||||||
@ -188,10 +185,7 @@ class IssuesControllerTest < ActionController::TestCase
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'index.rhtml'
|
assert_template 'index.rhtml'
|
||||||
assert_not_nil assigns(:issues)
|
assert_not_nil assigns(:issues)
|
||||||
count_by_group = assigns(:issue_count_by_group)
|
assert_not_nil assigns(:issue_count_by_group)
|
||||||
assert_kind_of Hash, count_by_group
|
|
||||||
assert_kind_of String, count_by_group.keys.first
|
|
||||||
assert_not_nil count_by_group['MySQL']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index_sort_by_field_not_included_in_columns
|
def test_index_sort_by_field_not_included_in_columns
|
||||||
|
@ -276,6 +276,32 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_issue_count_by_association_group
|
||||||
|
q = Query.new(:name => '_', :group_by => 'assigned_to')
|
||||||
|
count_by_group = q.issue_count_by_group
|
||||||
|
assert_kind_of Hash, count_by_group
|
||||||
|
assert_equal %w(NilClass User), count_by_group.keys.collect {|k| k.class.name}.uniq.sort
|
||||||
|
assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq
|
||||||
|
assert count_by_group.has_key?(User.find(3))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_issue_count_by_list_custom_field_group
|
||||||
|
q = Query.new(:name => '_', :group_by => 'cf_1')
|
||||||
|
count_by_group = q.issue_count_by_group
|
||||||
|
assert_kind_of Hash, count_by_group
|
||||||
|
assert_equal %w(NilClass String), count_by_group.keys.collect {|k| k.class.name}.uniq.sort
|
||||||
|
assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq
|
||||||
|
assert count_by_group.has_key?('MySQL')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_issue_count_by_date_custom_field_group
|
||||||
|
q = Query.new(:name => '_', :group_by => 'cf_8')
|
||||||
|
count_by_group = q.issue_count_by_group
|
||||||
|
assert_kind_of Hash, count_by_group
|
||||||
|
assert_equal %w(Date NilClass), count_by_group.keys.collect {|k| k.class.name}.uniq.sort
|
||||||
|
assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq
|
||||||
|
end
|
||||||
|
|
||||||
def test_label_for
|
def test_label_for
|
||||||
q = Query.new
|
q = Query.new
|
||||||
assert_equal 'assigned_to', q.label_for('assigned_to_id')
|
assert_equal 'assigned_to', q.label_for('assigned_to_id')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user