Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared/Raw/RawCsvExportModal.razor
T
Joseph Doherty 0f1f8ad8fa fix(adminui): lane D-b review r0 fixes (I1, M1, M2, M5-M9, N1-N3, N5, H3)
I1: /hosts eviction keyed off the AUTHORED DriverInstances, so a driver
deleted in /raw but not yet deployed - still running, still publishing -
vanished every tick. The stores' sweep is now EvictUnconfiguredStale(set,
olderThanUtc): an entry goes only when unconfigured AND its PublishedUtc is
older than 60 s. Tests cover unconfigured+fresh kept (positive control),
unconfigured+stale evicted, configured+stale kept, and the deploy hand-off.

M1: Test Connect falls back to the driver's documented ProbeTimeoutSeconds
default (Galaxy 30, OpcUaClient 15, ...) when the key is absent.
M2: the budget never undercuts the config's root timeoutMs (+1 s).
M5: RawBrowseModal compares the open generation captured before the await,
so a close-then-reopen mid-open closes the stale session.
M6: /alarms-historian keeps a 30 s re-poll on 'not registered' (a driver
node may still be starting) instead of stopping for good.
M7: /scripts source fetch failure shows in the dialog, not the error boundary.
M8: the export modal maps only its preview rows; the endpoint writes via
Results.Text (no second byte[] copy).
M9: /hosts config queries are ordered, so SequenceEqual change detection holds.
N1 tooltip, N2 CRLF-safe regex, N3 throttled Warning for subscriber faults,
N5 equipment-import help text now describes RFC 4180 quoting.
H3: MonacoEditor documents that themes are page-global.

Refs #745
Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
2026-10-22 18:21:46 -04:00

159 lines
6.6 KiB
Plaintext

@* CSV tag export for a Raw-tree Device / TagGroup (B2-WP5).
Reads the device's tags (via the WP5-owned RawTagCsvExportReader — no IRawTreeService extension) and
renders them in the same column shape RawCsvImportModal consumes (T0-2 CsvWriter, per-driver
CsvColumnMap). The download is a plain same-origin link to GET /api/raw/tags.csv (R04 P6) — the
file used to be embedded in the circuit twice (textarea + base64 data: URI); the modal now shows only
a bounded preview of the first RawTagCsvExport.PreviewLines lines.
Modal contract (the RawTree coordinator wires this in place of the OnExportCsv stub):
<RawCsvExportModal @bind-Visible="_exportVisible"
DeviceId="@_exportDeviceId" (may be blank if TagGroupId is supplied)
TagGroupId="@_exportTagGroupId" (when set, only that group's subtree is exported)
DriverType="@_exportDriverType" /> *@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Uns
@inject RawTagCsvExportReader ExportReader
@if (Visible)
{
<div class="modal-backdrop fade show" style="display:block"></div>
<div class="modal fade show" tabindex="-1" role="dialog" style="display:block">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Export tags — CSV</h5>
<button type="button" class="btn-close" aria-label="Close" @onclick="Close"></button>
</div>
<div class="modal-body">
@if (_loading)
{
<p class="text-muted"><span class="spinner-border spinner-border-sm"></span> Reading tags…</p>
}
else if (_error is not null)
{
<div class="alert alert-danger">@_error</div>
}
else
{
<p class="text-muted">
<span class="badge bg-secondary">@_rowCount tags</span>
for <span class="mono">@DriverType</span> device
@if (!string.IsNullOrEmpty(_groupFilter))
{
<span>, group <span class="mono">@_groupFilter</span></span>
}
</p>
@if (_truncated)
{
<p class="small text-muted mb-1">Preview — first @RawTagCsvExport.PreviewLines lines. Download for the full file.</p>
}
<textarea class="form-control mono small" rows="10" readonly>@_preview</textarea>
}
</div>
<div class="modal-footer">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" @onclick="Close">Close</button>
@if (!_loading && _error is null)
{
<a class="btn btn-primary" download="@_fileName" href="@_downloadUrl">Download CSV</a>
}
</div>
</div>
</div>
</div>
</div>
}
@code {
/// <summary>Whether the modal is shown (two-way bound).</summary>
[Parameter] public bool Visible { get; set; }
/// <summary>Raised when <see cref="Visible"/> changes (supports <c>@bind-Visible</c>).</summary>
[Parameter] public EventCallback<bool> VisibleChanged { get; set; }
/// <summary>The device to export. May be blank when <see cref="TagGroupId"/> is supplied.</summary>
[Parameter] public string DeviceId { get; set; } = "";
/// <summary>When set, only tags under this group's subtree are exported; null exports the whole device.</summary>
[Parameter] public string? TagGroupId { get; set; }
/// <summary>The device's driver-type string — selects the per-driver typed column set.</summary>
[Parameter] public string DriverType { get; set; } = "";
private bool _loading;
private bool _built;
private string? _error;
private string _preview = "";
private bool _truncated;
private string _downloadUrl = "";
private string _fileName = "tags.csv";
private int _rowCount;
private string? _groupFilter;
// Bumped on every open and close so a superseded build can't install its CSV under another device's modal.
private int _openGeneration;
protected override async Task OnParametersSetAsync()
{
if (Visible && !_built)
{
_built = true;
await BuildAsync(++_openGeneration);
}
else if (!Visible)
{
_built = false;
_openGeneration++;
}
}
private bool IsStale(int generation) => generation != _openGeneration || !Visible;
private async Task BuildAsync(int generation)
{
_loading = true;
_error = null;
try
{
_groupFilter = null;
// The same builder the download endpoint runs, so the preview matches the file — but mapping only
// the preview's rows (the header takes the first line), never the whole export (review r0 M8).
var export = await RawTagCsvExport.BuildAsync(ExportReader, DeviceId, TagGroupId, DriverType,
maxRows: RawTagCsvExport.PreviewLines - 1);
if (IsStale(generation)) { return; }
if (export is null)
{
_error = "Could not resolve the target device.";
return;
}
_groupFilter = export.GroupPath;
_rowCount = export.RowCount;
_fileName = export.FileName;
// Only the bounded preview is kept on the component; the full CSV is not held by the circuit.
(_preview, var cut) = RawTagCsvExport.Preview(export.Csv);
_truncated = cut || export.RowCount > RawTagCsvExport.PreviewLines - 1;
_downloadUrl = RawTagCsvExport.DownloadUrl(DeviceId, TagGroupId, DriverType);
}
catch (Exception ex)
{
if (!IsStale(generation)) { _error = ex.Message; }
}
finally
{
if (!IsStale(generation)) { _loading = false; }
}
}
private async Task Close()
{
_built = false;
_openGeneration++;
_preview = "";
_truncated = false;
_downloadUrl = "";
Visible = false;
await VisibleChanged.InvokeAsync(false);
}
}