Class: Jav::PaginatorComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/jav/paginator_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource: nil, parent_model: nil, pagy: nil, turbo_frame: nil, index_params: nil, discreet_pagination: nil) ⇒ PaginatorComponent

Returns a new instance of PaginatorComponent.



6
7
8
9
10
11
12
13
14
# File 'app/components/jav/paginator_component.rb', line 6

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

Instance Attribute Details

#discreet_paginationObject (readonly)

Returns the value of attribute discreet_pagination.



4
5
6
# File 'app/components/jav/paginator_component.rb', line 4

def discreet_pagination
  @discreet_pagination
end

#index_paramsObject (readonly)

Returns the value of attribute index_params.



4
5
6
# File 'app/components/jav/paginator_component.rb', line 4

def index_params
  @index_params
end

#pagyObject (readonly)

Returns the value of attribute pagy.



4
5
6
# File 'app/components/jav/paginator_component.rb', line 4

def pagy
  @pagy
end

#parent_modelObject (readonly)

Returns the value of attribute parent_model.



4
5
6
# File 'app/components/jav/paginator_component.rb', line 4

def parent_model
  @parent_model
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'app/components/jav/paginator_component.rb', line 4

def resource
  @resource
end

#turbo_frameObject (readonly)

Returns the value of attribute turbo_frame.



4
5
6
# File 'app/components/jav/paginator_component.rb', line 4

def turbo_frame
  @turbo_frame
end

Instance Method Details

#change_items_per_page_url(option) ⇒ Object



16
17
18
19
20
21
22
# File 'app/components/jav/paginator_component.rb', line 16

def change_items_per_page_url(option)
  if parent_model.present?
    helpers.related_resources_path(parent_model, parent_model, 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

#per_page_optionsObject



30
31
32
33
34
35
36
37
38
# File 'app/components/jav/paginator_component.rb', line 30

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

    options.prepend Jav.configuration.via_per_page if parent_model.present?

    options.sort.uniq
  end
end

#render?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'app/components/jav/paginator_component.rb', line 24

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

  @pagy.limit.positive?
end