Permalink
Browse files

Refactor: extract @available_criterias to utility method.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3825 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information...
edavis10 committed Jul 1, 2010
1 parent 64d2221 commit 11ff334cd86c26a432e3282e732e6b1262915248
Showing with 50 additions and 45 deletions.
  1. +50 −45 app/controllers/timelog_controller.rb
@@ -19,6 +19,7 @@ class TimelogController < ApplicationController
menu_item :issues
before_filter :find_project, :authorize, :only => [:edit, :destroy]
before_filter :find_optional_project, :only => [:report, :details]
+ before_filter :load_available_criterias, :only => [:report]
verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
@@ -30,51 +31,6 @@ class TimelogController < ApplicationController
include CustomFieldsHelper
def report
- @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
- :klass => Project,
- :label => :label_project},
- 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
- :klass => Version,
- :label => :label_version},
- 'category' => {:sql => "#{Issue.table_name}.category_id",
- :klass => IssueCategory,
- :label => :field_category},
- 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
- :klass => User,
- :label => :label_member},
- 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
- :klass => Tracker,
- :label => :label_tracker},
- 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
- :klass => TimeEntryActivity,
- :label => :label_activity},
- 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
- :klass => Issue,
- :label => :label_issue}
- }
-
- # Add list and boolean custom fields as available criterias
- custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
- custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
- @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
- :format => cf.field_format,
- :label => cf.name}
- end if @project
-
- # Add list and boolean time entry custom fields
- TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
- @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
- :format => cf.field_format,
- :label => cf.name}
- end
-
- # Add list and boolean time entry activity custom fields
- TimeEntryActivityCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
- @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Enumeration' AND c.customized_id = #{TimeEntry.table_name}.activity_id)",
- :format => cf.field_format,
- :label => cf.name}
- end
-
@criterias = params[:criterias] || []
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
@criterias.uniq!
@@ -308,4 +264,53 @@ def retrieve_date_range
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)
end
+
+ def load_available_criterias
+ @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
+ :klass => Project,
+ :label => :label_project},
+ 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
+ :klass => Version,
+ :label => :label_version},
+ 'category' => {:sql => "#{Issue.table_name}.category_id",
+ :klass => IssueCategory,
+ :label => :field_category},
+ 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
+ :klass => User,
+ :label => :label_member},
+ 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
+ :klass => Tracker,
+ :label => :label_tracker},
+ 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
+ :klass => TimeEntryActivity,
+ :label => :label_activity},
+ 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
+ :klass => Issue,
+ :label => :label_issue}
+ }
+
+ # Add list and boolean custom fields as available criterias
+ custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
+ custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
+ @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
+ :format => cf.field_format,
+ :label => cf.name}
+ end if @project
+
+ # Add list and boolean time entry custom fields
+ TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
+ @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
+ :format => cf.field_format,
+ :label => cf.name}
+ end
+
+ # Add list and boolean time entry activity custom fields
+ TimeEntryActivityCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
+ @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Enumeration' AND c.customized_id = #{TimeEntry.table_name}.activity_id)",
+ :format => cf.field_format,
+ :label => cf.name}
+ end
+
+ @available_criterias
+ end
end

0 comments on commit 11ff334

Please sign in to comment.