Add filters on cross-project issue list for custom fields marked as 'For all projects'.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1576 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b025b63111
commit
0d5b03bab7
|
@ -167,30 +167,19 @@ class Query < ActiveRecord::Base
|
||||||
|
|
||||||
if project
|
if project
|
||||||
# project specific filters
|
# project specific filters
|
||||||
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
unless @project.issue_categories.empty?
|
||||||
|
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
|
||||||
|
end
|
||||||
unless @project.versions.empty?
|
unless @project.versions.empty?
|
||||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
|
||||||
end
|
end
|
||||||
unless @project.active_children.empty?
|
unless @project.active_children.empty?
|
||||||
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
|
||||||
end
|
end
|
||||||
@project.all_custom_fields.select(&:is_filter?).each do |field|
|
add_custom_fields_filters(@project.all_custom_fields)
|
||||||
case field.field_format
|
else
|
||||||
when "text"
|
# global filters for cross project issue list
|
||||||
options = { :type => :text, :order => 20 }
|
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
||||||
when "list"
|
|
||||||
options = { :type => :list_optional, :values => field.possible_values, :order => 20}
|
|
||||||
when "date"
|
|
||||||
options = { :type => :date, :order => 20 }
|
|
||||||
when "bool"
|
|
||||||
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
|
||||||
else
|
|
||||||
options = { :type => :string, :order => 20 }
|
|
||||||
end
|
|
||||||
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
|
||||||
end
|
|
||||||
# remove category filter if no category defined
|
|
||||||
@available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
|
|
||||||
end
|
end
|
||||||
@available_filters
|
@available_filters
|
||||||
end
|
end
|
||||||
|
@ -368,4 +357,26 @@ class Query < ActiveRecord::Base
|
||||||
|
|
||||||
(project_clauses + filters_clauses).join(' AND ')
|
(project_clauses + filters_clauses).join(' AND ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def add_custom_fields_filters(custom_fields)
|
||||||
|
@available_filters ||= {}
|
||||||
|
|
||||||
|
custom_fields.select(&:is_filter?).each do |field|
|
||||||
|
case field.field_format
|
||||||
|
when "text"
|
||||||
|
options = { :type => :text, :order => 20 }
|
||||||
|
when "list"
|
||||||
|
options = { :type => :list_optional, :values => field.possible_values, :order => 20}
|
||||||
|
when "date"
|
||||||
|
options = { :type => :date, :order => 20 }
|
||||||
|
when "bool"
|
||||||
|
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
|
||||||
|
else
|
||||||
|
options = { :type => :string, :order => 20 }
|
||||||
|
end
|
||||||
|
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,6 +30,7 @@ custom_fields_003:
|
||||||
min_length: 0
|
min_length: 0
|
||||||
regexp: ""
|
regexp: ""
|
||||||
is_for_all: false
|
is_for_all: false
|
||||||
|
is_filter: true
|
||||||
type: ProjectCustomField
|
type: ProjectCustomField
|
||||||
max_length: 0
|
max_length: 0
|
||||||
possible_values: Stable|Beta|Alpha|Planning
|
possible_values: Stable|Beta|Alpha|Planning
|
||||||
|
|
|
@ -20,6 +20,12 @@ require File.dirname(__FILE__) + '/../test_helper'
|
||||||
class QueryTest < Test::Unit::TestCase
|
class QueryTest < Test::Unit::TestCase
|
||||||
fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
|
fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
|
||||||
|
|
||||||
|
def test_custom_fields_for_all_projects_should_be_available_in_global_queries
|
||||||
|
query = Query.new(:project => nil, :name => '_')
|
||||||
|
assert query.available_filters.has_key?('cf_1')
|
||||||
|
assert !query.available_filters.has_key?('cf_3')
|
||||||
|
end
|
||||||
|
|
||||||
def test_query_with_multiple_custom_fields
|
def test_query_with_multiple_custom_fields
|
||||||
query = Query.find(1)
|
query = Query.find(1)
|
||||||
assert query.valid?
|
assert query.valid?
|
||||||
|
|
Loading…
Reference in New Issue