Use default context sort order when returning autocomplete

Fixes #1403
This commit is contained in:
Dan Rice 2013-03-09 22:21:54 +02:00
parent b03651ee97
commit 7e432887dd

View file

@ -234,15 +234,7 @@ class ContextsController < ApplicationController
def render_autocomplete
lambda do
# find contexts and the todos count. use a join to prevent all count(todos) of each context to be fetched
context_and_todo_count = current_user.contexts.
select('contexts.*, count(todos.id) as todos_count').
joins('left outer join todos on context_id=contexts.id').
group('context_id')
filled_contexts = context_and_todo_count.reject { |ctx| ctx.todos.size == 0 }
empty_contexts = context_and_todo_count.find_all { |ctx| ctx.todos.size == 0 }
render :text => for_autocomplete(filled_contexts + empty_contexts, params[:term])
render :text => for_autocomplete(current_user.contexts, params[:term])
end
end