mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Add view for medias.
This commit is contained in:
@@ -26,6 +26,9 @@
|
|||||||
<NavLink class="nav-link" href="/admin/media-formats">
|
<NavLink class="nav-link" href="/admin/media-formats">
|
||||||
Media formats
|
Media formats
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
<NavLink class="nav-link" href="/admin/medias">
|
||||||
|
Medias
|
||||||
|
</NavLink>
|
||||||
<NavLink class="nav-link" href="/admin/operating-systems">
|
<NavLink class="nav-link" href="/admin/operating-systems">
|
||||||
Operating systems
|
Operating systems
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|||||||
75
Aaru.Server/Components/Admin/Pages/Medias/View.razor
Normal file
75
Aaru.Server/Components/Admin/Pages/Medias/View.razor
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
@page "/admin/medias"
|
||||||
|
@attribute [Authorize]
|
||||||
|
@layout AdminLayout
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
|
||||||
|
|
||||||
|
<PageTitle>Medias</PageTitle>
|
||||||
|
|
||||||
|
@if(!_initialized)
|
||||||
|
{
|
||||||
|
<div class="stats-section">
|
||||||
|
<h1 style="color: red; align-content: center; padding: 2rem">Loading...</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
<section class="stats-section">
|
||||||
|
<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(Media), nameof(Media.PhysicalType))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.LogicalType))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.Real))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
@DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.Count))
|
||||||
|
</th>
|
||||||
|
<th class="fw-bold bg-secondary text-light">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(Media item in _items)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.PhysicalType
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.LogicalType
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Real
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Count
|
||||||
|
</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 media?</div>
|
||||||
|
</BodyTemplate>
|
||||||
|
<FooterTemplate>
|
||||||
|
<button class="btn btn-secondary" @onclick="HideDeleteModal">Cancel</button>
|
||||||
|
<button class="btn btn-danger" @onclick="ConfirmDelete">Delete</button>
|
||||||
|
</FooterTemplate>
|
||||||
|
</BlazorBootstrap.Modal>
|
||||||
75
Aaru.Server/Components/Admin/Pages/Medias/View.razor.cs
Normal file
75
Aaru.Server/Components/Admin/Pages/Medias/View.razor.cs
Normal 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.Medias;
|
||||||
|
|
||||||
|
public partial class View
|
||||||
|
{
|
||||||
|
private int _deleteId;
|
||||||
|
private Modal? _deleteModal;
|
||||||
|
bool _initialized;
|
||||||
|
List<Media> _items;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
_items = (await ctx.Medias.ToListAsync()).OrderBy(static m => m.PhysicalType)
|
||||||
|
.ThenBy(static m => m.LogicalType)
|
||||||
|
.ThenBy(static m => m.Real)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_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();
|
||||||
|
Media? mediaFormat = await ctx.Medias.FindAsync(id);
|
||||||
|
|
||||||
|
if(mediaFormat is not null)
|
||||||
|
{
|
||||||
|
ctx.Medias.Remove(mediaFormat);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RefreshItemsAsync()
|
||||||
|
{
|
||||||
|
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
_items = (await ctx.Medias.ToListAsync()).OrderBy(static m => m.PhysicalType)
|
||||||
|
.ThenBy(static m => m.LogicalType)
|
||||||
|
.ThenBy(static m => m.Real)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user