mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add view for block descriptors.
This commit is contained in:
@@ -8,6 +8,9 @@
|
|||||||
<NavLink class="nav-link" href="/admin" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="/admin" Match="NavLinkMatch.All">
|
||||||
<span aria-hidden="true" class="bi bi-house-door-fill-nav-menu"></span> Dashboard
|
<span aria-hidden="true" class="bi bi-house-door-fill-nav-menu"></span> Dashboard
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
<NavLink class="nav-link" href="/admin/block-descriptors">
|
||||||
|
Block descriptors
|
||||||
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<!-- Add more admin links here -->
|
<!-- Add more admin links here -->
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Aaru.Server/DisplayNameHelper.cs
Normal file
20
Aaru.Server/DisplayNameHelper.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user