add some project grouping scenarios to edit_a_todo and fix failures

also refactor step definitions
This commit is contained in:
Reinier Balt 2013-04-17 22:11:24 +02:00
parent 5f8f2eefa9
commit 8641ecfc4e
16 changed files with 487 additions and 422 deletions

View file

@ -3,7 +3,7 @@ class TodosController < ApplicationController
skip_before_filter :login_required, :only => [:index, :calendar, :tag]
prepend_before_filter :login_or_feed_token_required, :only => [:index, :calendar, :tag]
append_before_filter :find_and_activate_ready, :only => [:index, :list_deferred]
append_before_filter :set_group_view_by, :only => [:index, :tag, :create, :list_deferred, :destroy, :defer, :update]
append_before_filter :set_group_view_by, :only => [:index, :tag, :create, :list_deferred, :destroy, :defer, :update, :toggle_check]
protect_from_forgery :except => :check_deferred
@ -328,8 +328,10 @@ class TodosController < ApplicationController
#
def toggle_check
@todo = current_user.todos.find(params['id'])
@source_view = params['_source_view'] || 'todo'
@original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo
@original_item_due = @todo.due
@original_item_was_deferred = @todo.deferred?
@original_item_was_pending = @todo.pending?
@ -494,6 +496,7 @@ class TodosController < ApplicationController
def destroy
@source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id'])
@original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo
@original_item_due = @todo.due
@context_id = @todo.context_id
@project_id = @todo.project_id

View file

