mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Add USB vendor details view.
This commit is contained in:
69
Aaru.Server/Components/Admin/Pages/Usb/Vendors/Details.razor
Normal file
69
Aaru.Server/Components/Admin/Pages/Usb/Vendors/Details.razor
Normal file
@@ -0,0 +1,69 @@
|
||||
@page "/admin/usb/vendors/{id:int}"
|
||||
@attribute [Authorize]
|
||||
@layout AdminLayout
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||
|
||||
<PageTitle>USB vendor</PageTitle>
|
||||
|
||||
@if(!_initialized)
|
||||
{
|
||||
<div class="stats-section">
|
||||
<h1 style="color: red; align-content: center; padding: 2rem">Loading...</h1>
|
||||
</div>
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
<section class="stats-section">
|
||||
<div>
|
||||
<h4>USB vendor</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(UsbVendor), nameof(UsbVendor.Vendor))
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@_model?.Vendor
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(UsbVendor), nameof(UsbVendor.VendorId))
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@_model?.VendorId
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Products:</h4>
|
||||
<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.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 _products)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.ProductName
|
||||
</td>
|
||||
<td>
|
||||
@item.ProductId
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/admin/usb/vendors" class="btn btn-secondary">Back to List</a>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,40 @@
|
||||
using Aaru.Server.Database.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DbContext = Aaru.Server.Database.DbContext;
|
||||
|
||||
namespace Aaru.Server.Components.Admin.Pages.Usb.Vendors;
|
||||
|
||||
public partial class Details
|
||||
{
|
||||
bool _initialized;
|
||||
UsbVendor? _model;
|
||||
List<UsbProductModel> _products;
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
StateHasChanged();
|
||||
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
_model = await ctx.UsbVendors.FirstOrDefaultAsync(m => m.VendorId == Id);
|
||||
|
||||
_products = await ctx.UsbProducts.Where(p => p.Vendor.VendorId == Id)
|
||||
.OrderBy(static p => p.Product)
|
||||
.ThenBy(static p => p.ProductId)
|
||||
.Select(static p => new UsbProductModel
|
||||
{
|
||||
ProductId = p.ProductId,
|
||||
ProductName = p.Product
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
_initialized = true;
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user