mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add USB to device report view.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
@page "/Report/View/{Id:int}"
|
||||
@using Aaru.Server.Database
|
||||
@using Blazorise
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||
|
||||
@@ -22,5 +24,40 @@
|
||||
}
|
||||
|
||||
<div class="stats-section">
|
||||
<h1 style="align-content: center; padding: 2rem">@_pageTitle</h1>
|
||||
</div>
|
||||
<h1 style="color: #e18fdc; align-content: center; padding: 2rem">@_pageTitle</h1>
|
||||
</div>
|
||||
|
||||
<Accordion class="stats-section">
|
||||
@if(UsbItem is not null)
|
||||
{
|
||||
<AccordionItem @bind-Visible="@accordionItem1Visible">
|
||||
<AccordionHeader>
|
||||
<Heading Size="HeadingSize.Is5">
|
||||
<AccordionToggle>USB characteristics</AccordionToggle>
|
||||
</Heading>
|
||||
</AccordionHeader>
|
||||
<AccordionBody>
|
||||
<Table FullWidth>
|
||||
<TableBody>
|
||||
<TableRow>
|
||||
<TableRowHeader class="text-end">Manufacturer</TableRowHeader>
|
||||
<TableRowCell>@UsbItem.Manufacturer</TableRowCell>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRowHeader class="text-end">Product</TableRowHeader>
|
||||
<TableRowCell>@UsbItem.Product</TableRowCell>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRowHeader class="text-end">Vendor ID</TableRowHeader>
|
||||
<TableRowCell>@UsbItem.VendorDescription</TableRowCell>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRowHeader class="text-end">Product ID</TableRowHeader>
|
||||
<TableRowCell>@UsbItem.ProductDescription</TableRowCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</AccordionBody>
|
||||
</AccordionItem>
|
||||
}
|
||||
</Accordion>
|
||||
@@ -9,12 +9,13 @@ public partial class View
|
||||
{
|
||||
bool _initialized;
|
||||
bool _notFound;
|
||||
bool accordionItem1Visible;
|
||||
string _pageTitle { get; set; } = "Aaru Device Report";
|
||||
[CascadingParameter]
|
||||
HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public Item? UsbItem { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -33,7 +34,8 @@ public partial class View
|
||||
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
Device? report = await ctx.Devices.FirstOrDefaultAsync(d => d.Id == Id);
|
||||
Device? report = await ctx.Devices.Include(static deviceReportV2 => deviceReportV2.USB)
|
||||
.FirstOrDefaultAsync(d => d.Id == Id);
|
||||
|
||||
if(report is null)
|
||||
{
|
||||
@@ -45,8 +47,51 @@ public partial class View
|
||||
|
||||
_pageTitle = $"Aaru Device Report for {report.Manufacturer} {report.Model} {report.Revision}";
|
||||
|
||||
if(report.USB != null)
|
||||
{
|
||||
string? usbVendorDescription = null;
|
||||
string? usbProductDescription = null;
|
||||
|
||||
UsbProduct? dbProduct = await ctx.UsbProducts.Include(static usbProduct => usbProduct.Vendor)
|
||||
.FirstOrDefaultAsync(p => p.ProductId == report.USB.ProductID &&
|
||||
p.Vendor.VendorId == report.USB.VendorID);
|
||||
|
||||
if(dbProduct is null)
|
||||
{
|
||||
UsbVendor? dbVendor = await ctx.UsbVendors.FirstOrDefaultAsync(v => v.VendorId == report.USB.VendorID);
|
||||
|
||||
if(dbVendor is not null) usbVendorDescription = dbVendor.Vendor;
|
||||
}
|
||||
else
|
||||
{
|
||||
usbProductDescription = dbProduct.Product;
|
||||
usbVendorDescription = dbProduct.Vendor.Vendor;
|
||||
}
|
||||
|
||||
UsbItem = new Item
|
||||
{
|
||||
Manufacturer = report.USB.Manufacturer,
|
||||
Product = report.USB.Product,
|
||||
VendorDescription =
|
||||
usbVendorDescription != null
|
||||
? $"0x{report.USB.VendorID:x4} ({usbVendorDescription})"
|
||||
: $"0x{report.USB.VendorID:x4}",
|
||||
ProductDescription = usbProductDescription != null
|
||||
? $"0x{report.USB.ProductID:x4} ({usbProductDescription})"
|
||||
: $"0x{report.USB.ProductID:x4}"
|
||||
};
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public class Item
|
||||
{
|
||||
public string Manufacturer;
|
||||
public string Product;
|
||||
public string ProductDescription;
|
||||
public string VendorDescription;
|
||||
}
|
||||
Reference in New Issue
Block a user