102 lines
3.2 KiB
Plaintext
102 lines
3.2 KiB
Plaintext
@page "/admin/servers/all/update/{Id:int}"
|
|
|
|
@using MoonCore.Blazor.FlyonUi.Components
|
|
@using MoonCore.Blazor.FlyonUi.Toasts
|
|
@using MoonCore.Helpers
|
|
@using Moonlight.Shared.Http.Responses.Admin.Users
|
|
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
|
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
|
@using MoonlightServers.Frontend.UI.Components.Servers.UpdatePartials
|
|
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
|
|
|
@inject HttpApiClient ApiClient
|
|
@inject NavigationManager Navigation
|
|
@inject ToastService ToastService
|
|
|
|
@attribute [Authorize(Policy = "permissions:admin.servers.update")]
|
|
|
|
<LazyLoader Load="Load">
|
|
<PageHeader Title="Update Server">
|
|
<a href="/admin/servers/all" class="btn btn-secondary">
|
|
<i class="icon-chevron-left"></i>
|
|
Back
|
|
</a>
|
|
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
|
<i class="icon-check"></i>
|
|
Update
|
|
</WButton>
|
|
</PageHeader>
|
|
|
|
<div class="mt-5">
|
|
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
|
<Tabs>
|
|
<Tab Name="General">
|
|
<General Request="Request" Parent="this"/>
|
|
</Tab>
|
|
<Tab Name="Allocations">
|
|
<Allocations Request="Request" Server="Server" Parent="this"/>
|
|
</Tab>
|
|
<Tab Name="Variables">
|
|
<Variables Request="Request" Server="Server"/>
|
|
</Tab>
|
|
<Tab Name="Advanced">
|
|
<Advanced Request="Request"/>
|
|
</Tab>
|
|
</Tabs>
|
|
</HandleForm>
|
|
</div>
|
|
</LazyLoader>
|
|
|
|
@code
|
|
{
|
|
[Parameter] public int Id { get; set; }
|
|
|
|
private HandleForm Form;
|
|
private UpdateServerRequest Request;
|
|
private ServerResponse Server;
|
|
|
|
public List<NodeAllocationResponse> Allocations = new();
|
|
public UserResponse Owner;
|
|
|
|
private async Task Load(LazyLoader _)
|
|
{
|
|
Server = await ApiClient.GetJson<ServerResponse>($"api/admin/servers/{Id}");
|
|
|
|
Request = new()
|
|
{
|
|
Name = Server.Name,
|
|
AllocationIds = Server.AllocationIds,
|
|
OwnerId = Server.OwnerId,
|
|
Bandwidth = Server.Bandwidth,
|
|
Cpu = Server.Cpu,
|
|
Disk = Server.Disk,
|
|
DockerImageIndex = Server.DockerImageIndex,
|
|
Memory = Server.Memory,
|
|
StartupOverride = Server.StartupOverride
|
|
};
|
|
|
|
foreach (var allocationId in Server.AllocationIds)
|
|
{
|
|
var allocation = await ApiClient.GetJson<NodeAllocationResponse>(
|
|
$"api/admin/servers/nodes/{Server.NodeId}/allocations/{allocationId}"
|
|
);
|
|
|
|
Allocations.Add(allocation);
|
|
}
|
|
|
|
Owner = await ApiClient.GetJson<UserResponse>(
|
|
$"api/admin/users/{Server.OwnerId}"
|
|
);
|
|
}
|
|
|
|
private async Task OnSubmit()
|
|
{
|
|
Request.AllocationIds = Allocations.Select(x => x.Id).ToArray();
|
|
Request.OwnerId = Owner.Id;
|
|
|
|
await ApiClient.Patch($"api/admin/servers/{Id}", Request);
|
|
|
|
await ToastService.Success("Successfully updated server");
|
|
Navigation.NavigateTo("/admin/servers/all");
|
|
}
|
|
} |