Class: Pagy::Keyset::Keynav

Inherits:
Pagy::Keyset show all
Includes:
Deprecated::Keynav, NumericHelpers
Defined in:
lib/pagy/classes/keyset/keynav.rb

Overview

Keyset pagination with broad UI support

Direct Known Subclasses

ActiveRecord, Sequel

Defined Under Namespace

Classes: ActiveRecord, Sequel

Constant Summary collapse

PRIOR_PREFIX =

Avoid conflicts between filter arguments in composite SQL fragments

'prior_'
PAGE_PREFIX =
'page_'

Constants inherited from Pagy

A_TAG, DEFAULT, DEFAULT_DATA_KEYS, DEFAULT_HEADERS_MAP, LABEL_TOKEN, LIMIT_TOKEN, Method, OPTIONS, PAGE_TOKEN, ROOT, SERIES_SLOTS, VERSION

Instance Attribute Summary collapse

Attributes inherited from Pagy

#in, #limit, #options, #page

Instance Method Summary collapse

Methods included from NumericHelpers

#info_tag, #input_nav_js, #limit_tag_js, #previous_tag, #series_nav, #series_nav_js

Methods inherited from Pagy::Keyset

mix_in_adapter, new, #records

Methods inherited from Pagy

#data_hash, #headers_hash, #next_tag, #page_url, #urls_hash

Methods included from Configurable

#dev_tools, #options, #sync, #sync_javascript, #translate_with_the_slower_i18n_gem!

Methods included from Discontinued

#assign_options

Methods included from Deprecated::Pagy

#assign_options

Constructor Details

#initialize(set) ⇒ Keynav

Finalize the instance variables needed for the UI



18
19
20
21
22
23
# File 'lib/pagy/classes/keyset/keynav.rb', line 18

def initialize(set, **)
  super

  @previous = @page - 1 unless @page == 1
  @in       = @records.size
end

Instance Attribute Details

#lastObject (readonly) Also known as: pages

Returns the value of attribute last.



25
26
27
# File 'lib/pagy/classes/keyset/keynav.rb', line 25

def last
  @last
end

#previousObject (readonly)

Returns the value of attribute previous.



25
26
27
# File 'lib/pagy/classes/keyset/keynav.rb', line 25

def previous
  @previous
end

#updateObject (readonly)

Returns the value of attribute update.



25
26
27
# File 'lib/pagy/classes/keyset/keynav.rb', line 25

def update
  @update
end

Instance Method Details

#nextObject

Prepare the @update for the client when it’s a new page, and return the next page number



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pagy/classes/keyset/keynav.rb', line 29

def next
  records
  @count = 0 if !@more && @page == 1  # empty records (trigger the right info message for known 0 count)
  return unless @more

  @next ||= begin
              unless @page_cutoff
                @page_cutoff = extract_cutoff
                @last       += 1                                # reflect the added cutoff
                @update.push(@last, [@page, 1, @page_cutoff])   # last + splice arguments for the client cutoffs
              end
              @page + 1
            end
end