From 9d9f24a21d237aa36f046736019c546031d1f388 Mon Sep 17 00:00:00 2001 From: Masu Baumgartner Date: Sun, 8 Sep 2024 12:52:06 +0000 Subject: [PATCH] Improved node list status display. Started overview live status --- .../UI/Components/Partials/NodeOverview.razor | 86 ++++++++++++++++--- .../UI/Views/Admin/Nodes.razor | 2 +- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/MoonlightServers.Client/UI/Components/Partials/NodeOverview.razor b/MoonlightServers.Client/UI/Components/Partials/NodeOverview.razor index 4656be1..b524dbe 100644 --- a/MoonlightServers.Client/UI/Components/Partials/NodeOverview.razor +++ b/MoonlightServers.Client/UI/Components/Partials/NodeOverview.razor @@ -1,15 +1,81 @@ -
- - - - - - - - -
+@using MoonlightServers.Shared.Http.Responses.Admin.Nodes + +@implements IDisposable + +@inject HttpApiClient HttpApiClient + + +
+ @if (IsOffline) + { + + + } + else + { + var cpuUsage = Math.Round(Status.CpuUsage.Average(x => x), 2) + "%"; + var memoryUsage = $"{Formatter.FormatSize((long)(Status.MemoryTotal - Status.MemoryAvailable))} / {Formatter.FormatSize((long)Status.MemoryTotal)}"; + var uptime = Formatter.FormatUptime(Status.Uptime); + var diskUsage = $"{Formatter.FormatSize((long)Status.DiskFree)} / {Formatter.FormatSize((long)Status.DiskTotal)}"; + +
+ + + + + + + + +
+ } +
+
@code { [Parameter] public int NodeId { get; set; } + + private bool IsOffline = false; + private bool KeepRefreshing = true; + + private StatusNodeResponse Status; + + private async Task Load(LazyLoader arg) + { + await UpdateStatus(); + + Task.Run(async () => + { + while (KeepRefreshing) + { + await UpdateStatus(); + await InvokeAsync(StateHasChanged); + + await Task.Delay(TimeSpan.FromSeconds(1)); + } + }); + } + + private async Task UpdateStatus() + { + IsOffline = false; + + try + { + Status = await HttpApiClient.GetJson($"admin/servers/nodes/{NodeId}/status"); + } + catch (Exception) + { + IsOffline = true; + } + } + + public void Dispose() + { + KeepRefreshing = false; + } } \ No newline at end of file diff --git a/MoonlightServers.Client/UI/Views/Admin/Nodes.razor b/MoonlightServers.Client/UI/Views/Admin/Nodes.razor index acf37b5..298c6b3 100644 --- a/MoonlightServers.Client/UI/Views/Admin/Nodes.razor +++ b/MoonlightServers.Client/UI/Views/Admin/Nodes.razor @@ -51,7 +51,7 @@
- @(response.CpuUsage.Average(x => x))% + @(Math.Round(response.CpuUsage.Average(x => x), 2))%