mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 12:58:48 +01:00
Ticket #300: Correctly activates/blocks dependent todos from mobile view also.
Conflicts: app/views/todos/toggle_check.js.rjs
This commit is contained in:
parent
c5df6b66b1
commit
cb76ecd866
2 changed files with 20 additions and 16 deletions
|
|
@ -166,26 +166,14 @@ class TodosController < ApplicationController
|
|||
@new_recurring_todo = check_for_next_todo(@todo) if @saved
|
||||
|
||||
if @todo.completed?
|
||||
logger.debug "completed #{@todo.description}"
|
||||
# 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}"
|
||||
@pending_to_activate = @todo.pending_to_activate
|
||||
@pending_to_activate.each do |t|
|
||||
t.activate!
|
||||
@pending_to_activate << t
|
||||
end
|
||||
end
|
||||
else
|
||||
# Block active successors for undone action
|
||||
@active_to_block = []
|
||||
logger.debug "undid #{@todo.description}"
|
||||
@todo.successors.each do |t|
|
||||
if t.state == 'active'
|
||||
logger.debug "blocked #{t.description}"
|
||||
@active_to_block = @todo.active_to_block
|
||||
@active_to_block.each do |t|
|
||||
t.block!
|
||||
@active_to_block << t
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -279,11 +267,17 @@ class TodosController < ApplicationController
|
|||
|
||||
if params['done'] == '1' && !@todo.completed?
|
||||
@todo.complete!
|
||||
@todo.pending_to_activate.each do |t|
|
||||
t.activate!
|
||||
end
|
||||
end
|
||||
# strange. if checkbox is not checked, there is no 'done' in params.
|
||||
# Therefore I've used the negation
|
||||
if !(params['done'] == '1') && @todo.completed?
|
||||
@todo.activate!
|
||||
@todo.active_to_block.each do |t|
|
||||
t.block!
|
||||
end
|
||||
end
|
||||
|
||||
@todo.attributes = params["todo"]
|
||||
|
|
|
|||
|
|
@ -233,6 +233,16 @@ class Todo < ActiveRecord::Base
|
|||
@predecessor_array << t.description
|
||||
end
|
||||
|
||||
# Return todos that should be activated if the current todo is completed
|
||||
def pending_to_activate
|
||||
return successors.find_all {|t| t.uncompleted_predecessors.empty?}
|
||||
end
|
||||
|
||||
# Return todos that should be blocked if the current todo is undone
|
||||
def active_to_block
|
||||
return successors.find_all {|t| t.active?}
|
||||
end
|
||||
|
||||
# Rich Todo API
|
||||
|
||||
def self.from_rich_message(user, default_context_id, description, notes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue