summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-26 08:12:44 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-26 08:12:44 +0000
commit42238a74f46423bf3d7514228e7cc818369a87b9 (patch)
treedd75d70ef47d78d81af12281ffc54372469be53a
parent7b12145ed904e531fa4e573cb5efb50abdedf6ac (diff)
downloadredmine-42238a74f46423bf3d7514228e7cc818369a87b9.tar.gz
redmine-42238a74f46423bf3d7514228e7cc818369a87b9.zip
Display all versions in query filter (#19271).
git-svn-id: http://svn.redmine.org/redmine/trunk@14623 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/custom_field.rb5
-rw-r--r--app/models/query.rb2
-rw-r--r--lib/redmine/field_format.rb33
-rw-r--r--test/unit/lib/redmine/field_format/version_field_format_test.rb10
4 files changed, 40 insertions, 10 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 1b8033a0e..ad87aa34e 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -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.
diff --git a/app/models/query.rb b/app/models/query.rb
index a232258e0..083b775a6 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -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"]
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index 5fd1d6aa1..c4897c16c 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -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
diff --git a/test/unit/lib/redmine/field_format/version_field_format_test.rb b/test/unit/lib/redmine/field_format/version_field_format_test.rb
index aad880e26..fb4a5dbc8 100644
--- a/test/unit/lib/redmine/field_format/version_field_format_test.rb
+++ b/test/unit/lib/redmine/field_format/version_field_format_test.rb
@@ -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