Class: Avo::Sidebar
- Inherits:
-
Object
- Object
- Avo::Sidebar
- Defined in:
- lib/avo/sidebar.rb
Defined Under Namespace
Classes: BaseItemComponent, GroupComponent, HeadingComponent, ItemSwitcherComponent, LinkComponent, SectionComponent
Instance Attribute Summary collapse
-
#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, view: nil, **args) ⇒ Sidebar
constructor
A new instance of Sidebar.
- #items ⇒ Object
- #not_visible_field(item) ⇒ Object
- #visible_items ⇒ Object
Methods included from Fields::FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update, #visible_on?
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, view: nil, **args) ⇒ Sidebar
Returns a new instance of Sidebar.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/avo/sidebar.rb', line 12 def initialize(name: nil, view: nil, **args) # Initialize the visibility markers super @name = name @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
#items_holder ⇒ Object
Returns the value of attribute items_holder.
10 11 12 |
# File 'lib/avo/sidebar.rb', line 10 def items_holder @items_holder end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/avo/sidebar.rb', line 8 def name @name end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
9 10 11 |
# File 'lib/avo/sidebar.rb', line 9 def view @view end |
Instance Method Details
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/avo/sidebar.rb', line 32 def empty? visible_items.blank? end |
#hydrate(view: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/avo/sidebar.rb', line 26 def hydrate(view: nil) @view = view self end |
#items ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/avo/sidebar.rb', line 36 def items if self.items_holder.present? self.items_holder.items else [] end end |
#not_visible_field(item) ⇒ Object
57 58 59 |
# File 'lib/avo/sidebar.rb', line 57 def not_visible_field(item) item.is_field? && !item.visible_on?(view) end |
#visible_items ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/avo/sidebar.rb', line 44 def visible_items items.map do |item| # Remove the fields that shouldn't be visible in this view # eg: has_many fields on edit if not_visible_field(item) nil else item end end .compact end |