Class: Avo::PaginatorComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/avo/paginator_component.rb

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Method Summary collapse

Methods inherited from BaseComponent

#component_name

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods included from Concerns::FindAssociationField

#find_association_field

Instance Method Details

#change_items_per_page_url(option) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/avo/paginator_component.rb', line 14

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

#current_per_page_labelObject



47
48
49
# File 'app/components/avo/paginator_component.rb', line 47

def current_per_page_label
  per_page_option_label(@index_params[:per_page])
end

#per_page_option_label(option) ⇒ Object



51
52
53
54
# File 'app/components/avo/paginator_component.rb', line 51

def per_page_option_label(option)
  num = helpers.(:span, option, class: "pagination__per-page-option-num")
  "#{num} #{t("avo.per_page").downcase}".html_safe
end

#per_page_optionsObject



35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/avo/paginator_component.rb', line 35

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

#render?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'app/components/avo/paginator_component.rb', line 29

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

  @pagy.limit > 0
end