Class: Avo::ItemSwitcherComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Turbo::FramesHelper
Defined in:
app/components/avo/item_switcher_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#has_with_trial

Constructor Details

#initialize(resource: nil, reflection: nil, item: nil, index: nil, view: nil, form: nil) ⇒ ItemSwitcherComponent

Returns a new instance of ItemSwitcherComponent.



12
13
14
15
16
17
18
19
# File 'app/components/avo/item_switcher_component.rb', line 12

def initialize(resource: nil, reflection: nil, item: nil, index: nil, view: nil, form: nil)
  @resource = resource
  @reflection = reflection
  @form = form
  @index = index
  @item = item
  @view = view
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#itemObject (readonly)

Returns the value of attribute item.



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

def item
  @item
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



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

def reflection
  @reflection
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#viewObject (readonly)

Returns the value of attribute view.



10
11
12
# File 'app/components/avo/item_switcher_component.rb', line 10

def view
  @view
end

Instance Method Details

#field_componentObject



44
45
46
47
# File 'app/components/avo/item_switcher_component.rb', line 44

def field_component
  final_item = item.dup.hydrate(resource: @resource, record: @resource.record, user: resource.user, view: view)
  final_item.component_for_view(@view).new(field: final_item, resource: @resource, index: index, form: form)
end

#formObject



21
22
23
# File 'app/components/avo/item_switcher_component.rb', line 21

def form
  @form || nil
end

#in_reflection?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/components/avo/item_switcher_component.rb', line 36

def in_reflection?
  @reflection.present?
end

#render?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'app/components/avo/item_switcher_component.rb', line 25

def render?
  # Stops rendering if the field should be hidden in reflections
  if item.is_field?
    return false if in_reflection? && item.hidden_in_reflection?
  end

  return false if item.is_main_panel?

  true
end

#tab_group_componentObject



40
41
42
# File 'app/components/avo/item_switcher_component.rb', line 40

def tab_group_component
  Avo::TabGroupComponent.new resource: @resource, group: item.hydrate(view: view), index: index, params: params, form: form, view: view
end