summaryrefslogtreecommitdiffstats
path: root/app/controllers/timelog_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-09 17:57:18 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-09 17:57:18 +0000
commitf8895a7cdd9c53f3335825a45be1d53862693370 (patch)
tree2d75806f7fda54ccc9118cb1f69ff26c6fb541cd /app/controllers/timelog_controller.rb
parent10998c9bae314057b5c2adf97418618f68efb3d7 (diff)
downloadredmine-f8895a7cdd9c53f3335825a45be1d53862693370.tar.gz
redmine-f8895a7cdd9c53f3335825a45be1d53862693370.zip
Adds TimeEntryQuery for listing time entries.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10967 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/timelog_controller.rb')
-rw-r--r--app/controllers/timelog_controller.rb37
1 files changed, 20 insertions, 17 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index a0c694bc4..a2dcfac7d 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -36,24 +36,14 @@ class TimelogController < ApplicationController
include TimelogHelper
helper :custom_fields
include CustomFieldsHelper
+ helper :queries
def index
- sort_init 'spent_on', 'desc'
- sort_update 'spent_on' => ['spent_on', "#{TimeEntry.table_name}.created_on"],
- 'user' => 'user_id',
- 'activity' => 'activity_id',
- 'project' => "#{Project.table_name}.name",
- 'issue' => 'issue_id',
- 'hours' => 'hours'
+ @query = TimeEntryQuery.build_from_params(params, :name => '_')
+ scope = time_entry_scope
- retrieve_date_range
-
- scope = TimeEntry.visible.spent_between(@from, @to)
- if @issue
- scope = scope.on_issue(@issue)
- elsif @project
- scope = scope.on_project(@project, Setting.display_subprojects_issues?)
- end
+ sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria)
+ sort_update(@query.sortable_columns)
respond_to do |format|
format.html {
@@ -100,8 +90,10 @@ class TimelogController < ApplicationController
end
def report
- retrieve_date_range
- @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], @from, @to)
+ @query = TimeEntryQuery.build_from_params(params, :name => '_')
+ scope = time_entry_scope
+
+ @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope)
respond_to do |format|
format.html { render :layout => !request.xhr? }
@@ -291,6 +283,17 @@ private
end
end
+ # Returns the TimeEntry scope for index and report actions
+ def time_entry_scope
+ scope = TimeEntry.visible.where(@query.statement)
+ if @issue
+ scope = scope.on_issue(@issue)
+ elsif @project
+ scope = scope.on_project(@project, Setting.display_subprojects_issues?)
+ end
+ scope
+ end
+
# Retrieves the date range based on predefined ranges or specific from/to param dates
def retrieve_date_range
@free_period = false