Project

General

Profile

Feature #5325 » 0001-groupable-by-parent-task.patch

Takenori TAKAKI, 2021-09-01 04:09

View differences:

app/helpers/issues_helper.rb
41 41
            !issue.is_descendant_of?(ancestors.last)
42 42
        ancestors.pop
43 43
      end
44
      yield issue, ancestors.size, group_name, group_count, group_totals
44
      level = (query.grouped? && query.group_by_column.name == :parent) ? 0 : ancestors.size
45
      yield issue, level, group_name, group_count, group_totals
45 46
      ancestors << issue unless issue.leaf?
46 47
    end
47 48
  end
app/models/issue_query.rb
28 28
    QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
29 29
    QueryColumn.new(:parent,
30 30
                    :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"],
31
                    :groupable => "#{Issue.table_name}.parent_id",
31 32
                    :default_order => 'desc', :caption => :field_parent_issue),
32 33
    QueryAssociationColumn.new(:parent, :subject, :caption => :field_parent_issue_subject),
33 34
    QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
app/models/query.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
class QueryColumn
21
  attr_accessor :name, :totalable, :default_order
22
  attr_writer   :sortable, :groupable
21
  attr_accessor :name, :totalable, :default_order, :groupable
22
  attr_writer   :sortable
23 23

  
24 24
  include Redmine::I18n
25 25

  
......
906 906
      if column.is_a?(TimestampQueryColumn)
907 907
        column_sortable = Redmine::Database.timestamp_to_date(column.sortable, User.current.time_zone)
908 908
      end
909
      if column.name == :parent
910
        column_sortable = Array(column.groupable)
911
      end
909 912
      Array(column_sortable).map {|s| Arel.sql("#{s} #{order}")}
910 913
    end
911 914
  end
test/unit/query_test.rb
1761 1761
    assert_nil q.group_by_statement
1762 1762
  end
1763 1763

  
1764
  def test_grouped_with_parent_task_should_sort_by_parent_id
1765
    Issue.delete_all
1766
    first, second, third  = Issue.generate!, Issue.generate!, Issue.generate!
1767
    Issue.generate!(:parent_id => second.id)
1768
    Issue.generate!(:parent_id => third.id)
1769
    Issue.generate!(:parent_id => first.id)
1770

  
1771
    q = IssueQuery.new(:group_by => 'parent')
1772
    assert_equal :parent, q.group_by_column.name
1773
    assert_equal ["#{Issue.table_name}.parent_id DESC"], q.group_by_sort_order
1774
    assert_equal [third.id, second.id, first.id, nil, nil, nil], q.issues.pluck(:parent_id)
1775
  end
1776

  
1764 1777
  def test_sortable_columns_should_sort_assignees_according_to_user_format_setting
1765 1778
    with_settings :user_format => 'lastname_comma_firstname' do
1766 1779
      q = IssueQuery.new
(4-4/4)