Add view for block descriptors.

This commit is contained in:
2025-09-11 15:36:56 +01:00
parent 5951eb6986
commit 8ac473586b
4 changed files with 101 additions and 0 deletions

View File

@@ -8,6 +8,9 @@
<NavLink class="nav-link" href="/admin" Match="NavLinkMatch.All">
<span aria-hidden="true" class="bi bi-house-door-fill-nav-menu"></span> Dashboard
</NavLink>
<NavLink class="nav-link" href="/admin/block-descriptors">
Block descriptors
</NavLink>
</div>
<!-- Add more admin links here -->
</nav>

View File

@@ -0,0 +1,48 @@
@page "/admin/block-descriptors"
@attribute [Authorize]
@layout AdminLayout
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>Block descriptors</PageTitle>
@if(!_initialized)
{
<div class="stats-section">
<h1 style="color: red; align-content: center; padding: 2rem">Loading...</h1>
</div>
return;
}
<table class="table">
<thead>
<tr>
<th>
@DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.Density))
</th>
<th>
@DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.Blocks))
</th>
<th>
@DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.BlockLength))
</th>
</tr>
</thead>
<tbody>
@foreach(BlockDescriptor item in _items)
{
<tr>
<td>
@item.Density
</td>
<td>
@item.Blocks
</td>
<td>
@item.BlockLength
</td>
</tr>
}
</tbody>
</table>

View File

@@ -0,0 +1,30 @@
using Aaru.CommonTypes.Metadata;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.BlockDescriptors;
public partial class View
{
bool _initialized;
List<BlockDescriptor> _items;
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
StateHasChanged();
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
_items = await ctx.BlockDescriptor.OrderBy(b => b.BlockLength)
.ThenBy(b => b.Blocks)
.ThenBy(b => b.Density)
.ToListAsync();
_initialized = true;
StateHasChanged();
}
}

View File

@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace Aaru.Server;
public static class DisplayNameHelper
{
public static string GetDisplayName(Type type, string propertyName)
{
PropertyInfo? prop = type.GetProperty(propertyName);
if(prop is null) return propertyName;
DisplayAttribute? displayAttr = prop.GetCustomAttributes(typeof(DisplayAttribute), true)
.OfType<DisplayAttribute>()
.FirstOrDefault();
return displayAttr?.Name ?? propertyName;
}
}