Sha256: cc0ea0c3b7c599798f8c622575e0fb59baab38cdf8ed71ff02bcc8b3fc2382f4

Contents?: true

Size: 1.26 KB

Versions: 46

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

class Avo::PaginatorComponent < ViewComponent::Base
  attr_reader :pagy
  attr_reader :turbo_frame
  attr_reader :index_params
  attr_reader :resource
  attr_reader :parent_record
  attr_reader :discreet_pagination

  def initialize(resource: nil, parent_record: nil, pagy: nil, turbo_frame: nil, index_params: nil, discreet_pagination: nil)
    @pagy = pagy
    @turbo_frame = turbo_frame
    @index_params = index_params
    @resource = resource
    @parent_record = parent_record
    @discreet_pagination = discreet_pagination
  end

  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

    @pagy.items > 0
  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
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
avo-3.6.4 app/components/avo/paginator_component.rb
avo-3.6.3 app/components/avo/paginator_component.rb
avo-3.6.2 app/components/avo/paginator_component.rb
avo-3.6.1 app/components/avo/paginator_component.rb
avo-3.6.0 app/components/avo/paginator_component.rb
avo-3.5.8 app/components/avo/paginator_component.rb
avo-3.5.7 app/components/avo/paginator_component.rb
avo-3.5.6 app/components/avo/paginator_component.rb
avo-3.5.6.beta1 app/components/avo/paginator_component.rb
avo-3.5.5 app/components/avo/paginator_component.rb
avo-3.5.4 app/components/avo/paginator_component.rb
avo-3.5.3 app/components/avo/paginator_component.rb
avo-3.5.2 app/components/avo/paginator_component.rb
avo-3.5.1 app/components/avo/paginator_component.rb
avo-3.5.0 app/components/avo/paginator_component.rb
avo-3.4.4 app/components/avo/paginator_component.rb
avo-3.4.3 app/components/avo/paginator_component.rb
avo-3.4.2 app/components/avo/paginator_component.rb
avo-3.4.1 app/components/avo/paginator_component.rb
avo-3.4.0 app/components/avo/paginator_component.rb