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_model: nil, parent_resource: nil) ⇒ IndexComponent

Returns a new instance of IndexComponent.



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

def initialize(field: nil, resource: nil, reflection: nil, index: 0, parent_model: nil, parent_resource: nil)
  @field = field
  @resource = resource
  @index = index
  @parent_model = parent_model
  @parent_resource = parent_resource
  @view = :index
  @reflection = reflection
end

Instance Attribute Details

#parent_resourceObject (readonly)

Returns the value of attribute parent_resource.



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

def parent_resource
  @parent_resource
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#field_wrapper_argsObject



32
33
34
35
36
37
# File 'app/components/avo/fields/index_component.rb', line 32

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

#resource_view_pathObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/avo/fields/index_component.rb', line 19

def resource_view_path
  args = {}

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

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