Class: ActiveElement::Components::ItemTable

Inherits:
Object
  • Object
show all
Includes:
LinkHelpers, SecretFields
Defined in:
lib/active_element/components/item_table.rb

Overview

A table component for rendering the fields of a single object horizontally.

Constant Summary

Constants included from SecretFields

SecretFields::SECRET_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SecretFields

#secret_field?

Constructor Details

#initialize(controller, item:, fields:, class_name: nil, model_name: nil, edit: false, new: false, destroy: false, style: nil, row_class: nil, title: nil, **_kwargs) ⇒ ItemTable

Returns a new instance of ItemTable.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_element/components/item_table.rb', line 12

def initialize(controller, item:, fields:, class_name: nil, model_name: nil,
               edit: false, new: false, destroy: false, style: nil, row_class: nil, title: nil, **_kwargs)
  @controller = controller
  @class_name = class_name
  @model_name = model_name
  @item = item
  @fields = fields
  @destroy = destroy
  @edit = edit
  @new = new
  @style = style
  @row_class = row_class
  @title = title
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



10
11
12
# File 'lib/active_element/components/item_table.rb', line 10

def controller
  @controller
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



10
11
12
# File 'lib/active_element/components/item_table.rb', line 10

def model_name
  @model_name
end

Instance Method Details

#localsObject

rubocop:disable Metrics/MethodLength



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_element/components/item_table.rb', line 31

def locals # rubocop:disable Metrics/MethodLength
  {
    component: self,
    class_name: class_name,
    item: item,
    fields: Util::FieldMapping.new(self, fields, class_name).mapped_fields,
    destroy: destroy,
    edit: edit,
    new: new,
    style: style,
    row_class_mapper: row_class_mapper,
    title: title
  }
end

#modelObject



46
47
48
# File 'lib/active_element/components/item_table.rb', line 46

def model
  item.class.is_a?(ActiveModel::Naming) ? item.class : nil
end

#templateObject



27
28
29
# File 'lib/active_element/components/item_table.rb', line 27

def template
  'active_element/components/table/item'
end