From 9723645dcd9cf68a7701f06471ce3f3d0d74f7a6 Mon Sep 17 00:00:00 2001 From: bsag Date: Fri, 31 Mar 2006 13:24:22 +0000 Subject: [PATCH] Fixes #243. The 'done' page was generating errors (a regression in the trunk since the tagging of 1.04). I think that the main problem was the code to find the done items, but while I was at it I simplified the completed() and completed_archive() methods by using the Rails Time::Calculation methods x.day.ago and x.week.ago. Works OK for me now. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@213 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/application.rb | 1 + tracks/app/controllers/todo_controller.rb | 30 +++++++++-------------- tracks/app/views/todo/completed.rhtml | 2 +- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index f518c35a..f80a3166 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -5,6 +5,7 @@ require_dependency "login_system" require_dependency "redcloth" require 'date' +require 'Time' class ApplicationController < ActionController::Base diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 3e367d6d..e13d81e5 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -165,34 +165,26 @@ class TodoController < ApplicationController end # List the completed tasks, sorted by completion date - # - # Use days declaration? 1.day.ago? + # @done_today: in the last 24 hours + # @done_this_week: in the last week + # @done_this_month: in the last 4 weeks (<=28 days) def completed self.init @page_title = "TRACKS::Completed tasks" - day = (60 * 60 * 24) - today = Time.now - - today_date = today - (1 * day) - week_begin = today - (1 * day) - week_end = today - (7 * day) - month_begin = today - (8 * day) - month_end = today - (31 * day) - - @done_today = @done.collect { |x| today_date <= x.completed ? x:nil }.compact - @done_this_week = @done.collect { |x| week_begin >= x.completed && week_end <= x.completed ? x:nil }.compact - @done_this_month = @done.collect { |x| month_begin >= x.completed && month_end <= x.completed ? x:nil }.compact - + unless @done.nil? + @done_today = @done.collect { |x| x.completed >= 1.day.ago ? x:nil }.compact + @done_this_week = @done.collect { |x| 1.week.ago <= x.completed ? x:nil }.compact + @done_this_month = @done.collect { |x| 4.week.ago <= x.completed ? x:nil }.compact + end end - # Archived completed items, older than 31 days + # Archived completed items, older than 28 days # def completed_archive self.init @page_title = "TRACKS::Archived completed tasks" - archive_date = Time.now - 32 * (60 * 60 * 24) - @done_archive = @done.collect { |x| archive_date >= x.completed ? x:nil }.compact + @done_archive = @done.collect { |x| 28.day.ago > x.completed ? x:nil }.compact end def feeds @@ -218,7 +210,7 @@ class TodoController < ApplicationController @projects = @user.projects @contexts = @user.contexts @todos = @user.todos - @done = @todos.find_all { |x| x.done } + @done = @todos.find(:all, :conditions => ["done = ?", true]) end end diff --git a/tracks/app/views/todo/completed.rhtml b/tracks/app/views/todo/completed.rhtml index 98909740..5dd4d5b6 100644 --- a/tracks/app/views/todo/completed.rhtml +++ b/tracks/app/views/todo/completed.rhtml @@ -1,7 +1,7 @@

You have completed <%= @done_today.length %> actions so far today.

-

Completed today

+

Completed in the last 24 hours

<%= render :partial => "done", :collection => @done_today %>