Added a basic allocation editor for servers

This commit is contained in:
Marcel Baumgartner 2023-06-20 19:18:18 +02:00
parent ef37088c7a
commit 1afd4e8b92
3 changed files with 101 additions and 0 deletions

View file

@ -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"
}
}
}

View file

@ -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<Server> ServerRepository
@inject Repository<NodeAllocation> NodeAllocationRepository
@inject AlertService AlertService
@inject SmartTranslateService SmartTranslateService
<div class="row">
<div class="col-12 col-md-6 mb-5">
<div class="card card-body">
<WButton Text="@(SmartTranslateService.Translate("Add allocation"))"
WorkingText="@(SmartTranslateService.Translate("Searching"))"
CssClasses="btn-primary"
OnClick="AddAllocation">
</WButton>
</div>
</div>
<div class="col-12 col-md-6">
<div class="card card-body">
<div class="table-responsive">
<table class="table table-bordered">
<tbody>
@foreach (var allocation in Server.Allocations)
{
<tr>
<td class="align-middle fs-5">
@(Server.Node.Fqdn + ":" + allocation.Port)
</td>
<td>
<WButton Text="@(SmartTranslateService.Translate("Delete"))"
WorkingText="@(SmartTranslateService.Translate("Deleting"))"
CssClasses="btn-danger"
OnClick="() => DeleteAllocation(allocation)">
</WButton>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
@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);
}
}

View file

@ -33,6 +33,7 @@
</Route>
<Route Path="/allocations">
<AdminServersViewNavigation Index="3" Server="Server"/>
<Allocations />
</Route>
<Route Path="/archive">
<AdminServersViewNavigation Index="4" Server="Server"/>
@ -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;