refactor(adminui): drive DriverEdit.razor through shared section components
No functional change — the identity, resilience, and save-bar are now each in their own reusable component so the typed driver pages (Phase 4) can share them. The middle "Driver config (JSON)" panel stays inlined for now — it's replaced wholesale by typed forms in Phase 4.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
@using ZB.MOM.WW.OtOpcUa.Configuration
|
@using ZB.MOM.WW.OtOpcUa.Configuration
|
||||||
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
||||||
|
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers
|
||||||
@inject IDbContextFactory<OtOpcUaConfigDbContext> DbFactory
|
@inject IDbContextFactory<OtOpcUaConfigDbContext> DbFactory
|
||||||
@inject NavigationManager Nav
|
@inject NavigationManager Nav
|
||||||
|
|
||||||
@@ -35,97 +36,24 @@ else
|
|||||||
{
|
{
|
||||||
<EditForm Model="_form" OnValidSubmit="SubmitAsync" FormName="driverEdit">
|
<EditForm Model="_form" OnValidSubmit="SubmitAsync" FormName="driverEdit">
|
||||||
<DataAnnotationsValidator />
|
<DataAnnotationsValidator />
|
||||||
<section class="panel rise" style="animation-delay:.02s">
|
<DriverFormShell IsNew="IsNew" Busy="_busy" Error="_error"
|
||||||
<div class="panel-head">@(IsNew ? "Identity" : $"Edit {_form.DriverInstanceId}")</div>
|
CancelHref="@($"/clusters/{ClusterId}/drivers")"
|
||||||
<div style="padding:1rem">
|
OnDelete="@(IsNew ? null : (EventCallback?)EventCallback.Factory.Create(this, DeleteAsync))">
|
||||||
<div class="row">
|
<DriverIdentitySection Model="_identityModel" Namespaces="_namespaces" IsNew="IsNew" ShowDriverType="true" />
|
||||||
<div class="col-md-6 mb-3">
|
|
||||||
<label class="form-label" for="instId">DriverInstanceId</label>
|
@* Driver config (JSON) — inlined; will be replaced by typed forms in Phase 4 *@
|
||||||
<InputText id="instId" @bind-Value="_form.DriverInstanceId" disabled="@(!IsNew)"
|
<section class="panel rise mt-3" style="animation-delay:.08s">
|
||||||
|
<div class="panel-head">Driver config (JSON)</div>
|
||||||
|
<div style="padding:1rem">
|
||||||
|
<InputTextArea @bind-Value="_form.DriverConfig" rows="12"
|
||||||
class="form-control form-control-sm mono"
|
class="form-control form-control-sm mono"
|
||||||
placeholder="drv-modbus-line3-01" />
|
placeholder='{ "endpoint": "10.0.0.42:502", "slaveId": 1 }' />
|
||||||
</div>
|
<div class="form-text">Schemaless per driver type — validated server-side at deploy time. JSON is reformatted on save.</div>
|
||||||
<div class="col-md-6 mb-3">
|
|
||||||
<label class="form-label" for="name">Display name</label>
|
|
||||||
<InputText id="name" @bind-Value="_form.Name" class="form-control form-control-sm"
|
|
||||||
placeholder="Line 3 Modbus" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
</section>
|
||||||
<div class="col-md-6 mb-3">
|
|
||||||
<label class="form-label" for="dtype">Driver type</label>
|
|
||||||
<InputSelect id="dtype" @bind-Value="_form.DriverType" disabled="@(!IsNew)"
|
|
||||||
class="form-select form-select-sm">
|
|
||||||
<option value="ModbusTcp">ModbusTcp</option>
|
|
||||||
<option value="AbCip">AbCip</option>
|
|
||||||
<option value="AbLegacy">AbLegacy</option>
|
|
||||||
<option value="S7">S7</option>
|
|
||||||
<option value="TwinCat">TwinCat</option>
|
|
||||||
<option value="Focas">Focas</option>
|
|
||||||
<option value="OpcUaClient">OpcUaClient</option>
|
|
||||||
<option value="Galaxy">Galaxy</option>
|
|
||||||
<option value="Historian.Wonderware">Historian.Wonderware</option>
|
|
||||||
</InputSelect>
|
|
||||||
<div class="form-text">Cannot be changed after creation — drives the actor type that owns this instance.</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-6 mb-3">
|
|
||||||
<label class="form-label" for="ns">Namespace</label>
|
|
||||||
<InputSelect id="ns" @bind-Value="_form.NamespaceId" class="form-select form-select-sm">
|
|
||||||
@foreach (var ns in _namespaces)
|
|
||||||
{
|
|
||||||
<option value="@ns.NamespaceId">@ns.NamespaceId (@ns.Kind)</option>
|
|
||||||
}
|
|
||||||
</InputSelect>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label" for="enabled">Enabled</label>
|
|
||||||
<div class="form-check form-switch">
|
|
||||||
<InputCheckbox id="enabled" @bind-Value="_form.Enabled" class="form-check-input" />
|
|
||||||
<label class="form-check-label" for="enabled">Spawn this driver in deployments</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="panel rise mt-3" style="animation-delay:.08s">
|
<DriverResilienceSection @bind-ResilienceConfig="_form.ResilienceConfig" />
|
||||||
<div class="panel-head">Driver config (JSON)</div>
|
</DriverFormShell>
|
||||||
<div style="padding:1rem">
|
|
||||||
<InputTextArea @bind-Value="_form.DriverConfig" rows="12"
|
|
||||||
class="form-control form-control-sm mono"
|
|
||||||
placeholder='{ "endpoint": "10.0.0.42:502", "slaveId": 1 }' />
|
|
||||||
<div class="form-text">Schemaless per driver type — validated server-side at deploy time. JSON is reformatted on save.</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="panel rise mt-3" style="animation-delay:.14s">
|
|
||||||
<div class="panel-head">Resilience overrides (optional)</div>
|
|
||||||
<div style="padding:1rem">
|
|
||||||
<InputTextArea @bind-Value="_form.ResilienceConfig" rows="6"
|
|
||||||
class="form-control form-control-sm mono"
|
|
||||||
placeholder='Leave blank to use tier defaults' />
|
|
||||||
<div class="form-text">Polly pipeline overrides per docs/v2/driver-stability.md — bulkhead, retry counts, breaker thresholds. Null = use the driver type's tier defaults.</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
@if (!string.IsNullOrWhiteSpace(_error))
|
|
||||||
{
|
|
||||||
<div class="panel notice mt-3" style="border-color:var(--alert)">@_error</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
<div class="mt-3 d-flex gap-2">
|
|
||||||
<button type="submit" class="btn btn-primary" disabled="@_busy">
|
|
||||||
@if (_busy) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
|
||||||
@(IsNew ? "Create" : "Save changes")
|
|
||||||
</button>
|
|
||||||
<a href="/clusters/@ClusterId/drivers" class="btn btn-outline-secondary">Cancel</a>
|
|
||||||
@if (!IsNew)
|
|
||||||
{
|
|
||||||
<button type="button" class="btn btn-outline-danger ms-auto" @onclick="DeleteAsync" disabled="@_busy">
|
|
||||||
Delete
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</EditForm>
|
</EditForm>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +63,7 @@ else
|
|||||||
|
|
||||||
private bool IsNew => string.IsNullOrEmpty(DriverInstanceId);
|
private bool IsNew => string.IsNullOrEmpty(DriverInstanceId);
|
||||||
|
|
||||||
|
private DriverIdentitySection.DriverIdentityModel _identityModel = new();
|
||||||
private FormModel _form = new();
|
private FormModel _form = new();
|
||||||
private DriverInstance? _existing;
|
private DriverInstance? _existing;
|
||||||
private List<Namespace> _namespaces = new();
|
private List<Namespace> _namespaces = new();
|
||||||
@@ -152,13 +81,16 @@ else
|
|||||||
|
|
||||||
if (IsNew)
|
if (IsNew)
|
||||||
{
|
{
|
||||||
_form = new FormModel
|
_identityModel = new DriverIdentitySection.DriverIdentityModel
|
||||||
{
|
{
|
||||||
DriverInstanceId = "",
|
DriverInstanceId = "",
|
||||||
Name = "",
|
Name = "",
|
||||||
DriverType = "ModbusTcp",
|
DriverType = "ModbusTcp",
|
||||||
NamespaceId = _namespaces.FirstOrDefault()?.NamespaceId ?? "",
|
NamespaceId = _namespaces.FirstOrDefault()?.NamespaceId ?? "",
|
||||||
Enabled = true,
|
Enabled = true,
|
||||||
|
};
|
||||||
|
_form = new FormModel
|
||||||
|
{
|
||||||
DriverConfig = "{}",
|
DriverConfig = "{}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -168,13 +100,16 @@ else
|
|||||||
.FirstOrDefaultAsync(d => d.ClusterId == ClusterId && d.DriverInstanceId == DriverInstanceId);
|
.FirstOrDefaultAsync(d => d.ClusterId == ClusterId && d.DriverInstanceId == DriverInstanceId);
|
||||||
if (_existing is not null)
|
if (_existing is not null)
|
||||||
{
|
{
|
||||||
_form = new FormModel
|
_identityModel = new DriverIdentitySection.DriverIdentityModel
|
||||||
{
|
{
|
||||||
DriverInstanceId = _existing.DriverInstanceId,
|
DriverInstanceId = _existing.DriverInstanceId,
|
||||||
Name = _existing.Name,
|
Name = _existing.Name,
|
||||||
DriverType = _existing.DriverType,
|
DriverType = _existing.DriverType,
|
||||||
NamespaceId = _existing.NamespaceId,
|
NamespaceId = _existing.NamespaceId,
|
||||||
Enabled = _existing.Enabled,
|
Enabled = _existing.Enabled,
|
||||||
|
};
|
||||||
|
_form = new FormModel
|
||||||
|
{
|
||||||
DriverConfig = _existing.DriverConfig,
|
DriverConfig = _existing.DriverConfig,
|
||||||
ResilienceConfig = _existing.ResilienceConfig,
|
ResilienceConfig = _existing.ResilienceConfig,
|
||||||
RowVersion = _existing.RowVersion,
|
RowVersion = _existing.RowVersion,
|
||||||
@@ -206,19 +141,19 @@ else
|
|||||||
await using var db = await DbFactory.CreateDbContextAsync();
|
await using var db = await DbFactory.CreateDbContextAsync();
|
||||||
if (IsNew)
|
if (IsNew)
|
||||||
{
|
{
|
||||||
if (await db.DriverInstances.AnyAsync(d => d.DriverInstanceId == _form.DriverInstanceId))
|
if (await db.DriverInstances.AnyAsync(d => d.DriverInstanceId == _identityModel.DriverInstanceId))
|
||||||
{
|
{
|
||||||
_error = $"Driver instance '{_form.DriverInstanceId}' already exists.";
|
_error = $"Driver instance '{_identityModel.DriverInstanceId}' already exists.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db.DriverInstances.Add(new DriverInstance
|
db.DriverInstances.Add(new DriverInstance
|
||||||
{
|
{
|
||||||
DriverInstanceId = _form.DriverInstanceId,
|
DriverInstanceId = _identityModel.DriverInstanceId,
|
||||||
ClusterId = ClusterId,
|
ClusterId = ClusterId,
|
||||||
NamespaceId = _form.NamespaceId,
|
NamespaceId = _identityModel.NamespaceId,
|
||||||
Name = _form.Name,
|
Name = _identityModel.Name,
|
||||||
DriverType = _form.DriverType,
|
DriverType = _identityModel.DriverType,
|
||||||
Enabled = _form.Enabled,
|
Enabled = _identityModel.Enabled,
|
||||||
DriverConfig = normalizedConfig,
|
DriverConfig = normalizedConfig,
|
||||||
ResilienceConfig = normalizedResilience,
|
ResilienceConfig = normalizedResilience,
|
||||||
});
|
});
|
||||||
@@ -233,9 +168,9 @@ else
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db.Entry(entity).Property(e => e.RowVersion).OriginalValue = _form.RowVersion;
|
db.Entry(entity).Property(e => e.RowVersion).OriginalValue = _form.RowVersion;
|
||||||
entity.NamespaceId = _form.NamespaceId;
|
entity.NamespaceId = _identityModel.NamespaceId;
|
||||||
entity.Name = _form.Name;
|
entity.Name = _identityModel.Name;
|
||||||
entity.Enabled = _form.Enabled;
|
entity.Enabled = _identityModel.Enabled;
|
||||||
entity.DriverConfig = normalizedConfig;
|
entity.DriverConfig = normalizedConfig;
|
||||||
entity.ResilienceConfig = normalizedResilience;
|
entity.ResilienceConfig = normalizedResilience;
|
||||||
}
|
}
|
||||||
@@ -306,15 +241,6 @@ else
|
|||||||
|
|
||||||
private sealed class FormModel
|
private sealed class FormModel
|
||||||
{
|
{
|
||||||
[Required, RegularExpression("^[A-Za-z0-9_-]+$", ErrorMessage = "Use letters, digits, dash, underscore.")]
|
|
||||||
public string DriverInstanceId { get; set; } = "";
|
|
||||||
[Required]
|
|
||||||
public string Name { get; set; } = "";
|
|
||||||
[Required]
|
|
||||||
public string DriverType { get; set; } = "ModbusTcp";
|
|
||||||
[Required]
|
|
||||||
public string NamespaceId { get; set; } = "";
|
|
||||||
public bool Enabled { get; set; } = true;
|
|
||||||
[Required]
|
[Required]
|
||||||
public string DriverConfig { get; set; } = "{}";
|
public string DriverConfig { get; set; } = "{}";
|
||||||
public string? ResilienceConfig { get; set; }
|
public string? ResilienceConfig { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user