@ -496,16 +496,20 @@ module TodosHelper
end
def update_needs_to_hide_container
return (@remaining_in_context == 0 && todo_moved_out_of_container ) ||
(@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) ||
(@remaining_in_context == 0 && @todo_was_deferred_from_active_state) ||
(@remaining_in_context == 0 && @tag_was_removed) ||
(@remaining_in_context == 0 && @todo_was_destroyed) ||
(@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag)
if source_view_is(:tag)
return @remaining_in_context == 0 && (
todo_moved_out_of_container ||
(@todo_hidden_state_changed && @todo.hidden?) ||
@todo_was_deferred_from_active_state ||
@tag_was_removed ||
@todo_was_destroyed ||
(@todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden))
)
end
return false if source_view_is_one_of(:project, :calendar, :done)
return false if source_view_is_one_of(:project, :calendar, :done, :context)
return (@remaining_in_context == 0) && !source_view_is(:context)
return @remaining_in_context == 0
end
def update_needs_to_remove_todo_from_container
@ -559,6 +563,15 @@ module TodosHelper
return "without_project_container-empty-d"
end
def context_container_empty_id(todo)
return "c#{todo.context_id}-empty-d"
end
def container_empty_id(todo)
raise Exception.new, "no todo set in TodosHelper::container_empty_id. You probably not assign @original_item" if !todo
@group_view_by == "project" ? project_container_empty_id(todo) : context_container_empty_id(todo)
end
def item_container_id (todo)
return "hidden_container" if source_view_is(:tag) && todo.hidden?
return "c#{todo.context_id}" if source_view_is :deferred
@ -576,13 +589,12 @@ module TodosHelper
source_view do |page|
page.project {
return "deferred_pending_container-empty-d" if empty_criteria_met
return "p#{todo.project_id}-empty-d"
return project_container_empty_id(todo)
}
page.tag {
return "deferred_pending_container-empty-d" if empty_criteria_met
return "hidden_container-empty-d" if @todo.hidden?
return "c#{todo.context_id}-empty-d" if @group_view_by == 'context'
return project_container_empty_id(todo)
return container_empty_id(todo)
}
page.calendar {
return "deferred_pending_container-empty-d" if empty_criteria_met
@ -590,15 +602,14 @@ module TodosHelper
}
page.context {
return "deferred_pending_container-empty-d" if empty_criteria_met
return "c#{todo.context_id}-empty-d"
return context_container_empty_id(todo)
}
page.todo {
return "c#{todo.context_id}-empty-d" if @group_view_by == 'context'
return project_container_empty_id(todo)
return container_empty_id(todo)
}
end
return "c#{todo.context_id}-empty-d"
return context_container_empty_id(todo)
end
def empty_criteria_met
@ -621,11 +632,11 @@ module TodosHelper
container_id = ""
source_view do |page|
page.project {
container_id = "p#{@original_item_project_id}-empty-d" if @remaining_in_context == 0
container_id = project_container_empty_id(@original_item) if @remaining_in_context == 0
container_id = "deferred_pending_container-empty-d" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.deferred { container_id = "c#{@original_item_context_id}-empty-d" if @remaining_in_context == 0 }
page.deferred { container_id = container_empty_id(@original_item) if @remaining_in_context == 0 }
page.calendar { container_id = "#{@original_item_due_id}_container-empty-d" if @old_due_empty }
page.tag {
container_id = "hidden_container-empty-d" if (@remaining_hidden_count == 0 && !@todo.hidden? && @todo_hidden_state_changed) ||
@ -635,11 +646,11 @@ module TodosHelper
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.context {
container_id = "c#{@original_item_context_id}-empty-d" if @remaining_in_context == 0
container_id = context_container_empty_id(@original_item) if @remaining_in_context == 0
container_id = "deferred_pending_container-empty-d" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.todo { container_id = "c#{@original_item_context_id}-empty-d" if @remaining_in_context == 0 }
page.todo { container_id = context_container_empty_id(@original_item) if @remaining_in_context == 0 }
page.done { container_id = "completed_#{@original_completed_period}_container-empty-d" if @remaining_in_context == 0 }
end
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);".html_safe

View file

@ -51,7 +51,7 @@
function add_todo_to_existing_container(next_steps) {
$('#<%= empty_container_msg_div_id %>').hide();
$('#<%= item_container_id(@todo) %>').append(html_for_new_todo());
$('#<%= item_container_id(@todo) %>_items').append(html_for_new_todo());
$('#<%= item_container_id(@todo) %>').slideDown(500, function() {
$('#<%= dom_id(@todo) %>').effect('highlight', {}, 2000 );
next_steps.go();

View file

@ -54,7 +54,7 @@ function show_new_todo_if_todo_was_recurring() {
<% if @todo.from_recurring_todo? -%>
<% unless @new_recurring_todo.nil? || @new_recurring_todo.deferred? -%>
TodoItemsContainer.ensureVisibleWithEffectAppear("<%=item_container_id(@new_recurring_todo)%>");
$('#<%=item_container_id(@new_recurring_todo)%>').append(html_for_new_recurring_todo());
$('#<%=item_container_id(@new_recurring_todo)%>_items').append(html_for_new_recurring_todo());
$('#<%= dom_id(@new_recurring_todo, 'line')%>').effect('highlight', {}, 2000 );
TracksPages.page_notify('notice', "<%=t('todos.recurring_action_deleted')%>", 5);
<% else -%>
@ -75,11 +75,11 @@ function activate_pending_todos() {
if source_view_is_one_of(:project,:tag) -%>
$('#<%= dom_id(t) %>').fadeOut(400, function() {
$('#<%= dom_id(t) %>').remove();
$('#<%= item_container_id(t) %>').append("<%= html %>");
$('#<%= item_container_id(t) %>_items').append("<%= html %>");
<%= "$('#deferred_pending_container-empty-d').show();".html_safe if @remaining_deferred_or_pending_count==0 -%>
});
<% else -%>
$('#<%= item_container_id(t) %>').append("<%= html%>");
$('#<%= item_container_id(t) %>_items').append("<%= html%>");
<% end -%>
TodoItems.highlight_todo('#<%= dom_id(t, 'line')%>');
<% end -%>

View file

@ -11,9 +11,8 @@
animation << "add_to_completed_container" unless source_view_is_one_of(:calendar, :deferred)
animation << "add_new_recurring_todo"
animation << "activate_pending_todos"
animation << "remove_source_container"
else
animation << "add_todo_to_context" unless source_view_is(:done)
animation << "add_todo_to_container" unless source_view_is(:done)
animation << "block_predecessors"
end
animation << "update_empty_container" if source_view_is_one_of(:tag, :todo, :deferred)
@ -34,7 +33,7 @@ function remove_todo(next_steps) {
<% if (@remaining_in_context == 0) && update_needs_to_hide_container
# remove context with deleted todo
-%>
$('#c<%=@todo.context_id%>').fadeOut(400, function() {
$('#<%= item_container_id(@original_item)%>').slideUp(400, function() {
$('#<%=dom_id(@todo)%>').remove();
next_steps.go();
});
@ -52,7 +51,7 @@ function remove_todo(next_steps) {
function add_to_completed_container(next_steps) {
<% unless current_user.prefs.hide_completed_actions? -%>
$('#<%= item_container_id(@todo) %>').prepend(html_for_todo());
$('#<%= item_container_id(@todo) %>_items').prepend(html_for_todo());
$("#completed_container-empty-d").slideUp(100);
highlight_updated_todo(next_steps);
<% end -%>
@ -63,10 +62,11 @@ function replace_todo(next_steps) {
next_steps.go();
}
function add_todo_to_context(next_steps) {
$('#<%= item_container_id(@todo) %>').append(html_for_todo());
function add_todo_to_container(next_steps) {
// <%= @group_view_by %>
$('#<%= item_container_id(@todo) %>_items').append(html_for_todo());
<% if should_make_context_visible -%>
$('#c<%= @todo.context_id %>').fadeIn(500, function() {
$('#<%= item_container_id(@todo) %>').slideDown(500, function() {
$("#<%= empty_container_msg_div_id %>").slideUp(100);
highlight_updated_todo(next_steps);
});
@ -83,8 +83,8 @@ function add_new_recurring_todo(next_steps) {
<% # show new todo if the completed todo was recurring
if @todo.from_recurring_todo?
unless @new_recurring_todo.nil? || (@new_recurring_todo.deferred? && !source_view_is(:deferred)) -%>
$('#<%= item_container_id(@new_recurring_todo) %>').append(html_for_recurring_todo());
$('#c<%= @new_recurring_todo.context_id %>').fadeIn(500, function() {
$('#<%= item_container_id(@new_recurring_todo) %>_items').append(html_for_recurring_todo());
$('#c<%= @new_recurring_todo.context_id %>').slideDown(500, function() {
highlight_updated_recurring_todo(next_steps);
});
<% else
@ -102,7 +102,7 @@ function update_empty_container(next_steps) {
<% if @down_count==0 -%>
$('#no_todos_in_view').slideDown(400, function(){ next_steps.go(); });
<% else -%>
$('#no_todos_in_view').fadeOut(100, function(){ next_steps.go(); });
$('#no_todos_in_view').slideUp(400, function(){ next_steps.go(); });
<% end -%>
}
@ -126,13 +126,13 @@ function activate_pending_todos(next_steps) {
html = escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))
# only project and tag view have a deferred/blocked container
if source_view_is_one_of(:project,:tag) -%>
$('#<%= dom_id(t) %>').fadeOut(400, function() {
$('#<%= dom_id(t) %>').slideUp(400, function() {
$('#<%= dom_id(t) %>').remove();
$('#<%= item_container_id(t) %>').append("<%= html %>");
$('#<%= item_container_id(t) %>_items').append("<%= html %>");
<%= "$('#deferred_pending_container-empty-d').show();".html_safe if @remaining_deferred_or_pending_count==0 -%>
});
<% else -%>
$('#<%= item_container_id(t) %>').append("<%= html%>");
$('#<%= item_container_id(t) %>_items').append("<%= html%>");
<% end -%>
TodoItems.highlight_todo('#<%= dom_id(t)%>');
<% end -%>
@ -145,10 +145,10 @@ function block_predecessors(next_steps) {
if @saved && @active_to_block
# do not render the js in case of an error or if no todos to block
@active_to_block.each do |t| %>
$('#<%= dom_id(t) %>').fadeOut(400, function() {
$('#<%= dom_id(t) %>').slideUp(400, function() {
$('#<%= dom_id(t) %>').remove();
<% if source_view_is(:project) or source_view_is(:tag) # Insert it in deferred/pending block if existing -%>
$('#<%= item_container_id(t) %>').append("<%= escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))%>");
$('#<%= item_container_id(t) %>_items').append("<%= escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))%>");
TodoItems.highlight_todo('#<%= dom_id(t)%>');
<% end -%>
});
@ -171,18 +171,6 @@ end
next_steps.go();
}
function remove_source_container(next_steps) {
<% if (@remaining_in_context == 0 && source_view_is_one_of(:todo, :tag))
# remove context with deleted todo
-%>
$('#c<%=@todo.context_id%>').fadeOut(1000, function() {
next_steps.go();
});
<% else %>
next_steps.go();
<% end %>
}
function html_for_recurring_todo() {
<%-
js = @saved && @new_recurring_todo ? escape_javascript(render(:partial => @new_recurring_todo, :locals => { :parent_container_type => parent_container_type })) : ""

View file

@ -101,7 +101,7 @@ function update_badge_count() {
function insert_new_context_with_updated_todo(next_steps) {
$('#display_box').prepend(html_for_new_context());
$('#c<%= @todo.context_id %>').fadeIn(500, function() { next_steps.go(); });
$('#<%= item_container_id(@todo) %>').fadeIn(500, function() { next_steps.go(); });
}
function html_for_todo() {