Sha256: c4636dbf8667d074f15ea50eb09a90c42c6eb701963136954e833fb3dfa7dbb0

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

class Avo::PaginatorComponent < Avo::BaseComponent
  prop :resource
  prop :parent_record
  prop :pagy
  prop :turbo_frame do |frame|
    frame.present? ? CGI.escapeHTML(frame) : :_top
  end
  prop :index_params
  prop :discreet_pagination

  def change_items_per_page_url(option)
    if @parent_record.present?
      helpers.related_resources_path(@parent_record, @parent_record, per_page: option, keep_query_params: true, page: 1)
    else
      helpers.resources_path(resource: @resource, per_page: option, keep_query_params: true, page: 1)
    end
  end

  def render?
    return false if @discreet_pagination && @pagy.pages <= 1

    if ::Pagy::VERSION >= ::Gem::Version.new("9.0")
      @pagy.limit > 0
    else
      @pagy.items > 0
    end
  end

  def per_page_options
    @per_page_options ||= begin
      options = [*Avo.configuration.per_page_steps, Avo.configuration.per_page.to_i, @index_params[:per_page].to_i]

      if @parent_record.present?
        options.prepend Avo.configuration.via_per_page
      end

      options.sort.uniq
    end
  end

  def pagy_major_version
    return nil unless defined?(Pagy::VERSION)
    version = Pagy::VERSION&.split(".")&.first&.to_i

    return "8-or-more" if version >= 8

    version
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
avo-3.15.1 app/components/avo/paginator_component.rb
avo-3.15.0 app/components/avo/paginator_component.rb
avo-3.14.5 app/components/avo/paginator_component.rb
avo-3.14.4 app/components/avo/paginator_component.rb
avo-3.14.3 app/components/avo/paginator_component.rb
avo-3.14.2 app/components/avo/paginator_component.rb
avo-3.14.1 app/components/avo/paginator_component.rb
avo-3.14.0 app/components/avo/paginator_component.rb
avo-3.13.7 app/components/avo/paginator_component.rb
avo-3.13.6 app/components/avo/paginator_component.rb