diff --git a/MoonlightServers.Client/UI/Views/Admin/Nodes.razor b/MoonlightServers.Client/UI/Views/Admin/Nodes.razor index 6e7e5c9..acf37b5 100644 --- a/MoonlightServers.Client/UI/Views/Admin/Nodes.razor +++ b/MoonlightServers.Client/UI/Views/Admin/Nodes.razor @@ -19,24 +19,81 @@ TUpdateForm="UpdateNodeRequest" OnConfigure="OnConfigure"> - + - + + + + - + - + - + @@ -45,10 +102,51 @@ @code { + private readonly Dictionary StatusCache = new(); + private void OnConfigure(CrudOptions options) { options.Loader = async (page, pageSize) => - await HttpApiClient.GetJson>($"admin/servers/nodes?page={page}&pageSize={pageSize}"); + { + var response = await HttpApiClient + .GetJson>($"admin/servers/nodes?page={page}&pageSize={pageSize}"); + + lock (StatusCache) + StatusCache.Clear(); + + Task.Run(async () => + { + foreach (var node in response.Items) + { + try + { + var status = await HttpApiClient.GetJson($"admin/servers/nodes/{node.Id}/status"); + + lock (StatusCache) + { + StatusCache.Add(node.Id, new() + { + Response = status + }); + } + } + catch (Exception e) + { + lock (StatusCache) + { + StatusCache.Add(node.Id, new() + { + Exception = e + }); + } + } + + await InvokeAsync(StateHasChanged); + } + }); + + return response; + }; options.CreateFunction = async request => await HttpApiClient.Post("admin/servers/nodes", request); options.UpdateFunction = async (request, item) => await HttpApiClient.Patch($"admin/servers/nodes/{item.Id}", request); @@ -57,24 +155,24 @@ options.ShowCreateAsModal = false; options.ShowUpdateAsModal = false; options.ShowDetailsAsModal = false; - + options.OnConfigureCreate = option => { option .DefaultPage .DefaultSection .AddProperty(x => x.Name); - + option .DefaultPage .DefaultSection .AddProperty(x => x.Fqdn); - + option .DefaultPage .DefaultSection .AddProperty(x => x.ApiPort); - + option .DefaultPage .DefaultSection @@ -104,4 +202,10 @@ .AddProperty(x => x.SslEnabled); }; } -} + + class NodeFetchState + { + public StatusNodeResponse? Response { get; set; } + public Exception? Exception { get; set; } + } +} \ No newline at end of file