Testing custom loaders

This commit is contained in:
Masu Baumgartner
2024-05-29 21:24:45 +02:00
parent a580e4335b
commit 0ff0ce1252
2 changed files with 13 additions and 1 deletions

View File

@@ -50,5 +50,6 @@ public class CreateServerForm
[Description("The allocations the server should have")]
[MultiSelection("Port", "Port", Icon = "bx-network-chart")]
[Section("Deployment", Icon = "bx-cube")]
[CustomItemLoader("FreeAllocations")]
public List<ServerAllocation> Allocations { get; set; } = new();
}

View File

@@ -41,6 +41,9 @@
</Template>
</CrudColumn>
</View>
<CustomLoaders>
<DefineCustomLoader T="ServerAllocation" Id="FreeAllocations" Func="LoadFreeAllocations" />
</CustomLoaders>
<NoItemsView>
<IconAlert Title="No servers found" Color="primary" Icon="bx-search-alt">
Create a new server in order to manage it using this page. Need help? Check out our <a href="https://docs.moonlightpanel.xyz">documentation</a>
@@ -56,9 +59,17 @@
.Get()
.Include(x => x.Owner)
.Include(x => x.Image)
.Include(x => x.Allocations)
.Include(x => x.Node);
}
private IEnumerable<ServerAllocation> LoadFreeAllocations(Repository<ServerAllocation> repository)
{
return repository
.Get()
.FromSqlRaw("SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL");
}
private async Task CustomAdd(Server form) => await ServerService.Create(form);
private async Task CustomDelete(Server s) => await ServerService.Delete(s);
@@ -71,7 +82,7 @@
if (oldServer.UseVirtualDisk != server.UseVirtualDisk)
throw new DisplayException("Unable to switch from/to virtual disks. This is not supported at the moment");
return Task.CompletedTask;
}
}