Commit 387e1ecf authored by jplang's avatar jplang
Browse files

Display all versions in query filter (#19271).

git-svn-id: https://svn.redmine.org/redmine/trunk@14623 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 43ff45d5
......@@ -144,6 +144,11 @@ class CustomField < ActiveRecord::Base
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.
......
......@@ -797,7 +797,7 @@ class Query < ActiveRecord::Base
# 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"]
......
......@@ -480,11 +480,16 @@ module Redmine
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
......@@ -716,12 +721,29 @@ module Redmine
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))
......@@ -732,13 +754,6 @@ module Redmine
[]
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
......@@ -66,4 +66,14 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment