namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Models { /// /// Represents a grid with potential child grids /// public class TestGridModel { public TestGridModel() { Id = Guid.NewGuid(); ChildGrids = new List(); Configuration = new GridConfiguration(); } // Identity public Guid Id { get; set; } public string GridName { get; set; } // View Component Information public string ViewComponentName { get; set; } public string ViewComponentLocation { get; set; } // Hierarchy public Guid? ParentGridId { get; set; } public int Level { get; set; } // 0 = top level, 1 = first nested, etc. public List ChildGrids { get; set; } // Grid Behavior Configuration public GridConfiguration Configuration { get; set; } // Data Context (optional - for passing entity IDs or filter params) public Dictionary DataContext { get; set; } } /// /// Configuration for grid rendering and behavior /// public class GridConfiguration { // Display Settings public bool ShowChildGridsAsTabs { get; set; } = true; public bool ShowChildGridsAsAccordion { get; set; } = false; public bool ShowChildGridsInline { get; set; } = false; // Rendering Options public string ChildGridContainerCssClass { get; set; } = "nested-grid-container"; public bool LazyLoadChildren { get; set; } = false; public bool CollapseByDefault { get; set; } = false; // Data Loading public string ChildDataEndpoint { get; set; } public bool RequiresParentRowSelection { get; set; } = false; // Metadata public string Description { get; set; } public int DisplayOrder { get; set; } } /// /// Builder class for easier model construction /// public class TestPageModelBuilder { private readonly TestPageModel _model; private readonly Dictionary _gridLookup; public TestPageModelBuilder() { _model = new TestPageModel(); _gridLookup = new Dictionary(); } public TestPageModelBuilder AddRootGrid(TestGridModel grid) { grid.Level = 0; grid.ParentGridId = null; _model.Grids.Add(grid); _gridLookup[grid.Id] = grid; return this; } public TestPageModelBuilder AddChildGrid(Guid parentId, TestGridModel childGrid) { if (_gridLookup.TryGetValue(parentId, out var parentGrid)) { childGrid.Level = parentGrid.Level + 1; childGrid.ParentGridId = parentId; parentGrid.ChildGrids.Add(childGrid); _gridLookup[childGrid.Id] = childGrid; } return this; } public TestPageModel Build() { return _model; } } /// /// Example usage helper /// public static class TestPageModelExample { public static TestPageModel CreateSampleModel() { var builder = new TestPageModelBuilder(); // Level 0 - Root Grids var customersGrid = new TestGridModel { GridName = "Customers", ViewComponentName = "CustomerGrid", Configuration = new GridConfiguration { RequiresParentRowSelection = false, Description = "Main customer list" } }; var ordersRootGrid = new TestGridModel { GridName = "All Orders", ViewComponentName = "OrderGrid" }; builder.AddRootGrid(customersGrid); builder.AddRootGrid(ordersRootGrid); // Level 1 - Child of Customers var customerOrdersGrid = new TestGridModel { GridName = "Customer Orders", ViewComponentName = "CustomerOrderGrid", Configuration = new GridConfiguration { RequiresParentRowSelection = true, ShowChildGridsAsTabs = true } }; var customerAddressesGrid = new TestGridModel { GridName = "Addresses", ViewComponentName = "CustomerAddressGrid" }; builder.AddChildGrid(customersGrid.Id, customerOrdersGrid); builder.AddChildGrid(customersGrid.Id, customerAddressesGrid); // Level 2 - Child of Customer Orders var orderItemsGrid = new TestGridModel { GridName = "Order Items", ViewComponentName = "OrderItemGrid", Configuration = new GridConfiguration { RequiresParentRowSelection = true } }; var orderShipmentsGrid = new TestGridModel { GridName = "Shipments", ViewComponentName = "OrderShipmentGrid" }; builder.AddChildGrid(customerOrdersGrid.Id, orderItemsGrid); builder.AddChildGrid(customerOrdersGrid.Id, orderShipmentsGrid); // Level 3 - Child of Order Items var itemAttributesGrid = new TestGridModel { GridName = "Item Attributes", ViewComponentName = "ItemAttributeGrid" }; builder.AddChildGrid(orderItemsGrid.Id, itemAttributesGrid); return builder.Build(); } } }