Class: Avo::Tab

Inherits:
Object
  • Object
show all
Includes:
Concerns::IsResourceItem, Concerns::VisibleItems, Fields::FieldExtensions::VisibleInDifferentViews
Defined in:
lib/avo/tab.rb

Instance Attribute Summary collapse

Attributes included from Fields::FieldExtensions::VisibleInDifferentViews

#show_on_edit, #show_on_index, #show_on_new, #show_on_show

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/avo/tab.rb', line 11

def description
  @description
end

#holds_one_fieldObject

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_holderObject

Returns the value of attribute items_holder.



12
13
14
# File 'lib/avo/tab.rb', line 12

def items_holder
  @items_holder
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/avo/tab.rb', line 9

def name
  @name
end

#viewObject (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

Returns:

  • (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

Returns:

  • (Boolean)


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