mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add FireWire registers management view with delete and consolidate functionality
This commit is contained in:
@@ -26,6 +26,9 @@
|
|||||||
<NavLink class="nav-link" href="/admin/filters">
|
<NavLink class="nav-link" href="/admin/filters">
|
||||||
Filters
|
Filters
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
<NavLink class="nav-link" href="/admin/firewire">
|
||||||
|
FireWire registers
|
||||||
|
</NavLink>
|
||||||
<NavLink class="nav-link" href="/admin/media-formats">
|
<NavLink class="nav-link" href="/admin/media-formats">
|
||||||
Media formats
|
Media formats
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|||||||
124
Aaru.Server/Components/Admin/Pages/FireWire/List.razor
Normal file
124
Aaru.Server/Components/Admin/Pages/FireWire/List.razor
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
@page "/admin/firewire"
|
||||||
|
@attribute [Authorize]
|
||||||
|
@layout AdminLayout
|
||||||
|
|
||||||
|
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||||
|
|
||||||
|
<PageTitle>FireWire registers</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>FireWire registers</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(FireWire), nameof(FireWire.Manufacturer))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(FireWire), nameof(FireWire.Product))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(FireWire), nameof(FireWire.VendorID))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(FireWire), nameof(FireWire.ProductID))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(FireWire), nameof(FireWire.RemovableMedia))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(FireWire item in _items)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.Manufacturer
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Product
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.VendorID
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.ProductID
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.RemovableMedia
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/admin/firewire/edit/@item.Id" class="btn btn-primary btn-sm">
|
||||||
|
<i class="bi bi-pencil"></i> Edit
|
||||||
|
</a>
|
||||||
|
<button class="btn btn-danger btn-sm" @onclick="async () => await ShowDeleteModal(item.Id)">
|
||||||
|
<i class="bi bi-trash"></i> Delete
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
@if(_duplicates.Count > 0)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
The following USB devices have duplicates.
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
@foreach(FireWireModel item in _duplicates)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.Manufacturer
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Product
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.VendorID
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.ProductID
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button class="btn btn-danger" @onclick="ConsolidateDuplicatesAsync">Consolidate Duplicates</Button>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<BlazorBootstrap.Modal @ref="_consolidateModal" Title="Consolidate duplicates" Size="ModalSize.Small">
|
||||||
|
<BodyTemplate>
|
||||||
|
<div class="text-danger">Are you sure you want to delete the duplicates?</div>
|
||||||
|
</BodyTemplate>
|
||||||
|
<FooterTemplate>
|
||||||
|
<button class="btn btn-secondary" @onclick="HideConsolidateModalAsync">Cancel</button>
|
||||||
|
<button class="btn btn-danger" @onclick="ConfirmConsolidateAsync">Delete</button>
|
||||||
|
</FooterTemplate>
|
||||||
|
</BlazorBootstrap.Modal>
|
||||||
|
|
||||||
|
<BlazorBootstrap.Modal @ref="_deleteModal" Title="Delete FireWire device" Size="ModalSize.Small">
|
||||||
|
<BodyTemplate>
|
||||||
|
<div class="text-danger">Are you sure you want to delete this FireWire device?</div>
|
||||||
|
</BodyTemplate>
|
||||||
|
<FooterTemplate>
|
||||||
|
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
|
||||||
|
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
|
||||||
|
</FooterTemplate>
|
||||||
|
</BlazorBootstrap.Modal>
|
||||||
136
Aaru.Server/Components/Admin/Pages/FireWire/List.razor.cs
Normal file
136
Aaru.Server/Components/Admin/Pages/FireWire/List.razor.cs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
using Aaru.Server.Database.Models;
|
||||||
|
using BlazorBootstrap;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
|
namespace Aaru.Server.Components.Admin.Pages.FireWire;
|
||||||
|
|
||||||
|
public partial class List
|
||||||
|
{
|
||||||
|
private Modal? _consolidateModal;
|
||||||
|
private int _deleteId;
|
||||||
|
private Modal? _deleteModal;
|
||||||
|
List<FireWireModel> _duplicates;
|
||||||
|
bool _initialized;
|
||||||
|
List<CommonTypes.Metadata.FireWire> _items;
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
|
||||||
|
await RefreshItemsAsync();
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task RefreshItemsAsync()
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
_items = await ctx.FireWire.OrderBy(static f => f.Manufacturer).ThenBy(static f => f.Product).ToListAsync();
|
||||||
|
|
||||||
|
_duplicates = await ctx.FireWire.GroupBy(static x => new
|
||||||
|
{
|
||||||
|
x.VendorID,
|
||||||
|
x.ProductID,
|
||||||
|
x.Manufacturer,
|
||||||
|
x.Product,
|
||||||
|
x.RemovableMedia
|
||||||
|
})
|
||||||
|
.Where(static x => x.Count() > 1)
|
||||||
|
.Select(static x => new FireWireModel
|
||||||
|
{
|
||||||
|
VendorID = x.Key.VendorID,
|
||||||
|
ProductID = x.Key.ProductID,
|
||||||
|
Manufacturer = x.Key.Manufacturer,
|
||||||
|
Product = x.Key.Product,
|
||||||
|
RemovableMedia = x.Key.RemovableMedia
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
Task ConsolidateDuplicatesAsync() => _consolidateModal?.ShowAsync();
|
||||||
|
|
||||||
|
Task HideConsolidateModalAsync() => _consolidateModal?.HideAsync();
|
||||||
|
|
||||||
|
async Task ConfirmConsolidateAsync()
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
foreach(FireWireModel duplicate in _duplicates)
|
||||||
|
{
|
||||||
|
CommonTypes.Metadata.FireWire? master = ctx.FireWire.FirstOrDefault(m => m.VendorID == duplicate.VendorID &&
|
||||||
|
m.ProductID ==
|
||||||
|
duplicate.ProductID &&
|
||||||
|
m.Manufacturer ==
|
||||||
|
duplicate.Manufacturer &&
|
||||||
|
m.Product ==
|
||||||
|
duplicate.Product &&
|
||||||
|
m.RemovableMedia ==
|
||||||
|
duplicate.RemovableMedia);
|
||||||
|
|
||||||
|
if(master is null) continue;
|
||||||
|
|
||||||
|
foreach(CommonTypes.Metadata.FireWire firewire in await ctx.FireWire
|
||||||
|
.Where(m => m.VendorID == duplicate.VendorID &&
|
||||||
|
m.ProductID == duplicate.ProductID &&
|
||||||
|
m.Manufacturer ==
|
||||||
|
duplicate.Manufacturer &&
|
||||||
|
m.Product == duplicate.Product &&
|
||||||
|
m.RemovableMedia ==
|
||||||
|
duplicate.RemovableMedia)
|
||||||
|
.Skip(1)
|
||||||
|
.ToArrayAsync())
|
||||||
|
{
|
||||||
|
foreach(Device device in ctx.Devices.Where(d => d.FireWire.Id == firewire.Id)) device.FireWire = master;
|
||||||
|
|
||||||
|
foreach(UploadedReport report in ctx.Reports.Where(d => d.FireWire.Id == firewire.Id))
|
||||||
|
report.FireWire = master;
|
||||||
|
|
||||||
|
ctx.FireWire.Remove(firewire);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
|
||||||
|
await RefreshItemsAsync();
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowDeleteModal(int id)
|
||||||
|
{
|
||||||
|
_deleteId = id;
|
||||||
|
if(_deleteModal != null) await _deleteModal.ShowAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HideDeleteModal()
|
||||||
|
{
|
||||||
|
if(_deleteModal != null) await _deleteModal.HideAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ConfirmDelete()
|
||||||
|
{
|
||||||
|
await DeleteAsync(_deleteId);
|
||||||
|
await HideDeleteModal();
|
||||||
|
await RefreshItemsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DeleteAsync(int id)
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
CommonTypes.Metadata.FireWire? firewire = await ctx.FireWire.FindAsync(id);
|
||||||
|
|
||||||
|
if(firewire is not null)
|
||||||
|
{
|
||||||
|
ctx.FireWire.Remove(firewire);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user