@page "/robot-config" @rendermode InteractiveWebAssemblyNoPrerender @attribute [Authorize] @using RobotApp.Common.Shares.Dtos @using RobotApp.Common.Shares.Enums @inject HttpClient Http Robot Configuration
@switch (SelectedType) { case RobotConfigType.VDA5050: @RenderList(VdaConfigs, () => SelectVda) break; case RobotConfigType.Safety: @RenderList(SafetyConfigs, () => SelectSafety) break; case RobotConfigType.Simulation: @RenderList(SimulationConfigs, () => SelectSimulation) break; case RobotConfigType.PLC: @RenderList(PlcConfigs, () => SelectPlc) break; case RobotConfigType.Core: @RenderList(CoreConfigs, () => SelectCore) break; default:
No configs.
break; }
@if (!HasSelection) {
Select a config from the list or click Add to create one.
} else { @switch (SelectedType) { case RobotConfigType.VDA5050: break; case RobotConfigType.Safety: break; case RobotConfigType.Simulation: break; case RobotConfigType.PLC: break; case RobotConfigType.Core: break; } }
@code { private List VdaConfigs { get; } = []; private List SafetyConfigs { get; } = []; private List SimulationConfigs { get; } = []; private List PlcConfigs { get; } = []; private List CoreConfigs { get; } = []; private RobotVDA5050ConfigDto? SelectedVda { get; set; } private RobotSafetyConfigDto? SelectedSafety { get; set; } private RobotSimulationConfigDto? SelectedSimulation { get; set; } private RobotPlcConfigDto? SelectedPlc { get; set; } private RobotConfigDto? SelectedCore { get; set; } private RobotConfigType SelectedType { get; set; } = RobotConfigType.VDA5050; private int SelectedIndex { get; set; } = -1; private bool HasSelection => SelectedIndex >= 0; RenderFragment RenderList(List list, Func> selectFactory) where T : class { return builder => { if (list is null || !list.Any()) { builder.OpenElement(0, "div"); builder.AddAttribute(1, "class", "p-2 text-muted"); builder.AddContent(2, "No configs found."); builder.CloseElement(); return; } builder.OpenElement(3, "ul"); builder.AddAttribute(4, "class", "list-group list-group-flush"); for (int i = 0; i < list.Count; i++) { var item = list[i]; var idx = i; builder.OpenElement(10 + i * 5, "li"); builder.AddAttribute(11 + i * 5, "class", $"list-group-item {(SelectedIndex==idx ? "active" : "")}"); builder.AddAttribute(12 + i * 5, "style", "cursor:pointer;padding:0.75rem 1rem;"); builder.AddAttribute(13 + i * 5, "onclick", EventCallback.Factory.Create(this, () => selectFactory()(idx))); // Only show ConfigName var nameProp = item.GetType().GetProperty("ConfigName"); var name = nameProp?.GetValue(item)?.ToString() ?? "Unnamed"; builder.AddContent(14 + i * 5, name); // Show active badge at end if IsActive == true var isActiveProp = item.GetType().GetProperty("IsActive"); var isActive = isActiveProp?.GetValue(item) is bool b && b; if (isActive) { builder.OpenElement(15 + i * 5, "span"); builder.AddAttribute(16 + i * 5, "class", "badge bg-success ms-2 float-end"); builder.AddContent(17 + i * 5, "Active"); builder.CloseElement(); } builder.CloseElement(); } builder.CloseElement(); }; } private Action SelectVda => idx => { SelectedIndex = idx; SelectedVda = idx >= 0 && idx < VdaConfigs.Count ? VdaConfigs[idx] with { } : null; StateHasChanged(); }; private Action SelectSafety => idx => { SelectedIndex = idx; SelectedSafety = idx >= 0 && idx < SafetyConfigs.Count ? SafetyConfigs[idx] with { } : null; StateHasChanged(); }; private Action SelectSimulation => idx => { SelectedIndex = idx; SelectedSimulation = idx >= 0 && idx < SimulationConfigs.Count ? SimulationConfigs[idx] with { } : null; StateHasChanged(); }; private Action SelectPlc => idx => { SelectedIndex = idx; SelectedPlc = idx >= 0 && idx < PlcConfigs.Count ? PlcConfigs[idx] with { } : null; StateHasChanged(); }; private Action SelectCore => idx => { SelectedIndex = idx; SelectedCore = idx >= 0 && idx < CoreConfigs.Count ? CoreConfigs[idx] with { } : null; StateHasChanged(); }; }