]> source.dussan.org Git - redmine.git/commitdiff
Get the count by group from the query directly.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 9 Mar 2017 20:01:01 +0000 (20:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 9 Mar 2017 20:01:01 +0000 (20:01 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16387 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/helpers/issues_helper.rb
app/helpers/queries_helper.rb
app/models/issue_query.rb
app/models/query.rb
app/views/issues/_list.html.erb
app/views/issues/index.html.erb
app/views/timelog/_list.html.erb
lib/redmine/export/pdf/issues_pdf_helper.rb
test/unit/query_test.rb

index 906130e1a5464bed7306561804ddba20fa11eaaf..a04c1a6b06d0b48c7a8f0ae2dba13c1b7e5ec2d1 100644 (file)
@@ -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? }
index f953382845253aa5ac8c11ef7e1f1ad9a0d702d4..7036079999561baff46cae6553661b5d2c923a84 100644 (file)
@@ -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
index c356ca0d472040b555543f44c9ba42e5d1663035..197bbb9989be7c5793df58f9e15187e1cec22ab7 100644 (file)
@@ -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
index 7f399f4698bb51d39820eaa3550390363807720e..71fe8d288e45ef7ce576a28662e0db35b3852de1 100644 (file)
@@ -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)}
index 321821a9394f621211e96ea35974e54ce8b7285e..7a43ca6fcfe1793e228606e158c2888c46f648eb 100644 (file)
@@ -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)
index ed97d046fd267db7a39b51ea7841786f5f3234c3..1e7d01ef71dd19bef478c4cb97247a84aab3e1b8 100644 (file)
@@ -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">
index 7828075cf9d952e6682baffc9a4e4465932454e3..80210814e49f576d1ec13b0d92ff1e408ce89d3b 100644 (file)
@@ -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 %>
 
index b39eb5cc3c06e8ba1dc8d675feee1bfa7631d889..d4836056a1b463260c26fa7ceed732354494d456 100644 (file)
@@ -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">
index cf8a79d3cf773ebf262991ec4b2d53fd9a275982..c72ff66572f36b7bd4736c8270fe20578c2a1259 100644 (file)
@@ -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)
index 7f2ef3d1cf973607f85ce773eb4671c805852c20..d691f66bef71cb2d5c6166e93e36eb78fdcbf153 100644 (file)
@@ -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