]> source.dussan.org Git - redmine.git/commitdiff
Extract grouping logic to an helper.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Feb 2015 09:39:39 +0000 (09:39 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Feb 2015 09:39:39 +0000 (09:39 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13972 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/issues_helper.rb
app/views/issues/_list.html.erb

index f974914ac0e9b6c5d8b694691bdb334b36dfe4cb..bfe3ae75a1eb5610d7644645fbd5b042d49ef64f 100644 (file)
@@ -32,6 +32,24 @@ module IssuesHelper
     end
   end
 
+  def grouped_issue_list(issues, query, issue_count_by_group, &block)
+    previous_group, first = false, true
+    issue_list(issues) do |issue, level|
+      group_name = group_count = nil
+      if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first)
+        if group.blank? && group != false
+          group_name = l(:label_none)
+        else
+          group_name = column_content(query.group_by_column, issue)
+        end
+        group_name ||= ""
+        group_count = issue_count_by_group[group]
+      end
+      yield issue, level, group_name, group_count
+      previous_group, first = group, false
+    end
+  end
+
   # Renders a HTML/CSS tooltip
   #
   # To use, a trigger div is needed.  This is a div with the class of "tooltip"
index 02486678229d130d586c4b7fb404a12e4cf74f87..c6c7613b48ba6d584713eb9ef8226bd02e7d5155 100644 (file)
       <% end %>
     </tr>
   </thead>
-  <% previous_group, first = false, true %>
   <tbody>
-  <% issue_list(issues) do |issue, level| -%>
-  <% if @query.grouped? && ((group = @query.group_by_column.value(issue)) != previous_group || first) %>
+  <% grouped_issue_list(issues, @query, @issue_count_by_group) do |issue, level, group_name, group_count| -%>
+  <% if group_name %>
     <% reset_cycle %>
     <tr class="group open">
       <td colspan="<%= query.inline_columns.size + 2 %>">
         <span class="expander" onclick="toggleRowGroup(this);">&nbsp;</span>
-        <%= (group.blank? && group != false) ? l(:label_none) : column_content(@query.group_by_column, issue) %> <span class="count"><%= @issue_count_by_group[group] %></span>
+        <%= group_name %> <span class="count"><%= group_count %></span>
         <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
                              "toggleAllRowGroups(this)", :class => 'toggle-all') %>
       </td>
     </tr>
-    <% previous_group, first = group, false %>
   <% end %>
   <tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
     <td class="checkbox hide-when-print"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>