Add find device reports page with linking functionality

This commit is contained in:
2025-09-13 03:54:13 +01:00
parent 6ebd049c4d
commit ad0472babb
3 changed files with 171 additions and 3 deletions

View File

@@ -2,9 +2,9 @@ namespace Aaru.Server.Database.Models;
public class FindReportModel : BaseModel<int> public class FindReportModel : BaseModel<int>
{ {
public string Manufacturer { get; set; } public string? Manufacturer { get; set; }
public string Model { get; set; } public string Model { get; set; }
public string Revision { get; set; } public string? Revision { get; set; }
public string Bus { get; set; } public string? Bus { get; set; }
public List<Device> LikeDevices { get; set; } public List<Device> LikeDevices { get; set; }
} }

View File

@@ -0,0 +1,101 @@
@page "/admin/devices/find/{id:int}"
@attribute [Authorize]
@layout AdminLayout
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>Find device reports</PageTitle>
@if(!_initialized)
{
<div class="stats-section">
<h1 style="color: red; align-content: center; padding: 2rem">Loading...</h1>
</div>
return;
}
<section class="stats-section">
<h4>Found device reports with similar data</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Manufacturer))
</dt>
<dd class="col-sm-10">
@_found.Manufacturer
</dd>
<dt class="col-sm-2">
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Model))
</dt>
<dd class="col-sm-10">
@_found.Model
</dd>
<dt class="col-sm-2">
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Revision))
</dt>
<dd class="col-sm-10">
@_found.Revision
</dd>
<dt class="col-sm-2">
@DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Bus))
</dt>
<dd class="col-sm-10">
@_found.Bus
</dd>
</dl>
@if(_found.LikeDevices.Count == 0)
{
<div>No device report with similar information has been found!</div>
}
else
{
<table class="table">
<thead>
<tr>
<th>
@DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Manufacturer))
</th>
<th>
@DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Model))
</th>
<th>
@DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Revision))
</th>
<th>
@DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.CompactFlash))
</th>
<th>
@DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Type))
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach(Device item in _found.LikeDevices)
{
<tr>
<td>
@item.Manufacturer
</td>
<td>
@item.Model
</td>
<td>
@item.Revision
</td>
<td>
@item.CompactFlash
</td>
<td>
@item.Type
</td>
<td>
<a @onclick="() => LinkReports(item.Id, _found.Id)" class="btn btn-secondary">Link</a>
</td>
</tr>
}
</tbody>
</table>
}
</section>

View File

@@ -0,0 +1,67 @@
using System.Collections.Specialized;
using System.Web;
using Aaru.Server.Database.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.Devices;
public partial class Find
{
FindReportModel _found;
bool _initialized;
[Parameter]
public int Id { get; set; }
[Inject]
NavigationManager Navigation { get; set; } = null!;
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
StateHasChanged();
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
// Get query parameters
Uri uri = Navigation.ToAbsoluteUri(Navigation.Uri);
NameValueCollection query = HttpUtility.ParseQueryString(uri.Query);
string model = query["model"] ?? "";
_found = new FindReportModel
{
Id = Id,
Manufacturer = query["manufacturer"],
Model = model,
Revision = query["revision"],
Bus = query["bus"],
#pragma warning disable RCS1155
LikeDevices = await ctx.Devices.Where(r => r.Model.ToLower().Contains(model.ToLower())).ToListAsync()
#pragma warning restore RCS1155
};
_initialized = true;
StateHasChanged();
}
async Task LinkReports(int deviceId, int statsId)
{
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
Device? device = await ctx.Devices.FirstOrDefaultAsync(m => m.Id == deviceId);
DeviceStat? stat = await ctx.DeviceStats.FirstOrDefaultAsync(m => m.Id == statsId);
if(stat != null)
{
stat.Report = device;
ctx.Update(stat);
}
await ctx.SaveChangesAsync();
Id = deviceId;
Navigation.NavigateTo($"/admin/devices/{deviceId}");
}
}