Skip to content

Commit

Permalink
fix TracksApp#922. You can now mark a todo complete from the tickler.…
Browse files Browse the repository at this point in the history
… Also fixed some small aasm corner cases found by this change
  • Loading branch information
lrbalt committed Aug 18, 2011
1 parent 367907e commit 07b05d0
Show file tree
Hide file tree
Showing 16 changed files with 247 additions and 118 deletions.
19 changes: 16 additions & 3 deletions app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ def show
def add_predecessor
@source_view = params['_source_view'] || 'todo'
@predecessor = current_user.todos.find(params['predecessor'])
@predecessors = @predecessor.predecessors
@todo = current_user.todos.find(params['successor'], :include => Todo::DEFAULT_INCLUDES)
@original_state = @todo.state
unless @predecessor.completed?
# Add predecessor
@todo.add_predecessor(@predecessor)
@todo.state = 'pending'
@todo.block!
@saved = @todo.save

@status_message = t('todos.added_dependency', :dependency => @predecessor.description)
Expand All @@ -262,6 +262,7 @@ def remove_predecessor
@source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id'], :include => Todo::DEFAULT_INCLUDES)
@predecessor = current_user.todos.find(params['predecessor'])
@predecessors = @predecessor.predecessors
@successor = @todo
@removed = @successor.remove_predecessor(@predecessor)
determine_remaining_in_context_count
Expand All @@ -277,14 +278,19 @@ def toggle_check
@source_view = params['_source_view'] || 'todo'
@original_item_due = @todo.due
@original_item_was_deferred = @todo.deferred?
@original_item_was_pending = @todo.pending?
@original_item_was_hidden = @todo.hidden?
@original_item_context_id = @todo.context_id
@original_item_project_id = @todo.project_id
@todo_was_completed_from_deferred_or_blocked_state = @original_item_was_deferred || @original_item_was_pending
@saved = @todo.toggle_completion!

@todo_was_blocked_from_completed_state = @todo.pending? # since we toggled_completion the previous state was completed

# check if this todo has a related recurring_todo. If so, create next todo
@new_recurring_todo = check_for_next_todo(@todo) if @saved

@predecessors = @todo.uncompleted_predecessors
if @saved
if @todo.completed?
@pending_to_activate = @todo.activate_pending_todos
Expand Down Expand Up @@ -1008,14 +1014,21 @@ def determine_remaining_in_context_count(context_id = @todo.context_id)
if tag.nil?
tag = Tag.new(:name => params['tag'])
end
@remaining_deferred_or_pending_count = current_user.todos.with_tag(tag).deferred_or_blocked.count
@remaining_in_context = current_user.contexts.find(context_id).todos.active.not_hidden.with_tag(tag).count
@target_context_count = current_user.contexts.find(@todo.context_id).todos.active.not_hidden.with_tag(tag).count
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag).count
}
from.project {
project_id = @project_changed ? @original_item_project_id : @todo.project_id
@remaining_deferred_or_pending_count = current_user.projects.find(project_id).todos.deferred_or_blocked.count
@remaining_in_context = current_user.projects.find(project_id).todos.active.count

if @todo_was_completed_from_deferred_or_blocked_state
@remaining_in_context = @remaining_deferred_or_pending_count
else
@remaining_in_context = current_user.projects.find(project_id).todos.active.count
end

@target_context_count = current_user.projects.find(project_id).todos.active.count
}
from.calendar {
Expand Down
27 changes: 21 additions & 6 deletions app/helpers/todos_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,21 @@ def empty_container_msg_div_id(todo = @todo || @successor)

source_view do |page|
page.project {
return "tickler-empty-nd" if @todo_was_deferred_from_active_state || @todo_was_blocked_from_active_state || @todo_was_destroyed_from_deferred_state || @todo_was_created_deferred
return "tickler-empty-nd" if
@todo_was_deferred_from_active_state ||
@todo_was_blocked_from_active_state ||
@todo_was_destroyed_from_deferred_state ||
@todo_was_created_deferred ||
@todo_was_blocked_from_completed_state
return "p#{todo.project_id}empty-nd"
}
page.tag {
return "tickler-empty-nd" if @todo_was_deferred_from_active_state || @todo_was_destroyed_from_deferred_state || @todo_was_created_deferred
return "tickler-empty-nd" if
@todo_was_deferred_from_active_state ||
@todo_was_blocked_from_active_state ||
@todo_was_destroyed_from_deferred_state ||
@todo_was_created_deferred ||
@todo_was_blocked_from_completed_state
return "hidden-empty-nd" if @todo.hidden?
return "c#{todo.context_id}empty-nd"
}
Expand All @@ -368,22 +378,27 @@ def empty_container_msg_div_id(todo = @todo || @successor)
return "c#{todo.context_id}empty-nd"
end

def todo_was_removed_from_deferred_or_blocked_container
return @todo_was_activated_from_deferred_state ||
@todo_was_activated_from_pending_state ||
@todo_was_destroyed_from_deferred_or_pending_state ||
@todo_was_completed_from_deferred_or_blocked_state
end

def show_empty_message_in_source_container
container_id = ""
source_view do |page|
page.project {
container_id = "p#{@original_item_project_id}empty-nd" if @remaining_in_context == 0
container_id = "tickler-empty-nd" if (
( (@todo_was_activated_from_deferred_state || @todo_was_activated_from_pending_state || @todo_was_destroyed_from_deferred_or_pending_state) && @remaining_deferred_or_pending_count == 0) ||
(@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && @todo.completed?) )
container_id = "tickler-empty-nd" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.deferred { container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0 }
page.calendar { container_id = "empty_#{@original_item_due_id}" if @old_due_empty }
page.tag {
container_id = "hidden-empty-nd" if (@remaining_hidden_count == 0 && !@todo.hidden? && @todo_hidden_state_changed) ||
(@remaining_hidden_count == 0 && @todo.completed? && @original_item_was_hidden)
container_id = "tickler-empty-nd" if (@todo_was_activated_from_deferred_state && @remaining_deferred_or_pending_count == 0) ||
container_id = "tickler-empty-nd" if (todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0) ||
(@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && (@todo.completed? || @tag_was_removed))
container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
Expand Down
Loading

0 comments on commit 07b05d0

Please sign in to comment.