Class: Panda::Core::Admin::PaginationComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/pagination_component.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, total_pages:, total_count:, per_page:, item_name: "items", **attrs) ⇒ PaginationComponent

Returns a new instance of PaginationComponent.



7
8
9
10
11
12
13
14
# File 'app/components/panda/core/admin/pagination_component.rb', line 7

def initialize(page:, total_pages:, total_count:, per_page:, item_name: "items", **attrs)
  @page = page
  @total_pages = total_pages
  @total_count = total_count
  @per_page = per_page
  @item_name = item_name
  super(**attrs)
end

Instance Attribute Details

#item_nameObject (readonly)

Returns the value of attribute item_name.



16
17
18
# File 'app/components/panda/core/admin/pagination_component.rb', line 16

def item_name
  @item_name
end

#pageObject (readonly)

Returns the value of attribute page.



16
17
18
# File 'app/components/panda/core/admin/pagination_component.rb', line 16

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



16
17
18
# File 'app/components/panda/core/admin/pagination_component.rb', line 16

def per_page
  @per_page
end

#total_countObject (readonly)

Returns the value of attribute total_count.



16
17
18
# File 'app/components/panda/core/admin/pagination_component.rb', line 16

def total_count
  @total_count
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



16
17
18
# File 'app/components/panda/core/admin/pagination_component.rb', line 16

def total_pages
  @total_pages
end

Instance Method Details

#first_itemObject



22
23
24
# File 'app/components/panda/core/admin/pagination_component.rb', line 22

def first_item
  ((page - 1) * per_page) + 1
end

#last_itemObject



26
27
28
# File 'app/components/panda/core/admin/pagination_component.rb', line 26

def last_item
  [page * per_page, total_count].min
end

#next_page?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/components/panda/core/admin/pagination_component.rb', line 34

def next_page?
  page < total_pages
end

#page_url(page_num) ⇒ Object



49
50
51
52
# File 'app/components/panda/core/admin/pagination_component.rb', line 49

def page_url(page_num)
  query = helpers.request.query_parameters.merge("page" => page_num)
  "#{helpers.request.path}?#{query.to_query}"
end

#previous_page?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/components/panda/core/admin/pagination_component.rb', line 30

def previous_page?
  page > 1
end

#render?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/components/panda/core/admin/pagination_component.rb', line 18

def render?
  total_pages > 1
end

#show_ellipsis?(page_num) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/components/panda/core/admin/pagination_component.rb', line 45

def show_ellipsis?(page_num)
  (page_num - page).abs == 3
end

#show_page?(page_num) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'app/components/panda/core/admin/pagination_component.rb', line 38

def show_page?(page_num)
  page_num == page ||
    (page_num - page).abs <= 2 ||
    page_num == 1 ||
    page_num == total_pages
end