mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Add view for SCSI SSC
This commit is contained in:
@@ -53,6 +53,9 @@
|
|||||||
<NavLink class="nav-link" href="/admin/scsi/modes">
|
<NavLink class="nav-link" href="/admin/scsi/modes">
|
||||||
SCSI MODE SENSE responses
|
SCSI MODE SENSE responses
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
<NavLink class="nav-link" href="/admin/scsi/ssc">
|
||||||
|
SCSI SSC
|
||||||
|
</NavLink>
|
||||||
<NavLink class="nav-link" href="/admin/supported-densities">
|
<NavLink class="nav-link" href="/admin/supported-densities">
|
||||||
Supported densities
|
Supported densities
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|||||||
106
Aaru.Server/Components/Admin/Pages/Scsi/Ssc/View.razor
Normal file
106
Aaru.Server/Components/Admin/Pages/Scsi/Ssc/View.razor
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
@page "/admin/scsi/ssc"
|
||||||
|
@attribute [Authorize]
|
||||||
|
@layout AdminLayout
|
||||||
|
|
||||||
|
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||||
|
|
||||||
|
<PageTitle>SCSI SSC</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>SCSI SSC</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(Ssc), nameof(Ssc.MinBlockLength))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(Ssc), nameof(Ssc.MaxBlockLength))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(Ssc), nameof(Ssc.BlockSizeGranularity))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(Ssc item in _items)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.MinBlockLength
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.MaxBlockLength
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.BlockSizeGranularity
|
||||||
|
</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>
|
||||||
|
|
||||||
|
@if(_duplicates.Count > 0)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
The following SSC have duplicates.
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
@foreach(SscModel item in _duplicates)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.MinBlockLength
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.MaxBlockLength
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.BlockSizeGranularity
|
||||||
|
</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 SSC" Size="ModalSize.Small">
|
||||||
|
<BodyTemplate>
|
||||||
|
<div class="text-danger">Are you sure you want to delete this SSC?</div>
|
||||||
|
</BodyTemplate>
|
||||||
|
<FooterTemplate>
|
||||||
|
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
|
||||||
|
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
|
||||||
|
</FooterTemplate>
|
||||||
|
</BlazorBootstrap.Modal>
|
||||||
127
Aaru.Server/Components/Admin/Pages/Scsi/Ssc/View.razor.cs
Normal file
127
Aaru.Server/Components/Admin/Pages/Scsi/Ssc/View.razor.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using Aaru.CommonTypes.Metadata;
|
||||||
|
using Aaru.Server.Database.Models;
|
||||||
|
using BlazorBootstrap;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
|
namespace Aaru.Server.Components.Admin.Pages.Scsi.Ssc;
|
||||||
|
|
||||||
|
public partial class View
|
||||||
|
{
|
||||||
|
private Modal? _consolidateModal;
|
||||||
|
private int _deleteId;
|
||||||
|
private Modal? _deleteModal;
|
||||||
|
List<SscModel> _duplicates;
|
||||||
|
bool _initialized;
|
||||||
|
List<CommonTypes.Metadata.Ssc> _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.Ssc.OrderBy(static s => s.MinBlockLength)
|
||||||
|
.ThenBy(static s => s.MaxBlockLength)
|
||||||
|
.ThenBy(static s => s.BlockSizeGranularity)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
_duplicates = await ctx.Ssc.GroupBy(static x => new
|
||||||
|
{
|
||||||
|
x.BlockSizeGranularity,
|
||||||
|
x.MaxBlockLength,
|
||||||
|
x.MinBlockLength
|
||||||
|
})
|
||||||
|
.Where(static x => x.Count() > 1)
|
||||||
|
.Select(static x => new SscModel
|
||||||
|
{
|
||||||
|
BlockSizeGranularity = x.Key.BlockSizeGranularity,
|
||||||
|
MaxBlockLength = x.Key.MaxBlockLength,
|
||||||
|
MinBlockLength = x.Key.MinBlockLength
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
Task ConsolidateDuplicatesAsync() => _consolidateModal?.ShowAsync();
|
||||||
|
|
||||||
|
Task HideConsolidateModalAsync() => _consolidateModal?.HideAsync();
|
||||||
|
|
||||||
|
async Task ConfirmConsolidateAsync()
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
foreach(SscModel duplicate in _duplicates)
|
||||||
|
{
|
||||||
|
CommonTypes.Metadata.Ssc? master =
|
||||||
|
ctx.Ssc.FirstOrDefault(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity &&
|
||||||
|
m.MaxBlockLength == duplicate.MaxBlockLength &&
|
||||||
|
m.MinBlockLength == duplicate.MinBlockLength);
|
||||||
|
|
||||||
|
if(master is null) continue;
|
||||||
|
|
||||||
|
foreach(CommonTypes.Metadata.Ssc ssc in await ctx.Ssc
|
||||||
|
.Where(m => m.BlockSizeGranularity ==
|
||||||
|
duplicate.BlockSizeGranularity &&
|
||||||
|
m.MaxBlockLength == duplicate.MaxBlockLength &&
|
||||||
|
m.MinBlockLength == duplicate.MinBlockLength)
|
||||||
|
.Skip(1)
|
||||||
|
.ToArrayAsync())
|
||||||
|
{
|
||||||
|
foreach(TestedSequentialMedia media in ctx.TestedSequentialMedia.Where(d => d.SscId == ssc.Id))
|
||||||
|
media.SscId = master.Id;
|
||||||
|
|
||||||
|
ctx.Ssc.Update(ssc);
|
||||||
|
ctx.Ssc.Remove(ssc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Ssc? ssc = await ctx.Ssc.FindAsync(id);
|
||||||
|
|
||||||
|
if(ssc is not null)
|
||||||
|
{
|
||||||
|
ctx.Ssc.Remove(ssc);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user