diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 8fd918b5..2e6bb825 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -1019,16 +1019,16 @@ class TodosController < ApplicationController def find_todos_in_project_container(todo) if todo.project.nil? # container with todos without project - todos_in_container = current_user.todos.where(:project_id => nil).active.not_hidden + todos_in_container = current_user.todos.where(:project_id => nil) else - todos_in_container = current_user.projects.find(todo.project_id).todos.active.not_hidden + todos_in_container = current_user.projects.find(todo.project_id).todos end end def find_todos_in_container_and_target_container(todo, target_todo) if @group_view_by == 'context' - todos_in_container = current_user.contexts.find(todo.context_id).todos.active.not_hidden - todos_in_target_container = current_user.contexts.find(@todo.context_id).todos.active.not_hidden + todos_in_container = current_user.contexts.find(todo.context_id).todos + todos_in_target_container = current_user.contexts.find(@todo.context_id).todos else todos_in_container = find_todos_in_project_container(todo) todos_in_target_container = find_todos_in_project_container(@todo) @@ -1039,9 +1039,9 @@ class TodosController < ApplicationController def determine_remaining_in_container_count(todo = @todo) source_view do |from| from.deferred { - # force reload to todos to get correct count and not a cached one - @remaining_in_context = current_user.contexts.find(todo.context_id).todos.deferred_or_blocked.count - @target_context_count = current_user.contexts.find(@todo.context_id).todos.deferred_or_blocked.count + todos_in_container, todos_in_target_container = find_todos_in_container_and_target_container(todo, @todo) + @remaining_in_context = todos_in_container.deferred_or_blocked.count + @target_context_count = todos_in_target_container.deferred_or_blocked.count } from.todo { todos_in_container, todos_in_target_container = find_todos_in_container_and_target_container(todo, @todo) @@ -1054,8 +1054,8 @@ class TodosController < ApplicationController todos_in_container, todos_in_target_container = find_todos_in_container_and_target_container(todo, @todo) - @remaining_in_context = todos_in_container.with_tag(tag.id).count - @target_context_count = todos_in_target_container.with_tag(tag.id).count + @remaining_in_context = todos_in_container.active.not_hidden.with_tag(tag.id).count + @target_context_count = todos_in_target_container.active.not_hidden.with_tag(tag.id).count @remaining_hidden_count = current_user.todos.hidden.with_tag(tag.id).count @remaining_deferred_or_pending_count = current_user.todos.with_tag(tag.id).deferred_or_blocked.count } diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 622c1516..c391f052 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -516,7 +516,7 @@ module TodosHelper source_view do |page| page.context { return @context_changed || @todo_deferred_state_changed || @todo_pending_state_changed || @todo_should_be_hidden } page.project { return @todo_deferred_state_changed || @todo_pending_state_changed || @project_changed} - page.deferred { return @context_changed || !(@todo.deferred? || @todo.pending?) } + page.deferred { return todo_moved_out_of_container || !(@todo.deferred? || @todo.pending?) } page.calendar { return @due_date_changed || !@todo.due } page.stats { return @todo.completed? } page.tag { return ( (@context_changed | @project_changed) && !@todo.hidden?) || @tag_was_removed || @todo_hidden_state_changed || @todo_deferred_state_changed } @@ -536,7 +536,7 @@ module TodosHelper source_view do |page| page.context { return !update_needs_to_remove_todo_from_container } page.project { return !update_needs_to_remove_todo_from_container } - page.deferred { return !@context_changed && (@todo.deferred? || @todo.pending?) } + page.deferred { return !todo_moved_out_of_container && (@todo.deferred? || @todo.pending?) } page.calendar { return !@due_date_changed && @todo.due } page.stats { return !@todo.completed? } page.tag { return !update_needs_to_remove_todo_from_container && !@tag_was_removed } @@ -550,7 +550,7 @@ module TodosHelper source_view do |page| page.context { return @todo_deferred_state_changed || @todo_pending_state_changed } page.project { return @todo_deferred_state_changed || @todo_pending_state_changed } - page.deferred { return @context_changed && (@todo.deferred? || @todo.pending?) } + page.deferred { return todo_moved_out_of_container && (@todo.deferred? || @todo.pending?) } page.calendar { return @due_date_changed && @todo.due } page.stats { return false } page.tag { return update_needs_to_remove_todo_from_container && !@tag_was_removed} @@ -564,6 +564,15 @@ module TodosHelper return "without_project_container" end + def context_container_id(todo) + return "c#{todo.context_id}" + end + + def todo_container_id(todo) + return project_container_id(todo) if @group_view_by == "project" + return context_container_id(todo) + end + def project_container_empty_id(todo) return "p#{todo.project_id}-empty-d" unless todo.project.nil? return "without_project_container-empty-d" @@ -573,20 +582,20 @@ module TodosHelper 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 + def todo_container_empty_id(todo) + raise Exception.new, "no todo set in TodosHelper::todo_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 + return todo_container_id(todo) if source_view_is :deferred return "#{@new_due_id}_container" if source_view_is :calendar return "deferred_pending_container" if !source_view_is(:todo) && (todo.deferred? || todo.pending?) return "completed_container" if todo.completed? return "p#{todo.project_id}" if source_view_is :project return project_container_id(todo) if source_view_is_one_of(:todo, :tag) && @group_view_by == 'project' - return "c#{todo.context_id}" + return context_container_id(todo) end def empty_container_msg_div_id(todo = @todo || @successor) @@ -600,7 +609,7 @@ module TodosHelper page.tag { return "deferred_pending_container-empty-d" if empty_criteria_met return "hidden_container-empty-d" if @todo.hidden? - return container_empty_id(todo) + return todo_container_empty_id(todo) } page.calendar { return "deferred_pending_container-empty-d" if empty_criteria_met @@ -611,7 +620,10 @@ module TodosHelper return context_container_empty_id(todo) } page.todo { - return container_empty_id(todo) + return todo_container_empty_id(todo) + } + page.deferred { + return todo_container_empty_id(todo) } end @@ -642,7 +654,7 @@ module TodosHelper 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 = container_empty_id(@original_item) if @remaining_in_context == 0 } + page.deferred { container_id = todo_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) || diff --git a/features/step_definitions/todo_create_steps.rb b/features/step_definitions/todo_create_steps.rb index 53d5ec80..ef4562dd 100644 --- a/features/step_definitions/todo_create_steps.rb +++ b/features/step_definitions/todo_create_steps.rb @@ -116,6 +116,13 @@ Given /^I have a deferred todo "([^"]*)" in context "([^"]*)" with tags "([^"]*) @todo.save! end +Given(/^I have a deferred todo "(.*?)" in the context "(.*?)" in the project "(.*?)"$/) do |action_description, context_name, project_name| + step "I have a todo \"#{action_description}\" in the context \"#{context_name}\" in the project \"#{project_name}\"" + @todo.show_from = @current_user.time + 1.week + @todo.save! +end + + ####### COMPLETED TODOS ####### Given /^I have ([0-9]+) completed todos in project "([^"]*)" in context "([^"]*)"$/ do |count, project_name, context_name| diff --git a/features/tickler.feature b/features/tickler.feature index aaade250..6efafd25 100644 --- a/features/tickler.feature +++ b/features/tickler.feature @@ -10,39 +10,60 @@ Feature: Manage deferred todos And there exists a project "manage me" for user "testuser" And I have logged in as "testuser" with password "secret" - @javascript - Scenario: I can add a deferred todo and it will show in the tickler + @javascript + Scenario Outline: I can add a deferred todo and it will show in the tickler # also adding the first deferred todo will hide the empty message Given I have a context called "test" + And I have selected the view for group by When I go to the tickler page Then I should see the empty tickler message When I submit a new deferred action with description "a new next action" Then I should see "a new next action" And I should not see the empty tickler message + Scenarios: + | grouping | + | context | + | project | + @javascript - Scenario: Editing the description of a todo in the tickler updated the todo + Scenario Outline: Editing the description of a todo in the tickler updated the todo Given I have a deferred todo "not yet now" + And I have selected the view for group by When I go to the tickler page Then I should see "not yet now" When I edit the description of "not yet now" to "almost" Then I should not see "not yet now" And I should see "almost" - @javascript - Scenario: Editing the context of a todo moves it to the new context - Given I have a context called "A" - And I have a context called "B" - And I have a deferred todo "not yet now" in the context "A" - When I go to the tickler page - Then I should see "not yet now" in the context container for "A" - When I edit the context of "not yet now" to "B" - Then I should see "not yet now" in the context container for "B" - And I should not see "not yet now" in the context container for "A" + Scenarios: + | grouping | + | context | + | project | @javascript - Scenario: Removing the show from date from a todo removes it from the tickler + Scenario Outline: Editing the container of a todo moves it to the new contaier + Given I have a context called "A" + And I have a context called "B" + And I have a project called "pA" + And I have a project called "pB" + And I have a deferred todo "not yet now" in the context "A" in the project "pA" + And I have selected the view for group by + When I go to the tickler page + Then I should see "not yet now" in the + When I edit the of "not yet now" to + Then I should see "not yet now" in the + And I should not see "not yet now" in the + + Scenarios: + | grouping | first container | new container name | new container | + | context | context container for "A" | "B" | context container for "B" | + | project | project container for "pA" | "pB" | project container for "pB" | + + @javascript + Scenario Outline: Removing the show from date from a todo removes it from the tickler Given I have a deferred todo "not yet now" + And I have selected the view for group by When I go to the tickler page Then I should see "not yet now" When I remove the show from date from "not yet now" @@ -51,6 +72,11 @@ Feature: Manage deferred todos When I go to the home page Then I should see "not yet now" + Scenarios: + | grouping | + | context | + | project | + Scenario: Opening the tickler page shows me all deferred todos Given I have a deferred todo "not yet now" And I have a todo "now is a good time" @@ -59,10 +85,16 @@ Feature: Manage deferred todos And I should not see "now is a good time" @javascript - Scenario: I can mark an action complete from the tickler + Scenario Outline: I can mark an action complete from the tickler Given I have a deferred todo "not yet now" + And I have selected the view for group by When I go to the tickler page And I mark "not yet now" as complete Then I should not see "not yet now" When I go to the done page Then I should see "not yet now" + + Scenarios: + | grouping | + | context | + | project |