From 7e40df815a26e9fbacc64dfd8513c968b8bd6902 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 12 Sep 2025 01:29:57 +0100 Subject: [PATCH] Add view for supported densities. --- .../Components/Admin/AdminNavMenu.razor | 3 + .../Admin/Pages/SupportedDensities/View.razor | 124 ++++++++++++++++++ .../Pages/SupportedDensities/View.razor.cs | 93 +++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor create mode 100644 Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor.cs diff --git a/Aaru.Server/Components/Admin/AdminNavMenu.razor b/Aaru.Server/Components/Admin/AdminNavMenu.razor index a4ba3fdc..1097636b 100644 --- a/Aaru.Server/Components/Admin/AdminNavMenu.razor +++ b/Aaru.Server/Components/Admin/AdminNavMenu.razor @@ -44,6 +44,9 @@ SCSI MODE SENSE responses + + Supported densities + USB Products diff --git a/Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor b/Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor new file mode 100644 index 00000000..48ffc764 --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor @@ -0,0 +1,124 @@ +@page "/admin/supported-densities" +@attribute [Authorize] +@layout AdminLayout +@rendermode InteractiveServer + +@inject Microsoft.EntityFrameworkCore.IDbContextFactory DbContextFactory + +Supported densities + +@if(!_initialized) +{ +
+

Loading...

+
+ + return; +} + +
+

Supported densities

+ + + + + + + + + + + + + + + + + + + + @foreach(SupportedDensity item in _items) + { + + + + + + + + + + + + + + + + } + +
+ @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Organization)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Name)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Description)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Capacity)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.PrimaryCode)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.SecondaryCode)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.BitsPerMm)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Width)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Tracks)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.DefaultDensity)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Writable)) + + @DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Duplicate)) + + Actions +
+ @item.Organization + + @item.Name + + @item.Description + + @item.Capacity + + @item.PrimaryCode + + @item.SecondaryCode + + @item.BitsPerMm + + @item.Width + + @item.Tracks + + @item.DefaultDensity + + @item.Writable + + @item.Duplicate + + +
+
+ + + +
Are you sure you want to delete this supported density?
+
+ + + + +
\ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor.cs b/Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor.cs new file mode 100644 index 00000000..80789a04 --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor.cs @@ -0,0 +1,93 @@ +using Aaru.CommonTypes.Metadata; +using BlazorBootstrap; +using Microsoft.EntityFrameworkCore; +using DbContext = Aaru.Server.Database.DbContext; + +namespace Aaru.Server.Components.Admin.Pages.SupportedDensities; + +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.SupportedDensity.OrderBy(static d => d.Organization) + .ThenBy(static d => d.Name) + .ThenBy(static d => d.Description) + .ThenBy(static d => d.Capacity) + .ThenBy(static d => d.PrimaryCode) + .ThenBy(static d => d.SecondaryCode) + .ThenBy(static d => d.BitsPerMm) + .ThenBy(static d => d.Width) + .ThenBy(static d => d.Tracks) + .ThenBy(static d => d.DefaultDensity) + .ThenBy(static d => d.Writable) + .ThenBy(static d => d.Duplicate) + .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 DeleteVersionAsync(_deleteId); + await HideDeleteModal(); + await RefreshItemsAsync(); + } + + private async Task DeleteVersionAsync(int id) + { + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + SupportedDensity? supportedDensity = await ctx.SupportedDensity.FindAsync(id); + + if(supportedDensity is not null) + { + ctx.SupportedDensity.Remove(supportedDensity); + await ctx.SaveChangesAsync(); + } + } + + private async Task RefreshItemsAsync() + { + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + + _items = await ctx.SupportedDensity.OrderBy(static d => d.Organization) + .ThenBy(static d => d.Name) + .ThenBy(static d => d.Description) + .ThenBy(static d => d.Capacity) + .ThenBy(static d => d.PrimaryCode) + .ThenBy(static d => d.SecondaryCode) + .ThenBy(static d => d.BitsPerMm) + .ThenBy(static d => d.Width) + .ThenBy(static d => d.Tracks) + .ThenBy(static d => d.DefaultDensity) + .ThenBy(static d => d.Writable) + .ThenBy(static d => d.Duplicate) + .ToListAsync(); + + StateHasChanged(); + } +} \ No newline at end of file