Module: Effective::EffectiveDatatable::Dsl::Datatable

Included in:
Datatable
Defined in:
app/models/effective/effective_datatable/dsl/datatable.rb

Instance Method Summary collapse

Instance Method Details

#actions_column(options = {}, proc = nil, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 29

def actions_column(options = {}, proc = nil, &block)
  show = options.fetch(:show, (EffectiveDatatables.actions_column[:show] rescue false))
  edit = options.fetch(:edit, (EffectiveDatatables.actions_column[:edit] rescue false))
  destroy = options.fetch(:destroy, (EffectiveDatatables.actions_column[:destroy] rescue false))
  unarchive = options.fetch(:unarchive, (EffectiveDatatables.actions_column[:unarchive] rescue false))
  name = options.fetch(:name, 'actions')

  opts = {
    sortable: false,
    filter: false,
    responsivePriority: 0,
    partial_locals: { show_action: show, edit_action: edit, destroy_action: destroy, unarchive_action: unarchive }
  }.merge(options)

  opts[:partial_local] ||= :resource unless opts[:partial].present?
  opts[:partial] ||= '/effective/datatables/actions_column' unless (block_given? || proc.present?)

  table_column(name, opts, proc, &block)
end

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



67
68
69
70
71
72
73
74
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 67

def aggregate(name, options = {}, &block)
  if block_given?
    raise "You cannot use proc: ... with the block syntax" if options[:proc]
    options[:block] = block
  end

  (@aggregates ||= HashWithIndifferentAccess.new)[name] = options
end

#array_column(name, options = {}, proc = nil, &block) ⇒ Object



25
26
27
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 25

def array_column(name, options = {}, proc = nil, &block)
  table_column(name, options.merge!(array_column: true), proc, &block)
end

#bulk_actions_column(options = {}, proc = nil, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 49

def bulk_actions_column(options = {}, proc = nil, &block)
  name = options.fetch(:name, 'bulk_actions')
  resource_method = options.fetch(:resource_method, :to_param)

  opts = {
    bulk_actions_column: true,
    label: '',
    partial_local: :resource,
    partial: '/effective/datatables/bulk_actions_column',
    partial_locals: { resource_method: resource_method },
    sortable: false,
    dropdown_partial: '/effective/datatables/bulk_actions_dropdown',
    dropdown_block: block
  }.merge(options)

  table_column(name, opts, proc)
end

#default_entries(entries) ⇒ Object



10
11
12
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 10

def default_entries(entries)
  @default_entries = entries
end

#default_order(name, direction = :asc) ⇒ Object

Instance Methods inside the datatable do .. end block



6
7
8
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 6

def default_order(name, direction = :asc)
  @default_order = {name => direction}
end

#table_column(name, options = {}, proc = nil, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/models/effective/effective_datatable/dsl/datatable.rb', line 14

def table_column(name, options = {}, proc = nil, &block)
  if block_given?
    raise "You cannot use partial: ... with the block syntax" if options[:partial]
    raise "You cannot use proc: ... with the block syntax" if options[:proc]
    options[:block] = block
  end
  raise "You cannot use both partial: ... and proc: ..." if options[:partial] && options[:proc]

  (@table_columns ||= HashWithIndifferentAccess.new)[name] = options
end