Class: Panda::Core::Admin::PaginationComponent
- Defined in:
- app/components/panda/core/admin/pagination_component.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#item_name ⇒ Object
readonly
Returns the value of attribute item_name.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #first_item ⇒ Object
-
#initialize(page:, total_pages:, total_count:, per_page:, item_name: "items", **attrs) ⇒ PaginationComponent
constructor
A new instance of PaginationComponent.
- #last_item ⇒ Object
- #next_page? ⇒ Boolean
- #page_url(page_num) ⇒ Object
- #previous_page? ⇒ Boolean
- #render? ⇒ Boolean
- #show_ellipsis?(page_num) ⇒ Boolean
- #show_page?(page_num) ⇒ Boolean
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_name ⇒ Object (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 |
#page ⇒ Object (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_page ⇒ Object (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_count ⇒ Object (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_pages ⇒ Object (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_item ⇒ Object
22 23 24 |
# File 'app/components/panda/core/admin/pagination_component.rb', line 22 def first_item ((page - 1) * per_page) + 1 end |
#last_item ⇒ Object
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
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
30 31 32 |
# File 'app/components/panda/core/admin/pagination_component.rb', line 30 def previous_page? page > 1 end |
#render? ⇒ 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
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
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 |