diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cab14070..d2b02d0a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 98c8c689..129bded8 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b3822ac4..af4da6ba 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 13a255b9..887acba6 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 692b9b89..f4854256 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -275,5 +275,27 @@ module ApplicationHelper javascript_include_tag("i18n/jquery.ui.datepicker-#{locale}.js") end end + + def determine_done_path + case @controller.controller_name + when "contexts" + done_todos_context_path(@context) + when "projects" + done_todos_project_path(@project) + else + done_todos_path + end + end + + def determine_all_done_path + case @controller.controller_name + when "contexts" + all_done_todos_context_path(@context) + when "projects" + all_done_todos_project_path(@project) + else + all_done_todos_path + end + end end diff --git a/app/models/todo.rb b/app/models/todo.rb index f98835d6..18e1acf7 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -44,7 +44,7 @@ class Todo < ActiveRecord::Base named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } } STARRED_TAG_NAME = "starred" - DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :pending_successors, :successors, :predecessors, :recurring_todo ] + DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :recurring_todo ] # regular expressions for dependencies RE_TODO = /[^']+/ diff --git a/app/views/todos/_completed.rhtml b/app/views/todos/_completed.rhtml index f795b30c..f54601fc 100644 --- a/app/views/todos/_completed.rhtml +++ b/app/views/todos/_completed.rhtml @@ -3,7 +3,7 @@ suppress_project ||= false -%>
You can see all completed actions <%= link_to "here", all_done_todos_path %>
+You can see all completed actions <%= link_to "here", determine_all_done_path %>
diff --git a/config/routes.rb b/config/routes.rb index dfa39af7..f57a7c94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ ActionController::Routing::Routes.draw do |map| users.signup 'signup', :action => "new" end - map.resources :contexts, :collection => {:order => :post} do |contexts| + map.resources :contexts, :collection => {:order => :post}, :member => {:done_todos => :get, :all_done_todos => :get} do |contexts| contexts.resources :todos, :name_prefix => "context_" end @@ -16,7 +16,8 @@ ActionController::Routing::Routes.draw do |map| contexts.done_contexts 'contexts/done', :action => 'done' end - map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post} do |projects| + map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post}, + :member => {:done_todos => :get, :all_done_todos => :get} do |projects| projects.resources :todos, :name_prefix => "project_" end diff --git a/lib/tracks/todo_list.rb b/lib/tracks/todo_list.rb index e4256370..b1a32229 100644 --- a/lib/tracks/todo_list.rb +++ b/lib/tracks/todo_list.rb @@ -54,6 +54,6 @@ module Tracks def deferred_todo_count self.todos.count_in_state(:deferred) end - + end end