summaryrefslogtreecommitdiffstats
path: root/app/models/time_entry_query.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-14 20:37:17 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-14 20:37:17 +0000
commit0be82ea2c45eb2d95e5cde32365dea8a5b333123 (patch)
tree32ddf23e177c988959f2a8a1797356ac46f4592f /app/models/time_entry_query.rb
parentf77edce621c6841c507ed3925ce04d01f2ad986b (diff)
downloadredmine-0be82ea2c45eb2d95e5cde32365dea8a5b333123.tar.gz
redmine-0be82ea2c45eb2d95e5cde32365dea8a5b333123.zip
Refactor: use an ordered hash to store available filters and remove :order option (#13154).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11372 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/time_entry_query.rb')
-rw-r--r--app/models/time_entry_query.rb40
1 files changed, 16 insertions, 24 deletions
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb
index 7283fbd2f..f0301ce32 100644
--- a/app/models/time_entry_query.rb
+++ b/app/models/time_entry_query.rb
@@ -35,13 +35,8 @@ class TimeEntryQuery < Query
add_filter('spent_on', '*') unless filters.present?
end
- def available_filters
- return @available_filters if @available_filters
- @available_filters = {
- "spent_on" => { :type => :date_past, :order => 0 },
- "comments" => { :type => :text, :order => 5 },
- "hours" => { :type => :float, :order => 6 }
- }
+ def initialize_available_filters
+ add_available_filter "spent_on", :type => :date_past
principals = []
if project
@@ -49,10 +44,9 @@ class TimeEntryQuery < Query
unless project.leaf?
subprojects = project.descendants.visible.all
if subprojects.any?
- @available_filters["subproject_id"] = {
- :type => :list_subprojects, :order => 1,
+ add_available_filter "subproject_id",
+ :type => :list_subprojects,
:values => subprojects.collect{|s| [s.name, s.id.to_s] }
- }
principals += Principal.member_of(subprojects)
end
end
@@ -66,9 +60,9 @@ class TimeEntryQuery < Query
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?
+ add_available_filter("project_id",
+ :type => :list, :values => project_values
+ ) unless project_values.empty?
end
end
principals.uniq!
@@ -78,22 +72,20 @@ class TimeEntryQuery < Query
users_values = []
users_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
users_values += users.collect{|s| [s.name, s.id.to_s] }
- @available_filters["user_id"] = {
- :type => :list_optional, :order => 2, :values => users_values
- } unless users_values.empty?
+ add_available_filter("user_id",
+ :type => :list_optional, :values => users_values
+ ) unless users_values.empty?
activities = (project ? project.activities : TimeEntryActivity.shared.active)
- @available_filters["activity_id"] = {
- :type => :list, :order => 3, :values => activities.map {|a| [a.name, a.id.to_s]}
- } unless activities.empty?
+ add_available_filter("activity_id",
+ :type => :list, :values => activities.map {|a| [a.name, a.id.to_s]}
+ ) unless activities.empty?
+
+ add_available_filter "comments", :type => :text
+ add_available_filter "hours", :type => :float
add_custom_fields_filters(TimeEntryCustomField.where(:is_filter => true).all)
add_associations_custom_fields_filters :project, :issue, :user
-
- @available_filters.each do |field, options|
- options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
- end
- @available_filters
end
def available_columns