Class: Karafka::Web::Ui::Lib::Paginations::WatermarkOffsetsBased

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb

Overview

Watermark offsets single message pagination engine

It is used to provide pagination for single message displays (explorer, errors)

Instance Attribute Summary

Attributes inherited from Base

#current_offset, #next_offset, #previous_offset

Instance Method Summary collapse

Constructor Details

#initialize(current_offset, low_watermark_offset, high_watermark_offset) ⇒ WatermarkOffsetsBased

Returns a new instance of WatermarkOffsetsBased.

Parameters:

  • current_offset (Integer)

    current message offset

  • low_watermark_offset (Integer)
  • high_watermark_offset (Integer)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 15

def initialize(
  current_offset,
  low_watermark_offset,
  high_watermark_offset
)
  @low_watermark_offset = low_watermark_offset
  @high_watermark_offset = high_watermark_offset
  @previous_offset = current_offset + 1
  @current_offset = current_offset
  @next_offset = current_offset - 1
  super()
end

Instance Method Details

#current_labelString

Returns shows as current page pagination the offset.

Returns:

  • (String)

    shows as current page pagination the offset



57
58
59
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 57

def current_label
  @current_offset.to_s
end

#current_offset?Boolean

Returns We always show current offset.

Returns:

  • (Boolean)

    We always show current offset



52
53
54
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 52

def current_offset?
  true
end

#first_offsetInteger

Returns highest available offset.

Returns:

  • (Integer)

    highest available offset



42
43
44
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 42

def first_offset
  @high_watermark_offset - 1
end

#first_offset?Boolean

Returns provide link to the first (newest).

Returns:

  • (Boolean)

    provide link to the first (newest)



37
38
39
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 37

def first_offset?
  @current_offset < @high_watermark_offset - 1
end

#next_offset?Boolean

Returns if not lowest, show.

Returns:

  • (Boolean)

    if not lowest, show



62
63
64
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 62

def next_offset?
  @current_offset > @low_watermark_offset
end

#offset_keyString

Returns params offset key.

Returns:

  • (String)

    params offset key



67
68
69
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 67

def offset_key
  'offset'
end

#paginate?Boolean

Returns show pagination only when there are other things to present.

Returns:

  • (Boolean)

    show pagination only when there are other things to present



29
30
31
32
33
34
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 29

def paginate?
  return true if @current_offset > @low_watermark_offset
  return true if @current_offset < @high_watermark_offset - 1

  false
end

#previous_offset?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/karafka/web/ui/lib/paginations/watermark_offsets_based.rb', line 47

def previous_offset?
  @current_offset < @high_watermark_offset - 1
end