To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / auto_completes_controller.rb @ 1034:ea5d9652c6f6

History | View | Annotate | Download (770 Bytes)

1
class AutoCompletesController < ApplicationController
2
  before_filter :find_project
3

    
4
  def issues
5
    @issues = []
6
    q = params[:q].to_s
7
    query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
8
    if q.match(/^\d+$/)
9
      @issues << query.visible.find_by_id(q.to_i)
10
    end
11
    unless q.blank?
12
      @issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
13
    end
14
    @issues.compact!
15
    render :layout => false
16
  end
17

    
18
  private
19

    
20
  def find_project
21
    project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
22
    @project = Project.find(project_id)
23
  rescue ActiveRecord::RecordNotFound
24
    render_404
25
  end
26

    
27
end