Commit 89842aa1 authored by jplang's avatar jplang
Browse files

Group versions by status in version custom field filter (#23265).

git-svn-id: https://svn.redmine.org/redmine/trunk@16194 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent c4259387
...@@ -826,7 +826,7 @@ module Redmine ...@@ -826,7 +826,7 @@ module Redmine
field_attributes :version_status field_attributes :version_status
def possible_values_options(custom_field, object=nil) def possible_values_options(custom_field, object=nil)
versions_options(custom_field, object) possible_values_records(custom_field, object).sort.collect{|v| [v.to_s, v.id.to_s] }
end end
def before_custom_field_save(custom_field) def before_custom_field_save(custom_field)
...@@ -839,13 +839,14 @@ module Redmine ...@@ -839,13 +839,14 @@ module Redmine
protected protected
def query_filter_values(custom_field, query) def query_filter_values(custom_field, query)
versions_options(custom_field, query.project, true) versions = possible_values_records(custom_field, query.project, true)
Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] }
end end
def versions_options(custom_field, object, all_statuses=false) def possible_values_records(custom_field, object=nil, all_statuses=false)
if object.is_a?(Array) if object.is_a?(Array)
projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq
projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || [] projects.map {|project| possible_values_records(custom_field, project)}.reduce(:&) || []
elsif object.respond_to?(:project) && object.project elsif object.respond_to?(:project) && object.project
scope = object.project.shared_versions scope = object.project.shared_versions
filtered_versions_options(custom_field, scope, all_statuses) filtered_versions_options(custom_field, scope, all_statuses)
...@@ -864,7 +865,7 @@ module Redmine ...@@ -864,7 +865,7 @@ module Redmine
scope = scope.where(:status => statuses.map(&:to_s)) scope = scope.where(:status => statuses.map(&:to_s))
end end
end end
scope.sort.collect{|u| [u.to_s, u.id.to_s] } scope
end end
end end
......
...@@ -82,7 +82,19 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase ...@@ -82,7 +82,19 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase
version = Version.generate!(:project => project, :status => 'locked') version = Version.generate!(:project => project, :status => 'locked')
query = Query.new(:project => project) query = Query.new(:project => project)
assert_not_include version.name, field.possible_values_options(project).map(&:first) full_name = "#{version.project} - #{version.name}"
assert_include version.name, field.query_filter_options(query)[:values].call.map(&:first) assert_not_include full_name, field.possible_values_options(project).map(&:first)
assert_include full_name, field.query_filter_options(query)[:values].call.map(&:first)
end
def test_query_filter_options_should_include_version_status_for_grouping
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)
full_name = "#{version.project} - #{version.name}"
assert_include [full_name, version.id.to_s, l(:version_status_locked)],
field.query_filter_options(query)[:values].call
end end
end end
Markdown is supported
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