From c7637053e1e182b11de35fc70fe22f01a7bc370f Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Tue, 3 Apr 2012 20:29:58 +0200 Subject: [PATCH] fix #1268. The default context in the new todo form on the home page is now the first active context Instead of the first context that could be hidden and thus appear random. Also fix setting the default context based on the project you select. --- app/controllers/todos_controller.rb | 4 ++-- app/helpers/todos_helper.rb | 3 ++- app/views/shared/_add_new_item_form.rhtml | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 793b753c..2bdb06c5 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -18,8 +18,8 @@ class TodosController < ApplicationController extend ActionView::Helpers::SanitizeHelper::ClassMethods def index - @projects = current_user.projects.find(:all, :include => [:default_context]) - @contexts = current_user.contexts.find(:all) + @projects = current_user.projects.all(:include => [:default_context]) + @contexts = current_user.contexts @contexts_to_show = current_user.contexts.active diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index eb31f8e7..3f616b86 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -1,4 +1,5 @@ module TodosHelper + def remote_star_icon(todo=@todo) link_to( image_tag_for_star(todo), @@ -272,7 +273,7 @@ module TodosHelper end def default_contexts_for_autocomplete - projects = current_user.uncompleted.projects.find(:all, :include => [:context], :conditions => ['default_context_id is not null']) + projects = current_user.projects.uncompleted.find(:all, :include => [:default_context], :conditions => ['NOT(default_context_id IS NULL)']) Hash[*projects.map{ |p| [escape_javascript(p.name), escape_javascript(p.default_context.name)] }.flatten].to_json end diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index 940dedb5..d8e3b9a7 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -1,6 +1,7 @@ <% -@initial_context_name = @context.name unless @context.nil? -@initial_context_name ||= @project.default_context.name unless @project.nil? || @project.default_context.nil? +@initial_context_name = @context.name if @context +@initial_context_name ||= @project.default_context.name unless @project.nil? || @project.default_context.nil? +@initial_context_name ||= @contexts.active.first.name unless @contexts.active.first.nil? @initial_context_name ||= @contexts.first.name unless @contexts.first.nil? @initial_project_name = @project.name unless @project.nil? @initial_tags ||= @default_tags