summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-06-01 10:56:12 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-06-01 10:56:12 +0000
commite27deb1ecee42918baf86d92e9ac31e1df75fe60 (patch)
treeb3f1036714cd1936f7ac8f09d383420dc999305a
parentbf76b3b286efcb4d25951bb6fcc8f59609200269 (diff)
downloadredmine-e27deb1ecee42918baf86d92e9ac31e1df75fe60.tar.gz
redmine-e27deb1ecee42918baf86d92e9ac31e1df75fe60.zip
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
-rw-r--r--app/models/issue_query.rb2
-rw-r--r--app/models/query.rb83
-rw-r--r--app/models/time_entry_query.rb2
3 files changed, 47 insertions, 40 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 5e0abfebe..cf6074f72 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -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!
diff --git a/app/models/query.rb b/app/models/query.rb
index a5e7abd4c..aa24857bd 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -730,54 +730,61 @@ 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|
- case field.field_format
- when "text"
- options = { :type => :text }
- when "list"
- options = { :type => :list_optional, :values => field.possible_values }
- when "date"
- options = { :type => :date }
- when "bool"
- options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] }
- when "int"
- options = { :type => :integer }
- when "float"
- options = { :type => :float }
- when "user", "version"
- next unless project
- values = field.possible_values_options(project)
- if User.current.logged? && field.field_format == 'user'
- values.unshift ["<< #{l(:label_me)} >>", "me"]
- end
- options = { :type => :list_optional, :values => values }
- else
- options = { :type => :string }
- end
- filter_id = "cf_#{field.id}"
- filter_name = field.name
- if assoc.present?
- filter_id = "#{assoc}.#{filter_id}"
- filter_name = l("label_attribute_of_#{assoc}", :name => filter_name)
+ # 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 }
+ when "list"
+ options = { :type => :list_optional, :values => field.possible_values }
+ when "date"
+ options = { :type => :date }
+ when "bool"
+ options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] }
+ when "int"
+ options = { :type => :integer }
+ when "float"
+ options = { :type => :float }
+ when "user", "version"
+ return unless project
+ values = field.possible_values_options(project)
+ if User.current.logged? && field.field_format == 'user'
+ values.unshift ["<< #{l(:label_me)} >>", "me"]
end
- add_available_filter filter_id, options.merge({
- :name => filter_name,
- :format => field.field_format,
- :field => field
- })
+ options = { :type => :list_optional, :values => values }
+ else
+ options = { :type => :string }
+ end
+ filter_id = "cf_#{field.id}"
+ filter_name = field.name
+ if assoc.present?
+ filter_id = "#{assoc}.#{filter_id}"
+ filter_name = l("label_attribute_of_#{assoc}", :name => filter_name)
end
+ add_available_filter filter_id, options.merge({
+ :name => filter_name,
+ :format => field.field_format,
+ :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
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb
index f0301ce32..dbccea03d 100644
--- a/app/models/time_entry_query.rb
+++ b/app/models/time_entry_query.rb
@@ -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