summaryrefslogtreecommitdiffstats
path: root/app/models/query.rb
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-10-02 10:29:18 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-10-02 10:29:18 +0000
commit1d4c8abe9687c428951916b2e51cf655af905ad9 (patch)
tree79eb93e897b7a02979040a32a448a4b48c8ce16b /app/models/query.rb
parentef988ba17cde0fef14d59be0df26bd068769b5ee (diff)
downloadredmine-1d4c8abe9687c428951916b2e51cf655af905ad9.tar.gz
redmine-1d4c8abe9687c428951916b2e51cf655af905ad9.zip
code layout cleanup Query available_filters method
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10545 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r--app/models/query.rb104
1 files changed, 71 insertions, 33 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 357bad5a8..35c4b950c 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -225,29 +225,41 @@ class Query < ActiveRecord::Base
def available_filters
return @available_filters if @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] } },
- "tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },
- "priority_id" => { :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] } },
- "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 }}
-
+ @available_filters = {
+ "status_id" => {
+ :type => :list_status, :order => 1,
+ :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] }
+ },
+ "tracker_id" => {
+ :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] }
+ },
+ "priority_id" => {
+ :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] }
+ },
+ "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|
- @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
-
principals = []
if project
principals += project.principals.sort
unless project.leaf?
subprojects = project.descendants.visible.all
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)
end
end
@@ -255,14 +267,15 @@ class Query < ActiveRecord::Base
if all_projects.any?
# members of visible projects
principals += Principal.member_of(all_projects)
-
# project filter
project_values = []
if User.current.logged? && User.current.memberships.any?
project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"]
end
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
principals.uniq!
@@ -271,59 +284,84 @@ class Query < ActiveRecord::Base
assigned_to_values = []
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] }
- @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => assigned_to_values } unless assigned_to_values.empty?
+ assigned_to_values += (Setting.issue_group_assignment? ?
+ 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 << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
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] }
- @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] }
- @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?
- @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
if project
# project specific filters
categories = project.issue_categories.all
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
versions = project.shared_versions.all
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
add_custom_fields_filters(project.all_issue_custom_fields)
else
# global filters for cross project issue list
system_shared_versions = Version.visible.find_all_by_sharing('system')
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
- 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
-
add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
-
if User.current.allowed_to?(:set_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
-
Tracker.disabled_core_fields(trackers).each {|field|
@available_filters.delete field
}
-
@available_filters.each do |field, options|
options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
end
-
@available_filters
end