@using MoonCore.Blazor.Tailwind.Alerts @using MoonlightServers.Shared.Http.Responses.Admin.Nodes @using MoonCore.Blazor.Tailwind.DataTable @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 NodeDetailResponse Node { get; set; } private ItemDataTable Table; private async Task> Load(int page, int pageSize) { return await ApiClient.GetJson>( $"api/admin/servers/nodes/{Node.Id}/allocations?page={page}&pageSize={pageSize}" ); } 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(isSilent: false, bypassCache: true); }; 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(isSilent: false, bypassCache: true); }; await ModalService.Launch(parameters => { parameters.Add("OnSubmit", onSubmit); }); } private async Task UpdateAllocation(NodeAllocationDetailResponse 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(isSilent: false, bypassCache: true); }; await ModalService.Launch(parameters => { parameters.Add("OnSubmit", onSubmit); parameters.Add("Allocation", allocation); }); } private async Task DeleteAllocation(NodeAllocationDetailResponse 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(isSilent: false, bypassCache: true); } ); } 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(isSilent: false, bypassCache: true); } ); } }