diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index de6e283e..71d22346 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -144,19 +144,25 @@ class TodosController < ApplicationController if @todo.completed? logger.debug "completed #{@todo.description}" - # A todo was completed - check for pending todos + # A todo was completed - check for pending todos to activate + @pending_to_activate = [] @todo.successors.each do |t| if t.uncompleted_predecessors.empty? # Activate pending todos logger.debug "activated #{t.description}" t.activate! + @pending_to_activate << t end end else - # Block todos for undone actions - (it does no harm if they are already pending) + # Block active successors for undone action + @active_to_block = [] logger.debug "undid #{@todo.description}" @todo.successors.each do |t| - logger.debug "blocked #{t.description}" - t.block! + if t.state == 'active' + logger.debug "blocked #{t.description}" + t.block! + @active_to_block << t + end end end diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index b39d5674..cfd1dbf8 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -203,7 +203,7 @@ module TodosHelper def item_container_id (todo) if source_view_is :project return "p#{todo.project_id}items" if todo.active? - return "tickler" if todo.deferred? + return "tickler" if todo.deferred? or todo.pending? end return "c#{todo.context_id}items" end diff --git a/app/views/todos/toggle_check.js.rjs b/app/views/todos/toggle_check.js.rjs index 5f9e2734..92289b16 100644 --- a/app/views/todos/toggle_check.js.rjs +++ b/app/views/todos/toggle_check.js.rjs @@ -8,9 +8,15 @@ if @saved page.insert_html :top, "completed_containeritems", :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => "completed" } page.visual_effect :highlight, dom_id(@todo, 'line'), {'startcolor' => "'#99ff99'"} page[empty_container_msg_div_id].show if @down_count == 0 && !empty_container_msg_div_id.nil? - page.show 'tickler-empty-nd' if source_view_is(:project) && @deferred_count == 0 + page.show 'tickler-empty-nd' if source_view_is(:project) && @deferred_count == 0 && @pending_count == 0 page.hide 'empty-d' # If we've checked something as done, completed items can't be empty end + # Activate pending todos that are successors of the completed + @pending_to_activate.each do |t| + logger.debug "#300: Removing #{t.description} from pending block and adding it to active" + page[t].remove + page.insert_html :bottom, item_container_id(t), :partial => 'todos/todo', :locals => { :todo => t, :parent_container_type => parent_container_type } + end # remove container if empty if @remaining_in_context == 0 && source_view_is(:todo) @@ -44,6 +50,14 @@ if @saved page.show "empty-d" if @completed_count == 0 page.show "c"+@todo.context.id.to_s page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? # If we've checked something as undone, incomplete items can't be empty + # If active todos are successors of the reactivated todo they will be blocked + @active_to_block.each do |t| + logger.debug "#300: Block #{t.description} that are a successor of #{@todo.description}" + page[t].remove # Remove it from active + # Insert it in deferred/pending block + logger.debug "Insert #{t.description} in deferred/pending block" + page.insert_html :bottom, item_container_id(t), :partial => 'todos/todo', :locals => { :todo => t, :parent_container_type => parent_container_type } + end end page.hide "status" diff --git a/db/tracks-17-test.db b/db/tracks-17-test.db new file mode 100644 index 00000000..3f79ee53 Binary files /dev/null and b/db/tracks-17-test.db differ