Sha256: 21621ac99ef23fbba9988c25f504155a38ad029316106f678dc40daccb1ee29f

Contents?: true

Size: 951 Bytes

Versions: 9

Compression:

Stored size: 951 Bytes

Contents

module Katello
  module Concerns
    module FilteredAutoCompleteSearch
      extend ActiveSupport::Concern

      PAGE_SIZE=20

      def auto_complete_search
        begin
          options = resource_class.respond_to?(:completer_scope_options) ? resource_class.completer_scope_options : {}
          items = resource_class.where(:id => self.index_relation).complete_for(params[:search], options)
          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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.4 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.3 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.2 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.1 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.0 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.0.rc3 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.0.rc2 app/controllers/katello/concerns/filtered_auto_complete_search.rb
katello-2.4.0.rc1 app/controllers/katello/concerns/filtered_auto_complete_search.rb