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")] [Description("The allocations the server should have")]
[MultiSelection("Port", "Port", Icon = "bx-network-chart")] [MultiSelection("Port", "Port", Icon = "bx-network-chart")]
[Section("Deployment", Icon = "bx-cube")] [Section("Deployment", Icon = "bx-cube")]
[CustomItemLoader("FreeAllocations")]
public List<ServerAllocation> Allocations { get; set; } = new(); public List<ServerAllocation> Allocations { get; set; } = new();
} }

View File

@@ -41,6 +41,9 @@
</Template> </Template>
</CrudColumn> </CrudColumn>
</View> </View>
<CustomLoaders>
<DefineCustomLoader T="ServerAllocation" Id="FreeAllocations" Func="LoadFreeAllocations" />
</CustomLoaders>
<NoItemsView> <NoItemsView>
<IconAlert Title="No servers found" Color="primary" Icon="bx-search-alt"> <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> 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() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Include(x => x.Image) .Include(x => x.Image)
.Include(x => x.Allocations)
.Include(x => x.Node); .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 CustomAdd(Server form) => await ServerService.Create(form);
private async Task CustomDelete(Server s) => await ServerService.Delete(s); private async Task CustomDelete(Server s) => await ServerService.Delete(s);