Class: Avo::Tab
- Inherits:
-
Object
- Object
- Avo::Tab
- 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.
- #items ⇒ Object
- #turbo_frame_id(parent: nil) ⇒ Object
- #visible_items ⇒ 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::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/avo/tab.rb', line 14 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.
10 11 12 |
# File 'lib/avo/tab.rb', line 10 def description @description end |
#holds_one_field ⇒ Object
Returns the value of attribute holds_one_field.
12 13 14 |
# File 'lib/avo/tab.rb', line 12 def holds_one_field @holds_one_field end |
#items_holder ⇒ Object
Returns the value of attribute items_holder.
11 12 13 |
# File 'lib/avo/tab.rb', line 11 def items_holder @items_holder end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/avo/tab.rb', line 8 def name @name end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
9 10 11 |
# File 'lib/avo/tab.rb', line 9 def view @view end |
Instance Method Details
#empty? ⇒ Boolean
44 45 46 |
# File 'lib/avo/tab.rb', line 44 def empty? visible_items.blank? end |
#hydrate(view: nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/avo/tab.rb', line 30 def hydrate(view: nil) @view = view self end |
#items ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/avo/tab.rb', line 57 def items if self.items_holder.present? self.items_holder.items else [] end end |
#turbo_frame_id(parent: nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/avo/tab.rb', line 36 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_items ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/avo/tab.rb', line 65 def visible_items items.map do |item| if item.is_field? visible = item.visible_on?(view) # Remove the fields that shouldn't be visible in this view # eg: has_many fields on edit item = nil unless visible end item end .compact end |
#visible_on?(view) ⇒ Boolean
Checks for visibility on itself or on theone field it holds
49 50 51 52 53 54 55 |
# File 'lib/avo/tab.rb', line 49 def visible_on?(view) if holds_one_field super(view) && items.first.visible_on?(view) else super(view) end end |