33281-v3.patch

Yuichi HARADA, 2020-05-07 07:31

Download (5.29 KB)

View differences:

app/models/project_query.rb
69 69
  def available_columns
70 70
    return @available_columns if @available_columns
71 71
    @available_columns = self.class.available_columns.dup
72
    @available_columns += ProjectCustomField.visible.
72
    @available_columns += project_custom_fields.visible.
73 73
                            map {|cf| QueryCustomFieldColumn.new(cf) }
74 74
    @available_columns
75 75
  end
app/models/query.rb
609 609
    if project
610 610
      project.rolled_up_custom_fields
611 611
    else
612
      IssueCustomField.all
612
      IssueCustomField.sorted
613 613
    end
614 614
  end
615 615

  
616 616
  # Returns a scope of project custom fields that are available as columns or filters
617 617
  def project_custom_fields
618
    ProjectCustomField.all
618
    ProjectCustomField.sorted
619
  end
620

  
621
  # Returns a scope of time entry custom fields that are available as columns or filters
622
  def time_entry_custom_fields
623
    TimeEntryCustomField.sorted
619 624
  end
620 625

  
621 626
  # Returns a scope of project statuses that are available as columns or filters
app/models/time_entry_query.rb
100 100
    add_available_filter "comments", :type => :text
101 101
    add_available_filter "hours", :type => :float
102 102

  
103
    add_custom_fields_filters(TimeEntryCustomField)
103
    add_custom_fields_filters(time_entry_custom_fields)
104 104
    add_associations_custom_fields_filters :project
105 105
    add_custom_fields_filters(issue_custom_fields, :issue)
106 106
    add_associations_custom_fields_filters :user
......
109 109
  def available_columns
110 110
    return @available_columns if @available_columns
111 111
    @available_columns = self.class.available_columns.dup
112
    @available_columns += TimeEntryCustomField.visible.
112
    @available_columns += time_entry_custom_fields.visible.
113 113
                            map {|cf| QueryCustomFieldColumn.new(cf) }
114 114
    @available_columns += issue_custom_fields.visible.
115 115
                            map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf, :totalable => false) }
116
    @available_columns += ProjectCustomField.visible.
116
    @available_columns += project_custom_fields.visible.
117 117
                            map {|cf| QueryAssociationCustomFieldColumn.new(:project, cf) }
118 118
    @available_columns
119 119
  end
test/unit/query_test.rb
1802 1802
    assert_include "cf_#{field.id}".to_sym, q.available_totalable_columns.map(&:name)
1803 1803
  end
1804 1804

  
1805
  def test_available_totalable_columns_should_sort_in_position_order_for_custom_field
1806
    ProjectCustomField.delete_all
1807
    cf_pos3 = ProjectCustomField.generate!(:position => 3, :is_for_all => true, :field_format => 'int')
1808
    cf_pos4 = ProjectCustomField.generate!(:position => 4, :is_for_all => true, :field_format => 'float')
1809
    cf_pos1 = ProjectCustomField.generate!(:position => 1, :is_for_all => true, :field_format => 'float')
1810
    cf_pos2 = ProjectCustomField.generate!(:position => 2, :is_for_all => true, :field_format => 'int')
1811
    q = ProjectQuery.new
1812
    custom_field_columns = q.available_totalable_columns.select{|column| column.is_a?(QueryCustomFieldColumn)}
1813
    assert_equal [cf_pos1, cf_pos2, cf_pos3, cf_pos4], custom_field_columns.collect(&:custom_field)
1814

  
1815
    IssueCustomField.delete_all
1816
    cf_pos3 = IssueCustomField.generate!(:position => 3, :is_for_all => true, :field_format => 'int')
1817
    cf_pos4 = IssueCustomField.generate!(:position => 4, :is_for_all => true, :field_format => 'float')
1818
    cf_pos1 = IssueCustomField.generate!(:position => 1, :is_for_all => true, :field_format => 'float')
1819
    cf_pos2 = IssueCustomField.generate!(:position => 2, :is_for_all => true, :field_format => 'int')
1820
    q = IssueQuery.new
1821
    custom_field_columns = q.available_totalable_columns.select{|column| column.is_a?(QueryCustomFieldColumn)}
1822
    assert_equal [cf_pos1, cf_pos2, cf_pos3, cf_pos4], custom_field_columns.collect(&:custom_field)
1823

  
1824
    ProjectCustomField.delete_all
1825
    IssueCustomField.delete_all
1826
    TimeEntryCustomField.delete_all
1827
    cf_pos3 = TimeEntryCustomField.generate!(:position => 3, :is_for_all => true, :field_format => 'int')
1828
    cf_pos4 = TimeEntryCustomField.generate!(:position => 4, :is_for_all => true, :field_format => 'float')
1829
    cf_pos1 = TimeEntryCustomField.generate!(:position => 1, :is_for_all => true, :field_format => 'float')
1830
    cf_pos2 = TimeEntryCustomField.generate!(:position => 2, :is_for_all => true, :field_format => 'int')
1831
    q = TimeEntryQuery.new
1832
    custom_field_columns = q.available_totalable_columns.select{|column| column.is_a?(QueryCustomFieldColumn)}
1833
    assert_equal [cf_pos1, cf_pos2, cf_pos3, cf_pos4], custom_field_columns.collect(&:custom_field)
1834
  end
1835

  
1805 1836
  def test_total_for_estimated_hours
1806 1837
    Issue.delete_all
1807 1838
    Issue.generate!(:estimated_hours => 5.5)