diff --git a/src/ScadaLink.CentralUI/Components/Pages/Admin/DataConnections.razor b/src/ScadaLink.CentralUI/Components/Pages/Admin/DataConnections.razor
index 3417a62..6e07fa0 100644
--- a/src/ScadaLink.CentralUI/Components/Pages/Admin/DataConnections.razor
+++ b/src/ScadaLink.CentralUI/Components/Pages/Admin/DataConnections.razor
@@ -25,50 +25,51 @@
}
else
{
-
-
-
- | ID |
- Name |
- Protocol |
- Site |
- Primary Config |
- Backup Config |
- Actions |
-
-
-
- @if (_connections.Count == 0)
+
+
+ @if (node.Kind == DcNodeKind.Site)
{
-
- | No data connections configured. |
-
+ @node.Label
+ @node.Children.Count
}
- @foreach (var conn in _connections)
+ else
{
-
- | @conn.Id |
- @conn.Name |
- @conn.Protocol |
- @(_siteLookup.GetValueOrDefault(conn.SiteId)?.Name ?? $"Site {conn.SiteId}") |
- @(conn.PrimaryConfiguration ?? "—") |
- @(conn.BackupConfiguration ?? "—") |
-
-
-
- |
-
+ @node.Label
+ @node.Connection!.Protocol
}
-
-
+
+
+ @if (node.Kind == DcNodeKind.DataConnection)
+ {
+
+
+
+ }
+
+
+ No data connections configured.
+
+
}
@code {
+ record DcTreeNode(string Key, string Label, DcNodeKind Kind, List Children,
+ DataConnection? Connection = null);
+ enum DcNodeKind { Site, DataConnection }
+
+ private List _treeRoots = new();
private List _connections = new();
- private Dictionary _siteLookup = new();
private bool _loading = true;
private string? _errorMessage;
@@ -87,8 +88,22 @@
try
{
var sites = await SiteRepository.GetAllSitesAsync();
- _siteLookup = sites.ToDictionary(s => s.Id);
_connections = (await SiteRepository.GetAllDataConnectionsAsync()).ToList();
+
+ var connBySite = _connections.GroupBy(c => c.SiteId).ToDictionary(g => g.Key, g => g.ToList());
+ _treeRoots = sites.Select(site => new DcTreeNode(
+ Key: $"site-{site.Id}",
+ Label: site.Name,
+ Kind: DcNodeKind.Site,
+ Children: (connBySite.GetValueOrDefault(site.Id) ?? new())
+ .Select(c => new DcTreeNode(
+ Key: $"conn-{c.Id}",
+ Label: c.Name,
+ Kind: DcNodeKind.DataConnection,
+ Children: new(),
+ Connection: c))
+ .ToList()
+ )).ToList();
}
catch (Exception ex)
{