From 60934fb8c8013f30a27876a819848c825385392e Mon Sep 17 00:00:00 2001 From: bsag Date: Sun, 13 Feb 2005 17:45:45 +0000 Subject: [PATCH] Added some rudimentary sorting of completed items. They are now sorted in to done today, done in the last 7 days and done in the last 31 days. At the bottom of completed.rhtml, there's a link to completed_archive.rhtml, which shows archived items older than 31 days. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@23 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 20 ++++++++++++++++++- tracks/app/helpers/todo_helper.rb | 1 + tracks/app/views/todo/completed.rhtml | 20 +++++++++++++++++-- tracks/app/views/todo/completed_archive.rhtml | 11 ++++++++++ tracks/doc/CHANGENOTES.txt | 3 +++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tracks/app/views/todo/completed_archive.rhtml diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 7a9b98b2..9f1ea15b 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -25,9 +25,27 @@ class TodoController < ApplicationController # def completed @page_title = "Completed tasks" - @done = Todo.find_all( "done=1", "completed DESC" ) + today_query = "DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= completed" + week_query = "DATE_SUB(CURDATE(),INTERVAL 2 DAY) >= completed + AND DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= completed" + month_query = "DATE_SUB(CURDATE(),INTERVAL 8 DAY) >= completed + AND DATE_SUB(CURDATE(),INTERVAL 31 DAY) <= completed" + @done_today = Todo.find_by_sql( "SELECT * FROM todos WHERE done = 1 AND #{today_query} + ORDER BY completed DESC;" ) + @done_this_week = Todo.find_by_sql( "SELECT * FROM todos WHERE done = 1 AND #{week_query} + ORDER BY completed DESC;" ) + @done_this_month = Todo.find_by_sql( "SELECT * FROM todos WHERE done = 1 AND #{month_query} + ORDER BY completed DESC;" ) end + # Archived completed items, older than 31 days + # + def completed_archive + @page_title = "Archived completed tasks" + archive_query = "DATE_SUB(CURDATE(),INTERVAL 32 DAY) >= completed" + @done_archive = Todo.find_by_sql( "SELECT * FROM todos WHERE done = 1 AND #{archive_query} + ORDER BY completed DESC;" ) + end # Called by a form button # Parameters from form fields should be passed to create new item diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index bd33f44f..07404715 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -12,4 +12,5 @@ module TodoHelper return count end + end diff --git a/tracks/app/views/todo/completed.rhtml b/tracks/app/views/todo/completed.rhtml index 581ac05e..9d8ba71c 100644 --- a/tracks/app/views/todo/completed.rhtml +++ b/tracks/app/views/todo/completed.rhtml @@ -1,10 +1,26 @@
+

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

-

Completed items

+

Completed today

- <%= render_collection_of_partials "done", @done %> + <%= render_collection_of_partials "done", @done_today %>
+
+

Completed in last 7 days

+ + <%= render_collection_of_partials "done", @done_this_week %> +
+
+ +
Completed in the last 31 days + + <%= render_collection_of_partials "done", @done_this_month %> +
+
+ +

Older completed items: <%= link_to( "Older than 31 days", :controller => "todo", :action => "completed_archive" ) %>

diff --git a/tracks/app/views/todo/completed_archive.rhtml b/tracks/app/views/todo/completed_archive.rhtml new file mode 100644 index 00000000..15643012 --- /dev/null +++ b/tracks/app/views/todo/completed_archive.rhtml @@ -0,0 +1,11 @@ +
+ +

There are <%= @done_archive.length %> completed actions in the archive.

+
+

Completed more than 31 days ago

+ + <%= render_collection_of_partials "done", @done_archive %> +
+
+ +
diff --git a/tracks/doc/CHANGENOTES.txt b/tracks/doc/CHANGENOTES.txt index fee53359..4eb4d952 100644 --- a/tracks/doc/CHANGENOTES.txt +++ b/tracks/doc/CHANGENOTES.txt @@ -16,6 +16,9 @@ Project wiki: 7. Changed the method of adding due dates to drop-down option lists. It's more obvious and less error prone than typing in the date. Your preferences for date formatting are still honoured when displaying due dates. 8. Added a favicon, kindly produced by Jim Ray. 9. Added border="0" to the button images to stop Firefox putting a red border around them. +10. Added a new path:, base: setting in settings.yml. This is used in constructing URLs in standard.rhtml and other places for the javascripts and stylesheets. You need to specify it in the format, + http://my.domain.tld/subdir/tracks +or whatever the full URL is. This should help people who put Tracks in a subdirectory. ## Version 1.01