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: