format.value_from_keyword(self, keyword, customized)
end
+ # Returns the options hash used to build a query filter for the field
+ def query_filter_options(query)
+ format.query_filter_options(self, query)
+ end
+
# Returns a ORDER BY clause that can used to sort customized
# objects by their value of the custom field.
# Returns nil if the custom field can not be used for sorting.
# Adds a filter for the given custom field
def add_custom_field_filter(field, assoc=nil)
- options = field.format.query_filter_options(field, self)
+ options = field.query_filter_options(self)
if field.format.target_class && field.format.target_class <= User
if options[:values].is_a?(Array) && User.current.logged?
options[:values].unshift ["<< #{l(:label_me)} >>", "me"]
end
def query_filter_options(custom_field, query)
- {:type => :list_optional, :values => possible_values_options(custom_field, query.project)}
+ {:type => :list_optional, :values => query_filter_values(custom_field, query)}
end
protected
+ # Returns the values that are available in the field filter
+ def query_filter_values(custom_field, query)
+ possible_values_options(custom_field, query.project)
+ end
+
# Renders the edit tag as a select tag
def select_edit_tag(view, tag_id, tag_name, custom_value, options={})
blank_option = ''.html_safe
field_attributes :version_status
def possible_values_options(custom_field, object=nil)
+ versions_options(custom_field, object)
+ end
+
+ def before_custom_field_save(custom_field)
+ super
+ if custom_field.version_status.is_a?(Array)
+ custom_field.version_status.map!(&:to_s).reject!(&:blank?)
+ end
+ end
+
+ protected
+
+ def query_filter_values(custom_field, query)
+ versions_options(custom_field, query.project, true)
+ end
+
+ def versions_options(custom_field, object, all_statuses=false)
if object.is_a?(Array)
projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq
projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || []
elsif object.respond_to?(:project) && object.project
scope = object.project.shared_versions
- if custom_field.version_status.is_a?(Array)
+ if !all_statuses && custom_field.version_status.is_a?(Array)
statuses = custom_field.version_status.map(&:to_s).reject(&:blank?)
if statuses.any?
scope = scope.where(:status => statuses.map(&:to_s))
[]
end
end
-
- def before_custom_field_save(custom_field)
- super
- if custom_field.version_status.is_a?(Array)
- custom_field.version_status.map!(&:to_s).reject!(&:blank?)
- end
- end
end
end
end
field.cast_value([1,2, 42])
end
end
+
+ def test_query_filter_options_should_include_versions_with_any_status
+ field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"])
+ project = Project.find(1)
+ version = Version.generate!(:project => project, :status => 'locked')
+ query = Query.new(:project => project)
+
+ assert_not_include version.name, field.possible_values_options(project).map(&:first)
+ assert_include version.name, field.query_filter_options(query)[:values].map(&:first)
+ end
end