Add view for USB products.

This commit is contained in:
2025-09-11 21:01:42 +01:00
parent 5389463cc0
commit 6c2b552892
3 changed files with 93 additions and 0 deletions

View File

@@ -26,6 +26,9 @@
<NavLink class="nav-link" href="/admin/partitions">
Partitions
</NavLink>
<NavLink class="nav-link" href="/admin/usb/products">
USB Products
</NavLink>
<NavLink class="nav-link" href="/admin/versions">
Versions
</NavLink>

View File

@@ -0,0 +1,51 @@
@page "/admin/usb/products"
@attribute [Authorize]
@layout AdminLayout
@rendermode InteractiveServer
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>USB products</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(UsbProductModel), nameof(UsbProductModel.VendorName))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UsbProductModel), nameof(UsbProductModel.ProductName))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UsbProductModel), nameof(UsbProductModel.ProductId))
</th>
</tr>
</thead>
<tbody>
@foreach(UsbProductModel item in _items)
{
<tr>
<td>
<a href="/admin/usb/vendors/@item.VendorId" target="_blank">@item.VendorName</a>
</td>
<td>
@item.ProductName
</td>
<td>
@item.ProductId
</td>
</tr>
}
</tbody>
</table>
</section>

View File

@@ -0,0 +1,39 @@
using Aaru.Server.Database.Models;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.Usb.Products;
public partial class List
{
bool _initialized;
List<UsbProductModel> _items;
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
StateHasChanged();
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
_items = await ctx.UsbProducts.Include(static u => u.Vendor)
.OrderBy(static p => p.Vendor.Vendor)
.ThenBy(static p => p.Product)
.ThenBy(static p => p.ProductId)
.Select(static p => new UsbProductModel
{
ProductId = p.ProductId,
ProductName = p.Product,
VendorId = p.Vendor.Id,
VendorName = p.Vendor.Vendor
})
.ToListAsync();
_initialized = true;
StateHasChanged();
}
}