Class: AdminIt::TableContext

Inherits:
CollectionContext show all
Defined in:
lib/admin_it/context/table_context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from AdminIt::Context

Class Method Details

.pathObject



21
22
23
24
# File 'lib/admin_it/context/table_context.rb', line 21

def self.path
  AdminIt::Engine.routes
    .url_helpers.send("table_#{resource.plural}_path")
end

Instance Method Details

#headersObject



62
63
64
# File 'lib/admin_it/context/table_context.rb', line 62

def headers
  Hash[fields.map { |f| [f.name, f.display_name] }]
end

#pageObject



40
41
42
# File 'lib/admin_it/context/table_context.rb', line 40

def page
  @page ||= 1
end

#page=(value) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/admin_it/context/table_context.rb', line 44

def page=(value)
  if value.is_a?(String)
    value = case value.downcase
    when 'next' then page + 1
    when 'prev', 'previous' then page - 1
    when 'first' then 1
    when 'last' then pages
    else value.to_i
    end
  end
  if value.is_a?(Fixnum) && value > 0 && value <= pages
    # reset entities enumerator if page changed
    @enumerator = nil if !@enumerator.nil? && value != @page
    @page = value
  end
  @page ||= 1
end

#pagesObject



36
37
38
# File 'lib/admin_it/context/table_context.rb', line 36

def pages
  @pages ||= (count.to_f / page_size).ceil
end