get the done view on a context and a project

This commit is contained in:
Reinier Balt 2011-06-17 14:30:32 +02:00
parent 35fe362b93
commit a58e832945
10 changed files with 96 additions and 14 deletions

View file

@ -224,6 +224,24 @@ class ApplicationController < ActionController::Base
def prefered_auth?
self.class.prefered_auth?
end
def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_after(start_of_this_day).all(includes)
end
def get_done_this_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_week = Time.zone.now.beginning_of_week
start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
end
def get_done_this_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_month = Time.zone.now.beginning_of_month
start_of_this_week = Time.zone.now.beginning_of_week
completed_todos.completed_after(start_of_this_month).completed_before(start_of_this_week).all(includes)
end
private

View file

@ -165,6 +165,29 @@ class ContextsController < ApplicationController
redirect_to :action => 'index'
end
def done_todos
@source_view = 'context'
@page_title = t('context.completed_tasks_title')
completed_todos = current_user.contexts.find(params[:id]).todos.completed
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
render :template => 'todos/done'
end
def all_done_todos
@source_view = 'context'
@page_title = t('context.completed_tasks_title')
@done = current_user.contexts.find(params[:id]).todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@count = @done.size
render :template => 'todos/all_done'
end
protected
def update_state_counts

View file

@ -215,6 +215,29 @@ class ProjectsController < ApplicationController
@contexts = current_user.contexts
end
def done_todos
@source_view = 'project'
@page_title = t('project.completed_tasks_title')
completed_todos = current_user.projects.find(params[:id]).todos.completed
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
render :template => 'todos/done'
end
def all_done_todos
@source_view = 'project'
@page_title = t('project.completed_tasks_title')
@done = current_user.projects.find(params[:id]).todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@count = @done.size
render :template => 'todos/all_done'
end
protected
def update_state_counts

View file

@ -472,15 +472,10 @@ class TodosController < ApplicationController
@page_title = t('todos.completed_tasks_title')
completed_todos = current_user.todos.completed
start_of_this_day = Time.zone.now.beginning_of_day
start_of_this_week = Time.zone.now.beginning_of_week
start_of_this_month = Time.zone.now.beginning_of_month
start_of_previous_month = (Time.zone.now.beginning_of_month - 1.day).beginning_of_month
includes = {:include => Todo::DEFAULT_INCLUDES}
@done_today = completed_todos.completed_after(start_of_this_day).all(includes)
@done_this_week = completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
@done_this_month = completed_todos.completed_after(start_of_this_month).completed_before(start_of_this_week).all(includes)
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
end