Class: Jav::ItemSwitcherComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Turbo::FramesHelper
Defined in:
app/components/jav/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.



8
9
10
11
12
13
14
15
16
# File 'app/components/jav/item_switcher_component.rb', line 8

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#itemObject (readonly)

Returns the value of attribute item.



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

def item
  @item
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



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

def reflection
  @reflection
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#field_componentObject



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

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

#formObject



18
19
20
# File 'app/components/jav/item_switcher_component.rb', line 18

def form
  @form || nil
end

#in_reflection?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/components/jav/item_switcher_component.rb', line 31

def in_reflection?
  @reflection.present?
end

#render?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'app/components/jav/item_switcher_component.rb', line 22

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

  return false if item.is_main_panel?

  true
end

#tab_group_componentObject



35
36
37
# File 'app/components/jav/item_switcher_component.rb', line 35

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