Class: Practical::Views::Navigation::PaginationComponent
- Inherits:
-
ApplicationComponent
- Object
- ApplicationComponent
- Practical::Views::Navigation::PaginationComponent
- Includes:
- Pagy::Frontend
- Defined in:
- app/components/practical/views/navigation/pagination_component.rb
Instance Attribute Summary collapse
-
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
-
#item_name ⇒ Object
Returns the value of attribute item_name.
-
#pagy ⇒ Object
Returns the value of attribute pagy.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #goto_page_dialog_id ⇒ Object
-
#initialize(pagy:, request:, item_name: nil, i18n_key: nil) ⇒ PaginationComponent
constructor
A new instance of PaginationComponent.
- #next_item ⇒ Object
- #page_detail_text ⇒ Object
- #page_item(item) ⇒ Object
- #previous_item ⇒ Object
Constructor Details
#initialize(pagy:, request:, item_name: nil, i18n_key: nil) ⇒ PaginationComponent
Returns a new instance of PaginationComponent.
8 9 10 11 12 13 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 8 def initialize(pagy:, request:, item_name: nil, i18n_key: nil) @pagy = pagy @request = request @item_name = item_name @i18n_key = i18n_key end |
Instance Attribute Details
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
6 7 8 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 6 def i18n_key @i18n_key end |
#item_name ⇒ Object
Returns the value of attribute item_name.
6 7 8 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 6 def item_name @item_name end |
#pagy ⇒ Object
Returns the value of attribute pagy.
6 7 8 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 6 def pagy @pagy end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 5 def request @request end |
Instance Method Details
#goto_page_dialog_id ⇒ Object
75 76 77 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 75 def goto_page_dialog_id return [item_name, "pagy-goto-form"].compact.join("-") end |
#next_item ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 56 def next_item classes = helpers.class_names(:page, :next, disabled: !pagy.next) text = icon_text( icon: icon_set.next_arrow, text: pagy_t('pagy.nav.v2_next') ) tag.div(class: classes, role: :listitem){ if pagy.next tag.a(href: pagy_url_for(pagy, pagy.next), title: pagy_t("pagy.nav.next_page_title")) { text } else text end } end |
#page_detail_text ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 15 def page_detail_text pagy_count = pagy.count if pagy_count == 0 key = "pagy.info.no_items" elsif pagy.pages == 1 key = "pagy.info.single_page" else key = "pagy.info.multiple_pages" end item_name = item_name.presence || pagy_t(i18n_key || pagy.vars[:i18n_key], count: pagy_count) item_text = pagy_t(key, item_name: item_name, count: pagy_count, from: pagy.from, to: pagy.to ) page_count_text = pagy_t("pagy.info.page_count", page: pagy.page, count: pagy.pages) return pagy_t("pagy.info.page_detail_text", item_text: item_text, page_count_text: page_count_text) end |
#page_item(item) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 79 def page_item(item) case item when Integer tag.div(class: :page, role: :listitem) { tag.a(item, href: pagy_url_for(pagy, item), title: pagy_t("pagy.nav.page_title", page_number: item)) } when String tag.div( item, class: "page current", role: :listitem, title: pagy_t("pagy.nav.current_page_title", page_number: item) ) when :gap render Practical::Views::Navigation::Pagination::GotoFormComponent.new( pagy: pagy, dialog_id: goto_page_dialog_id, page_detail_text: page_detail_text ) end end |
#previous_item ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/practical/views/navigation/pagination_component.rb', line 37 def previous_item classes = helpers.class_names(:page, :previous, disabled: !pagy.prev) text = icon_text( icon: icon_set.previous_arrow, text: pagy_t('pagy.nav.v2_prev') ) tag.div(class: classes, role: :listitem){ if pagy.prev tag.a(href: pagy_url_for(pagy, pagy.prev), title: pagy_t("pagy.nav.prev_page_title")) { text } else text end } end |