diff --git a/Aaru.Server/Components/Admin/AdminNavMenu.razor b/Aaru.Server/Components/Admin/AdminNavMenu.razor index 161f9efc..8753f584 100644 --- a/Aaru.Server/Components/Admin/AdminNavMenu.razor +++ b/Aaru.Server/Components/Admin/AdminNavMenu.razor @@ -23,6 +23,9 @@ Filters + + Media formats + Operating systems diff --git a/Aaru.Server/Components/Admin/Pages/Chs/View.razor b/Aaru.Server/Components/Admin/Pages/Chs/View.razor index d03970ce..0e6ae690 100644 --- a/Aaru.Server/Components/Admin/Pages/Chs/View.razor +++ b/Aaru.Server/Components/Admin/Pages/Chs/View.razor @@ -53,7 +53,6 @@
The following CHS have duplicates. - @foreach(ChsModel item in _duplicates) { diff --git a/Aaru.Server/Components/Admin/Pages/MediaFormats/View.razor b/Aaru.Server/Components/Admin/Pages/MediaFormats/View.razor new file mode 100644 index 00000000..7ffb2428 --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/MediaFormats/View.razor @@ -0,0 +1,63 @@ +@page "/admin/media-formats" +@attribute [Authorize] +@layout AdminLayout +@rendermode InteractiveServer + +@inject Microsoft.EntityFrameworkCore.IDbContextFactory DbContextFactory + +Media formats + +@if(!_initialized) +{ +
+

Loading...

+
+ + return; +} + +
+
+ + + + + + + + + @foreach(MediaFormat item in _items) + { + + + + + + } + +
+ @DisplayNameHelper.GetDisplayName(typeof(MediaFormat), nameof(MediaFormat.Name)) + + @DisplayNameHelper.GetDisplayName(typeof(MediaFormat), nameof(MediaFormat.Count)) + + Actions +
+ @item.Name + + @item.Count + + +
+ + + + +
Are you sure you want to delete this media format?
+
+ + + + +
\ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/MediaFormats/View.razor.cs b/Aaru.Server/Components/Admin/Pages/MediaFormats/View.razor.cs new file mode 100644 index 00000000..8705c52c --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/MediaFormats/View.razor.cs @@ -0,0 +1,67 @@ +using Aaru.Server.Database.Models; +using BlazorBootstrap; +using Microsoft.EntityFrameworkCore; +using DbContext = Aaru.Server.Database.DbContext; + +namespace Aaru.Server.Components.Admin.Pages.MediaFormats; + +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.MediaFormats.OrderBy(static mf => mf.Name).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 DeleteVersionAsync(_deleteId); + await HideDeleteModal(); + await RefreshItemsAsync(); + } + + private async Task DeleteVersionAsync(int id) + { + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + MediaFormat? mediaFormat = await ctx.MediaFormats.FindAsync(id); + + if(mediaFormat is not null) + { + ctx.MediaFormats.Remove(mediaFormat); + await ctx.SaveChangesAsync(); + } + } + + private async Task RefreshItemsAsync() + { + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + _items = await ctx.MediaFormats.OrderBy(static mf => mf.Name).ToListAsync(); + StateHasChanged(); + } +} \ No newline at end of file