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

.actions?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/admin_it/context/table_context.rb', line 18

def self.actions?
  @actions.nil? ? true : @actions == true
end

.page_sizeObject



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

def self.page_size
  @page_size ||= 10
end

.page_size=(value) ⇒ Object



26
27
28
# File 'lib/admin_it/context/table_context.rb', line 26

def self.page_size=(value)
  @page_size = value.is_a?(Fixnum) && value > 0 ? value : 10
end

.pathObject



30
31
32
# File 'lib/admin_it/context/table_context.rb', line 30

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

Instance Method Details

#headersObject



71
72
73
# File 'lib/admin_it/context/table_context.rb', line 71

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

#pageObject



48
49
50
# File 'lib/admin_it/context/table_context.rb', line 48

def page
  @page ||= 1
end

#page=(value) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/admin_it/context/table_context.rb', line 52

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



44
45
46
# File 'lib/admin_it/context/table_context.rb', line 44

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