Added a basic allocation editor for servers
This commit is contained in:
parent
ef37088c7a
commit
1afd4e8b92
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
85
Moonlight/Shared/Views/Admin/Servers/View/Allocations.razor
Normal file
85
Moonlight/Shared/Views/Admin/Servers/View/Allocations.razor
Normal 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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue