Class: Component::CollectionTable

Inherits:
Base
  • Object
show all
Includes:
ActsAsListConcern, ActsAsPublishedConcern, AwesomeNestedSetConcern, BatchActionsConcern, BooleanConcern
Defined in:
app/components/component/collection_table.rb

Overview

Example:

= collection_table(collection: @posts, resource_class: Post) do |t|
  = t.column :id, sort: true
  = t.column :title
  = t.column :body
  = t.boolean :visible
  = t.timestamps format: :short

Defined Under Namespace

Modules: ActsAsListConcern, ActsAsPublishedConcern, AwesomeNestedSetConcern, BatchActionsConcern, BooleanConcern

Constant Summary collapse

SIZE_MAP =
{
  default: nil,
  small:   :sm
}

Instance Method Summary collapse

Methods included from BooleanConcern

#boolean

Methods included from BatchActionsConcern

#batch_actions

Methods included from ActsAsListConcern

#acts_as_list_actions

Methods included from ActsAsPublishedConcern

#acts_as_published_actions

Methods included from AwesomeNestedSetConcern

#awesome_nested_set_actions

Methods inherited from Base

#perform

Constructor Details

#initialize(*args) ⇒ CollectionTable


23
24
25
26
27
28
29
30
# File 'app/components/component/collection_table.rb', line 23

def initialize(*args)
  super
  @options.reverse_merge!(header: true)

  @columns        = {}
  @collection     = @options.delete(:collection)
  @resource_class = @options.delete(:resource_class) || @collection.first.class
end

Instance Method Details

#association(name, options = {}, &block) ⇒ Object

Example:

= table.association :category, sortable: true, label_method: :name, link_to: ->(r) { url_for(r.category) }

56
57
58
59
# File 'app/components/component/collection_table.rb', line 56

def association(name, options = {}, &block)
  options.reverse_merge!(render_as: :association)
  column(name, options, &block)
end

#column(name, options = {}, &block) ⇒ Object


32
33
34
35
36
# File 'app/components/component/collection_table.rb', line 32

def column(name, options = {}, &block)
  options.reverse_merge!(render_as: :default)
  options.reverse_merge!(block: block) if block_given?
  @columns[name] = options
end

#id(options = {}, &block) ⇒ Object


38
39
40
# File 'app/components/component/collection_table.rb', line 38

def id(options = {}, &block)
  column(:id, options, &block)
end

#timestamp(name, options = {}, &block) ⇒ Object


42
43
44
45
# File 'app/components/component/collection_table.rb', line 42

def timestamp(name, options = {}, &block)
  options.reverse_merge!(render_as: :timestamp, format: Rails::AddOns::Configuration.table_default_timestamp_format)
  column(name, options, &block)
end

#timestamps(options = {}) ⇒ Object


47
48
49
50
# File 'app/components/component/collection_table.rb', line 47

def timestamps(options = {})
  timestamp(:created_at, options)
  timestamp(:updated_at, options)
end