@using MoonCore.Blazor.FlyonUi.Alerts @using MoonCore.Blazor.FlyonUi.DataTables @using MoonCore.Blazor.FlyonUi.Modals @using MoonCore.Blazor.FlyonUi.Toasts @using MoonCore.Blazor.Tailwind.Alerts @using MoonlightServers.Shared.Http.Responses.Admin.Nodes @using MoonCore.Blazor.Tailwind.Dt @using MoonCore.Blazor.Tailwind.Modals @using MoonCore.Blazor.Tailwind.Toasts @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
Actions
@code { [Parameter] public NodeResponse Node { get; set; } private DataTable Table; private async Task> LoadData(PaginationOptions options) { return await ApiClient.GetJson>( $"api/admin/servers/nodes/{Node.Id}/allocations?page={options.Page}&pageSize={options.PerPage}" ); } private async Task AddAllocationRange() { Func 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(parameters => { parameters.Add("OnSubmit", onSubmit); }); } private async Task AddAllocation() { Func 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(parameters => { parameters.Add("OnSubmit", onSubmit); }); } private async Task UpdateAllocation(NodeAllocationResponse allocation) { Func 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(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(); } ); } }