Add view for commands.

This commit is contained in:
2025-09-11 16:23:40 +01:00
parent 8ac473586b
commit 7e3a99f463
5 changed files with 108 additions and 32 deletions

View File

@@ -11,6 +11,9 @@
<NavLink class="nav-link" href="/admin/block-descriptors">
Block descriptors
</NavLink>
<NavLink class="nav-link" href="/admin/commands">
Commands
</NavLink>
</div>
<!-- Add more admin links here -->
</nav>

View File

@@ -15,16 +15,17 @@
return;
}
<table class="table">
<thead>
<section class="stats-section">
<table class="table table-dark table-striped table-bordered mt-4 mb-4">
<thead class="thead-dark">
<tr>
<th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.Density))
</th>
<th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.Blocks))
</th>
<th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.BlockLength))
</th>
</tr>
@@ -45,4 +46,5 @@
</tr>
}
</tbody>
</table>
</table>
</section>

View File

@@ -18,9 +18,9 @@ public partial class View
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
_items = await ctx.BlockDescriptor.OrderBy(b => b.BlockLength)
.ThenBy(b => b.Blocks)
.ThenBy(b => b.Density)
_items = await ctx.BlockDescriptor.OrderBy(static b => b.BlockLength)
.ThenBy(static b => b.Blocks)
.ThenBy(static b => b.Density)
.ToListAsync();
_initialized = true;

View File

@@ -0,0 +1,44 @@
@page "/admin/commands"
@attribute [Authorize]
@layout AdminLayout
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>Commands</PageTitle>
@if(!_initialized)
{
<div class="stats-section">
<h1 style="color: red; align-content: center; padding: 2rem">Loading...</h1>
</div>
return;
}
<section class="stats-section">
<table class="table table-dark table-striped table-bordered mt-4 mb-4">
<thead class="thead-dark">
<tr>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(Command), nameof(Command.Name))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(Command), nameof(Command.Count))
</th>
</tr>
</thead>
<tbody>
@foreach(Command item in _items)
{
<tr>
<td>
@item.Name
</td>
<td>
@item.Count
</td>
</tr>
}
</tbody>
</table>
</section>

View File

@@ -0,0 +1,27 @@
using Aaru.Server.Database.Models;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.Commands;
public partial class View
{
bool _initialized;
List<Command> _items;
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
StateHasChanged();
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
_items = await ctx.Commands.OrderBy(static c => c.Name).ToListAsync();
_initialized = true;
StateHasChanged();
}
}