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

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10555 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-10-04 04:48:48 +00:00
parent fb4210b6d9
commit 88e1587b08
4 changed files with 49 additions and 2 deletions

View File

@ -24,7 +24,28 @@ module QueriesHelper
def filters_options(query) def filters_options(query)
options = [[]] 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] [field_options[:name], field]
end end
end end

View File

@ -51,6 +51,8 @@ class CustomField < ActiveRecord::Base
:label => DocumentCategory::OptionName} :label => DocumentCategory::OptionName}
] ]
CUSTOM_FIELDS_NAMES = CUSTOM_FIELDS_TABS.collect{|v| v[:name]}
def set_searchable def set_searchable
# make sure these fields are not searchable # make sure these fields are not searchable
self.searchable = false if %w(int float date bool).include?(field_format) self.searchable = false if %w(int float date bool).include?(field_format)

View File

@ -993,7 +993,11 @@ class Query < ActiveRecord::Base
filter_id = "#{assoc}.#{filter_id}" filter_id = "#{assoc}.#{filter_id}"
filter_name = l("label_attribute_of_#{assoc}", :name => filter_name) filter_name = l("label_attribute_of_#{assoc}", :name => filter_name)
end 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
end end

View File

@ -19,6 +19,7 @@ require File.expand_path('../../../test_helper', __FILE__)
class QueriesHelperTest < ActionView::TestCase class QueriesHelperTest < ActionView::TestCase
include QueriesHelper include QueriesHelper
include Redmine::I18n
fixtures :projects, :enabled_modules, :users, :members, fixtures :projects, :enabled_modules, :users, :members,
:member_roles, :roles, :trackers, :issue_statuses, :member_roles, :roles, :trackers, :issue_statuses,
@ -42,4 +43,23 @@ class QueriesHelperTest < ActionView::TestCase
assert_equal "watcher_id", fo[17][1] assert_equal "watcher_id", fo[17][1]
assert_equal "is_private", fo[18][1] assert_equal "is_private", fo[18][1]
end 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 end