update
This commit is contained in:
@@ -2,18 +2,20 @@
|
||||
@rendermode InteractiveWebAssemblyNoPrerender
|
||||
@attribute [Authorize]
|
||||
|
||||
@using RobotApp.Common.Shares.Dtos
|
||||
@using RobotApp.Common.Shares.Enums
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
@using System.Net.Http.Json
|
||||
@using RobotApp.Common.Shares.Dtos
|
||||
|
||||
<PageTitle>Robot Configuration</PageTitle>
|
||||
|
||||
<div class="d-flex w-100 h-100 p-2 overflow-hidden flex-column">
|
||||
<div class="d-flex w-100 h-100 p-2 overflow-hidden flex-column position-relative">
|
||||
<div class="rcm-toolbar">
|
||||
<div class="rcm-toolbar-left">
|
||||
<label class="rcm-label" for="configType">Config Type</label>
|
||||
<div class="rcm-select-wrapper">
|
||||
<select id="configType" class="form-select rcm-select" @bind="SelectedType">
|
||||
<select id="configType" class="form-select rcm-select" value="@SelectedType" @onchange="OnTypeChanged">
|
||||
@foreach (var type in Enum.GetValues<RobotConfigType>())
|
||||
{
|
||||
<option value="@type">@type</option>
|
||||
@@ -21,7 +23,7 @@
|
||||
</select>
|
||||
<span class="rcm-select-icon" aria-hidden="true">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<path d="M7 10l5 5 5-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M7 10l5 5 5-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
@@ -29,15 +31,15 @@
|
||||
|
||||
<div class="rcm-toolbar-right">
|
||||
<div class="rcm-action-group">
|
||||
<button type="button" class="btn rcm-icon-btn" data-tooltip="Add config" aria-label="Add">
|
||||
<button type="button" class="btn rcm-icon-btn" data-tooltip="Add config" aria-label="Add" @onclick="OpenAddConfig">
|
||||
<i class="mdi mdi-plus" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn rcm-icon-btn" data-tooltip="Update config" aria-label="Update">
|
||||
<button type="button" class="btn rcm-icon-btn" data-tooltip="Update config" aria-label="Update" @onclick="SaveConfig">
|
||||
<i class="mdi mdi-content-save" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn rcm-icon-btn rcm-danger" data-tooltip="Delete config" aria-label="Delete">
|
||||
<button type="button" class="btn rcm-icon-btn rcm-danger" data-tooltip="Delete config" aria-label="Delete" @onclick="DeleteConfig">
|
||||
<i class="mdi mdi-delete" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -49,19 +51,19 @@
|
||||
@switch (SelectedType)
|
||||
{
|
||||
case RobotConfigType.VDA5050:
|
||||
@RenderList(VdaConfigs, () => SelectVda)
|
||||
@RenderList(VdaConfigs, SelectVda, v => v.ConfigName, v => v.IsActive)
|
||||
break;
|
||||
case RobotConfigType.Safety:
|
||||
@RenderList(SafetyConfigs, () => SelectSafety)
|
||||
@RenderList(SafetyConfigs, SelectSafety, s => s.ConfigName, s => s.IsActive)
|
||||
break;
|
||||
case RobotConfigType.Simulation:
|
||||
@RenderList(SimulationConfigs, () => SelectSimulation)
|
||||
@RenderList(SimulationConfigs, SelectSimulation, s => s.ConfigName, s => s.IsActive)
|
||||
break;
|
||||
case RobotConfigType.PLC:
|
||||
@RenderList(PlcConfigs, () => SelectPlc)
|
||||
@RenderList(PlcConfigs, SelectPlc, p => p.ConfigName, p => p.IsActive)
|
||||
break;
|
||||
case RobotConfigType.Core:
|
||||
@RenderList(CoreConfigs, () => SelectCore)
|
||||
@RenderList(CoreConfigs, SelectCore, c => c.ConfigName, c => c.IsActive)
|
||||
break;
|
||||
default:
|
||||
<div class="p-2">No configs.</div>
|
||||
@@ -100,14 +102,93 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (IsLoading)
|
||||
{
|
||||
<div class="rcm-overlay" role="status" aria-live="polite" aria-busy="true">
|
||||
<div class="rcm-overlay-content" aria-hidden="false">
|
||||
<div class="spinner-border text-light" role="status" aria-hidden="true"></div>
|
||||
<div class="rcm-overlay-message ms-2">Loading…</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (IsAddingNew)
|
||||
{
|
||||
<div class="rcm-modal-overlay" role="dialog" aria-modal="true">
|
||||
<div class="rcm-modal">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<strong>Create @SelectedType Config</strong>
|
||||
<button class="btn btn-sm btn-link text-muted" @onclick="CloseAddDialog" aria-label="Close">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<EditForm Model="addForm" OnValidSubmit="SaveNewConfigAsync">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Config name</label>
|
||||
<InputText class="form-control" @bind-Value="addForm.ConfigName" />
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Description</label>
|
||||
<InputText class="form-control" @bind-Value="addForm.Description" />
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Copy parameters from existing (@SelectedType)</label>
|
||||
<select class="form-select" @bind="SelectedTemplateIdString">
|
||||
@foreach (var t in GetTemplatesForSelectedType())
|
||||
{
|
||||
<option value="@t.Id">@t.Name</option>
|
||||
}
|
||||
</select>
|
||||
<div class="form-text">If you choose an existing config, its parameter fields will be copied into the new config; you can still change name/description.</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-end gap-2 mt-3">
|
||||
<button type="button" class="btn btn-outline-secondary" @onclick="CloseAddDialog">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Create</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (ShowDeleteConfirm)
|
||||
{
|
||||
<div class="rcm-modal-overlay" role="dialog" aria-modal="true">
|
||||
<div class="rcm-modal">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<strong>Confirm Delete</strong>
|
||||
<button class="btn btn-sm btn-link text-muted" @onclick="CancelDelete" aria-label="Close">✕</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>Are you sure you want to delete configuration "<strong>@DeletePendingName</strong>"?</p>
|
||||
<div class="d-flex justify-content-end gap-2 mt-3">
|
||||
<button class="btn btn-outline-secondary" @onclick="CancelDelete">Cancel</button>
|
||||
<button class="btn btn-danger" @onclick="ConfirmDeleteAsync">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<RobotVDA5050ConfigDto> VdaConfigs { get; } = [];
|
||||
private List<RobotSafetyConfigDto> SafetyConfigs { get; } = [];
|
||||
private List<RobotSimulationConfigDto> SimulationConfigs { get; } = [];
|
||||
private List<RobotPlcConfigDto> PlcConfigs { get; } = [];
|
||||
private List<RobotConfigDto> CoreConfigs { get; } = [];
|
||||
private List<RobotVDA5050ConfigDto> VdaConfigs { get; set; } = new();
|
||||
private List<RobotSafetyConfigDto> SafetyConfigs { get; set; } = new();
|
||||
private List<RobotSimulationConfigDto> SimulationConfigs { get; set; } = new();
|
||||
private List<RobotPlcConfigDto> PlcConfigs { get; set; } = new();
|
||||
private List<RobotConfigDto> CoreConfigs { get; set; } = new();
|
||||
|
||||
private RobotVDA5050ConfigDto? SelectedVda { get; set; }
|
||||
private RobotSafetyConfigDto? SelectedSafety { get; set; }
|
||||
@@ -115,13 +196,96 @@
|
||||
private RobotPlcConfigDto? SelectedPlc { get; set; }
|
||||
private RobotConfigDto? SelectedCore { get; set; }
|
||||
|
||||
private RobotConfigType SelectedType { get; set; } = RobotConfigType.VDA5050;
|
||||
private CreateRobotVDA5050ConfigDto CreateVda = new();
|
||||
private CreateRobotConfigDto CreateSafety = new();
|
||||
private CreateRobotSafetyConfigDto CreateSimulation = new();
|
||||
private CreateRobotSimulationConfigDto CreatePlc = new();
|
||||
private CreateRobotPlcConfigDto CreateCore = new();
|
||||
|
||||
private int SelectedIndex { get; set; } = -1;
|
||||
private RobotConfigType SelectedType = RobotConfigType.VDA5050;
|
||||
|
||||
private int SelectedIndex = -1;
|
||||
private bool HasSelection => SelectedIndex >= 0;
|
||||
private bool IsLoading = false;
|
||||
private bool IsAddingNew = false;
|
||||
|
||||
RenderFragment RenderList<T>(List<T> list, Func<Action<int>> selectFactory) where T : class
|
||||
private bool ShowDeleteConfirm = false;
|
||||
private Guid? DeletePendingId;
|
||||
private string DeletePendingName = string.Empty;
|
||||
|
||||
private class AddFormModel
|
||||
{
|
||||
public string ConfigName { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
}
|
||||
private AddFormModel addForm = new();
|
||||
|
||||
private string SelectedTemplateIdString = string.Empty;
|
||||
|
||||
private IEnumerable<(Guid Id, string Name, bool Active)> GetTemplatesForSelectedType()
|
||||
{
|
||||
return SelectedType switch
|
||||
{
|
||||
RobotConfigType.VDA5050 => VdaConfigs.Select(x => (x.Id, x.ConfigName ?? string.Empty, x.IsActive)),
|
||||
RobotConfigType.Safety => SafetyConfigs.Select(x => (x.Id, x.ConfigName ?? string.Empty, x.IsActive)),
|
||||
RobotConfigType.Simulation => SimulationConfigs.Select(x => (x.Id, x.ConfigName ?? string.Empty, x.IsActive)),
|
||||
RobotConfigType.PLC => PlcConfigs.Select(x => (x.Id, x.ConfigName ?? string.Empty, x.IsActive)),
|
||||
RobotConfigType.Core => CoreConfigs.Select(x => (x.Id, x.ConfigName ?? string.Empty, x.IsActive)),
|
||||
_ => [],
|
||||
};
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
await LoadForTypeAsync(SelectedType);
|
||||
}
|
||||
|
||||
private async Task OnTypeChanged(ChangeEventArgs e)
|
||||
{
|
||||
if (e?.Value is null) return;
|
||||
if (!Enum.TryParse<RobotConfigType>(e.Value.ToString(), out var newType)) return;
|
||||
if (newType == SelectedType) return;
|
||||
|
||||
SelectedType = newType;
|
||||
await LoadForTypeAsync(newType);
|
||||
}
|
||||
|
||||
private async Task LoadForTypeAsync(RobotConfigType type)
|
||||
{
|
||||
IsLoading = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case RobotConfigType.VDA5050:
|
||||
await LoadVDA5050Configs();
|
||||
break;
|
||||
case RobotConfigType.Safety:
|
||||
await LoadRobotSafetyConfigs();
|
||||
break;
|
||||
case RobotConfigType.Simulation:
|
||||
await LoadRobotSimulationConfigs();
|
||||
break;
|
||||
case RobotConfigType.PLC:
|
||||
await LoadRobotPlcConfigs();
|
||||
break;
|
||||
case RobotConfigType.Core:
|
||||
await LoadRobotConfigs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
RenderFragment RenderList<T>(List<T> list, Action<int> onSelect, Func<T, string> nameSelector, Func<T, bool>? isActiveSelector = null) where T : class
|
||||
{
|
||||
return builder =>
|
||||
{
|
||||
@@ -141,31 +305,47 @@
|
||||
{
|
||||
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)));
|
||||
builder.OpenElement(10 + i * 6, "li");
|
||||
builder.AddAttribute(11 + i * 6, "class", $"list-group-item {(SelectedIndex == idx ? "active" : "")}");
|
||||
builder.AddAttribute(12 + i * 6, "style", "cursor:pointer;padding:0.75rem 1rem;");
|
||||
builder.AddAttribute(13 + i * 6, "onclick", EventCallback.Factory.Create(this, () => onSelect(idx)));
|
||||
|
||||
// Only show ConfigName
|
||||
var nameProp = item.GetType().GetProperty("ConfigName");
|
||||
var name = nameProp?.GetValue(item)?.ToString() ?? "Unnamed";
|
||||
builder.AddContent(14 + i * 5, name);
|
||||
string name;
|
||||
try
|
||||
{
|
||||
name = nameSelector(item) ?? "Unnamed";
|
||||
}
|
||||
catch
|
||||
{
|
||||
name = "Unnamed";
|
||||
}
|
||||
builder.AddContent(14 + i * 6, name);
|
||||
|
||||
bool isActive = false;
|
||||
if (isActiveSelector is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
isActive = isActiveSelector(item);
|
||||
}
|
||||
catch
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.OpenElement(15 + i * 6, "span");
|
||||
builder.AddAttribute(16 + i * 6, "class", "badge bg-success ms-2 float-end");
|
||||
builder.AddContent(17 + i * 6, "Active");
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -204,5 +384,47 @@
|
||||
StateHasChanged();
|
||||
};
|
||||
|
||||
private void OpenAddConfig()
|
||||
{
|
||||
addForm = new AddFormModel();
|
||||
var model = GetTemplatesForSelectedType();
|
||||
var modelActive = model.Where(x => x.Active).ToList();
|
||||
SelectedTemplateIdString = modelActive.Count > 0 ? modelActive.First().Id.ToString() : model.Any() ? model.First().Id.ToString() : string.Empty;
|
||||
IsAddingNew = true;
|
||||
}
|
||||
|
||||
private void CloseAddDialog()
|
||||
{
|
||||
IsAddingNew = false;
|
||||
}
|
||||
|
||||
private void DeleteConfig()
|
||||
{
|
||||
var tuple = SelectedType switch
|
||||
{
|
||||
RobotConfigType.VDA5050 => (Id: SelectedVda?.Id, Name: SelectedVda?.ConfigName),
|
||||
RobotConfigType.Safety => (Id: SelectedSafety?.Id, Name: SelectedSafety?.ConfigName),
|
||||
RobotConfigType.Simulation => (Id: SelectedSimulation?.Id, Name: SelectedSimulation?.ConfigName),
|
||||
RobotConfigType.PLC => (Id: SelectedPlc?.Id, Name: SelectedPlc?.ConfigName),
|
||||
RobotConfigType.Core => (Id: SelectedCore?.Id, Name: SelectedCore?.ConfigName),
|
||||
_ => (Id: (Guid?)null, Name: (string?)null)
|
||||
};
|
||||
|
||||
if (tuple.Id is null || tuple.Id == Guid.Empty)
|
||||
{
|
||||
Snackbar.Add("No config selected to delete.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
DeletePendingId = tuple.Id;
|
||||
DeletePendingName = tuple.Name ?? string.Empty;
|
||||
ShowDeleteConfirm = true;
|
||||
}
|
||||
|
||||
private void CancelDelete()
|
||||
{
|
||||
ShowDeleteConfirm = false;
|
||||
DeletePendingId = null;
|
||||
DeletePendingName = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user