Commit 48471ee8 authored by jplang's avatar jplang

Get the count by group from the query directly.

git-svn-id: https://svn.redmine.org/redmine/trunk@16387 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 9a80bd80
......@@ -69,7 +69,6 @@ class IssuesController < ApplicationController
@issues = @query.issues(:order => sort_clause,
:offset => @offset,
:limit => @limit)
@issue_count_by_group = @query.issue_count_by_group
respond_to do |format|
format.html { render :template => 'issues/index', :layout => !request.xhr? }
......
......@@ -32,9 +32,9 @@ module IssuesHelper
end
end
def grouped_issue_list(issues, query, issue_count_by_group, &block)
def grouped_issue_list(issues, query, &block)
ancestors = []
grouped_query_results(issues, query, issue_count_by_group) do |issue, group_name, group_count, group_totals|
grouped_query_results(issues, query) do |issue, group_name, group_count, group_totals|
while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
ancestors.pop
end
......
......@@ -115,7 +115,8 @@ module QueriesHelper
render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name}
end
def grouped_query_results(items, query, item_count_by_group, &block)
def grouped_query_results(items, query, &block)
result_count_by_group = query.result_count_by_group
previous_group, first = false, true
totals_by_group = query.totalable_columns.inject({}) do |h, column|
h[column] = query.total_by_group_for(column)
......@@ -132,7 +133,7 @@ module QueriesHelper
group_name = format_object(group)
end
group_name ||= ""
group_count = item_count_by_group ? item_count_by_group[group] : nil
group_count = result_count_by_group ? result_count_by_group[group] : nil
group_totals = totals_by_group.map {|column, t| total_tag(column, t[group] || 0)}.join(" ").html_safe
end
end
......
......@@ -245,13 +245,6 @@ class IssueQuery < Query
raise StatementInvalid.new(e.message)
end
# Returns the issue count by group or nil if query is not grouped
def issue_count_by_group
grouped_query do |scope|
scope.count
end
end
# Returns sum of all the issue's estimated_hours
def total_for_estimated_hours(scope)
map_total(scope.sum(:estimated_hours)) {|t| t.to_f.round(2)}
......
......@@ -846,6 +846,13 @@ class Query < ActiveRecord::Base
filters_clauses.any? ? filters_clauses.join(' AND ') : nil
end
# Returns the result count by group or nil if query is not grouped
def result_count_by_group
grouped_query do |scope|
scope.count
end
end
# Returns the sum of values for the given column
def total_for(column)
total_with_scope(column, base_scope)
......
......@@ -14,7 +14,7 @@
</tr>
</thead>
<tbody>
<% grouped_issue_list(issues, query, issue_count_by_group) do |issue, level, group_name, group_count, group_totals| -%>
<% grouped_issue_list(issues, query) do |issue, level, group_name, group_count, group_totals| -%>
<% if group_name %>
<% reset_cycle %>
<tr class="group open">
......
......@@ -16,7 +16,7 @@
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<%= render_query_totals(@query) %>
<%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query, :issue_count_by_group => @issue_count_by_group} %>
<%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %>
<span class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></span>
<% end %>
......
......@@ -15,7 +15,7 @@
</tr>
</thead>
<tbody>
<% grouped_query_results(entries, @query, @entry_count_by_group) do |entry, group_name, group_count, group_totals| -%>
<% grouped_query_results(entries, @query) do |entry, group_name, group_count, group_totals| -%>
<% if group_name %>
<% reset_cycle %>
<tr class="group open">
......
......@@ -299,12 +299,14 @@ module Redmine
totals_by_group = query.totals_by_group
render_table_header(pdf, query, col_width, row_height, table_width)
previous_group = false
result_count_by_group = query.result_count_by_group
issue_list(issues) do |issue, level|
if query.grouped? &&
(group = query.group_by_column.value(issue)) != previous_group
pdf.SetFontStyle('B',10)
group_label = group.blank? ? 'None' : group.to_s.dup
group_label << " (#{query.issue_count_by_group[group]})"
group_label << " (#{result_count_by_group[group]})"
pdf.bookmark group_label, 0, -1
pdf.RDMCell(table_width, row_height * 2, group_label, 'LR', 1, 'L')
pdf.SetFontStyle('',8)
......
......@@ -1653,7 +1653,7 @@ class QueryTest < ActiveSupport::TestCase
def test_issue_count_by_association_group
q = IssueQuery.new(:name => '_', :group_by => 'assigned_to')
count_by_group = q.issue_count_by_group
count_by_group = q.result_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(#{INTEGER_KLASS}), count_by_group.values.collect {|k| k.class.name}.uniq
......@@ -1662,7 +1662,7 @@ class QueryTest < ActiveSupport::TestCase
def test_issue_count_by_list_custom_field_group
q = IssueQuery.new(:name => '_', :group_by => 'cf_1')
count_by_group = q.issue_count_by_group
count_by_group = q.result_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(#{INTEGER_KLASS}), count_by_group.values.collect {|k| k.class.name}.uniq
......@@ -1671,7 +1671,7 @@ class QueryTest < ActiveSupport::TestCase
def test_issue_count_by_date_custom_field_group
q = IssueQuery.new(:name => '_', :group_by => 'cf_8')
count_by_group = q.issue_count_by_group
count_by_group = q.result_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(#{INTEGER_KLASS}), count_by_group.values.collect {|k| k.class.name}.uniq
......@@ -1681,7 +1681,7 @@ class QueryTest < ActiveSupport::TestCase
Issue.update_all("assigned_to_id = NULL")
q = IssueQuery.new(:name => '_', :group_by => 'assigned_to')
count_by_group = q.issue_count_by_group
count_by_group = q.result_count_by_group
assert_kind_of Hash, count_by_group
assert_equal 1, count_by_group.keys.size
assert_nil count_by_group.keys.first
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment