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
-
#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
- #row(**args, &block) ⇒ Object
- #sidebar(**args, &block) ⇒ Object
- #tab(name, **args, &block) ⇒ Object
- #tabs(tab = nil, id: nil, name: nil, **kwargs, &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
75 76 77 78 79 |
# File 'lib/avo/resources/items/holder.rb', line 75 def add_item(instance) @items << instance increment_order_index 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 |
# 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) # 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: as, # resource: resource_class.name, message: "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>" }) 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.
65 66 67 |
# File 'lib/avo/resources/items/holder.rb', line 65 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
60 61 62 |
# File 'lib/avo/resources/items/holder.rb', line 60 def panel(panel_name = nil, **args, &block) add_item Avo::Resources::Items::ItemGroup::Builder.parse_block(name: panel_name, parent: @parent, **args, &block) end |
#row(**args, &block) ⇒ Object
52 53 54 |
# File 'lib/avo/resources/items/holder.rb', line 52 def row(**args, &block) add_item Avo::Resources::Items::Row::Builder.parse_block(parent: @parent, **args, &block) end |
#sidebar(**args, &block) ⇒ Object
69 70 71 72 73 |
# File 'lib/avo/resources/items/holder.rb', line 69 def (**args, &block) add_item Avo::Resources::Items::Sidebar::Builder.parse_block(parent: @parent, **args, &block) end |
#tab(name, **args, &block) ⇒ Object
48 49 50 |
# File 'lib/avo/resources/items/holder.rb', line 48 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, **kwargs, &block) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/avo/resources/items/holder.rb', line 40 def tabs(tab = nil, id: nil, name: nil, **kwargs, &block) if tab.present? add_item tab else add_item Avo::Resources::Items::TabGroup::Builder.parse_block(parent: @parent, id: id, name: name, **kwargs, &block) end end |
#tool(klass, **args) ⇒ Object
56 57 58 |
# File 'lib/avo/resources/items/holder.rb', line 56 def tool(klass, **args) add_item klass.new(**args, view: self.parent.view, parent: self.parent) end |