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)


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

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

.page_sizeObject



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

def self.page_size
  @page_size ||= 10
end

.page_size=(value) ⇒ Object



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

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

.pathObject



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

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

Instance Method Details

#headersObject



69
70
71
# File 'lib/admin_it/context/table_context.rb', line 69

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

#pageObject



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

def page
  @page ||= 1
end

#page=(value) ⇒ Object



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

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



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

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