mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-27 12:28:48 +01:00
fix #1195. Update all autocompleters for more sane order of returned items
This commit is contained in:
parent
d2d229c23a
commit
033afda0e1
3 changed files with 46 additions and 31 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ProjectsController < ApplicationController
|
|||
format.rss &render_rss_feed
|
||||
format.atom &render_atom_feed
|
||||
format.text &render_text_feed
|
||||
format.autocomplete { render :text => for_autocomplete(current_user.projects.uncompleted, params[:term]) }
|
||||
format.autocomplete &render_autocomplete
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -385,6 +385,13 @@ class ProjectsController < ApplicationController
|
|||
render :action => 'index', :layout => false, :content_type => Mime::TEXT
|
||||
end
|
||||
end
|
||||
|
||||
def render_autocomplete
|
||||
lambda do
|
||||
projects = current_user.projects.active + current_user.projects.hidden
|
||||
render :text => for_autocomplete(projects, params[:term])
|
||||
end
|
||||
end
|
||||
|
||||
def set_project_from_params
|
||||
@project = current_user.projects.find_by_params(params)
|
||||
|
|
|
|||
|
|
@ -694,9 +694,13 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def tags
|
||||
@tags = Tag.find(:all, :conditions =>['name like ?', '%'+params[:term]+'%'])
|
||||
# TODO: limit to current_user
|
||||
tags_beginning = Tag.find(:all, :conditions => ['name like ?', params[:term]+'%'])
|
||||
tags_all = Tag.find(:all, :conditions =>['name like ?', '%'+params[:term]+'%'])
|
||||
tags_all= tags_all - tags_beginning
|
||||
|
||||
respond_to do |format|
|
||||
format.autocomplete { render :text => for_autocomplete(@tags, params[:term]) }
|
||||
format.autocomplete { render :text => for_autocomplete(tags_beginning+tags_all, params[:term]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -805,36 +809,32 @@ class TodosController < ApplicationController
|
|||
def auto_complete_for_predecessor
|
||||
unless params['id'].nil?
|
||||
get_todo_from_params
|
||||
# Begin matching todos in current project
|
||||
@items = current_user.todos.find(:all,
|
||||
# Begin matching todos in current project, excluding @todo itself
|
||||
@items = @todo.project.todos.not_completed.find(:all,
|
||||
:include => [:context, :project],
|
||||
:conditions => [ '(todos.state = ? OR todos.state = ? OR todos.state = ?) AND ' +
|
||||
'NOT (todos.id = ?) AND lower(todos.description) LIKE ? AND todos.project_id = ?',
|
||||
'active', 'pending', 'deferred',
|
||||
@todo.id,
|
||||
'%' + params[:predecessor_list].downcase + '%',
|
||||
@todo.project_id ],
|
||||
:conditions => ['(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id],
|
||||
:order => 'description ASC',
|
||||
:limit => 10
|
||||
)
|
||||
if @items.empty? # Match todos in other projects
|
||||
@items = current_user.todos.find(:all,
|
||||
:include => [:context, :project],
|
||||
:conditions => [ '(todos.state = ? OR todos.state = ? OR todos.state = ?) AND ' +
|
||||
'NOT (todos.id = ?) AND lower(todos.description) LIKE ?',
|
||||
'active', 'pending', 'deferred',
|
||||
params[:id], '%' + params[:term].downcase + '%' ],
|
||||
:order => 'description ASC',
|
||||
:limit => 10
|
||||
)
|
||||
end
|
||||
else
|
||||
# New todo - TODO: Filter on project
|
||||
@items = current_user.todos.find(:all,
|
||||
) unless @todo.project.nil?
|
||||
# Then look in the current context, excluding @todo itself
|
||||
@items = @todo.context.todos.not_completed.find(:all,
|
||||
:include => [:context, :project],
|
||||
:conditions => [ '(todos.state = ? OR todos.state = ? OR todos.state = ?) AND lower(todos.description) LIKE ?',
|
||||
'active', 'pending', 'deferred',
|
||||
'%' + params[:term].downcase + '%' ],
|
||||
:conditions => ['(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id],
|
||||
:order => 'description ASC',
|
||||
:limit => 10
|
||||
) unless !@items.empty? || @todo.context.nil?
|
||||
# Match todos in other projects, excluding @todo itself
|
||||
@items = current_user.todos.not_completed.find(:all,
|
||||
:include => [:context, :project],
|
||||
:conditions => ['(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id],
|
||||
:order => 'description ASC',
|
||||
:limit => 10
|
||||
) unless !@items.empty?
|
||||
else
|
||||
# New todo - TODO: Filter on current project in project view
|
||||
@items = current_user.todos.not_completed.find(:all,
|
||||
:include => [:context, :project],
|
||||
:conditions => ['(LOWER(todos.description) LIKE ?)', "%#{params[:term].downcase}%"],
|
||||
:order => 'description ASC',
|
||||
:limit => 10
|
||||
)
|
||||
|
|
@ -847,7 +847,6 @@ class TodosController < ApplicationController
|
|||
@project = current_user.projects.new(:name => @todo.description, :description => @todo.notes,
|
||||
:default_context => @todo.context)
|
||||
|
||||
|
||||
unless @project.invalid?
|
||||
@todo.destroy
|
||||
@project.save!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue