@@ -144,6 +144,11 class CustomField < ActiveRecord::Base | |||||
144 | format.value_from_keyword(self, keyword, customized) |
|
144 | format.value_from_keyword(self, keyword, customized) | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
|
147 | # Returns the options hash used to build a query filter for the field | |||
|
148 | def query_filter_options(query) | |||
|
149 | format.query_filter_options(self, query) | |||
|
150 | end | |||
|
151 | ||||
147 | # Returns a ORDER BY clause that can used to sort customized |
|
152 | # Returns a ORDER BY clause that can used to sort customized | |
148 | # objects by their value of the custom field. |
|
153 | # objects by their value of the custom field. | |
149 | # Returns nil if the custom field can not be used for sorting. |
|
154 | # Returns nil if the custom field can not be used for sorting. |
@@ -797,7 +797,7 class Query < ActiveRecord::Base | |||||
797 |
|
797 | |||
798 | # Adds a filter for the given custom field |
|
798 | # Adds a filter for the given custom field | |
799 | def add_custom_field_filter(field, assoc=nil) |
|
799 | def add_custom_field_filter(field, assoc=nil) | |
800 |
options = field. |
|
800 | options = field.query_filter_options(self) | |
801 | if field.format.target_class && field.format.target_class <= User |
|
801 | if field.format.target_class && field.format.target_class <= User | |
802 | if options[:values].is_a?(Array) && User.current.logged? |
|
802 | if options[:values].is_a?(Array) && User.current.logged? | |
803 | options[:values].unshift ["<< #{l(:label_me)} >>", "me"] |
|
803 | options[:values].unshift ["<< #{l(:label_me)} >>", "me"] |
@@ -480,11 +480,16 module Redmine | |||||
480 | end |
|
480 | end | |
481 |
|
481 | |||
482 | def query_filter_options(custom_field, query) |
|
482 | def query_filter_options(custom_field, query) | |
483 |
{:type => :list_optional, :values => |
|
483 | {:type => :list_optional, :values => query_filter_values(custom_field, query)} | |
484 | end |
|
484 | end | |
485 |
|
485 | |||
486 | protected |
|
486 | protected | |
487 |
|
487 | |||
|
488 | # Returns the values that are available in the field filter | |||
|
489 | def query_filter_values(custom_field, query) | |||
|
490 | possible_values_options(custom_field, query.project) | |||
|
491 | end | |||
|
492 | ||||
488 | # Renders the edit tag as a select tag |
|
493 | # Renders the edit tag as a select tag | |
489 | def select_edit_tag(view, tag_id, tag_name, custom_value, options={}) |
|
494 | def select_edit_tag(view, tag_id, tag_name, custom_value, options={}) | |
490 | blank_option = ''.html_safe |
|
495 | blank_option = ''.html_safe | |
@@ -716,12 +721,29 module Redmine | |||||
716 | field_attributes :version_status |
|
721 | field_attributes :version_status | |
717 |
|
722 | |||
718 | def possible_values_options(custom_field, object=nil) |
|
723 | def possible_values_options(custom_field, object=nil) | |
|
724 | versions_options(custom_field, object) | |||
|
725 | end | |||
|
726 | ||||
|
727 | def before_custom_field_save(custom_field) | |||
|
728 | super | |||
|
729 | if custom_field.version_status.is_a?(Array) | |||
|
730 | custom_field.version_status.map!(&:to_s).reject!(&:blank?) | |||
|
731 | end | |||
|
732 | end | |||
|
733 | ||||
|
734 | protected | |||
|
735 | ||||
|
736 | def query_filter_values(custom_field, query) | |||
|
737 | versions_options(custom_field, query.project, true) | |||
|
738 | end | |||
|
739 | ||||
|
740 | def versions_options(custom_field, object, all_statuses=false) | |||
719 | if object.is_a?(Array) |
|
741 | if object.is_a?(Array) | |
720 | projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq |
|
742 | projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq | |
721 | projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || [] |
|
743 | projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || [] | |
722 | elsif object.respond_to?(:project) && object.project |
|
744 | elsif object.respond_to?(:project) && object.project | |
723 | scope = object.project.shared_versions |
|
745 | scope = object.project.shared_versions | |
724 | if custom_field.version_status.is_a?(Array) |
|
746 | if !all_statuses && custom_field.version_status.is_a?(Array) | |
725 | statuses = custom_field.version_status.map(&:to_s).reject(&:blank?) |
|
747 | statuses = custom_field.version_status.map(&:to_s).reject(&:blank?) | |
726 | if statuses.any? |
|
748 | if statuses.any? | |
727 | scope = scope.where(:status => statuses.map(&:to_s)) |
|
749 | scope = scope.where(:status => statuses.map(&:to_s)) | |
@@ -732,13 +754,6 module Redmine | |||||
732 | [] |
|
754 | [] | |
733 | end |
|
755 | end | |
734 | end |
|
756 | end | |
735 |
|
||||
736 | def before_custom_field_save(custom_field) |
|
|||
737 | super |
|
|||
738 | if custom_field.version_status.is_a?(Array) |
|
|||
739 | custom_field.version_status.map!(&:to_s).reject!(&:blank?) |
|
|||
740 | end |
|
|||
741 | end |
|
|||
742 | end |
|
757 | end | |
743 | end |
|
758 | end | |
744 | end |
|
759 | end |
@@ -66,4 +66,14 class Redmine::VersionFieldFormatTest < ActionView::TestCase | |||||
66 | field.cast_value([1,2, 42]) |
|
66 | field.cast_value([1,2, 42]) | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
|
69 | ||||
|
70 | def test_query_filter_options_should_include_versions_with_any_status | |||
|
71 | field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"]) | |||
|
72 | project = Project.find(1) | |||
|
73 | version = Version.generate!(:project => project, :status => 'locked') | |||
|
74 | query = Query.new(:project => project) | |||
|
75 | ||||
|
76 | assert_not_include version.name, field.possible_values_options(project).map(&:first) | |||
|
77 | assert_include version.name, field.query_filter_options(query)[:values].map(&:first) | |||
|
78 | end | |||
69 | end |
|
79 | end |
General Comments 0
You need to be logged in to leave comments.
Login now