summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2020-05-08 04:46:27 +0000
committerGo MAEDA <maeda@farend.jp>2020-05-08 04:46:27 +0000
commit117ad7e4c2cf380f86167c59c6c8e2d36409c325 (patch)
tree67b8970d10c21fc913b608e997b008eaa170b8f5
parentc57ba74f2bc2ff2614a6a61b6bee5764ea494217 (diff)
downloadredmine-117ad7e4c2cf380f86167c59c6c8e2d36409c325.tar.gz
redmine-117ad7e4c2cf380f86167c59c6c8e2d36409c325.zip
Merged r19758 from trunk to 4.1-stable (#33281).
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@19759 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/project_query.rb2
-rw-r--r--app/models/query.rb9
-rw-r--r--app/models/time_entry_query.rb6
-rw-r--r--test/unit/query_test.rb31
4 files changed, 42 insertions, 6 deletions
diff --git a/app/models/project_query.rb b/app/models/project_query.rb
index 55c785e89..4f4889380 100644
--- a/app/models/project_query.rb
+++ b/app/models/project_query.rb
@@ -70,7 +70,7 @@ class ProjectQuery < Query
def available_columns
return @available_columns if @available_columns
@available_columns = self.class.available_columns.dup
- @available_columns += ProjectCustomField.visible.
+ @available_columns += project_custom_fields.visible.
map {|cf| QueryCustomFieldColumn.new(cf) }
@available_columns
end
diff --git a/app/models/query.rb b/app/models/query.rb
index 0dec7d211..854aeb62b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -609,13 +609,18 @@ class Query < ActiveRecord::Base
if project
project.rolled_up_custom_fields
else
- IssueCustomField.all
+ IssueCustomField.sorted
end
end
# Returns a scope of project custom fields that are available as columns or filters
def project_custom_fields
- ProjectCustomField.all
+ ProjectCustomField.sorted
+ end
+
+ # Returns a scope of time entry custom fields that are available as columns or filters
+ def time_entry_custom_fields
+ TimeEntryCustomField.sorted
end
# Returns a scope of project statuses that are available as columns or filters
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb
index a51601620..6f704ded0 100644
--- a/app/models/time_entry_query.rb
+++ b/app/models/time_entry_query.rb
@@ -101,7 +101,7 @@ class TimeEntryQuery < Query
add_available_filter "comments", :type => :text
add_available_filter "hours", :type => :float
- add_custom_fields_filters(TimeEntryCustomField)
+ add_custom_fields_filters(time_entry_custom_fields)
add_associations_custom_fields_filters :project
add_custom_fields_filters(issue_custom_fields, :issue)
add_associations_custom_fields_filters :user
@@ -110,11 +110,11 @@ class TimeEntryQuery < Query
def available_columns
return @available_columns if @available_columns
@available_columns = self.class.available_columns.dup
- @available_columns += TimeEntryCustomField.visible.
+ @available_columns += time_entry_custom_fields.visible.
map {|cf| QueryCustomFieldColumn.new(cf) }
@available_columns += issue_custom_fields.visible.
map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf, :totalable => false) }
- @available_columns += ProjectCustomField.visible.
+ @available_columns += project_custom_fields.visible.
map {|cf| QueryAssociationCustomFieldColumn.new(:project, cf) }
@available_columns
end
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 895398264..dee450718 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1800,6 +1800,37 @@ class QueryTest < ActiveSupport::TestCase
assert_include "cf_#{field.id}".to_sym, q.available_totalable_columns.map(&:name)
end
+ def test_available_totalable_columns_should_sort_in_position_order_for_custom_field
+ ProjectCustomField.delete_all
+ cf_pos3 = ProjectCustomField.generate!(:position => 3, :is_for_all => true, :field_format => 'int')
+ cf_pos4 = ProjectCustomField.generate!(:position => 4, :is_for_all => true, :field_format => 'float')
+ cf_pos1 = ProjectCustomField.generate!(:position => 1, :is_for_all => true, :field_format => 'float')
+ cf_pos2 = ProjectCustomField.generate!(:position => 2, :is_for_all => true, :field_format => 'int')
+ q = ProjectQuery.new
+ custom_field_columns = q.available_totalable_columns.select{|column| column.is_a?(QueryCustomFieldColumn)}
+ assert_equal [cf_pos1, cf_pos2, cf_pos3, cf_pos4], custom_field_columns.collect(&:custom_field)
+
+ IssueCustomField.delete_all
+ cf_pos3 = IssueCustomField.generate!(:position => 3, :is_for_all => true, :field_format => 'int')
+ cf_pos4 = IssueCustomField.generate!(:position => 4, :is_for_all => true, :field_format => 'float')
+ cf_pos1 = IssueCustomField.generate!(:position => 1, :is_for_all => true, :field_format => 'float')
+ cf_pos2 = IssueCustomField.generate!(:position => 2, :is_for_all => true, :field_format => 'int')
+ q = IssueQuery.new
+ custom_field_columns = q.available_totalable_columns.select{|column| column.is_a?(QueryCustomFieldColumn)}
+ assert_equal [cf_pos1, cf_pos2, cf_pos3, cf_pos4], custom_field_columns.collect(&:custom_field)
+
+ ProjectCustomField.delete_all
+ IssueCustomField.delete_all
+ TimeEntryCustomField.delete_all
+ cf_pos3 = TimeEntryCustomField.generate!(:position => 3, :is_for_all => true, :field_format => 'int')
+ cf_pos4 = TimeEntryCustomField.generate!(:position => 4, :is_for_all => true, :field_format => 'float')
+ cf_pos1 = TimeEntryCustomField.generate!(:position => 1, :is_for_all => true, :field_format => 'float')
+ cf_pos2 = TimeEntryCustomField.generate!(:position => 2, :is_for_all => true, :field_format => 'int')
+ q = TimeEntryQuery.new
+ custom_field_columns = q.available_totalable_columns.select{|column| column.is_a?(QueryCustomFieldColumn)}
+ assert_equal [cf_pos1, cf_pos2, cf_pos3, cf_pos4], custom_field_columns.collect(&:custom_field)
+ end
+
def test_total_for_estimated_hours
Issue.delete_all
Issue.generate!(:estimated_hours => 5.5)