summaryrefslogtreecommitdiffstats
path: root/app/controllers/timelog_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-04 22:49:46 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-04 22:49:46 +0000
commit9e5ed4208b8dc531f77708e84f6d11eba3f1ca4a (patch)
treea8a6b0ef7a6593ed41dd0ac919ca44d644eba982 /app/controllers/timelog_controller.rb
parentff0f141126e4f196deebf74e74e6eb16e8e72e5f (diff)
downloadredmine-9e5ed4208b8dc531f77708e84f6d11eba3f1ca4a.tar.gz
redmine-9e5ed4208b8dc531f77708e84f6d11eba3f1ca4a.zip
Adds named scopes for time entries index.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8084 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/timelog_controller.rb')
-rw-r--r--app/controllers/timelog_controller.rb59
1 files changed, 29 insertions, 30 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 063df30cc..719e0b864 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -41,55 +41,54 @@ class TimelogController < ApplicationController
'issue' => 'issue_id',
'hours' => 'hours'
- cond = ARCondition.new
+ retrieve_date_range
+
+ scope = TimeEntry.visible.spent_between(@from, @to)
if @issue
- cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
+ scope = scope.on_issue(@issue)
elsif @project
- cond << @project.project_condition(Setting.display_subprojects_issues?)
+ scope = scope.on_project(@project, Setting.display_subprojects_issues?)
end
- retrieve_date_range
- cond << ['spent_on BETWEEN ? AND ?', @from, @to]
-
respond_to do |format|
format.html {
# Paginate results
- @entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
+ @entry_count = scope.count
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
- @entries = TimeEntry.visible.find(:all,
- :include => [:project, :activity, :user, {:issue => :tracker}],
- :conditions => cond.conditions,
- :order => sort_clause,
- :limit => @entry_pages.items_per_page,
- :offset => @entry_pages.current.offset)
- @total_hours = TimeEntry.visible.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
+ @entries = scope.all(
+ :include => [:project, :activity, :user, {:issue => :tracker}],
+ :order => sort_clause,
+ :limit => @entry_pages.items_per_page,
+ :offset => @entry_pages.current.offset
+ )
+ @total_hours = scope.sum(:hours).to_f
render :layout => !request.xhr?
}
format.api {
- @entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
+ @entry_count = scope.count
@offset, @limit = api_offset_and_limit
- @entries = TimeEntry.visible.find(:all,
- :include => [:project, :activity, :user, {:issue => :tracker}],
- :conditions => cond.conditions,
- :order => sort_clause,
- :limit => @limit,
- :offset => @offset)
+ @entries = scope.all(
+ :include => [:project, :activity, :user, {:issue => :tracker}],
+ :order => sort_clause,
+ :limit => @limit,
+ :offset => @offset
+ )
}
format.atom {
- entries = TimeEntry.visible.find(:all,
- :include => [:project, :activity, :user, {:issue => :tracker}],
- :conditions => cond.conditions,
- :order => "#{TimeEntry.table_name}.created_on DESC",
- :limit => Setting.feeds_limit.to_i)
+ entries = scope.all(
+ :include => [:project, :activity, :user, {:issue => :tracker}],
+ :order => "#{TimeEntry.table_name}.created_on DESC",
+ :limit => Setting.feeds_limit.to_i
+ )
render_feed(entries, :title => l(:label_spent_time))
}
format.csv {
# Export all entries
- @entries = TimeEntry.visible.find(:all,
- :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
- :conditions => cond.conditions,
- :order => sort_clause)
+ @entries = scope.all(
+ :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
+ :order => sort_clause
+ )
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
}
end