Class: Voom::Presenters::DSL::Components::Table::Pagination

Inherits:
Base
  • Object
show all
Defined in:
lib/voom/presenters/dsl/components/table.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #css_class, #draggable, #drop_zone, #id, #tag, #type

Instance Method Summary collapse

Methods inherited from Base

#expand!

Methods included from Pluggable

#include_plugins, #plugin, #plugin_module

Methods included from Mixins::YieldTo

#yield_to

Methods included from Serializer

#to_hash

Methods included from Lockable

#locked?

Constructor Details

#initialize(**attribs_, &block) ⇒ Pagination

Returns a new instance of Pagination.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/voom/presenters/dsl/components/table.rb', line 119

def initialize(**attribs_, &block)
  super(type: :pagination, **attribs_, &block)
  @page_size = attribs.delete(:page_size){10}.to_i
  @page_size_options = attribs.delete(:page_size_options){[10,20,30,40,50,100]}
  @total = attribs.delete(:total)
  @current_page = attribs.delete(:current_page){ 1 }.to_i
  @replace_id = attribs.delete(:replace_id)
  @replace_presenter = attribs.delete(:replace_presenter)
  previous_button_icon
  next_button_icon
  per_page_select
  range
  expand!
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



117
118
119
# File 'lib/voom/presenters/dsl/components/table.rb', line 117

def current_page
  @current_page
end

#next_buttonObject

Returns the value of attribute next_button.



117
118
119
# File 'lib/voom/presenters/dsl/components/table.rb', line 117

def next_button
  @next_button
end

#page_sizeObject

Returns the value of attribute page_size.



117
118
119
# File 'lib/voom/presenters/dsl/components/table.rb', line 117

def page_size
  @page_size
end

#per_pageObject

Returns the value of attribute per_page.



117
118
119
# File 'lib/voom/presenters/dsl/components/table.rb', line 117

def per_page
  @per_page
end

#previous_buttonObject

Returns the value of attribute previous_button.



117
118
119
# File 'lib/voom/presenters/dsl/components/table.rb', line 117

def previous_button
  @previous_button
end

#totalObject

Returns the value of attribute total.



117
118
119
# File 'lib/voom/presenters/dsl/components/table.rb', line 117

def total
  @total
end

Instance Method Details

#next_button_icon(icon = :keyboard_arrow_right) ⇒ Object



146
147
148
149
# File 'lib/voom/presenters/dsl/components/table.rb', line 146

def next_button_icon(icon = :keyboard_arrow_right)
  return @next_button if locked?
  @next_button = button(icon, [total_pages, @current_page+1].min)
end

#per_page_selectObject



151
152
153
154
# File 'lib/voom/presenters/dsl/components/table.rb', line 151

def per_page_select
  return @per_page if locked?
  @per_page = select(@page_size_options, @page_size, @total)
end

#previous_button_icon(icon = :keyboard_arrow_left) ⇒ Object



141
142
143
144
# File 'lib/voom/presenters/dsl/components/table.rb', line 141

def previous_button_icon(icon = :keyboard_arrow_left)
  return @previous_button if locked?
  @previous_button = button(icon, [1, @current_page-1].max)
end

#rangeObject



134
135
136
137
138
139
# File 'lib/voom/presenters/dsl/components/table.rb', line 134

def range
  return @range if locked?
  end_range = @total - (@total - @page_size * @current_page.to_i)
  start_range = end_range - @page_size + 1
  @range = [start_range, end_range]
end