Class: Avo::Tab
- Inherits:
-
Object
- Object
- Avo::Tab
- Includes:
- Concerns::IsResourceItem, Concerns::VisibleItems, Fields::FieldExtensions::VisibleInDifferentViews
- Defined in:
- lib/avo/tab.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#holds_one_field ⇒ Object
Returns the value of attribute holds_one_field.
-
#items_holder ⇒ Object
Returns the value of attribute items_holder.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Attributes included from Fields::FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #hydrate(view: nil) ⇒ Object
-
#initialize(name: nil, description: nil, view: nil, holds_one_field: false, **args) ⇒ Tab
constructor
A new instance of Tab.
- #turbo_frame_id(parent: nil) ⇒ Object
-
#visible_on?(view) ⇒ Boolean
Checks for visibility on itself or on theone field it holds.
Methods included from Fields::FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update
Methods included from Concerns::VisibleItems
#items, #visible, #visible?, #visible_items
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Constructor Details
#initialize(name: nil, description: nil, view: nil, holds_one_field: false, **args) ⇒ Tab
Returns a new instance of Tab.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/avo/tab.rb', line 15 def initialize(name: nil, description: nil, view: nil, holds_one_field: false, **args) # Initialize the visibility markers super @name = name @description = description @holds_one_field = holds_one_field @items_holder = Avo::ItemsHolder.new @view = view show_on args[:show_on] if args[:show_on].present? hide_on args[:hide_on] if args[:hide_on].present? only_on args[:only_on] if args[:only_on].present? except_on args[:except_on] if args[:except_on].present? end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
11 12 13 |
# File 'lib/avo/tab.rb', line 11 def description @description end |
#holds_one_field ⇒ Object
Returns the value of attribute holds_one_field.
13 14 15 |
# File 'lib/avo/tab.rb', line 13 def holds_one_field @holds_one_field end |
#items_holder ⇒ Object
Returns the value of attribute items_holder.
12 13 14 |
# File 'lib/avo/tab.rb', line 12 def items_holder @items_holder end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/avo/tab.rb', line 9 def name @name end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
10 11 12 |
# File 'lib/avo/tab.rb', line 10 def view @view end |
Instance Method Details
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/avo/tab.rb', line 49 def empty? visible_items.blank? end |
#hydrate(view: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/avo/tab.rb', line 31 def hydrate(view: nil) @view = view items_holder.items.grep(Avo::Panel).each do |panel| panel.hydrate(view: view) end self end |
#turbo_frame_id(parent: nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/avo/tab.rb', line 41 def turbo_frame_id(parent: nil) id = "#{Avo::Tab.to_s.parameterize} #{name}".parameterize return id if parent.nil? "#{parent.turbo_frame_id} #{id}".parameterize end |
#visible_on?(view) ⇒ Boolean
Checks for visibility on itself or on theone field it holds
54 55 56 57 58 59 60 |
# File 'lib/avo/tab.rb', line 54 def visible_on?(view) if holds_one_field super(view) && items.first.visible_on?(view) else super(view) end end |