@using MoonCore.Blazor.FlyonUi.Alerts @using MoonCore.Blazor.FlyonUi.Grid @using MoonCore.Blazor.FlyonUi.Grid.Columns @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
Actions
@code { [Parameter] public NodeResponse Node { get; set; } private DataGrid Grid; private async Task> ItemsProviderAsync( DataGridItemRequest request ) { var query = $"?startIndex={request.StartIndex}&count={request.Count}"; var countedData = await ApiClient.GetJson>( $"api/admin/servers/nodes/{Node.Id}/allocations{query}" ); return new() { TotalCount = countedData.TotalCount, Items = countedData.Items }; } private async Task AddAllocationRangeAsync() { Func onSubmit = async request => { await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations/range", request); await ToastService.SuccessAsync("Successfully created allocations"); await Grid.RefreshAsync(); }; await ModalService.LaunchAsync(parameters => { parameters.Add("OnSubmit", onSubmit); }); } private async Task AddAllocationAsync() { Func onSubmit = async request => { await ApiClient.Post($"api/admin/servers/nodes/{Node.Id}/allocations", request); await ToastService.SuccessAsync("Successfully created allocation"); await Grid.RefreshAsync(); }; await ModalService.LaunchAsync(parameters => { parameters.Add("OnSubmit", onSubmit); }); } private async Task UpdateAllocationAsync(NodeAllocationResponse allocation) { Func onSubmit = async request => { await ApiClient.Patch($"api/admin/servers/nodes/{Node.Id}/allocations/{allocation.Id}", request); await ToastService.SuccessAsync("Successfully updated allocation"); await Grid.RefreshAsync(); }; await ModalService.LaunchAsync(parameters => { parameters.Add("OnSubmit", onSubmit); parameters.Add("Allocation", allocation); }); } private async Task DeleteAllocationAsync(NodeAllocationResponse allocation) { await AlertService.ConfirmDangerAsync( "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.SuccessAsync("Successfully deleted allocation"); await Grid.RefreshAsync(); } ); } private async Task DeleteAllAllocationsAsync() { await AlertService.ConfirmDangerAsync( "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.SuccessAsync("Successfully deleted allocations"); await Grid.RefreshAsync(); } ); } }