diff options
-rw-r--r-- | app/helpers/queries_helper.rb | 23 | ||||
-rw-r--r-- | app/models/custom_field.rb | 2 | ||||
-rw-r--r-- | app/models/query.rb | 6 | ||||
-rw-r--r-- | test/unit/helpers/queries_helper_test.rb | 20 |
4 files changed, 49 insertions, 2 deletions
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index c85e014e0..6ea879a35 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -24,7 +24,28 @@ module QueriesHelper def filters_options(query) options = [[]] - options += query.available_filters.sort {|a,b| a[1][:order] <=> b[1][:order]}.map do |field, field_options| + sorted_options = query.available_filters.sort do |a, b| + ord = 0 + if !(a[1][:order] == 20 && b[1][:order] == 20) + ord = a[1][:order] <=> b[1][:order] + else + cn = (CustomField::CUSTOM_FIELDS_NAMES.index(a[1][:field].class.name) <=> + CustomField::CUSTOM_FIELDS_NAMES.index(b[1][:field].class.name)) + if cn != 0 + ord = cn + else + f = (a[1][:field] <=> b[1][:field]) + if f != 0 + ord = f + else + # assigned_to or author + ord = (a[0] <=> b[0]) + end + end + end + ord + end + options += sorted_options.map do |field, field_options| [field_options[:name], field] end end diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index a934cc877..86227a4cf 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -51,6 +51,8 @@ class CustomField < ActiveRecord::Base :label => DocumentCategory::OptionName} ] + CUSTOM_FIELDS_NAMES = CUSTOM_FIELDS_TABS.collect{|v| v[:name]} + def set_searchable # make sure these fields are not searchable self.searchable = false if %w(int float date bool).include?(field_format) diff --git a/app/models/query.rb b/app/models/query.rb index 12a46c73f..dfb00825d 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -993,7 +993,11 @@ class Query < ActiveRecord::Base filter_id = "#{assoc}.#{filter_id}" filter_name = l("label_attribute_of_#{assoc}", :name => filter_name) end - @available_filters[filter_id] = options.merge({ :name => filter_name, :format => field.field_format }) + @available_filters[filter_id] = options.merge({ + :name => filter_name, + :format => field.field_format, + :field => field + }) end end diff --git a/test/unit/helpers/queries_helper_test.rb b/test/unit/helpers/queries_helper_test.rb index 67371bb80..ce23648d2 100644 --- a/test/unit/helpers/queries_helper_test.rb +++ b/test/unit/helpers/queries_helper_test.rb @@ -19,6 +19,7 @@ require File.expand_path('../../../test_helper', __FILE__) class QueriesHelperTest < ActionView::TestCase include QueriesHelper + include Redmine::I18n fixtures :projects, :enabled_modules, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, @@ -42,4 +43,23 @@ class QueriesHelperTest < ActionView::TestCase assert_equal "watcher_id", fo[17][1] assert_equal "is_private", fo[18][1] end + + def test_order_custom_fields + set_language_if_valid 'en' + field = UserCustomField.new( + :name => 'order test', :field_format => 'string', + :is_for_all => true, :is_filter => true + ) + assert field.save + User.current = User.find_by_login('admin') + query = Query.new(:project => nil, :name => '_') + assert_equal 32, query.available_filters.size + fo = filters_options(query) + assert_equal 33, fo.size + assert_equal "Searchable field", fo[19][0] + assert_equal "Database", fo[20][0] + assert_equal "Project's Development status", fo[21][0] + assert_equal "Assignee's order test", fo[22][0] + assert_equal "Author's order test", fo[23][0] + end end |