|
@@
-730,54
+730,61
class Query < ActiveRecord::Base
|
|
730
|
return sql
|
|
730
|
return sql
|
|
731
|
end
|
|
731
|
end
|
|
732
|
|
|
732
|
|
|
733
|
def add_custom_fields_filters(custom_fields, assoc=nil)
|
|
733
|
# Adds a filter for the given custom field
|
|
734
|
return unless custom_fields.present?
|
|
734
|
def add_custom_field_filter(field, assoc=nil)
|
|
735
|
|
|
735
|
case field.field_format
|
|
736
|
custom_fields.select(&:is_filter?).sort.each do |field|
|
|
736
|
when "text"
|
|
737
|
case field.field_format
|
|
737
|
options = { :type => :text }
|
|
738
|
when "text"
|
|
738
|
when "list"
|
|
739
|
options = { :type => :text }
|
|
739
|
options = { :type => :list_optional, :values => field.possible_values }
|
|
740
|
when "list"
|
|
740
|
when "date"
|
|
741
|
options = { :type => :list_optional, :values => field.possible_values }
|
|
741
|
options = { :type => :date }
|
|
742
|
when "date"
|
|
742
|
when "bool"
|
|
743
|
options = { :type => :date }
|
|
743
|
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] }
|
|
744
|
when "bool"
|
|
744
|
when "int"
|
|
745
|
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] }
|
|
745
|
options = { :type => :integer }
|
|
746
|
when "int"
|
|
746
|
when "float"
|
|
747
|
options = { :type => :integer }
|
|
747
|
options = { :type => :float }
|
|
748
|
when "float"
|
|
748
|
when "user", "version"
|
|
749
|
options = { :type => :float }
|
|
749
|
return unless project
|
|
750
|
when "user", "version"
|
|
750
|
values = field.possible_values_options(project)
|
|
751
|
next unless project
|
|
751
|
if User.current.logged? && field.field_format == 'user'
|
|
752
|
values = field.possible_values_options(project)
|
|
752
|
values.unshift ["<< #{l(:label_me)} >>", "me"]
|
|
753
|
if User.current.logged? && field.field_format == 'user'
|
|
|
|
|
754
|
values.unshift ["<< #{l(:label_me)} >>", "me"]
|
|
|
|
|
755
|
end
|
|
|
|
|
756
|
options = { :type => :list_optional, :values => values }
|
|
|
|
|
757
|
else
|
|
|
|
|
758
|
options = { :type => :string }
|
|
|
|
|
759
|
end
|
|
|
|
|
760
|
filter_id = "cf_#{field.id}"
|
|
|
|
|
761
|
filter_name = field.name
|
|
|
|
|
762
|
if assoc.present?
|
|
|
|
|
763
|
filter_id = "#{assoc}.#{filter_id}"
|
|
|
|
|
764
|
filter_name = l("label_attribute_of_#{assoc}", :name => filter_name)
|
|
|
|
|
765
|
end
|
|
753
|
end
|
|
766
|
add_available_filter filter_id, options.merge({
|
|
754
|
options = { :type => :list_optional, :values => values }
|
|
767
|
:name => filter_name,
|
|
755
|
else
|
|
768
|
:format => field.field_format,
|
|
756
|
options = { :type => :string }
|
|
769
|
:field => field
|
|
757
|
end
|
|
770
|
})
|
|
758
|
filter_id = "cf_#{field.id}"
|
|
|
|
|
759
|
filter_name = field.name
|
|
|
|
|
760
|
if assoc.present?
|
|
|
|
|
761
|
filter_id = "#{assoc}.#{filter_id}"
|
|
|
|
|
762
|
filter_name = l("label_attribute_of_#{assoc}", :name => filter_name)
|
|
771
|
end
|
|
763
|
end
|
|
|
|
|
764
|
add_available_filter filter_id, options.merge({
|
|
|
|
|
765
|
:name => filter_name,
|
|
|
|
|
766
|
:format => field.field_format,
|
|
|
|
|
767
|
:field => field
|
|
|
|
|
768
|
})
|
|
772
|
end
|
|
769
|
end
|
|
773
|
|
|
770
|
|
|
|
|
|
771
|
# Adds filters for the given custom fields scope
|
|
|
|
|
772
|
def add_custom_fields_filters(scope, assoc=nil)
|
|
|
|
|
773
|
scope.where(:is_filter => true).sorted.each do |field|
|
|
|
|
|
774
|
add_custom_field_filter(field, assoc)
|
|
|
|
|
775
|
end
|
|
|
|
|
776
|
end
|
|
|
|
|
777
|
|
|
|
|
|
778
|
# Adds filters for the given associations custom fields
|
|
774
|
def add_associations_custom_fields_filters(*associations)
|
|
779
|
def add_associations_custom_fields_filters(*associations)
|
|
775
|
fields_by_class = CustomField.where(:is_filter => true).group_by(&:class)
|
|
780
|
fields_by_class = CustomField.where(:is_filter => true).group_by(&:class)
|
|
776
|
associations.each do |assoc|
|
|
781
|
associations.each do |assoc|
|
|
777
|
association_klass = queried_class.reflect_on_association(assoc).klass
|
|
782
|
association_klass = queried_class.reflect_on_association(assoc).klass
|
|
778
|
fields_by_class.each do |field_class, fields|
|
|
783
|
fields_by_class.each do |field_class, fields|
|
|
779
|
if field_class.customized_class <= association_klass
|
|
784
|
if field_class.customized_class <= association_klass
|
|
780
|
add_custom_fields_filters(fields, assoc)
|
|
785
|
fields.sort.each do |field|
|
|
|
|
|
786
|
add_custom_field_filter(field, assoc)
|
|
|
|
|
787
|
end
|
|
781
|
end
|
|
788
|
end
|
|
782
|
end
|
|
789
|
end
|
|
783
|
end
|
|
790
|
end
|