Module: Foreman::Controller::AutoCompleteSearch

Instance Method Summary collapse

Instance Method Details

#auto_complete_searchObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/concerns/foreman/controller/auto_complete_search.rb', line 9

def auto_complete_search
  begin
    model = (controller_name == "hosts") ? Host::Managed : model_of_controller
    @items = model.complete_for(params[:search], {:controller => controller_name})
    @items = @items.map do |item|
      category = ['and', 'or', 'not', 'has'].include?(item.to_s.sub(/^.*\s+/, '')) ? _('Operators') : ''
      part = item.to_s.sub(/^.*\b(and|or)\b/i) { |match| match.sub(/^.*\s+/, '') }
      completed = item.to_s.chomp(part)
      {:completed => CGI.escapeHTML(completed), :part => CGI.escapeHTML(part), :label => item, :category => category}
    end
  rescue ScopedSearch::QueryNotSupported => e
    @items = [{:error => e.to_s}]
  end
  render :json => @items
end

#invalid_search_query(e) ⇒ Object


25
26
27
28
# File 'app/controllers/concerns/foreman/controller/auto_complete_search.rb', line 25

def invalid_search_query(e)
  error (_("Invalid search query: %s") % e)
  redirect_back(fallback_location: public_send("#{controller_name}_path"))
end

#reset_redirect_to_urlObject


30
31
32
# File 'app/controllers/concerns/foreman/controller/auto_complete_search.rb', line 30

def reset_redirect_to_url
  session["redirect_to_url_#{controller_name}"] = nil
end

#store_redirect_to_urlObject


34
35
36
# File 'app/controllers/concerns/foreman/controller/auto_complete_search.rb', line 34

def store_redirect_to_url
  session["redirect_to_url_#{controller_name}"] ||= request.referer
end