mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add delete button for versions page.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
@using Version = Aaru.Server.Database.Models.Version
|
@using Version = Aaru.Server.Database.Models.Version
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
@layout AdminLayout
|
@layout AdminLayout
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||||
|
|
||||||
@@ -26,6 +27,9 @@
|
|||||||
<th class="fw-bold bg-secondary text-light">
|
<th class="fw-bold bg-secondary text-light">
|
||||||
@DisplayNameHelper.GetDisplayName(typeof(Version), nameof(Version.Count))
|
@DisplayNameHelper.GetDisplayName(typeof(Version), nameof(Version.Count))
|
||||||
</th>
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -38,8 +42,23 @@
|
|||||||
<td>
|
<td>
|
||||||
@item.Count
|
@item.Count
|
||||||
</td>
|
</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>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<BlazorBootstrap.Modal @ref="_deleteModal" Title="Delete Version" Size="ModalSize.Small">
|
||||||
|
<BodyTemplate>
|
||||||
|
<div class="text-danger">Are you sure you want to delete this version?</div>
|
||||||
|
</BodyTemplate>
|
||||||
|
<FooterTemplate>
|
||||||
|
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
|
||||||
|
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
|
||||||
|
</FooterTemplate>
|
||||||
|
</BlazorBootstrap.Modal>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using BlazorBootstrap;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using DbContext = Aaru.Server.Database.DbContext;
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
using Version = Aaru.Server.Database.Models.Version;
|
using Version = Aaru.Server.Database.Models.Version;
|
||||||
@@ -6,8 +7,10 @@ namespace Aaru.Server.Components.Admin.Pages.Versions;
|
|||||||
|
|
||||||
public partial class View
|
public partial class View
|
||||||
{
|
{
|
||||||
bool _initialized;
|
private int _deleteId;
|
||||||
List<Version> _items;
|
private Modal? _deleteModal;
|
||||||
|
bool _initialized;
|
||||||
|
List<Version> _items;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
@@ -24,4 +27,41 @@ public partial class View
|
|||||||
|
|
||||||
StateHasChanged();
|
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();
|
||||||
|
Version? version = await ctx.Versions.FindAsync(id);
|
||||||
|
|
||||||
|
if(version is not null)
|
||||||
|
{
|
||||||
|
ctx.Versions.Remove(version);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RefreshItemsAsync()
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
_items = await ctx.Versions.OrderBy(static v => v.Name).ToListAsync();
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user