From 14334563ee4174fd1432f23a1bd6a2716dfa14f1 Mon Sep 17 00:00:00 2001 From: bsag Date: Fri, 25 Feb 2005 15:24:58 +0000 Subject: [PATCH] Modified the 'count' badge on todo/list: now shows the number of uncompleted items in contexts that *aren't* hidden (i.e. the actions actually listed on todo/list). Number of items in hidden contexts are shown in parentheses after the link to that context. So you don't forget about that stuff ;-) git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@29 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 15 +++++++++++---- tracks/app/helpers/application_helper.rb | 1 - tracks/app/helpers/todo_helper.rb | 17 +++++------------ tracks/app/views/todo/list.rhtml | 3 ++- tracks/config/environment.rb | 5 ++--- tracks/config/routes.rb | 2 ++ tracks/doc/CHANGENOTES.txt | 8 ++++++++ 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index e1eefe87..4c017f98 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -14,10 +14,17 @@ class TodoController < ApplicationController @page_title = "List tasks" @projects = Project.find_all @places = Context.find_all - @shown_places = Context.find_all( "hide=0", "id ASC") - @hidden_places = Context.find_all( "hide=1") - @done = Todo.find_all( "done=1", "completed DESC", 5 ) - @count = Todo.count( "done=0" ) + @shown_places = Context.find_all_by_hide( 0, "id ASC" ) + @hidden_places = Context.find_all_by_hide( 1 ) + @done = Todo.find_all_by_done( 1, "completed DESC", 5 ) + + # Set count badge to number of not-done, not hidden context items + count = 0 + sub = 0 + @hidden_places.each do |h| + sub = Todo.find_all("done=0 AND context_id=#{h.id}").length + sub + end + @count = Todo.find_all("done=0").length - sub end diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index 07d47c0d..a57b17c9 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -48,5 +48,4 @@ module ApplicationHelper "" + format_date(due) + " " end end - end diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index 07404715..bf5b199c 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -1,16 +1,9 @@ module TodoHelper - - def count_items(items, context) - # Count the number of items in the selected context - # - count = 0 - for item in items - if item.context['name'] == context - count += 1 - end - end - return count + + # Counts the number of uncompleted items in the selected context + # + def count_items(context) + count = Todo.find_all("done=0 AND context_id=#{context.id}").length end - end diff --git a/tracks/app/views/todo/list.rhtml b/tracks/app/views/todo/list.rhtml index cced3b8e..41fd85bc 100644 --- a/tracks/app/views/todo/list.rhtml +++ b/tracks/app/views/todo/list.rhtml @@ -20,7 +20,8 @@

Hidden contexts: <% for @hidden_place in @hidden_places %> - "show", :id => "#{@hidden_place.id}" ) %>"><%= @hidden_place.name.capitalize %> | + <% num = count_items(@hidden_place) %> + "show", :id => "#{@hidden_place.id}" ) %>"><%= @hidden_place.name.capitalize %> (<%= num %>) | <% end %>

diff --git a/tracks/config/environment.rb b/tracks/config/environment.rb index 0779d89c..62a7c668 100644 --- a/tracks/config/environment.rb +++ b/tracks/config/environment.rb @@ -37,11 +37,10 @@ require_gem 'rails' # Try loading gem Redcloth first, but if that fails # fall back on lib version -# FIXME begin require_gem 'redcloth', '>= 3.0.3' -rescue StandardError - require_dependency "redcloth" +rescue LoadError + require_or_load( "redcloth" ) end # Environment-specific configuration. diff --git a/tracks/config/routes.rb b/tracks/config/routes.rb index 4532b72b..86027ebc 100644 --- a/tracks/config/routes.rb +++ b/tracks/config/routes.rb @@ -12,6 +12,8 @@ ActionController::Routing::Routes.draw do |map| map.connect '', :controller => 'todo', :action => 'list' + map.connect 'add_item', :controller => 'todo', :action => 'add_item' + # Install the default route as the lowest priority. map.connect ':controller/:action/:id' end diff --git a/tracks/doc/CHANGENOTES.txt b/tracks/doc/CHANGENOTES.txt index 3a09a33a..4e34c547 100644 --- a/tracks/doc/CHANGENOTES.txt +++ b/tracks/doc/CHANGENOTES.txt @@ -21,6 +21,14 @@ Project wiki: or whatever the full URL is. This should help people who put Tracks in a subdirectory. 11. 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. 12. Changed the method of generating links to stylesheet and javascripts. Together with the new Routes, this should sort out any problems with putting Tracks in a sub-directory. +13. config/environment.rb now checks to see if a gem version of Redcloth is installed that is greater than version 3.0.3. If that fails, it falls back on the packaged lib version. Note that there's an odd bug I can't seem to pin down that means that if you are using the packaged lib version, you'll get some errors like: + + `./script/../config/..//lib/redcloth.rb:169: warning: already initialized constant VERSION` + + `./script/../config/..//lib/redcloth.rb:170: warning: already initialized constant DEFAULT_RULES` + +but ONLY if you're using the development environment; with production it's fine, and with the gem version of Redcloth it's fine in both environments. +13. Modified the 'count' badge on todo/list: now shows the number of uncompleted items in contexts that *aren't* hidden (i.e. the actions actually listed on todo/list). Number of items in hidden contexts are shown in parentheses after the link to that context. So you don't forget about that stuff ;-) ## Version 1.01