Class: Avo::PaginatorComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Avo::PaginatorComponent
- Defined in:
- app/components/avo/paginator_component.rb
Instance Attribute Summary collapse
-
#discreet_pagination ⇒ Object
readonly
Returns the value of attribute discreet_pagination.
-
#index_params ⇒ Object
readonly
Returns the value of attribute index_params.
-
#pagy ⇒ Object
readonly
Returns the value of attribute pagy.
-
#parent_record ⇒ Object
readonly
Returns the value of attribute parent_record.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#turbo_frame ⇒ Object
readonly
Returns the value of attribute turbo_frame.
Instance Method Summary collapse
- #change_items_per_page_url(option) ⇒ Object
-
#initialize(resource: nil, parent_record: nil, pagy: nil, turbo_frame: nil, index_params: nil, discreet_pagination: nil) ⇒ PaginatorComponent
constructor
A new instance of PaginatorComponent.
- #pagy_major_version ⇒ Object
- #per_page_options ⇒ Object
- #render? ⇒ Boolean
Constructor Details
#initialize(resource: nil, parent_record: nil, pagy: nil, turbo_frame: nil, index_params: nil, discreet_pagination: nil) ⇒ PaginatorComponent
Returns a new instance of PaginatorComponent.
11 12 13 14 15 16 17 18 |
# File 'app/components/avo/paginator_component.rb', line 11 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 |
Instance Attribute Details
#discreet_pagination ⇒ Object (readonly)
Returns the value of attribute discreet_pagination.
9 10 11 |
# File 'app/components/avo/paginator_component.rb', line 9 def discreet_pagination @discreet_pagination end |
#index_params ⇒ Object (readonly)
Returns the value of attribute index_params.
6 7 8 |
# File 'app/components/avo/paginator_component.rb', line 6 def index_params @index_params end |
#pagy ⇒ Object (readonly)
Returns the value of attribute pagy.
4 5 6 |
# File 'app/components/avo/paginator_component.rb', line 4 def pagy @pagy end |
#parent_record ⇒ Object (readonly)
Returns the value of attribute parent_record.
8 9 10 |
# File 'app/components/avo/paginator_component.rb', line 8 def parent_record @parent_record end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'app/components/avo/paginator_component.rb', line 7 def resource @resource end |
#turbo_frame ⇒ Object (readonly)
Returns the value of attribute turbo_frame.
5 6 7 |
# File 'app/components/avo/paginator_component.rb', line 5 def turbo_frame @turbo_frame end |
Instance Method Details
#change_items_per_page_url(option) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/components/avo/paginator_component.rb', line 20 def change_items_per_page_url(option) if parent_record.present? helpers.(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 |
#pagy_major_version ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/components/avo/paginator_component.rb', line 46 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 |
#per_page_options ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/avo/paginator_component.rb', line 34 def @per_page_options ||= begin = [*Avo.configuration.per_page_steps, Avo.configuration.per_page.to_i, index_params[:per_page].to_i] if parent_record.present? .prepend Avo.configuration.via_per_page end .sort.uniq end end |
#render? ⇒ Boolean
28 29 30 31 32 |
# File 'app/components/avo/paginator_component.rb', line 28 def render? return false if discreet_pagination && pagy.pages <= 1 @pagy.items > 0 end |