diff --git a/Aaru.Server.Database/Models/FindReportModel.cs b/Aaru.Server.Database/Models/FindReportModel.cs index c7f41dc0..f47d94cb 100644 --- a/Aaru.Server.Database/Models/FindReportModel.cs +++ b/Aaru.Server.Database/Models/FindReportModel.cs @@ -2,9 +2,9 @@ namespace Aaru.Server.Database.Models; public class FindReportModel : BaseModel { - public string Manufacturer { get; set; } + public string? Manufacturer { get; set; } public string Model { get; set; } - public string Revision { get; set; } - public string Bus { get; set; } + public string? Revision { get; set; } + public string? Bus { get; set; } public List LikeDevices { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/Devices/Find.razor b/Aaru.Server/Components/Admin/Pages/Devices/Find.razor new file mode 100644 index 00000000..be9ba38b --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/Devices/Find.razor @@ -0,0 +1,101 @@ +@page "/admin/devices/find/{id:int}" +@attribute [Authorize] +@layout AdminLayout + +@inject Microsoft.EntityFrameworkCore.IDbContextFactory DbContextFactory + +Find device reports + +@if(!_initialized) +{ +
+

Loading...

+
+ + return; +} + +
+

Found device reports with similar data

+
+
+
+ @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Manufacturer)) +
+
+ @_found.Manufacturer +
+
+ @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Model)) +
+
+ @_found.Model +
+
+ @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Revision)) +
+
+ @_found.Revision +
+
+ @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Bus)) +
+
+ @_found.Bus +
+
+ @if(_found.LikeDevices.Count == 0) + { +
No device report with similar information has been found!
+ } + else + { + + + + + + + + + + + + + @foreach(Device item in _found.LikeDevices) + { + + + + + + + + + } + +
+ @DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Manufacturer)) + + @DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Model)) + + @DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Revision)) + + @DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.CompactFlash)) + + @DisplayNameHelper.GetDisplayName(typeof(Device), nameof(Device.Type)) +
+ @item.Manufacturer + + @item.Model + + @item.Revision + + @item.CompactFlash + + @item.Type + + Link +
+ } +
\ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/Devices/Find.razor.cs b/Aaru.Server/Components/Admin/Pages/Devices/Find.razor.cs new file mode 100644 index 00000000..a432ac6a --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/Devices/Find.razor.cs @@ -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!; + + /// + 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}"); + } +} \ No newline at end of file