Query#add_custom_fields_filters now takes a custom fields scope.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11917 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-06-01 10:56:12 +00:00
parent bf76b3b286
commit e27deb1ece
3 changed files with 47 additions and 40 deletions

View File

@ -81,7 +81,7 @@ class IssueQuery < Query
principals += Principal.member_of(all_projects)
end
versions = Version.visible.find_all_by_sharing('system')
issue_custom_fields = IssueCustomField.where(:is_filter => true, :is_for_all => true).all
issue_custom_fields = IssueCustomField.where(:is_for_all => true)
end
principals.uniq!
principals.sort!

View File

@ -730,10 +730,8 @@ class Query < ActiveRecord::Base
return sql
end
def add_custom_fields_filters(custom_fields, assoc=nil)
return unless custom_fields.present?
custom_fields.select(&:is_filter?).sort.each do |field|
# Adds a filter for the given custom field
def add_custom_field_filter(field, assoc=nil)
case field.field_format
when "text"
options = { :type => :text }
@ -748,7 +746,7 @@ class Query < ActiveRecord::Base
when "float"
options = { :type => :float }
when "user", "version"
next unless project
return unless project
values = field.possible_values_options(project)
if User.current.logged? && field.field_format == 'user'
values.unshift ["<< #{l(:label_me)} >>", "me"]
@ -769,15 +767,24 @@ class Query < ActiveRecord::Base
:field => field
})
end
# Adds filters for the given custom fields scope
def add_custom_fields_filters(scope, assoc=nil)
scope.where(:is_filter => true).sorted.each do |field|
add_custom_field_filter(field, assoc)
end
end
# Adds filters for the given associations custom fields
def add_associations_custom_fields_filters(*associations)
fields_by_class = CustomField.where(:is_filter => true).group_by(&:class)
associations.each do |assoc|
association_klass = queried_class.reflect_on_association(assoc).klass
fields_by_class.each do |field_class, fields|
if field_class.customized_class <= association_klass
add_custom_fields_filters(fields, assoc)
fields.sort.each do |field|
add_custom_field_filter(field, assoc)
end
end
end
end

View File

@ -84,7 +84,7 @@ class TimeEntryQuery < Query
add_available_filter "comments", :type => :text
add_available_filter "hours", :type => :float
add_custom_fields_filters(TimeEntryCustomField.where(:is_filter => true).all)
add_custom_fields_filters(TimeEntryCustomField)
add_associations_custom_fields_filters :project, :issue, :user
end