Class: Karafka::Web::Ui::Lib::Paginations::PageBased

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

Overview

Regular page-based pagination engine

Instance Attribute Summary

Attributes inherited from Base

#current_offset, #next_offset, #previous_offset

Instance Method Summary collapse

Constructor Details

#initialize(current_offset, show_next_offset) ⇒ PageBased

Returns a new instance of PageBased.

Parameters:

  • current_offset (Integer)

    current page

  • show_next_offset (Boolean)

    should we show next page (value is computed automatically)



13
14
15
16
17
18
19
20
21
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 13

def initialize(
  current_offset,
  show_next_offset
)
  @previous_offset = current_offset - 1
  @current_offset = current_offset
  @next_offset = show_next_offset ? current_offset + 1 : false
  super()
end

Instance Method Details

#current_labelString

Returns label of the current page.

Returns:

  • (String)

    label of the current page



51
52
53
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 51

def current_label
  @current_offset.to_s
end

#current_offset?Boolean

Returns always show current offset pagination value.

Returns:

  • (Boolean)

    always show current offset pagination value



46
47
48
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 46

def current_offset?
  true
end

#first_offsetBoolean

Returns first page for page based pagination is always empty as it moves us to the initial page so we do not include any page info.

Returns:

  • (Boolean)

    first page for page based pagination is always empty as it moves us to the initial page so we do not include any page info



36
37
38
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 36

def first_offset
  false
end

#first_offset?Boolean

Returns active the first page link when we are not on the first page.

Returns:

  • (Boolean)

    active the first page link when we are not on the first page



30
31
32
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 30

def first_offset?
  @current_offset > 1
end

#next_offset?Boolean

Returns move to the next page if not false. False indicates, that there is no next page to move to.

Returns:

  • (Boolean)

    move to the next page if not false. False indicates, that there is no next page to move to



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

def next_offset?
  @next_offset
end

#offset_keyString

Returns for page pages pagination, always use page as the url value.

Returns:

  • (String)

    for page pages pagination, always use page as the url value



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

def offset_key
  'page'
end

#paginate?Boolean

Show pagination only when there is more than one page

Returns:

  • (Boolean)


25
26
27
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 25

def paginate?
  @current_offset && (@current_offset > 1 || !!@next_offset)
end

#previous_offset?Boolean

Returns Active previous page link when it is not the first page.

Returns:

  • (Boolean)

    Active previous page link when it is not the first page



41
42
43
# File 'lib/karafka/web/ui/lib/paginations/page_based.rb', line 41

def previous_offset?
  @current_offset > 1
end