diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index ff541978..a92b0f58 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -162,14 +162,12 @@ class TodosController < ApplicationController params['item']['show_from'] = parse_date_per_user_prefs(params['item']['show_from']) end - - @saved = @item.update_attributes params["item"] @context_changed = @original_item_context_id != @item.context_id @item_was_activated_from_deferred_state = @original_item_was_deferred && @item.active? - if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todos.length; end + if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todo_count; end @project_changed = @original_item_project_id != @item.project_id - if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todos.length; end + if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todo_count; end determine_down_count end @@ -196,7 +194,7 @@ class TodosController < ApplicationController determine_down_count source_view do |from| from.todo do - @remaining_undone_in_context = @user.contexts.find(@context_id).not_done_todos.length + @remaining_undone_in_context = @user.contexts.find(@context_id).not_done_todo_count end end end diff --git a/tracks/app/views/todos/update.rjs b/tracks/app/views/todos/update.rjs index 77b96adc..fe1f8f14 100644 --- a/tracks/app/views/todos/update.rjs +++ b/tracks/app/views/todos/update.rjs @@ -42,13 +42,13 @@ if @saved page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0) page.insert_html :bottom, "tickler", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } page['tickler-empty-nd'].hide - page.replace_html "badge_count", @remaining_undone_in_project + page.replace_html "badge_count", @down_count elsif @item_was_activated_from_deferred_state page[@item].remove page['tickler-empty-nd'].show if (@deferred_count == 0) page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } page["p#{@item.project_id}empty-nd"].hide - page.replace_html "badge_count", @remaining_undone_in_project + page.replace_html "badge_count", @down_count else page.replace dom_id(@item), :partial => 'todos/item', :locals => { :parent_container_type => parent_container_type } page.visual_effect :highlight, dom_id(@item), :duration => 3 diff --git a/tracks/lib/todo_list.rb b/tracks/lib/todo_list.rb index 41dd8498..14c5c3b1 100644 --- a/tracks/lib/todo_list.rb +++ b/tracks/lib/todo_list.rb @@ -14,30 +14,33 @@ module Tracks end def find_not_done_todos(opts={}) - self.todos.find(:all, :conditions => not_done_conditions(opts), - :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC") + with_not_done_scope(opts) do + self.todos.find(:all, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC") + end end def find_deferred_todos(opts={}) - self.todos.find(:all, :conditions => ["todos.state = ?", "deferred"], - :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC") + self.todos.find_in_state(:all, :deferred, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC") end - def not_done_conditions(opts) + def find_done_todos + self.todos.find_in_state(:all, :completed, :order => "todos.completed_at DESC", :limit => self.user.prefs.show_number_completed) + end + + def not_done_todo_count(opts={}) + with_not_done_scope(opts) do + self.todos.count + end + end + + def with_not_done_scope(opts={}) conditions = ["todos.state = ?", 'active'] if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true) conditions = ["(todos.state = ? or todos.state = ?)", 'active', 'project_hidden'] end - conditions - end - - def find_done_todos - self.todos.find(:all, :conditions => ["todos.state = ?", "completed"], - :order => "todos.completed_at DESC", :limit => self.user.prefs.show_number_completed) - end - - def not_done_todo_count(opts={}) - self.todos.count(not_done_conditions(opts)) + self.todos.with_scope :find => {:conditions => conditions} do + yield + end end def done_todo_count diff --git a/tracks/test/selenium/project_detail/activate_deferred_todo.rsel b/tracks/test/selenium/project_detail/activate_deferred_todo.rsel index 2a6bef9b..6e1a5866 100644 --- a/tracks/test/selenium/project_detail/activate_deferred_todo.rsel +++ b/tracks/test/selenium/project_detail/activate_deferred_todo.rsel @@ -9,3 +9,4 @@ type "show_from_todo_15", "" click "//input[@value='Update']" wait_for_element_present "xpath=//div[@id='p1'] //div[@id='todo_15']" assert_not_visible "tickler-empty-nd" +assert_text 'badge_count', '3' diff --git a/tracks/test/selenium/project_detail/defer_todo.rsel b/tracks/test/selenium/project_detail/defer_todo.rsel index 6c31daac..b3cc9cac 100644 --- a/tracks/test/selenium/project_detail/defer_todo.rsel +++ b/tracks/test/selenium/project_detail/defer_todo.rsel @@ -7,3 +7,4 @@ type "show_from_todo_5", "1/1/2030" click "//input[@value='Update']" wait_for_element_present "xpath=//div[@id='tickler'] //div[@id='todo_5']" assert_not_visible "tickler-empty-nd" +assert_text 'badge_count', '1'