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 ⇒ Integer
-1 because it will then select the highest offsets.
-
#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.
80 81 82 83 84 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 80 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.
60 61 62 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 60 def current_offset? true end |
#first_offset ⇒ Integer
Returns -1 because it will then select the highest offsets.
49 50 51 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 49 def first_offset -1 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 && @previous_offset != false 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
73 74 75 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 73 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.
66 67 68 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 66 def next_offset? !!@next_offset end |
#offset_key ⇒ String
Returns for offset based pagination we use the offset param name.
87 88 89 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 87 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.
54 55 56 |
# File 'lib/karafka/web/ui/lib/paginations/offset_based.rb', line 54 def previous_offset? !!@previous_offset end |