Class: Avo::Fields::IndexComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
ResourcesHelper
Defined in:
app/components/avo/fields/index_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table

Methods inherited from BaseComponent

#has_with_trial

Constructor Details

#initialize(field: nil, resource: nil, reflection: nil, index: 0, parent_record: nil, parent_resource: nil, **kwargs) ⇒ IndexComponent

Returns a new instance of IndexComponent.



11
12
13
14
15
16
17
18
19
20
# File 'app/components/avo/fields/index_component.rb', line 11

def initialize(field: nil, resource: nil, reflection: nil, index: 0, parent_record: nil, parent_resource: nil, **kwargs)
  @field = field
  @resource = resource
  @index = index
  @kwargs = kwargs
  @parent_record = parent_record
  @parent_resource = parent_resource
  @view = Avo::ViewInquirer.new("index")
  @reflection = reflection
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'app/components/avo/fields/index_component.rb', line 6

def field
  @field
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



7
8
9
# File 'app/components/avo/fields/index_component.rb', line 7

def kwargs
  @kwargs
end

#parent_resourceObject (readonly)

Returns the value of attribute parent_resource.



8
9
10
# File 'app/components/avo/fields/index_component.rb', line 8

def parent_resource
  @parent_resource
end

#viewObject (readonly)

Returns the value of attribute view.



9
10
11
# File 'app/components/avo/fields/index_component.rb', line 9

def view
  @view
end

Instance Method Details

#field_wrapper_argsObject



35
36
37
38
39
40
# File 'app/components/avo/fields/index_component.rb', line 35

def field_wrapper_args
  {
    field: @field,
    resource: @resource
  }
end

#resource_view_pathObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/avo/fields/index_component.rb', line 22

def resource_view_path
  args = {}

  if @parent_record.present?
    args = {
      via_resource_class: @parent_resource.class,
      via_record_id: @parent_record.to_param
    }
  end

  helpers.resource_view_path(record: @resource.record, resource: parent_or_child_resource, **args)
end