get some corner cases on toggle complete and empty messages working

This commit is contained in:
Reinier Balt 2011-01-11 02:47:29 +01:00
parent 1a821a228f
commit d81e82a135
6 changed files with 136 additions and 31 deletions

View file

@ -257,6 +257,9 @@ class TodosController < ApplicationController
@source_view = params['_source_view'] || 'todo'
@original_item_due = @todo.due
@original_item_was_deferred = @todo.deferred?
@original_item_was_hidden = @todo.hidden?
@original_item_context_id = @todo.context_id
@original_item_project_id = @todo.project_id
@saved = @todo.toggle_completion!
# check if this todo has a related recurring_todo. If so, create next todo
@ -871,9 +874,7 @@ class TodosController < ApplicationController
end
@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
if !@todo.hidden? && @todo_hidden_state_changed
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag).count
end
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag).count
}
from.project {
@remaining_deferred_or_pending_count = current_user.projects.find(@todo.project_id).todos.deferred_or_blocked.count
@ -891,16 +892,23 @@ class TodosController < ApplicationController
def determine_completed_count
source_view do |from|
from.todo do
@completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', current_user.id, 'completed', false])
@completed_count = current_user.todos.not_hidden.completed.count
end
from.context do
@completed_count = current_user.contexts.find(@todo.context_id).done_todo_count
todos = current_user.contexts.find(@todo.context_id).todos.completed
todos = todos.not_hidden if !@todo.context.hidden?
@completed_count = todos.count
end
from.project do
unless @todo.project_id == nil
@completed_count = current_user.projects.find(@todo.project_id).done_todos.count
todos = current_user.projects.find(@todo.project_id).todos.completed
todos = todos.not_hidden if !@todo.project.hidden?
@completed_count = todos.count
end
end
from.tag do
@completed_count = current_user.todos.with_tag(@tag).completed.count
end
end
end

View file

@ -233,6 +233,10 @@ module TodosHelper
return false
end
def should_make_context_visible
return @todo.active? && (!@todo.hidden? && !source_view_is(:project) )
end
def should_add_new_context
return @new_context_created && !source_view_is(:project)
end
@ -280,8 +284,11 @@ module TodosHelper
def update_needs_to_hide_context
return (@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) ||
(@remaining_in_context == 0 && @todo_was_deferred_from_active_state) if source_view_is(:tag)
(@remaining_in_context == 0 && @todo_was_deferred_from_active_state) ||
(@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag)
return false if source_view_is(:project)
return (@remaining_in_context == 0) && !source_view_is(:context)
end
@ -360,14 +367,17 @@ module TodosHelper
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 && @remaining_deferred_or_pending_count == 0
container_id = "tickler-empty-nd" if (@todo_was_activated_from_deferred_state && @remaining_deferred_or_pending_count == 0) ||
(@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && @todo.completed?)
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 !@todo.hidden? && @todo_hidden_state_changed && @remaining_hidden_count == 0
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) ||
(@original_item_was_deferred && @deferred_tag_count == 0 && @todo.completed?)
(@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && @todo.completed?)
container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.context { container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0 }

View file

