Refactored ui. Improved console experience. Added command endpoint
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
@using MoonCore.Blazor.FlyonUi.Alerts
|
||||
@using MoonCore.Blazor.FlyonUi.DataTables
|
||||
@using MoonCore.Blazor.FlyonUi.Modals
|
||||
@using MoonCore.Blazor.FlyonUi.Toasts
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Nodes
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonlightServers.Frontend.UI.Components.Nodes.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.NodeAllocations
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject ModalService ModalService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 md:gap-x-5">
|
||||
<div class="col-span-1">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">Actions</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="flex flex-col gap-y-3">
|
||||
<button type="button" @onclick="AddAllocation" class="btn btn-primary">Create</button>
|
||||
<button type="button" @onclick="AddAllocationRange" class="btn btn-accent">Create multiple</button>
|
||||
<button type="button" @onclick="DeleteAllAllocations" class="btn btn-error">Delete all</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-span-1 md:col-span-2 -mb-3">
|
||||
<DataTable @ref="Table" TItem="NodeAllocationResponse">
|
||||
<Configuration>
|
||||
<Pagination TItem="NodeAllocationResponse" ItemSource="LoadData"/>
|
||||
|
||||
<DataTableColumn TItem="NodeAllocationResponse" Field="@(x => x.IpAddress)" Name="IP Address"/>
|
||||
<DataTableColumn TItem="NodeAllocationResponse" Field="@(x => x.Port)" Name="Port"/>
|
||||
<DataTableColumn TItem="NodeAllocationResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end items-center">
|
||||
<a @onclick="() => UpdateAllocation(context)"
|
||||
@onclick:preventDefault href="#"
|
||||
class="text-primary mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
<a @onclick="() => DeleteAllocation(context)"
|
||||
@onclick:preventDefault href="#"
|
||||
class="text-error">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
</Configuration>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public NodeResponse Node { get; set; }
|
||||
|
||||
private DataTable<NodeAllocationResponse> Table;
|
||||
|
||||
private async Task<IPagedData<NodeAllocationResponse>> LoadData(PaginationOptions options)
|
||||
{
|
||||
return await ApiClient.GetJson<PagedData<NodeAllocationResponse>>(
|
||||
$"api/admin/servers/nodes/{Node.Id}/allocations?page={options.Page}&pageSize={options.PerPage}"
|
||||
);
|
||||
}
|
||||
|
||||
private async Task AddAllocationRange()
|
||||
{
|
||||
Func<CreateNodeAllocationRangeRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations/range", request);
|
||||
|
||||
await ToastService.Success("Successfully created allocations");
|
||||
await Table.Refresh();
|
||||
};
|
||||
|
||||
await ModalService.Launch<CreateMultipleAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
|
||||
}
|
||||
|
||||
private async Task AddAllocation()
|
||||
{
|
||||
Func<CreateNodeAllocationRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations", request);
|
||||
|
||||
await ToastService.Success("Successfully created allocation");
|
||||
await Table.Refresh();
|
||||
};
|
||||
|
||||
await ModalService.Launch<CreateAllocationModal>(parameters => { parameters.Add("OnSubmit", onSubmit); });
|
||||
}
|
||||
|
||||
private async Task UpdateAllocation(NodeAllocationResponse allocation)
|
||||
{
|
||||
Func<UpdateNodeAllocationRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}", request);
|
||||
|
||||
await ToastService.Success("Successfully updated allocation");
|
||||
await Table.Refresh();
|
||||
};
|
||||
|
||||
await ModalService.Launch<UpdateAllocationModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("Allocation", allocation);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task DeleteAllocation(NodeAllocationResponse allocation)
|
||||
{
|
||||
await AlertService.ConfirmDanger(
|
||||
"Delete allocation",
|
||||
"Do you really want to delete the selected allocation? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}");
|
||||
|
||||
await ToastService.Success("Successfully deleted allocation");
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async Task DeleteAllAllocations()
|
||||
{
|
||||
await AlertService.ConfirmDanger(
|
||||
"Delete all allocations",
|
||||
"Do you really want to delete all allocations? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/nodes/{Node.Id}/allocations/all");
|
||||
|
||||
await ToastService.Success("Successfully deleted allocations");
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user