55e8bf70d9
Falls back to legacy DriverEdit until Phase 4 populates the type-map.
69 lines
2.8 KiB
Plaintext
69 lines
2.8 KiB
Plaintext
@* Dispatch page: reads DriverInstance.DriverType and renders the matching typed editor
|
|
via <DynamicComponent>. Falls back to the legacy DriverEdit for any type not yet in
|
|
the map. The route collides with DriverEdit.razor's identical directive — that's
|
|
intentional. Task 3.4 removes the route from DriverEdit.razor. Blazor route conflicts
|
|
are runtime, not build-time, so the build succeeds now. *@
|
|
@page "/clusters/{ClusterId}/drivers/{DriverInstanceId}"
|
|
@attribute [Microsoft.AspNetCore.Authorization.Authorize]
|
|
@rendermode RenderMode.InteractiveServer
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
|
@inject IDbContextFactory<OtOpcUaConfigDbContext> DbFactory
|
|
|
|
@if (!_loaded)
|
|
{
|
|
<p>Loading…</p>
|
|
}
|
|
else if (_existing is null)
|
|
{
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h4 class="mb-0">Edit driver instance · <span class="mono">@ClusterId</span></h4>
|
|
<a href="/clusters/@ClusterId/drivers" class="btn btn-outline-secondary btn-sm">Cancel</a>
|
|
</div>
|
|
<ClusterNav ClusterId="@ClusterId" ActiveTab="drivers" />
|
|
<section class="panel notice rise" style="animation-delay:.02s">
|
|
Driver instance <span class="mono">@DriverInstanceId</span> was not found in cluster <span class="mono">@ClusterId</span>.
|
|
</section>
|
|
}
|
|
else
|
|
{
|
|
<DynamicComponent Type="ResolveComponentType()" Parameters="BuildParameters()" />
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string ClusterId { get; set; } = "";
|
|
[Parameter] public string DriverInstanceId { get; set; } = "";
|
|
|
|
private DriverInstance? _existing;
|
|
private bool _loaded;
|
|
|
|
private static readonly IReadOnlyDictionary<string, Type> _componentMap =
|
|
new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
// Populated by Phase 4 — until then, all driver types fall back to DriverEdit.
|
|
// Keys must match DriverInstance.DriverType strings:
|
|
// ModbusTcp, AbCip, AbLegacy, S7, TwinCat, Focas, OpcUaClient, Galaxy, Historian.Wonderware
|
|
};
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await using var db = await DbFactory.CreateDbContextAsync();
|
|
_existing = await db.DriverInstances.AsNoTracking()
|
|
.FirstOrDefaultAsync(d => d.ClusterId == ClusterId && d.DriverInstanceId == DriverInstanceId);
|
|
_loaded = true;
|
|
}
|
|
|
|
private Type ResolveComponentType()
|
|
=> _componentMap.TryGetValue(_existing!.DriverType, out var t)
|
|
? t
|
|
: typeof(ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.DriverEdit);
|
|
|
|
private IDictionary<string, object> BuildParameters()
|
|
=> new Dictionary<string, object>
|
|
{
|
|
["ClusterId"] = ClusterId,
|
|
["DriverInstanceId"] = DriverInstanceId,
|
|
};
|
|
}
|