]> source.dussan.org Git - redmine.git/commitdiff
Display all versions in query filter (#19271).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 26 Sep 2015 08:12:44 +0000 (08:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 26 Sep 2015 08:12:44 +0000 (08:12 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14623 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/custom_field.rb
app/models/query.rb
lib/redmine/field_format.rb
test/unit/lib/redmine/field_format/version_field_format_test.rb

index 1b8033a0ed071b5ebee575cd5ead981db55904ab..ad87aa34eb80d53d300f68c7716b041eac379d75 100644 (file)
@@ -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.
index a232258e084cc00d021677b359d53ad82dbff486..083b775a658fe6cda775432b065dd5923b383d16 100644 (file)
@@ -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"]
index 5fd1d6aa1d18a392a643847313ebaf34eb9ef99b..c4897c16c630e18169e823f92833d0ba6af69762 100644 (file)
@@ -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
index aad880e26ef9dc882f58596815d503f4006f513f..fb4a5dbc868ce9b8fba8c4c4a0c648d56259639e 100644 (file)
@@ -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