Sha256: fc3d706cad6bdb1b075ee226978ffe2115934b694502ae13261d29a16e54f2f2

Contents?: true

Size: 1.24 KB

Versions: 21

Compression:

Stored size: 1.24 KB

Contents

module Spree
  module Admin
    class SearchController < Spree::Admin::BaseController
      respond_to :json
      layout false

      # TODO: Clean this up by moving searching out to user_class_extensions
      # And then JSON building with something like Active Model Serializers
      def users
        if params[:ids]
          # split here may be String#split or Array#split, so we must flatten the results
          @users = Spree.user_class.where(id: params[:ids].split(',').flatten)
        else
          @users = Spree.user_class.ransack({
            m: 'or',
            email_start: params[:q],
            addresses_firstname_start: params[:q],
            addresses_lastname_start: params[:q]
          }).result.limit(10)
        end
      end

      def products
        if params[:ids]
          # split here may be String#split or Array#split, so we must flatten the results
          @products = Product.where(id: params[:ids].split(",").flatten)
        else
          @products = Product.ransack(params[:q]).result
        end

        @products = @products.distinct.page(params[:page]).per(params[:per_page])
        expires_in 15.minutes, public: true
        headers['Surrogate-Control'] = "max-age=#{15.minutes}"
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_backend-2.1.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.0.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.4.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.3.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.0.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.4.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.1.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.1.0.rc1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.0.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.1.0.beta1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.0.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.4.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.0.0.rc1 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.4.0.rc1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.0.0.beta1 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.4.0.beta1 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.3.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.3.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.3.0.rc2 app/controllers/spree/admin/search_controller.rb
solidus_backend-1.3.0.rc1 app/controllers/spree/admin/search_controller.rb