Class: Karafka::Web::Ui::Lib::Paginations::OffsetBased
- Defined in:
- lib/karafka/web/ui/lib/paginations/offset_based.rb
Overview
Kafka offset based pagination backend
Allows us to support paginating over offsets
Instance Attribute Summary
Attributes inherited from Base
#current_offset, #previous_offset
Instance Method Summary collapse
-
#current_label ⇒ String
Label of the current page.
-
#current_offset? ⇒ Boolean
We show current label with offsets that are present on the given page.
-
#first_offset ⇒ Boolean
First page offset is always nothing because we use the default -1 for the offset.
-
#first_offset? ⇒ Boolean
Active only when we are not on the first page.
-
#initialize(previous_offset, current_offset, next_offset, visible_offsets) ⇒ OffsetBased
constructor
A new instance of OffsetBased.
-
#next_offset ⇒ Integer
If there is no next offset, we point to 0 as there should be no smaller offset than that in Kafka ever.
-
#next_offset? ⇒ Boolean
Move to the next page if not false.
-
#offset_key ⇒ String
For offset based pagination we use the offset param name.
-
#paginate? ⇒ Boolean
Show pagination only when there is more than one page of results to be presented.
-
#previous_offset? ⇒ Boolean
Active previous page link when it is not the first page.
Constructor Details
#initialize(previous_offset, current_offset, next_offset, visible_offsets) ⇒ OffsetBased
Returns a new instance of OffsetBased.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 19 def initialize( previous_offset, current_offset, next_offset, visible_offsets ) @previous_offset = previous_offset @current_offset = current_offset @next_offset = next_offset @visible_offsets = visible_offsets super() end |
Instance Method Details
#current_label ⇒ String
Returns label of the current page. It is combined out of the first and the last offsets to show the range where we are. It will be empty if no offsets but this is not a problem as then we should not display pagination at all.
81 82 83 84 85 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 81 def current_label first = @visible_offsets.first last = @visible_offsets.last [first, last].compact.uniq.join(' - ').to_s end |
#current_offset? ⇒ Boolean
Returns We show current label with offsets that are present on the given page.
61 62 63 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 61 def current_offset? true end |
#first_offset ⇒ Boolean
Returns first page offset is always nothing because we use the default -1 for the offset.
50 51 52 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 50 def first_offset false end |
#first_offset? ⇒ Boolean
Returns active only when we are not on the first page. First page is always indicated by the current offset being -1. If there is someone that sets up the current offset to a value equal to the last message in the topic partition, we do not consider it as a first page and we allow to “reset” to -1 via the first page button.
44 45 46 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 44 def first_offset? @current_offset != -1 end |
#next_offset ⇒ Integer
If there is no next offset, we point to 0 as there should be no smaller offset than that in Kafka ever
74 75 76 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 74 def next_offset next_offset? ? @next_offset : 0 end |
#next_offset? ⇒ Boolean
Returns move to the next page if not false. False indicates, that there is no next page to move to.
67 68 69 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 67 def next_offset? !!@next_offset end |
#offset_key ⇒ String
Returns for offset based pagination we use the offset param name.
88 89 90 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 88 def offset_key 'offset' end |
#paginate? ⇒ Boolean
Show pagination only when there is more than one page of results to be presented
35 36 37 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 35 def paginate? @current_offset && (!!@previous_offset || !!@next_offset) end |
#previous_offset? ⇒ Boolean
Returns Active previous page link when it is not the first page.
55 56 57 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 55 def previous_offset? !!@previous_offset end |