diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index 6553bd85..a6d5658e 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -414,7 +414,7 @@ class TodosController < ApplicationController @todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? or todos.state = ?', current_user.id, 'active', 'completed'], :include => [ :project, :context, :tags ]) # Exclude hidden projects from the home page - @not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? AND (projects.state = ? OR todos.project_id IS NULL)', current_user.id, 'active', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ]) + @not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', current_user.id, 'active', false, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ]) end @@ -444,7 +444,15 @@ class TodosController < ApplicationController def determine_down_count source_view do |from| from.todo do - @down_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, 'active', false]) + @down_count = Todo.count( + :all, + :conditions => ['todos.user_id = ? and todos.state = ? and contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', current_user.id, 'active', false, 'active'], + :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", + :include => [ :project, :context ]) + # #@down_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, 'active', + # false]) end from.context do @down_count = current_user.contexts.find(@todo.context_id).not_done_todo_count @@ -505,7 +513,16 @@ class TodosController < ApplicationController @done = current_user.completed_todos.find(:all, :limit => max_completed, :include => [ :context, :project, :tags ]) unless max_completed == 0 # Set count badge to number of not-done, not hidden context items - @count = @todos.reject { |x| !x.active? || x.context.hide? }.size + @count = 0 + @todos.each do |x| + if x.active? + if x.project.nil? + @count += 1 if !x.context.hide? + else + @count += 1 if x.project.active? && !x.context.hide? + end + end + end @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json diff --git a/tracks/test/selenium/home/create_todo_in_completed_project.rsel b/tracks/test/selenium/home/create_todo_in_completed_project.rsel new file mode 100644 index 00000000..2755adad --- /dev/null +++ b/tracks/test/selenium/home/create_todo_in_completed_project.rsel @@ -0,0 +1,24 @@ +setup :fixtures => :all +login :as => 'admin' + +# set project to hidden state +open "/projects/2" +click 'project_state_completed' + +# monitor badge count on home page. It should be 7 at the start +open "/" +assert_text 'badge_count', '7' + +# add todo to hidden project +type "todo_description", "should be hidden" +type "todo_project_name", "Make more money than Billy Gates" +type "todo_context_name", "agenda" +click "css=#todo-form-new-action .submit_box button" + +# wait for flash to appear +wait_for_visible "flash" + +verify_text_not_present 'should be hidden' + +# badge count should still be same +assert_text 'badge_count', '7' \ No newline at end of file diff --git a/tracks/test/selenium/home/create_todo_in_hidden_project.rsel b/tracks/test/selenium/home/create_todo_in_hidden_project.rsel new file mode 100644 index 00000000..9c039336 --- /dev/null +++ b/tracks/test/selenium/home/create_todo_in_hidden_project.rsel @@ -0,0 +1,24 @@ +setup :fixtures => :all +login :as => 'admin' + +# set project to hidden state +open "/projects/2" +click 'project_state_hidden' + +# monitor badge count on home page. It should be 7 at the start +open "/" +assert_text 'badge_count', '7' + +# add todo to hidden project +type "todo_description", "should be hidden" +type "todo_project_name", "Make more money than Billy Gates" +type "todo_context_name", "agenda" +click "css=#todo-form-new-action .submit_box button" + +# wait for flash to (dis)appear +wait_for_visible "flash" + +verify_text_not_present 'should be hidden' + +# badge count should still be same +assert_text 'badge_count', '7' \ No newline at end of file