Files
Servers/MoonlightServers.Frontend/UI/Views/Admin/All/Create.razor
2025-07-16 21:29:43 +02:00

79 lines
2.4 KiB
Plaintext

@page "/admin/servers/all/create"
@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.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
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.create")]
<PageHeader Title="Create Server">
<a href="/admin/servers/all" class="btn btn-secondary">
<i class="icon-chevron-left mr-1"></i>
Back
</a>
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
<i class="icon-check mr-1"></i>
Create
</WButton>
</PageHeader>
<div class="mt-5">
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
<Tabs>
<Tab Name="General">
<GeneralServerCreate Request="Request" Parent="this" />
</Tab>
<Tab Name="Allocations">
<AllocationsServerCreate Request="Request" Parent="this" />
</Tab>
<Tab Name="Variables">
<VariablesServerCreate Request="Request" Parent="this" />
</Tab>
<Tab Name="Advanced">
<AdvancedServerCreate Request="Request" />
</Tab>
</Tabs>
</HandleForm>
</div>
@code
{
private HandleForm Form;
private CreateServerRequest Request;
public List<NodeAllocationResponse> Allocations = new();
public UserResponse? Owner;
public StarDetailResponse? Star;
public NodeResponse? Node;
protected override void OnInitialized()
{
Request = new();
}
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");
Navigation.NavigateTo("/admin/servers/all");
}
}