Class: Avo::Resources::Items::Holder
- Inherits:
-
Object
- Object
- Avo::Resources::Items::Holder
- Defined in:
- lib/avo/resources/items/holder.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#invalid_fields ⇒ Object
Returns the value of attribute invalid_fields.
-
#items ⇒ Object
Returns the value of attribute items.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #add_item(instance) ⇒ Object
- #cluster(**args, &block) ⇒ Object (also: #row)
-
#field(field_name, **args, &block) ⇒ Object
Adds a field to the items_holder.
-
#initialize(from: nil, parent: nil) ⇒ Holder
constructor
A new instance of Holder.
-
#main_panel(**args, &block) ⇒ Object
The main panel is the one that also render the header of the resource with the breadcrumbs, the title and the controls.
- #panel(panel_name = nil, **args, &block) ⇒ Object
- #sidebar(**args, &block) ⇒ Object
- #tab(name, **args, &block) ⇒ Object
- #tabs(tab = nil, id: nil, name: nil, title: nil, description: nil, **args, &block) ⇒ Object
- #tool(klass, **args) ⇒ Object
Constructor Details
#initialize(from: nil, parent: nil) ⇒ Holder
Returns a new instance of Holder.
6 7 8 9 10 11 12 |
# File 'lib/avo/resources/items/holder.rb', line 6 def initialize(from: nil, parent: nil) @items = [] @items_index = 0 @invalid_fields = [] @from = from @parent = parent end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
2 3 4 |
# File 'lib/avo/resources/items/holder.rb', line 2 def from @from end |
#invalid_fields ⇒ Object
Returns the value of attribute invalid_fields.
4 5 6 |
# File 'lib/avo/resources/items/holder.rb', line 4 def invalid_fields @invalid_fields end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/avo/resources/items/holder.rb', line 3 def items @items end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2 3 4 |
# File 'lib/avo/resources/items/holder.rb', line 2 def parent @parent end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
2 3 4 |
# File 'lib/avo/resources/items/holder.rb', line 2 def tools @tools end |
Instance Method Details
#add_item(instance) ⇒ Object
94 95 96 97 98 |
# File 'lib/avo/resources/items/holder.rb', line 94 def add_item(instance) @items << instance increment_order_index end |
#cluster(**args, &block) ⇒ Object Also known as: row
68 69 70 |
# File 'lib/avo/resources/items/holder.rb', line 68 def cluster(**args, &block) add_item Avo::Resources::Items::Row::Builder.parse_block(parent: @parent, **args, &block) end |
#field(field_name, **args, &block) ⇒ Object
Adds a field to the items_holder
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/avo/resources/items/holder.rb', line 15 def field(field_name, **args, &block) # If the field is paresed inside a tab group, add it to the tab # This will happen when the field is parsed inside a tab group from a resource method if from.present? && from.class == Avo::Resources::Items::TabGroup::Builder return from.field(field_name, holder: self, **args, &block) end field_parser = Avo::Dsl::FieldParser.new(id: field_name, order_index: @items_index, **args, &block).parse if field_parser.invalid? as = args.fetch(:as, nil) alert_type = :error = "There's an invalid field configuration for this resource. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as: :#{as}</code>" if as == :markdown alert_type = :warning = "In Avo 3.16.2 we renamed the <code>:markdown</code> field to <code>:easy_mde</code>. <br/><br/>You may continue to use that one or the new and improved one with Active Storage support. <br/><br/> Read more about it in the <a href=\"https://docs.avohq.io/3.0/fields/markdown.html\" target=\"_blank\">docs</a>." end # End execution ehre and add the field to the invalid_fileds payload so we know to wanr the developer about that. # @todo: Make sure this warning is still active return add_invalid_field({ name: field_name, as:, alert_type:, message: }) end add_item field_parser.instance end |
#main_panel(**args, &block) ⇒ Object
The main panel is the one that also render the header of the resource with the breadcrumbs, the title and the controls.
84 85 86 |
# File 'lib/avo/resources/items/holder.rb', line 84 def main_panel(**args, &block) add_item Avo::Resources::Items::MainPanel::Builder.parse_block(name: "main_panel", parent: @parent, **args, &block) end |
#panel(panel_name = nil, **args, &block) ⇒ Object
79 80 81 |
# File 'lib/avo/resources/items/holder.rb', line 79 def panel(panel_name = nil, **args, &block) add_item Avo::Resources::Items::ItemGroup::Builder.parse_block(name: panel_name, parent: @parent, **args, &block) end |
#sidebar(**args, &block) ⇒ Object
88 89 90 91 92 |
# File 'lib/avo/resources/items/holder.rb', line 88 def (**args, &block) add_item Avo::Resources::Items::Sidebar::Builder.parse_block(parent: @parent, **args, &block) end |
#tab(name, **args, &block) ⇒ Object
64 65 66 |
# File 'lib/avo/resources/items/holder.rb', line 64 def tab(name, **args, &block) add_item Avo::Resources::Items::Tab::Builder.parse_block(name: name, parent: @parent, **args, &block) end |
#tabs(tab = nil, id: nil, name: nil, title: nil, description: nil, **args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/avo/resources/items/holder.rb', line 48 def tabs(tab = nil, id: nil, name: nil, title: nil, description: nil, **args, &block) if tab.present? add_item tab else add_item Avo::Resources::Items::TabGroup::Builder.parse_block( parent: @parent, id: id, name: name, title: title, description: description, **args, &block ) end end |
#tool(klass, **args) ⇒ Object
75 76 77 |
# File 'lib/avo/resources/items/holder.rb', line 75 def tool(klass, **args) add_item klass.new(**args, view: self.parent.view, parent: self.parent) end |