fix #1195. Update all autocompleters for more sane order of returned items

This commit is contained in:
Reinier Balt 2012-04-09 12:48:40 +02:00
parent d2d229c23a
commit 033afda0e1
3 changed files with 46 additions and 31 deletions

View file

@ -31,7 +31,7 @@ class ContextsController < ApplicationController
@all_contexts = current_user.contexts.all
render :action => 'index', :layout => false, :content_type => Mime::TEXT
end
format.autocomplete { render :text => for_autocomplete(@active_contexts + @hidden_contexts, params[:term])}
format.autocomplete &render_autocomplete
end
end
@ -248,6 +248,15 @@ class ContextsController < ApplicationController
:author => lambda { |c| nil } }
end
end
def render_autocomplete
lambda do
# first get active contexts with todos then those without
filled_contexts = @active_contexts.reject { |ctx| ctx.todos.count == 0 } + @hidden_contexts.reject { |ctx| ctx.todos.count == 0 }
empty_contexts = @active_contexts.find_all { |ctx| ctx.todos.count == 0 } + @hidden_contexts.find_all { |ctx| ctx.todos.count == 0 }
render :text => for_autocomplete(filled_contexts + empty_contexts, params[:term])
end
end
def feed_options
Context.feed_options(current_user)