@page "/systems/list"
@using RackPeek.Domain.Persistence
@using RackPeek.Domain.Resources.SystemResources
@using RackPeek.Domain.Resources.SystemResources.UseCases
@inject NavigationManager Nav
@code {
[Inject] IResourceCollection Repo { get; set; } = default!;
[Inject] ISystemRepository SystemRepo { get; set; } = default!;
[Inject] UpdateSystemUseCase UpdateSystemUseCase { get; set; } = default!;
[Parameter]
[SupplyParameterFromQuery(Name = "type")]
public string? Type { get; set; }
[Parameter]
[SupplyParameterFromQuery(Name = "os")]
public string? Os { get; set; }
public IReadOnlyList Systems { get; set; } = new List();
// Computed title that reflects active filters
private string PageTitle
{
get
{
var type = Normalize(Type);
var os = Normalize(Os);
if (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(os))
return "Systems";
var parts = new List();
if (!string.IsNullOrEmpty(type)) parts.Add(type);
if (!string.IsNullOrEmpty(os)) parts.Add(os);
return $"Systems ({string.Join(" / ", parts)})";
}
}
protected override async Task OnInitializedAsync()
{
await Reload();
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
// If query params change while staying on the page, keep list + title in sync
await Reload();
await base.OnParametersSetAsync();
}
private async Task Reload(string _ = "")
{
var type = Normalize(Type);
var os = Normalize(Os);
if (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(os))
{
Systems = await Repo.GetAllOfTypeAsync();
}
else
{
Systems = await SystemRepo.GetFilteredAsync(type, os);
}
}
private static string? Normalize(string? s)
{
return string.IsNullOrWhiteSpace(s) ? null : s.Trim();
}
private async Task UpdateSystem(SystemEditModel edit)
{
await UpdateSystemUseCase.ExecuteAsync(
edit.Name,
edit.Type,
edit.Os,
edit.Cores,
edit.Ram,
edit.Ip,
edit.RunsOn,
edit.Notes
);
await Reload();
}
private Task NavigateToNewResource(string name)
{
Nav.NavigateTo($"resources/systems/{Uri.EscapeDataString(name)}");
return Task.CompletedTask;
}
}