From 1afd4e8b92363e1e8693afb2b95712209b2d1131 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Tue, 20 Jun 2023 19:18:18 +0200 Subject: [PATCH] Added a basic allocation editor for servers --- Moonlight/Properties/launchSettings.json | 14 +++ .../Admin/Servers/View/Allocations.razor | 85 +++++++++++++++++++ .../Views/Admin/Servers/View/Index.razor | 2 + 3 files changed, 101 insertions(+) create mode 100644 Moonlight/Shared/Views/Admin/Servers/View/Allocations.razor diff --git a/Moonlight/Properties/launchSettings.json b/Moonlight/Properties/launchSettings.json index 39b73b38..be9982ad 100644 --- a/Moonlight/Properties/launchSettings.json +++ b/Moonlight/Properties/launchSettings.json @@ -31,6 +31,20 @@ }, "applicationUrl": "http://moonlight.testy:5118;https://localhost:7118;http://localhost:5118", "dotnetRunMessages": true + }, + "Watch": { + "commandName": "Executable", + "executablePath": "dotnet", + "workingDirectory": "$(ProjectDir)", + "hotReloadEnabled": true, + "hotReloadProfile": "aspnetcore", + "commandLineArgs": "watch run", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ML_DEBUG": "true" + }, + "applicationUrl": "http://moonlight.testy:5118;https://localhost:7118;http://localhost:5118" } } } \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Servers/View/Allocations.razor b/Moonlight/Shared/Views/Admin/Servers/View/Allocations.razor new file mode 100644 index 00000000..acce61c7 --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Servers/View/Allocations.razor @@ -0,0 +1,85 @@ +@using Moonlight.App.Database.Entities +@using Moonlight.App.Repositories +@using Microsoft.EntityFrameworkCore +@using Moonlight.App.Services +@using Moonlight.App.Services.Interop +@using BlazorTable + +@inject Repository ServerRepository +@inject Repository NodeAllocationRepository +@inject AlertService AlertService +@inject SmartTranslateService SmartTranslateService + +
+
+
+ + +
+
+
+
+
+ + + @foreach (var allocation in Server.Allocations) + { + + + + + } + +
+ @(Server.Node.Fqdn + ":" + allocation.Port) + + + +
+
+
+
+
+ +@code +{ + [CascadingParameter] + public Server Server { get; set; } + + private async Task AddAllocation() + { + // We have sadly no choice to use entity framework to do what the sql call does, there + // are only slower ways, so we will use a raw sql call as a exception + + var freeAllocation = NodeAllocationRepository + .Get() + .FromSqlRaw($"SELECT * FROM `NodeAllocations` WHERE ServerId IS NULL AND NodeId={Server.Node.Id} LIMIT 1") + .FirstOrDefault(); + + if (freeAllocation == null) + { + await AlertService.Error( + SmartTranslateService.Translate("No free allocation found")); + return; + } + + Server.Allocations.Add(freeAllocation); + ServerRepository.Update(Server); + + await InvokeAsync(StateHasChanged); + } + + private async Task DeleteAllocation(NodeAllocation nodeAllocation) + { + Server.Allocations.Remove(nodeAllocation); + ServerRepository.Update(Server); + + await InvokeAsync(StateHasChanged); + } +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Servers/View/Index.razor b/Moonlight/Shared/Views/Admin/Servers/View/Index.razor index cf2bc28a..526016b8 100644 --- a/Moonlight/Shared/Views/Admin/Servers/View/Index.razor +++ b/Moonlight/Shared/Views/Admin/Servers/View/Index.razor @@ -33,6 +33,7 @@ + @@ -72,6 +73,7 @@ .Include(x => x.Allocations) .Include(x => x.MainAllocation) .Include(x => x.Variables) + .Include(x => x.Node) .FirstOrDefault(x => x.Id == Id); return Task.CompletedTask;