Add uploaded reports page with delete functionality and navigation link

This commit is contained in:
2025-09-13 04:07:36 +01:00
parent ad0472babb
commit 70be4691ff
3 changed files with 168 additions and 0 deletions

View File

@@ -83,6 +83,9 @@
<NavLink class="nav-link" href="/admin/tested-media/sequential">
Tested sequential media
</NavLink>
<NavLink class="nav-link" href="/admin/reports">
Uploaded reports
</NavLink>
<NavLink class="nav-link" href="/admin/usb/devices">
USB Devices
</NavLink>

View File

@@ -0,0 +1,93 @@
@page "/admin/reports"
@attribute [Authorize]
@layout AdminLayout
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>Uploaded 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>Uploaded reports</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(UploadedReport), nameof(UploadedReport.UploadedWhen))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UploadedReport), nameof(UploadedReport.Manufacturer))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UploadedReport), nameof(UploadedReport.Model))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UploadedReport), nameof(UploadedReport.Revision))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UploadedReport), nameof(UploadedReport.CompactFlash))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(UploadedReport), nameof(UploadedReport.Type))
</th>
<th class="fw-bold bg-secondary text-light">
Actions
</th>
</tr>
</thead>
<tbody>
@foreach(UploadedReport item in _items)
{
<tr>
<td>
@item.UploadedWhen
</td>
<td>
@item.Manufacturer
</td>
<td>
@item.Model
</td>
<td>
@item.Revision
</td>
<td>
@item.CompactFlash
</td>
<td>
@item.Type
</td>
<td>
<a href="/admin/reports/@item.Id" class="btn btn-primary btn-sm">
<i class="bi bi-eye"></i> Details
</a>
<a href="/admin/reports/edit/@item.Id" class="btn btn-secondary 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>
</section>
<BlazorBootstrap.Modal @ref="_deleteModal" Title="Delete uploaded report" Size="ModalSize.Small">
<BodyTemplate>
<div class="text-danger">Are you sure you want to delete this uploaded report?</div>
</BodyTemplate>
<FooterTemplate>
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
</FooterTemplate>
</BlazorBootstrap.Modal>

View File

@@ -0,0 +1,72 @@
using Aaru.Server.Database.Models;
using BlazorBootstrap;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.Reports;
public partial class List
{
private int _deleteId;
private Modal? _deleteModal;
bool _initialized;
List<UploadedReport> _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.Reports.OrderBy(static r => r.Manufacturer)
.ThenBy(static r => r.Model)
.ThenBy(static r => r.Revision)
.ThenBy(static r => r.CompactFlash)
.ThenBy(static r => r.Type)
.ToListAsync();
}
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();
UploadedReport? report = await ctx.Reports.FindAsync(id);
if(report is not null)
{
ctx.Reports.Remove(report);
await ctx.SaveChangesAsync();
}
}
}