From 5fbd375b429025221c74677a58f88b4091389cd8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 13 Sep 2025 03:32:10 +0100 Subject: [PATCH] Add device statistics page with delete functionality for device stats --- .../Components/Admin/AdminNavMenu.razor | 3 + .../Admin/Pages/DeviceStats/View.razor | 95 +++++++++++++++++++ .../Admin/Pages/DeviceStats/View.razor.cs | 75 +++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor create mode 100644 Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor.cs diff --git a/Aaru.Server/Components/Admin/AdminNavMenu.razor b/Aaru.Server/Components/Admin/AdminNavMenu.razor index 35697904..ceb3483d 100644 --- a/Aaru.Server/Components/Admin/AdminNavMenu.razor +++ b/Aaru.Server/Components/Admin/AdminNavMenu.razor @@ -26,6 +26,9 @@ Device reports + + Device statistics + Filesystems diff --git a/Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor b/Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor new file mode 100644 index 00000000..d72a20fb --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor @@ -0,0 +1,95 @@ +@page "/admin/device-stats" +@attribute [Authorize] +@layout AdminLayout +@rendermode InteractiveServer + +@inject Microsoft.EntityFrameworkCore.IDbContextFactory DbContextFactory + +Device statistics + +@if(!_initialized) +{ +
+

Loading...

+
+ + return; +} + +
+

Device statistics

+ + + + + + + + + + + + + @foreach(DeviceStat item in _items) + { + + + + + + + + + } + +
+ @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Manufacturer)) + + @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Model)) + + @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Revision)) + + @DisplayNameHelper.GetDisplayName(typeof(DeviceStat), nameof(DeviceStat.Bus)) + + Has report? + + Actions +
+ @item.Manufacturer + + @item.Model + + @item.Revision + + @item.Bus + + @if(item.Report is null) + { + @("No") + + (Find) + } + else + { + Yes + } + + + Edit + + +
+
+ + + +
Are you sure you want to delete this device statistic?
+
+ + + + +
\ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor.cs b/Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor.cs new file mode 100644 index 00000000..81664beb --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/DeviceStats/View.razor.cs @@ -0,0 +1,75 @@ +using Aaru.Server.Database.Models; +using BlazorBootstrap; +using Microsoft.EntityFrameworkCore; +using DbContext = Aaru.Server.Database.DbContext; + +namespace Aaru.Server.Components.Admin.Pages.DeviceStats; + +public partial class View +{ + private int _deleteId; + private Modal? _deleteModal; + bool _initialized; + List _items; + + /// + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + StateHasChanged(); + + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + + _items = await ctx.DeviceStats.OrderBy(static d => d.Manufacturer) + .ThenBy(static d => d.Model) + .ThenBy(static d => d.Bus) + .ToListAsync(); + + _initialized = true; + + 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(); + DeviceStat? stat = await ctx.DeviceStats.FindAsync(id); + + if(stat is not null) + { + ctx.DeviceStats.Remove(stat); + await ctx.SaveChangesAsync(); + } + } + + private async Task RefreshItemsAsync() + { + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + + _items = await ctx.DeviceStats.OrderBy(static d => d.Manufacturer) + .ThenBy(static d => d.Model) + .ThenBy(static d => d.Bus) + .ToListAsync(); + + StateHasChanged(); + } +} \ No newline at end of file