diff --git a/Aaru.Server/Components/Admin/AdminNavMenu.razor b/Aaru.Server/Components/Admin/AdminNavMenu.razor index 8753f584..5a98ea7d 100644 --- a/Aaru.Server/Components/Admin/AdminNavMenu.razor +++ b/Aaru.Server/Components/Admin/AdminNavMenu.razor @@ -26,6 +26,9 @@ Media formats + + Medias + Operating systems diff --git a/Aaru.Server/Components/Admin/Pages/Medias/View.razor b/Aaru.Server/Components/Admin/Pages/Medias/View.razor new file mode 100644 index 00000000..c617e731 --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/Medias/View.razor @@ -0,0 +1,75 @@ +@page "/admin/medias" +@attribute [Authorize] +@layout AdminLayout +@rendermode InteractiveServer + +@inject Microsoft.EntityFrameworkCore.IDbContextFactory DbContextFactory + +Medias + +@if(!_initialized) +{ +
+

Loading...

+
+ + return; +} + +
+ + + + + + + + + + + + @foreach(Media item in _items) + { + + + + + + + + } + +
+ @DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.PhysicalType)) + + @DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.LogicalType)) + + @DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.Real)) + + @DisplayNameHelper.GetDisplayName(typeof(Media), nameof(Media.Count)) + + Actions +
+ @item.PhysicalType + + @item.LogicalType + + @item.Real + + @item.Count + + +
+
+ + + +
Are you sure you want to delete this media?
+
+ + + + +
\ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/Medias/View.razor.cs b/Aaru.Server/Components/Admin/Pages/Medias/View.razor.cs new file mode 100644 index 00000000..b2539eb2 --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/Medias/View.razor.cs @@ -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 _items; + + /// + 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(); + } +} \ No newline at end of file