From 186fd5694d75629e209099dcf46d9761d575c3f9 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 24 Jul 2008 23:22:16 +0200 Subject: [PATCH] fix editing a todo from tag view saving worked, but the edit form did not disappear and the updated todo did not show up in the right place --- app/controllers/todos_controller.rb | 14 ++++++++++---- app/views/todos/update.js.rjs | 7 ++++--- lib/tracks/todo_list.rb | 7 +++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index ae745ab6..e3b048cc 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -542,11 +542,17 @@ class TodosController < ApplicationController end def determine_remaining_in_context_count(context_id = @todo.context_id) - if source_view_is :deferred - @remaining_in_context = current_user.contexts.find(context_id).deferred_todo_count - else - @remaining_in_context = current_user.contexts.find(context_id).not_done_todo_count + source_view do |from| + from.deferred { @remaining_in_context = current_user.contexts.find(context_id).deferred_todo_count } + from.tag { + tag = Tag.find_by_name(params['_tag_name']) + if tag.nil? + tag = Tag.new(:name => params['tag']) + end + @remaining_in_context = current_user.contexts.find(context_id).not_done_todo_count({:tag => tag.id}) + } end + @remaining_in_context = current_user.contexts.find(context_id).not_done_todo_count if @remaining_in_context.nil? end def determine_completed_count diff --git a/app/views/todos/update.js.rjs b/app/views/todos/update.js.rjs index 76a7632e..6cfc48d2 100644 --- a/app/views/todos/update.js.rjs +++ b/app/views/todos/update.js.rjs @@ -9,7 +9,7 @@ if @saved # #update auto completer arrays for context and project page << "contextAutoCompleter.options.array = #{context_names_for_autocomplete}; contextAutoCompleter.changed = true" if @new_context_created page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}; projectAutoCompleter.changed = true" if @new_project_created - if source_view_is_one_of(:todo, :context) + if source_view_is_one_of(:todo, :context, :tag) if @context_changed || @todo.deferred? page[@todo].remove @@ -17,11 +17,12 @@ if @saved # remove context container from page if empty source_view do |from| from.todo { page.visual_effect :fade, "c#{@original_item_context_id}", :duration => 0.4 } + from.tag { page.visual_effect :fade, "c#{@original_item_context_id}", :duration => 0.4 } from.context { page.show "c#{@original_item_context_id}empty-nd" } end end - if source_view_is(:todo) && @todo.active? + if source_view_is_one_of(:todo, :tag) && @todo.active? page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" page.call "todoItems.expandNextActionListingByContext", "c#{@todo.context_id}items", true page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? @@ -36,7 +37,7 @@ if @saved # show todo in context page.delay(0.5) do page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items" - if source_view_is(:todo) && @todo.active? + if source_view_is_one_of(:todo, :tag) && @todo.active? page.call "todoItems.ensureContainerHeight", "c#{@todo.context_id}items" page.visual_effect :highlight, dom_id(@todo), :duration => 3 end diff --git a/lib/tracks/todo_list.rb b/lib/tracks/todo_list.rb index 55a1b9e8..8efe2ae8 100644 --- a/lib/tracks/todo_list.rb +++ b/lib/tracks/todo_list.rb @@ -36,9 +36,12 @@ module Tracks def with_not_done_scope(opts={}) conditions = ["todos.state = ?", 'active'] if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true) - conditions = ["(todos.state = ? or todos.state = ?)", 'active', 'project_hidden'] + conditions = ["(todos.state = ? OR todos.state = ?)", 'active', 'project_hidden'] end - self.todos.send :with_scope, :find => {:conditions => conditions} do + if opts.has_key?(:tag) + conditions = ["todos.state = ? AND taggings.tag_id = ?", 'active', opts[:tag]] + end + self.todos.send :with_scope, :find => {:conditions => conditions, :include => [:taggings]} do yield end end