feat(ui): add primary/backup endpoint fields to data connection form
This commit is contained in:
@@ -55,10 +55,43 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="form-label small">Configuration (JSON)</label>
|
<label class="form-label small">Primary Endpoint Configuration</label>
|
||||||
<input type="text" class="form-control form-control-sm" @bind="_formConfiguration"
|
<input type="text" class="form-control form-control-sm" @bind="_formConfiguration"
|
||||||
placeholder='e.g. {"endpoint":"opc.tcp://..."}' />
|
placeholder='e.g. {"endpoint":"opc.tcp://..."}' />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if (!_showBackup)
|
||||||
|
{
|
||||||
|
<div class="mb-3">
|
||||||
|
<button type="button" class="btn btn-outline-secondary btn-sm"
|
||||||
|
@onclick="() => _showBackup = true">
|
||||||
|
Add Backup Endpoint
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
||||||
|
<label class="form-label small mb-0">Backup Endpoint Configuration</label>
|
||||||
|
<button type="button" class="btn btn-outline-danger btn-sm"
|
||||||
|
@onclick="RemoveBackup">
|
||||||
|
Remove Backup
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<textarea class="form-control form-control-sm" rows="4"
|
||||||
|
@bind="_formBackupConfiguration"
|
||||||
|
placeholder='{"Host": "backup-host", "Port": 50101}' />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label small">Failover Retry Count</label>
|
||||||
|
<input type="number" class="form-control form-control-sm" style="max-width: 120px;"
|
||||||
|
min="1" max="20"
|
||||||
|
@bind="_formFailoverRetryCount" />
|
||||||
|
<div class="form-text">Retries on active endpoint before switching to backup (default: 3)</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@if (_formError != null)
|
@if (_formError != null)
|
||||||
{
|
{
|
||||||
<div class="text-danger small mt-2">@_formError</div>
|
<div class="text-danger small mt-2">@_formError</div>
|
||||||
@@ -83,6 +116,9 @@
|
|||||||
private string _formName = string.Empty;
|
private string _formName = string.Empty;
|
||||||
private string _formProtocol = string.Empty;
|
private string _formProtocol = string.Empty;
|
||||||
private string? _formConfiguration;
|
private string? _formConfiguration;
|
||||||
|
private bool _showBackup;
|
||||||
|
private string? _formBackupConfiguration;
|
||||||
|
private int _formFailoverRetryCount = 3;
|
||||||
private string? _formError;
|
private string? _formError;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
@@ -101,6 +137,9 @@
|
|||||||
_formName = _editingConnection.Name;
|
_formName = _editingConnection.Name;
|
||||||
_formProtocol = _editingConnection.Protocol;
|
_formProtocol = _editingConnection.Protocol;
|
||||||
_formConfiguration = _editingConnection.PrimaryConfiguration;
|
_formConfiguration = _editingConnection.PrimaryConfiguration;
|
||||||
|
_formBackupConfiguration = _editingConnection.BackupConfiguration;
|
||||||
|
_formFailoverRetryCount = _editingConnection.FailoverRetryCount;
|
||||||
|
_showBackup = _editingConnection.BackupConfiguration != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -125,13 +164,17 @@
|
|||||||
_editingConnection.Name = _formName.Trim();
|
_editingConnection.Name = _formName.Trim();
|
||||||
_editingConnection.Protocol = _formProtocol;
|
_editingConnection.Protocol = _formProtocol;
|
||||||
_editingConnection.PrimaryConfiguration = _formConfiguration?.Trim();
|
_editingConnection.PrimaryConfiguration = _formConfiguration?.Trim();
|
||||||
|
_editingConnection.BackupConfiguration = _showBackup ? _formBackupConfiguration?.Trim() : null;
|
||||||
|
_editingConnection.FailoverRetryCount = _showBackup ? _formFailoverRetryCount : 3;
|
||||||
await SiteRepository.UpdateDataConnectionAsync(_editingConnection);
|
await SiteRepository.UpdateDataConnectionAsync(_editingConnection);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var conn = new DataConnection(_formName.Trim(), _formProtocol, _formSiteId)
|
var conn = new DataConnection(_formName.Trim(), _formProtocol, _formSiteId)
|
||||||
{
|
{
|
||||||
PrimaryConfiguration = _formConfiguration?.Trim()
|
PrimaryConfiguration = _formConfiguration?.Trim(),
|
||||||
|
BackupConfiguration = _showBackup ? _formBackupConfiguration?.Trim() : null,
|
||||||
|
FailoverRetryCount = _showBackup ? _formFailoverRetryCount : 3
|
||||||
};
|
};
|
||||||
await SiteRepository.AddDataConnectionAsync(conn);
|
await SiteRepository.AddDataConnectionAsync(conn);
|
||||||
}
|
}
|
||||||
@@ -144,6 +187,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RemoveBackup()
|
||||||
|
{
|
||||||
|
_showBackup = false;
|
||||||
|
_formBackupConfiguration = null;
|
||||||
|
_formFailoverRetryCount = 3;
|
||||||
|
}
|
||||||
|
|
||||||
private void GoBack()
|
private void GoBack()
|
||||||
{
|
{
|
||||||
NavigationManager.NavigateTo("/admin/data-connections");
|
NavigationManager.NavigateTo("/admin/data-connections");
|
||||||
|
|||||||
@@ -32,7 +32,8 @@
|
|||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Protocol</th>
|
<th>Protocol</th>
|
||||||
<th>Site</th>
|
<th>Site</th>
|
||||||
<th>Configuration</th>
|
<th>Primary Config</th>
|
||||||
|
<th>Backup Config</th>
|
||||||
<th style="width: 160px;">Actions</th>
|
<th style="width: 160px;">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -40,7 +41,7 @@
|
|||||||
@if (_connections.Count == 0)
|
@if (_connections.Count == 0)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-muted text-center">No data connections configured.</td>
|
<td colspan="7" class="text-muted text-center">No data connections configured.</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@foreach (var conn in _connections)
|
@foreach (var conn in _connections)
|
||||||
@@ -51,6 +52,7 @@
|
|||||||
<td><span class="badge bg-secondary">@conn.Protocol</span></td>
|
<td><span class="badge bg-secondary">@conn.Protocol</span></td>
|
||||||
<td>@(_siteLookup.GetValueOrDefault(conn.SiteId)?.Name ?? $"Site {conn.SiteId}")</td>
|
<td>@(_siteLookup.GetValueOrDefault(conn.SiteId)?.Name ?? $"Site {conn.SiteId}")</td>
|
||||||
<td class="text-muted small text-truncate" style="max-width: 300px;">@(conn.PrimaryConfiguration ?? "—")</td>
|
<td class="text-muted small text-truncate" style="max-width: 300px;">@(conn.PrimaryConfiguration ?? "—")</td>
|
||||||
|
<td class="text-muted small text-truncate" style="max-width: 300px;">@(conn.BackupConfiguration ?? "—")</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-outline-primary btn-sm py-0 px-1 me-1"
|
<button class="btn btn-outline-primary btn-sm py-0 px-1 me-1"
|
||||||
@onclick='() => NavigationManager.NavigateTo($"/admin/data-connections/{conn.Id}/edit")'>Edit</button>
|
@onclick='() => NavigationManager.NavigateTo($"/admin/data-connections/{conn.Id}/edit")'>Edit</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user