Sha256: 8fc19f8b591b8874ed17beab627cd9731259f1b9036dab542b6cc86b7c79d1ec

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

module Avo
  module Concerns
    module Pagination
      extend ActiveSupport::Concern

      included do
        include Pagy::Backend

        class_attribute :pagination, default: {}

        unless defined? PAGINATION_METHOD
          PAGINATION_METHOD = {
            default: :pagy,
            countless: :pagy_countless,
          }
        end

        unless defined? PAGINATION_DEFAULTS
          PAGINATION_DEFAULTS = {
            type: :default,
            size: [1, 2, 2, 1],
          }
        end
      end

      def pagination_type
        @pagination_type ||= ActiveSupport::StringInquirer.new(pagination_hash[:type].to_s)
      end

      def apply_pagination(index_params:, query:)
        extra_pagy_params = {}

        # Reset open filters when a user navigates to a new page
        if params[:keep_filters_panel_open] == "1"
          extra_pagy_params[:keep_filters_panel_open] = "0"
        end

        send PAGINATION_METHOD[pagination_type.to_sym],
          query,
          items: index_params[:per_page],
          link_extra: "data-turbo-frame=\"#{params[:turbo_frame]}\"",
          params: extra_pagy_params,
          size: pagination_hash[:size]
      end

      private

      def pagination_hash
        @pagination ||= PAGINATION_DEFAULTS.merge Avo::ExecutionContext.new(
          target: pagination,
          resource: self,
          view: @view
        ).handle
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
avo-3.6.1 lib/avo/concerns/pagination.rb
avo-3.6.0 lib/avo/concerns/pagination.rb
avo-3.5.8 lib/avo/concerns/pagination.rb
avo-3.5.7 lib/avo/concerns/pagination.rb
avo-3.5.6 lib/avo/concerns/pagination.rb
avo-3.5.6.beta1 lib/avo/concerns/pagination.rb
avo-3.5.5 lib/avo/concerns/pagination.rb
avo-3.5.4 lib/avo/concerns/pagination.rb
avo-3.5.3 lib/avo/concerns/pagination.rb
avo-3.5.2 lib/avo/concerns/pagination.rb
avo-3.5.1 lib/avo/concerns/pagination.rb
avo-3.5.0 lib/avo/concerns/pagination.rb
avo-3.4.4 lib/avo/concerns/pagination.rb
avo-3.4.3 lib/avo/concerns/pagination.rb
avo-3.4.2 lib/avo/concerns/pagination.rb