mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Add view for supported densities.
This commit is contained in:
@@ -44,6 +44,9 @@
|
||||
<NavLink class="nav-link" href="/admin/scsi/modes">
|
||||
SCSI MODE SENSE responses
|
||||
</NavLink>
|
||||
<NavLink class="nav-link" href="/admin/supported-densities">
|
||||
Supported densities
|
||||
</NavLink>
|
||||
<NavLink class="nav-link" href="/admin/usb/products">
|
||||
USB Products
|
||||
</NavLink>
|
||||
|
||||
124
Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor
Normal file
124
Aaru.Server/Components/Admin/Pages/SupportedDensities/View.razor
Normal file
@@ -0,0 +1,124 @@
|
||||
@page "/admin/supported-densities"
|
||||
@attribute [Authorize]
|
||||
@layout AdminLayout
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||
|
||||
<PageTitle>Supported densities</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>Supported densities</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(SupportedDensity), nameof(SupportedDensity.Organization))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Name))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Description))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Capacity))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.PrimaryCode))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.SecondaryCode))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.BitsPerMm))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Width))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Tracks))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.DefaultDensity))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Writable))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
@DisplayNameHelper.GetDisplayName(typeof(SupportedDensity), nameof(SupportedDensity.Duplicate))
|
||||
</th>
|
||||
<th class="fw-bold bg-secondary text-light">
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach(SupportedDensity item in _items)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.Organization
|
||||
</td>
|
||||
<td>
|
||||
@item.Name
|
||||
</td>
|
||||
<td>
|
||||
@item.Description
|
||||
</td>
|
||||
<td>
|
||||
@item.Capacity
|
||||
</td>
|
||||
<td>
|
||||
@item.PrimaryCode
|
||||
</td>
|
||||
<td>
|
||||
@item.SecondaryCode
|
||||
</td>
|
||||
<td>
|
||||
@item.BitsPerMm
|
||||
</td>
|
||||
<td>
|
||||
@item.Width
|
||||
</td>
|
||||
<td>
|
||||
@item.Tracks
|
||||
</td>
|
||||
<td>
|
||||
@item.DefaultDensity
|
||||
</td>
|
||||
<td>
|
||||
@item.Writable
|
||||
</td>
|
||||
<td>
|
||||
@item.Duplicate
|
||||
</td>
|
||||
<td>
|
||||
<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 Version" Size="ModalSize.Small">
|
||||
<BodyTemplate>
|
||||
<div class="text-danger">Are you sure you want to delete this supported density?</div>
|
||||
</BodyTemplate>
|
||||
<FooterTemplate>
|
||||
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
|
||||
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
|
||||
</FooterTemplate>
|
||||
</BlazorBootstrap.Modal>
|
||||
@@ -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<SupportedDensity> _items;
|
||||
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user