2010-08-17 19:03:58 +04:00
|
|
|
class AutoCompletesController < ApplicationController
|
|
|
|
before_filter :find_project
|
|
|
|
|
|
|
|
def issues
|
|
|
|
@issues = []
|
|
|
|
q = params[:q].to_s
|
2011-05-04 21:12:56 +04:00
|
|
|
|
|
|
|
if q.present?
|
|
|
|
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
|
|
|
|
|
|
|
|
@issues |= query.visible.find_all_by_id(q.to_i) if q =~ /^\d+$/
|
|
|
|
|
|
|
|
@issues |= query.visible.find(:all,
|
2011-03-14 03:11:04 +03:00
|
|
|
:limit => 10,
|
|
|
|
:order => "#{Issue.table_name}.id ASC",
|
|
|
|
:conditions => ["LOWER(#{Issue.table_name}.subject) LIKE :q OR CAST(#{Issue.table_name}.id AS CHAR(13)) LIKE :q", {:q => "%#{q.downcase}%" }])
|
2010-08-17 19:03:58 +04:00
|
|
|
end
|
2011-05-04 21:12:56 +04:00
|
|
|
|
2010-08-17 19:03:58 +04:00
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_project
|
|
|
|
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
|
|
|
@project = Project.find(project_id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|