@@ -81,7 +81,7 class IssueQuery < Query | |||
|
81 | 81 | principals += Principal.member_of(all_projects) |
|
82 | 82 | end |
|
83 | 83 | versions = Version.visible.find_all_by_sharing('system') |
|
84 |
issue_custom_fields = IssueCustomField.where( |
|
|
84 | issue_custom_fields = IssueCustomField.where(:is_for_all => true) | |
|
85 | 85 | end |
|
86 | 86 | principals.uniq! |
|
87 | 87 | principals.sort! |
@@ -730,54 +730,61 class Query < ActiveRecord::Base | |||
|
730 | 730 | return sql |
|
731 | 731 | end |
|
732 | 732 | |
|
733 | def add_custom_fields_filters(custom_fields, assoc=nil) | |
|
734 | return unless custom_fields.present? | |
|
735 | ||
|
736 | custom_fields.select(&:is_filter?).sort.each do |field| | |
|
737 | case field.field_format | |
|
738 |
|
|
|
739 | options = { :type => :text } | |
|
740 |
|
|
|
741 | options = { :type => :list_optional, :values => field.possible_values } | |
|
742 |
|
|
|
743 | options = { :type => :date } | |
|
744 |
|
|
|
745 | options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] } | |
|
746 |
|
|
|
747 |
|
|
|
748 | when "float" | |
|
749 | options = { :type => :float } | |
|
750 | when "user", "version" | |
|
751 | next unless project | |
|
752 | values = field.possible_values_options(project) | |
|
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) | |
|
733 | # Adds a filter for the given custom field | |
|
734 | def add_custom_field_filter(field, assoc=nil) | |
|
735 | case field.field_format | |
|
736 | when "text" | |
|
737 | options = { :type => :text } | |
|
738 | when "list" | |
|
739 | options = { :type => :list_optional, :values => field.possible_values } | |
|
740 | when "date" | |
|
741 | options = { :type => :date } | |
|
742 | when "bool" | |
|
743 | options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] } | |
|
744 | when "int" | |
|
745 | options = { :type => :integer } | |
|
746 | when "float" | |
|
747 | options = { :type => :float } | |
|
748 | when "user", "version" | |
|
749 | return unless project | |
|
750 | values = field.possible_values_options(project) | |
|
751 | if User.current.logged? && field.field_format == 'user' | |
|
752 | values.unshift ["<< #{l(:label_me)} >>", "me"] | |
|
765 | 753 | end |
|
766 | add_available_filter filter_id, options.merge({ | |
|
767 | :name => filter_name, | |
|
768 | :format => field.field_format, | |
|
769 | :field => field | |
|
770 | }) | |
|
754 | options = { :type => :list_optional, :values => values } | |
|
755 | else | |
|
756 | options = { :type => :string } | |
|
757 | end | |
|
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 | 763 | end |
|
764 | add_available_filter filter_id, options.merge({ | |
|
765 | :name => filter_name, | |
|
766 | :format => field.field_format, | |
|
767 | :field => field | |
|
768 | }) | |
|
772 | 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 | 779 | def add_associations_custom_fields_filters(*associations) |
|
775 | 780 | fields_by_class = CustomField.where(:is_filter => true).group_by(&:class) |
|
776 | 781 | associations.each do |assoc| |
|
777 | 782 | association_klass = queried_class.reflect_on_association(assoc).klass |
|
778 | 783 | fields_by_class.each do |field_class, fields| |
|
779 | 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 | 788 | end |
|
782 | 789 | end |
|
783 | 790 | end |
@@ -84,7 +84,7 class TimeEntryQuery < Query | |||
|
84 | 84 | add_available_filter "comments", :type => :text |
|
85 | 85 | add_available_filter "hours", :type => :float |
|
86 | 86 | |
|
87 |
add_custom_fields_filters(TimeEntryCustomField |
|
|
87 | add_custom_fields_filters(TimeEntryCustomField) | |
|
88 | 88 | add_associations_custom_fields_filters :project, :issue, :user |
|
89 | 89 | end |
|
90 | 90 |
General Comments 0
You need to be logged in to leave comments.
Login now