Commit 96cdb458 authored by tmaruyama's avatar tmaruyama

sort custom field issue filter by type and position (#12018)

git-svn-id: https://svn.redmine.org/redmine/trunk@10555 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 5ff8b029
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment