镜像来自
https://github.com/redmine/redmine.git
synced 2024-08-27 17:54:48 +02:00
![Toshi MARUYAMA](/assets/img/avatar_default.png)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6796 e93f8b46-1217-0410-a6f0-8f06a7374b81
28 line
770 B
Ruby
28 line
770 B
Ruby
class AutoCompletesController < ApplicationController
|
|
before_filter :find_project
|
|
|
|
def issues
|
|
@issues = []
|
|
q = params[:q].to_s
|
|
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
|
|
if q.match(/^\d+$/)
|
|
@issues << query.visible.find_by_id(q.to_i)
|
|
end
|
|
unless q.blank?
|
|
@issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
|
|
end
|
|
@issues.compact!
|
|
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
|