Sha256: 76209bc1c5615ac0256cb9969812c86f6a9b38303d09245fab2e9fadfbe4ba71
Contents?: true
Size: 837 Bytes
Versions: 5
Compression:
Stored size: 837 Bytes
Contents
module Foreman::Controller::AutoCompleteSearch def auto_complete_search begin model = controller_name == "hosts" ? Host::Managed : controller_name.singularize.camelize.constantize @items = model.complete_for(params[:search]) @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 => completed, :part => part, :label => item, :category => category} end rescue ScopedSearch::QueryNotSupported => e @items = [{:error =>e.to_s}] end render :json => @items end def invalid_search_query(e) error (_("Invalid search query: %s") % e) redirect_to :back end end
Version data entries
5 entries across 5 versions & 1 rubygems