@@ -81,7 +81,7 class IssueQuery < Query | |||||
81 | principals += Principal.member_of(all_projects) |
|
81 | principals += Principal.member_of(all_projects) | |
82 | end |
|
82 | end | |
83 | versions = Version.visible.find_all_by_sharing('system') |
|
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 | end |
|
85 | end | |
86 | principals.uniq! |
|
86 | principals.uniq! | |
87 | principals.sort! |
|
87 | principals.sort! |
@@ -730,10 +730,8 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 |
|
||||
736 | custom_fields.select(&:is_filter?).sort.each do |field| |
|
|||
737 |
|
|
735 | case field.field_format | |
738 |
|
|
736 | when "text" | |
739 |
|
|
737 | options = { :type => :text } | |
@@ -748,7 +746,7 class Query < ActiveRecord::Base | |||||
748 |
|
|
746 | when "float" | |
749 |
|
|
747 | options = { :type => :float } | |
750 |
|
|
748 | when "user", "version" | |
751 |
|
|
749 | return unless project | |
752 |
|
|
750 | values = field.possible_values_options(project) | |
753 |
|
|
751 | if User.current.logged? && field.field_format == 'user' | |
754 |
|
|
752 | values.unshift ["<< #{l(:label_me)} >>", "me"] | |
@@ -769,15 +767,24 class Query < ActiveRecord::Base | |||||
769 |
|
|
767 | :field => field | |
770 | }) |
|
768 | }) | |
771 |
|
|
769 | end | |
|
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 | |||
772 | end |
|
776 | end | |
773 |
|
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 |
@@ -84,7 +84,7 class TimeEntryQuery < Query | |||||
84 | add_available_filter "comments", :type => :text |
|
84 | add_available_filter "comments", :type => :text | |
85 | add_available_filter "hours", :type => :float |
|
85 | add_available_filter "hours", :type => :float | |
86 |
|
86 | |||
87 |
add_custom_fields_filters(TimeEntryCustomField |
|
87 | add_custom_fields_filters(TimeEntryCustomField) | |
88 | add_associations_custom_fields_filters :project, :issue, :user |
|
88 | add_associations_custom_fields_filters :project, :issue, :user | |
89 | end |
|
89 | end | |
90 |
|
90 |
General Comments 0
You need to be logged in to leave comments.
Login now