Class: Admino::Table::HeadRow

Inherits:
Row
  • Object
show all
Defined in:
lib/admino/table/head_row.rb

Instance Attribute Summary collapse

Attributes inherited from Row

#view_context

Instance Method Summary collapse

Methods inherited from Row

#parse_action_args, #parse_column_args

Constructor Details

#initialize(resource_klass, query, view_context) ⇒ HeadRow

Returns a new instance of HeadRow.



10
11
12
13
14
15
16
# File 'lib/admino/table/head_row.rb', line 10

def initialize(resource_klass, query, view_context)
  @resource_klass = resource_klass
  @query = query
  @columns = ""

  super(view_context)
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



8
9
10
# File 'lib/admino/table/head_row.rb', line 8

def query
  @query
end

#resource_klassObject (readonly)

Returns the value of attribute resource_klass.



7
8
9
# File 'lib/admino/table/head_row.rb', line 7

def resource_klass
  @resource_klass
end

Instance Method Details

#actions(*args, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/admino/table/head_row.rb', line 18

def actions(*args, &block)
  default_options = column_html_options(:actions)
  label = I18n.t(
    :"#{resource_klass.model_name.i18n_key}.title",
    scope: 'table.actions',
    default: [
      :title,
      'Actions'
    ]
  )

  @columns << h.(:th, label.to_s, default_options)
end

#column(*args, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/admino/table/head_row.rb', line 32

def column(*args, &block)
  attribute_name, label, html_options = parse_column_args(args)

  if label.nil?
    label = column_label(attribute_name)
  elsif label.is_a? Symbol
    label = column_label(label)
  end

  html_options = complete_column_html_options(
    attribute_name,
    html_options
  )

  sorting_scope = html_options.delete(:sorting)
  sorting_html_options = html_options.delete(:sorting_html_options) { {} }

  if sorting_scope
    raise ArgumentError, 'query object is required' unless query
    label = query.sorting.scope_link(sorting_scope, label, sorting_html_options)
  end

  @columns << h.(:th, label.to_s, html_options)
end

#to_htmlObject



57
58
59
# File 'lib/admino/table/head_row.rb', line 57

def to_html
  @columns.html_safe
end