From 29874a22bddf634fe3cbab186bb98a77c8f08413 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 4 Apr 2023 16:27:54 +0200 Subject: [PATCH] Added server node status screen check thingy --- Moonlight/Shared/Views/Server/Index.razor | 246 ++++++++++-------- Moonlight/resources/lang/de_de.lang | 4 + .../wwwroot/assets/media/svg/serverdown.svg | 1 + 3 files changed, 147 insertions(+), 104 deletions(-) create mode 100644 Moonlight/wwwroot/assets/media/svg/serverdown.svg diff --git a/Moonlight/Shared/Views/Server/Index.razor b/Moonlight/Shared/Views/Server/Index.razor index a6a6567d..eccbd3f9 100644 --- a/Moonlight/Shared/Views/Server/Index.razor +++ b/Moonlight/Shared/Views/Server/Index.razor @@ -17,6 +17,7 @@ @inject ServerRepository ServerRepository @inject WingsConsoleHelper WingsConsoleHelper @inject MessageService MessageService +@inject NodeService NodeService @inject NavigationManager NavigationManager @implements IDisposable @@ -26,10 +27,12 @@ {
- Not found image + Not found image
-

Server not found

-

+

+ Server not found +

+

A server with that id cannot be found or you have no access for this server

@@ -38,107 +41,126 @@ } else { - if (Console.ConnectionState == ConnectionState.Connected) + if (NodeOnline) { - if (Console.ServerState == ServerState.Installing) + if (Console.ConnectionState == ConnectionState.Connected) { -
-
-
-
- - Server installation is currently running - + if (Console.ServerState == ServerState.Installing) + { +
+
+
+
+ + Server installation is currently running + +
+
-
-
- } - else if (CurrentServer.Installing) - { -
-
-
-
- - Server installation is currently running - + } + else if (CurrentServer.Installing) + { +
+
+
+
+ + Server installation is currently running + +
+
-
-
- } - else - { - - - - - - - @{ - var index = 0; + } + else + { + + + + + + + @{ + var index = 0; - switch (Route) - { - case "files": - index = 1; - break; - case "backups": - index = 2; - break; - case "network": - index = 3; - break; - case "addons": - index = 4; - break; - case "settings": - index = 5; - break; - default: - index = 0; - break; + switch (Route) + { + case "files": + index = 1; + break; + case "backups": + index = 2; + break; + case "network": + index = 3; + break; + case "addons": + index = 4; + break; + case "settings": + index = 5; + break; + default: + index = 0; + break; + } } - } - - @switch (Route) - { - case "files": - - break; - case "backups": - - break; - case "network": - - break; - case "addons": - - break; - case "settings": - - break; - default: - - break; - } - + + @switch (Route) + { + case "files": + + break; + case "backups": + + break; + case "network": + + break; + case "addons": + + break; + case "settings": + + break; + default: + + break; + } + + - + } + } + else + { +
+ Connecting +
} } else { -
- Connecting +
+
+ Not found image +
+

+ Node offline +

+

+ The node the server is running on is currently offline +

+
+
} } @@ -149,7 +171,7 @@ [Parameter] public string ServerUuid { get; set; } - + [CascadingParameter] public User User { get; set; } @@ -159,6 +181,7 @@ private PteroConsole? Console; private Server? CurrentServer; private Node Node; + private bool NodeOnline = false; private Image Image; private NodeAllocation NodeAllocation; private string[] Tags; @@ -205,7 +228,7 @@ .Include(x => x.Owner) .First(x => x.Uuid == uuid); - if (CurrentServer.Owner.Id != User!.Id && User.Admin) + if (CurrentServer.Owner.Id != User!.Id && !User.Admin) CurrentServer = null; } catch (Exception) @@ -215,28 +238,43 @@ if (CurrentServer != null) { - await lazyLoader.SetText("Requesting tags"); + await lazyLoader.SetText("Checking node online status"); - var image = ImageRepository - .Get() - .First(x => x.Id == CurrentServer.Image.Id); - - Tags = JsonConvert.DeserializeObject(image.TagsJson) ?? Array.Empty(); - Image = image; - - await lazyLoader.SetText("Connecting to console"); - - await WingsConsoleHelper.ConnectWings(Console!, CurrentServer); - - MessageService.Subscribe($"server.{CurrentServer.Uuid}.installcomplete", this, server => + try { - Task.Run(() => + //TODO: Implement status caching + var data = await NodeService.GetStatus(CurrentServer.Node); + + if (data != null) + NodeOnline = true; + } + catch (Exception) + { + // ignored + } + + if (NodeOnline) + { + await lazyLoader.SetText("Requesting tags"); + + var image = ImageRepository + .Get() + .First(x => x.Id == CurrentServer.Image.Id); + + Tags = JsonConvert.DeserializeObject(image.TagsJson) ?? Array.Empty(); + Image = image; + + await lazyLoader.SetText("Connecting to console"); + + await WingsConsoleHelper.ConnectWings(Console!, CurrentServer); + + MessageService.Subscribe($"server.{CurrentServer.Uuid}.installcomplete", this, server => { - NavigationManager.NavigateTo(NavigationManager.Uri); + Task.Run(() => { NavigationManager.NavigateTo(NavigationManager.Uri); }); + + return Task.CompletedTask; }); - - return Task.CompletedTask; - }); + } } else { diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 8e6714e3..429e88a1 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -478,3 +478,7 @@ Enter your information;Enter your information You need to enter your full name in order to use moonlight;You need to enter your full name in order to use moonlight No node found;No node found No node found to deploy to found;No node found to deploy to found +Node offline;Node offline +The node the server is running on is currently offline;The node the server is running on is currently offline +Server not found;Server not found +A server with that id cannot be found or you have no access for this server;A server with that id cannot be found or you have no access for this server diff --git a/Moonlight/wwwroot/assets/media/svg/serverdown.svg b/Moonlight/wwwroot/assets/media/svg/serverdown.svg new file mode 100644 index 00000000..ca37dc52 --- /dev/null +++ b/Moonlight/wwwroot/assets/media/svg/serverdown.svg @@ -0,0 +1 @@ +server down \ No newline at end of file