Add Compact Disc Offsets management view with delete functionality

This commit is contained in:
2025-09-12 12:55:15 +01:00
parent f5cd821b1c
commit 172e61c1fd
3 changed files with 175 additions and 0 deletions

View File

@@ -17,6 +17,9 @@
<NavLink class="nav-link" href="/admin/commands"> <NavLink class="nav-link" href="/admin/commands">
Commands Commands
</NavLink> </NavLink>
<NavLink class="nav-link" href="/admin/cd-offsets">
Compact Disc Offsets
</NavLink>
<NavLink class="nav-link" href="/admin/filesystems"> <NavLink class="nav-link" href="/admin/filesystems">
Filesystems Filesystems
</NavLink> </NavLink>

View File

@@ -0,0 +1,97 @@
@page "/admin/cd-offsets"
@attribute [Authorize]
@layout AdminLayout
@rendermode InteractiveServer
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>Compact Disc Offsets</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>Compact Disc Offsets</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(CompactDiscOffset), nameof(CompactDiscOffset.Manufacturer))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(CompactDiscOffset), nameof(CompactDiscOffset.Model))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(CompactDiscOffset), nameof(CompactDiscOffset.Offset))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(CompactDiscOffset), nameof(CompactDiscOffset.Submissions))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(CompactDiscOffset), nameof(CompactDiscOffset.Agreement))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(CompactDiscOffset), nameof(CompactDiscOffset.AddedWhen))
</th>
<th class="fw-bold bg-secondary text-light">
@DisplayNameHelper.GetDisplayName(typeof(CompactDiscOffset), nameof(CompactDiscOffset.ModifiedWhen))
</th>
<th class="fw-bold bg-secondary text-light">
Actions
</th>
</tr>
</thead>
<tbody>
@foreach(CompactDiscOffset item in _items)
{
<tr>
<td>
@item.Manufacturer
</td>
<td>
@item.Model
</td>
<td>
@item.Offset
</td>
<td>
@item.Submissions
</td>
<td>
@item.Agreement
</td>
<td>
@item.AddedWhen
</td>
<td>
@item.ModifiedWhen
</td>
<td>
<a href="/admin/cd-offsets/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 Version" Size="ModalSize.Small">
<BodyTemplate>
<div class="text-danger">Are you sure you want to delete this offset?</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,75 @@
using Aaru.Server.Database.Models;
using BlazorBootstrap;
using Microsoft.EntityFrameworkCore;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.CompactDiscOffsets;
public partial class View
{
private int _deleteId;
private Modal? _deleteModal;
bool _initialized;
List<CompactDiscOffset> _items;
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
StateHasChanged();
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
_items = await ctx.CdOffsets.OrderBy(static o => o.Manufacturer)
.ThenBy(static o => o.Model)
.ThenBy(static o => o.Offset)
.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();
CompactDiscOffset? offset = await ctx.CdOffsets.FindAsync(id);
if(offset is not null)
{
ctx.CdOffsets.Remove(offset);
await ctx.SaveChangesAsync();
}
}
private async Task RefreshItemsAsync()
{
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
_items = await ctx.CdOffsets.OrderBy(static o => o.Manufacturer)
.ThenBy(static o => o.Model)
.ThenBy(static o => o.Offset)
.ToListAsync();
StateHasChanged();
}
}