@ -30,7 +30,8 @@ function insert_new_context_with_new_todo() {
function add_todo_to_existing_context() {
<% if source_view_is_one_of(:todo, :deferred, :tag) -%>
TodoItemsContainer.ensureVisibleWithEffectAppear("c<%=@todo.context_id%>");
$('#c<%= @todo.context_id %>').fadeIn(500, function() {});
$('#no_todos_in_tag_view').slideUp(100);
<% end -%>
$('#<%=empty_container_msg_div_id%>').hide();
$('#<%=item_container_id(@todo)%>').append(html_for_new_todo());

View file

@ -1,7 +1,7 @@
<% if !@saved -%>
TracksPages.page_notify('error', "Could not mark this todo complete", 5);
<% else -%>
<% if @wants_redirect_after_complete -%>
<% if @wants_redirect_after_complete && @todo.completed? -%>
redirect_after_complete();
<% else
animation = []
@ -14,7 +14,8 @@
else
animation << "add_todo_to_context"
animation << "block_predecessors"
end -%>
end
animation << "update_empty_tag_container" if source_view_is(:tag) -%>
<%= render_animation(animation) %>
TracksPages.set_page_badge(<%= @down_count %>);
<% end -%>
@ -25,11 +26,23 @@ function redirect_after_complete() {
}
function remove_todo(next_steps) {
$('#<%= dom_id(@todo) %>').fadeOut(400, function() {
$('#<%= dom_id(@todo) %>').remove();
<% if (@remaining_in_context == 0) && update_needs_to_hide_context
# remove context with deleted todo
-%>
$('#c<%=@todo.context_id%>').fadeOut(400, function() {
$('#<%=dom_id(@todo)%>').remove();
next_steps.go();
});
<%= show_empty_message_in_source_container -%>
next_steps.go();
<% else
# remove only the todo
-%>
<%= show_empty_message_in_source_container %>
$('#<%=dom_id(@todo)%>').slideUp(400, function() {
$('#<%=dom_id(@todo)%>').remove();
next_steps.go();
});
<% end -%>
}
function add_to_completed_container(next_steps) {
@ -42,10 +55,15 @@ function add_to_completed_container(next_steps) {
function add_todo_to_context(next_steps) {
$('#<%= item_container_id(@todo) %>').append(html_for_todo());
$('#c<%= @todo.context_id %>').fadeIn(500, function() {
<% if should_make_context_visible -%>
$('#c<%= @todo.context_id %>').fadeIn(500, function() {
$("#<%= empty_container_msg_div_id %>").slideUp(100);
highlight_updated_todo(next_steps);
});
<% else -%>
$("#<%= empty_container_msg_div_id(@todo) %>").slideUp(100);
highlight_updated_todo(next_steps);
<%= show_empty_message_in_source_container -%>
});
<% end -%>
}
function add_new_recurring_todo(next_steps) {
@ -59,9 +77,20 @@ function add_new_recurring_todo(next_steps) {
<% else
if @todo.recurring_todo.todos.active.count == 0 && @new_recurring_todo.nil? -%>
TracksPages.page_notify('notice', "<%=t('todos.recurrence_completed')%>", 6);
<% end
end
end -%>
<% end -%>
next_steps.go();
<% end
else -%>
next_steps.go();
<% end -%>
}
function update_empty_tag_container(next_steps) {
<% if @down_count==0 -%>
$('#no_todos_in_tag_view').slideDown(400, function(){ next_steps.go(); });
<% else -%>
$('#no_todos_in_tag_view').fadeOut(100, function(){ next_steps.go(); });
<% end -%>
}
<% if @new_recurring_todo # hide js if @new_recurring_todo is not there-%>
@ -82,19 +111,19 @@ function highlight_todo(id) {
function activate_pending_todos(next_steps) {
<% # Activate pending todos that are successors of the completed
if @saved && @pending_to_activate
if @saved && @pending_to_activate
# do not render the js in case of an error or if no todos to activate
@pending_to_activate.each do |t|
if source_view_is(:project) or source_view_is(:tag) -%>
if source_view_is_one_of(:project,:tag) -%>
$('#<%= dom_id(t) %>').fadeOut(400, function() {
$('#<%= dom_id(t) %>').remove();
next_steps.go();
});
<% end -%>
$('#<%= item_container_id(t) %>').append("<%= escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))%>");
highlight_todo('#<%= dom_id(t)%>');
<% end -%>
<% end -%>
next_steps.go();
}
function block_predecessors(next_steps) {
@ -110,8 +139,8 @@ function block_predecessors(next_steps) {
<% end -%>
});
<% end -%>
next_steps.go();
<% end -%>
next_steps.go();
}
function remove_source_container(next_steps) {
@ -121,6 +150,8 @@ function remove_source_container(next_steps) {
$('#c<%=@todo.context_id%>').fadeOut(1000, function() {
next_steps.go();
});
<% else %>
next_steps.go();
<% end %>
}

View file

@ -48,7 +48,7 @@ function add_to_existing_container(next_steps) {
});
<% else -%>
next_steps.go();
<% if (@target_context_count==1) || (@todo.deferred? && @remaining_deferred_or_pending_count == 1) -%>
<% if (@target_context_count==1) || (@todo.deferred? && @remaining_deferred_or_pending_count == 1) || (@todo.hidden? && @remaining_hidden_count == 1) -%>
$("#<%= empty_container_msg_div_id %>").slideUp(100);
<% end -%>
<% end -%>

View file

@ -21,11 +21,66 @@ Feature: Edit a next action from every page
Scenario: Deleting the last todo in container will show empty message # only project, context, tag, not todo
Given this is a pending scenario
Scenario: I can mark a todo complete
@selenium @wip
Scenario Outline: I can mark an active todo complete and it will update empty messages
When I go to the <page>
Then I should see "<empty message>"
When I submit a new action with description "visible todo" to project "visible project" with tags "test" in the context "visible context"
Then I should see "visible todo"
And I should not see "<empty message>"
When I mark the todo complete
Then I should not see "visible context"
And I should see "<empty message>"
And I should see "visible todo" in the completed todos container
Scenarios:
| page | empty message |
| tag page for "starred" | No actions found |
| home page | No actions found |
| context page for "visible context" | Currently there are no deferred or pending actions |
| project page for "visible project" | Currently there are no deferred or pending actions |
@selenium @wip
Scenario Outline: I can mark a deferred todo complete and it will update empty messages
When I go to the <page> # not for home page because it does not show deferred todos
Then I should see "<empty message>"
When I submit a new deferred action with description "visible todo" to project "visible project" with tags "test" in the context "visible context"
Then I should see "visible todo"
And I should not see "<empty message>"
When I mark the todo complete
Then I should not see "visible context"
And I should see "<empty message>"
And I should see "visible todo" in the completed todos container
Scenarios:
| page | empty message |
| tag page for "starred" | Currently there are no deferred or pending actions |
| context page for "visible context" | Currently there are no deferred or pending actions |
| project page for "visible project" | Currently there are no deferred or pending actions |
@selenium @wip
Scenario: I can mark a deferred todo complete and it will update empty messages
Given this is a pending scenario
Scenario: I can mark a completed todo active
Given this is a pending scenario
@selenium @wip
Scenario Outline: I can mark a completed todo active and it will update empty messages
Given I have a completed todo with description "visible todo" to project "visible project" with tags "test" in the context "visible context"
When I go to the <page>
Then I should see "<empty message>"
And I should not see "visible context"
And I should see "<empty completed message>"
When I mark the complete todo "visible todo" active
Then I should see "visible context"
And I should see "<empty completed message>"
And I should see "visible todo" in context container for "visible context"
And I should not see "<empty message>"
Scenarios:
| page | empty message |
| tag page for "starred" | No actions found |
| home page | No actions found |
| context page for "visible context" | Currently there are no deferred or pending actions |
| project page for "visible project" | Currently there are no deferred or pending actions |
Scenario: I can edit a todo to change its description
Given this is a pending scenario