Refactored frontend to work with the latest mooncore changes
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
|
||||
@using MoonlightServers.Frontend.UI.Components.Servers.CreateServerPartials
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@@ -29,13 +31,13 @@
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<Tabs>
|
||||
<Tab Name="General">
|
||||
<GeneralServerCreate Request="Request" />
|
||||
<GeneralServerCreate Request="Request" Star="Star" Node="Node" User="Owner" />
|
||||
</Tab>
|
||||
<Tab Name="Allocations">
|
||||
<AllocationsServerCreate Request="Request" />
|
||||
<AllocationsServerCreate Request="Request" Allocations="Allocations" Node="Node" />
|
||||
</Tab>
|
||||
<Tab Name="Variables">
|
||||
<VariablesServerCreate Request="Request" />
|
||||
<VariablesServerCreate Request="Request" Star="Star" />
|
||||
</Tab>
|
||||
<Tab Name="Advanced">
|
||||
<AdvancedServerCreate Request="Request" />
|
||||
@@ -49,6 +51,11 @@
|
||||
private HandleForm Form;
|
||||
private CreateServerRequest Request;
|
||||
|
||||
private List<NodeAllocationResponse> Allocations = new();
|
||||
private UserResponse? Owner;
|
||||
private StarDetailResponse? Star;
|
||||
private NodeResponse? Node;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
@@ -56,6 +63,14 @@
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
Request.AllocationIds = Allocations
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
Request.StarId = Star?.Id ?? -1;
|
||||
Request.NodeId = Node?.Id ?? -1;
|
||||
Request.OwnerId = Owner?.Id ?? -1;
|
||||
|
||||
await ApiClient.Post("api/admin/servers", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Server");
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.DataTables
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject AlertService AlertService
|
||||
@@ -67,7 +64,7 @@
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => Delete(context)" @onclick:preventDefault
|
||||
class="text-danger">
|
||||
class="text-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
@using MoonCore.Blazor.FlyonUi.Components
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.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.UpdateServerPartials
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@@ -31,16 +31,16 @@
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<Tabs>
|
||||
<Tab Name="General">
|
||||
<GeneralServerUpdate Request="Request" />
|
||||
<GeneralServerUpdate Request="Request" Owner="Owner"/>
|
||||
</Tab>
|
||||
<Tab Name="Allocations">
|
||||
<AllocationsServerUpdate Request="Request" Server="Server" />
|
||||
<AllocationsServerUpdate Request="Request" Server="Server" Allocations="Allocations"/>
|
||||
</Tab>
|
||||
<Tab Name="Variables">
|
||||
<VariablesServerUpdate Request="Request" Server="Server" />
|
||||
<VariablesServerUpdate Request="Request" Server="Server"/>
|
||||
</Tab>
|
||||
<Tab Name="Advanced">
|
||||
<AdvancedServerUpdate Request="Request" />
|
||||
<AdvancedServerUpdate Request="Request"/>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</HandleForm>
|
||||
@@ -55,14 +55,45 @@
|
||||
private UpdateServerRequest Request;
|
||||
private ServerResponse Server;
|
||||
|
||||
private List<NodeAllocationResponse> Allocations = new();
|
||||
private UserResponse Owner;
|
||||
|
||||
private async Task Load(LazyLoader _)
|
||||
{
|
||||
Server = await ApiClient.GetJson<ServerResponse>($"api/admin/servers/{Id}");
|
||||
Request = Mapper.Map<UpdateServerRequest>(Server);
|
||||
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user