Class: Avo::ItemSwitcherComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::ItemSwitcherComponent
- Includes:
- Turbo::FramesHelper
- Defined in:
- app/components/avo/item_switcher_component.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #field_component ⇒ Object
- #form ⇒ Object
- #in_reflection? ⇒ Boolean
-
#initialize(resource: nil, reflection: nil, item: nil, index: nil, view: nil, form: nil) ⇒ ItemSwitcherComponent
constructor
A new instance of ItemSwitcherComponent.
- #render? ⇒ Boolean
- #tab_group_component ⇒ Object
Methods inherited from BaseComponent
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'app/components/avo/item_switcher_component.rb', line 8 def index @index end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
9 10 11 |
# File 'app/components/avo/item_switcher_component.rb', line 9 def item @item end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
7 8 9 |
# File 'app/components/avo/item_switcher_component.rb', line 7 def reflection @reflection end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'app/components/avo/item_switcher_component.rb', line 6 def resource @resource end |
#view ⇒ Object (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_component ⇒ Object
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 |
#form ⇒ Object
21 22 23 |
# File 'app/components/avo/item_switcher_component.rb', line 21 def form @form || nil end |
#in_reflection? ⇒ Boolean
36 37 38 |
# File 'app/components/avo/item_switcher_component.rb', line 36 def in_reflection? @reflection.present? end |
#render? ⇒ 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_component ⇒ Object
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 |