code layout cleanup Query available_filters method
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10545 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ef988ba17c
commit
1d4c8abe96
|
@ -225,29 +225,41 @@ class Query < ActiveRecord::Base
|
||||||
|
|
||||||
def available_filters
|
def available_filters
|
||||||
return @available_filters if @available_filters
|
return @available_filters if @available_filters
|
||||||
|
@available_filters = {
|
||||||
@available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
|
"status_id" => {
|
||||||
"tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },
|
:type => :list_status, :order => 1,
|
||||||
"priority_id" => { :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] } },
|
:values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] }
|
||||||
"subject" => { :type => :text, :order => 8 },
|
},
|
||||||
"created_on" => { :type => :date_past, :order => 9 },
|
"tracker_id" => {
|
||||||
"updated_on" => { :type => :date_past, :order => 10 },
|
:type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] }
|
||||||
"start_date" => { :type => :date, :order => 11 },
|
},
|
||||||
"due_date" => { :type => :date, :order => 12 },
|
"priority_id" => {
|
||||||
"estimated_hours" => { :type => :float, :order => 13 },
|
:type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] }
|
||||||
"done_ratio" => { :type => :integer, :order => 14 }}
|
},
|
||||||
|
"subject" => { :type => :text, :order => 8 },
|
||||||
|
"created_on" => { :type => :date_past, :order => 9 },
|
||||||
|
"updated_on" => { :type => :date_past, :order => 10 },
|
||||||
|
"start_date" => { :type => :date, :order => 11 },
|
||||||
|
"due_date" => { :type => :date, :order => 12 },
|
||||||
|
"estimated_hours" => { :type => :float, :order => 13 },
|
||||||
|
"done_ratio" => { :type => :integer, :order => 14 }
|
||||||
|
}
|
||||||
IssueRelation::TYPES.each do |relation_type, options|
|
IssueRelation::TYPES.each do |relation_type, options|
|
||||||
@available_filters[relation_type] = {:type => :relation, :order => @available_filters.size + 100, :label => options[:name]}
|
@available_filters[relation_type] = {
|
||||||
|
:type => :relation, :order => @available_filters.size + 100,
|
||||||
|
:label => options[:name]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
principals = []
|
principals = []
|
||||||
if project
|
if project
|
||||||
principals += project.principals.sort
|
principals += project.principals.sort
|
||||||
unless project.leaf?
|
unless project.leaf?
|
||||||
subprojects = project.descendants.visible.all
|
subprojects = project.descendants.visible.all
|
||||||
if subprojects.any?
|
if subprojects.any?
|
||||||
@available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => subprojects.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["subproject_id"] = {
|
||||||
|
:type => :list_subprojects, :order => 13,
|
||||||
|
:values => subprojects.collect{|s| [s.name, s.id.to_s] }
|
||||||
|
}
|
||||||
principals += Principal.member_of(subprojects)
|
principals += Principal.member_of(subprojects)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -255,14 +267,15 @@ class Query < ActiveRecord::Base
|
||||||
if all_projects.any?
|
if all_projects.any?
|
||||||
# members of visible projects
|
# members of visible projects
|
||||||
principals += Principal.member_of(all_projects)
|
principals += Principal.member_of(all_projects)
|
||||||
|
|
||||||
# project filter
|
# project filter
|
||||||
project_values = []
|
project_values = []
|
||||||
if User.current.logged? && User.current.memberships.any?
|
if User.current.logged? && User.current.memberships.any?
|
||||||
project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"]
|
project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"]
|
||||||
end
|
end
|
||||||
project_values += all_projects_values
|
project_values += all_projects_values
|
||||||
@available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values} unless project_values.empty?
|
@available_filters["project_id"] = {
|
||||||
|
:type => :list, :order => 1, :values => project_values
|
||||||
|
} unless project_values.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
principals.uniq!
|
principals.uniq!
|
||||||
|
@ -271,59 +284,84 @@ class Query < ActiveRecord::Base
|
||||||
|
|
||||||
assigned_to_values = []
|
assigned_to_values = []
|
||||||
assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
||||||
assigned_to_values += (Setting.issue_group_assignment? ? principals : users).collect{|s| [s.name, s.id.to_s] }
|
assigned_to_values += (Setting.issue_group_assignment? ?
|
||||||
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => assigned_to_values } unless assigned_to_values.empty?
|
principals : users).collect{|s| [s.name, s.id.to_s] }
|
||||||
|
@available_filters["assigned_to_id"] = {
|
||||||
|
:type => :list_optional, :order => 4, :values => assigned_to_values
|
||||||
|
} unless assigned_to_values.empty?
|
||||||
|
|
||||||
author_values = []
|
author_values = []
|
||||||
author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
||||||
author_values += users.collect{|s| [s.name, s.id.to_s] }
|
author_values += users.collect{|s| [s.name, s.id.to_s] }
|
||||||
@available_filters["author_id"] = { :type => :list, :order => 5, :values => author_values } unless author_values.empty?
|
@available_filters["author_id"] = {
|
||||||
|
:type => :list, :order => 5, :values => author_values
|
||||||
|
} unless author_values.empty?
|
||||||
|
|
||||||
group_values = Group.all.collect {|g| [g.name, g.id.to_s] }
|
group_values = Group.all.collect {|g| [g.name, g.id.to_s] }
|
||||||
@available_filters["member_of_group"] = { :type => :list_optional, :order => 6, :values => group_values } unless group_values.empty?
|
@available_filters["member_of_group"] = {
|
||||||
|
:type => :list_optional, :order => 6, :values => group_values
|
||||||
|
} unless group_values.empty?
|
||||||
|
|
||||||
role_values = Role.givable.collect {|r| [r.name, r.id.to_s] }
|
role_values = Role.givable.collect {|r| [r.name, r.id.to_s] }
|
||||||
@available_filters["assigned_to_role"] = { :type => :list_optional, :order => 7, :values => role_values } unless role_values.empty?
|
@available_filters["assigned_to_role"] = {
|
||||||
|
:type => :list_optional, :order => 7, :values => role_values
|
||||||
|
} unless role_values.empty?
|
||||||
|
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
@available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] }
|
@available_filters["watcher_id"] = {
|
||||||
|
:type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if project
|
if project
|
||||||
# project specific filters
|
# project specific filters
|
||||||
categories = project.issue_categories.all
|
categories = project.issue_categories.all
|
||||||
unless categories.empty?
|
unless categories.empty?
|
||||||
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => categories.collect{|s| [s.name, s.id.to_s] } }
|
@available_filters["category_id"] = {
|
||||||
|
:type => :list_optional, :order => 6,
|
||||||
|
:values => categories.collect{|s| [s.name, s.id.to_s] }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
versions = project.shared_versions.all
|
versions = project.shared_versions.all
|
||||||
unless versions.empty?
|
unless versions.empty?
|
||||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
@available_filters["fixed_version_id"] = {
|
||||||
|
:type => :list_optional, :order => 7,
|
||||||
|
:values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
add_custom_fields_filters(project.all_issue_custom_fields)
|
add_custom_fields_filters(project.all_issue_custom_fields)
|
||||||
else
|
else
|
||||||
# global filters for cross project issue list
|
# global filters for cross project issue list
|
||||||
system_shared_versions = Version.visible.find_all_by_sharing('system')
|
system_shared_versions = Version.visible.find_all_by_sharing('system')
|
||||||
unless system_shared_versions.empty?
|
unless system_shared_versions.empty?
|
||||||
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
|
@available_filters["fixed_version_id"] = {
|
||||||
|
:type => :list_optional, :order => 7,
|
||||||
|
:values => system_shared_versions.sort.collect{|s|
|
||||||
|
["#{s.project.name} - #{s.name}", s.id.to_s]
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
|
add_custom_fields_filters(
|
||||||
|
IssueCustomField.find(:all,
|
||||||
|
:conditions => {
|
||||||
|
:is_filter => true,
|
||||||
|
:is_for_all => true
|
||||||
|
}))
|
||||||
end
|
end
|
||||||
|
|
||||||
add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
|
add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
|
||||||
|
|
||||||
if User.current.allowed_to?(:set_issues_private, nil, :global => true) ||
|
if User.current.allowed_to?(:set_issues_private, nil, :global => true) ||
|
||||||
User.current.allowed_to?(:set_own_issues_private, nil, :global => true)
|
User.current.allowed_to?(:set_own_issues_private, nil, :global => true)
|
||||||
@available_filters["is_private"] = { :type => :list, :order => 15, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] }
|
@available_filters["is_private"] = {
|
||||||
|
:type => :list, :order => 15,
|
||||||
|
:values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
Tracker.disabled_core_fields(trackers).each {|field|
|
Tracker.disabled_core_fields(trackers).each {|field|
|
||||||
@available_filters.delete field
|
@available_filters.delete field
|
||||||
}
|
}
|
||||||
|
|
||||||
@available_filters.each do |field, options|
|
@available_filters.each do |field, options|
|
||||||
options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
|
options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
|
||||||
end
|
end
|
||||||
|
|
||||||
@available_filters
|
@available_filters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue