diff --git a/Aaru.Server/Components/Admin/AdminNavMenu.razor b/Aaru.Server/Components/Admin/AdminNavMenu.razor index da5c9b1b..100b28da 100644 --- a/Aaru.Server/Components/Admin/AdminNavMenu.razor +++ b/Aaru.Server/Components/Admin/AdminNavMenu.razor @@ -8,6 +8,9 @@ Dashboard + + Block descriptors + diff --git a/Aaru.Server/Components/Admin/Pages/BlockDescriptors/View.razor b/Aaru.Server/Components/Admin/Pages/BlockDescriptors/View.razor new file mode 100644 index 00000000..8640a746 --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/BlockDescriptors/View.razor @@ -0,0 +1,48 @@ +@page "/admin/block-descriptors" +@attribute [Authorize] +@layout AdminLayout + +@inject Microsoft.EntityFrameworkCore.IDbContextFactory DbContextFactory + +Block descriptors + +@if(!_initialized) +{ +
+

Loading...

+
+ + return; +} + + + + + + + + + + + @foreach(BlockDescriptor item in _items) + { + + + + + + } + +
+ @DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.Density)) + + @DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.Blocks)) + + @DisplayNameHelper.GetDisplayName(typeof(BlockDescriptor), nameof(BlockDescriptor.BlockLength)) +
+ @item.Density + + @item.Blocks + + @item.BlockLength +
\ No newline at end of file diff --git a/Aaru.Server/Components/Admin/Pages/BlockDescriptors/View.razor.cs b/Aaru.Server/Components/Admin/Pages/BlockDescriptors/View.razor.cs new file mode 100644 index 00000000..4264798e --- /dev/null +++ b/Aaru.Server/Components/Admin/Pages/BlockDescriptors/View.razor.cs @@ -0,0 +1,30 @@ +using Aaru.CommonTypes.Metadata; +using Microsoft.EntityFrameworkCore; +using DbContext = Aaru.Server.Database.DbContext; + +namespace Aaru.Server.Components.Admin.Pages.BlockDescriptors; + +public partial class View +{ + bool _initialized; + List _items; + + /// + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + + StateHasChanged(); + + await using DbContext ctx = await DbContextFactory.CreateDbContextAsync(); + + _items = await ctx.BlockDescriptor.OrderBy(b => b.BlockLength) + .ThenBy(b => b.Blocks) + .ThenBy(b => b.Density) + .ToListAsync(); + + _initialized = true; + + StateHasChanged(); + } +} \ No newline at end of file diff --git a/Aaru.Server/DisplayNameHelper.cs b/Aaru.Server/DisplayNameHelper.cs new file mode 100644 index 00000000..79eac68d --- /dev/null +++ b/Aaru.Server/DisplayNameHelper.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.Reflection; + +namespace Aaru.Server; + +public static class DisplayNameHelper +{ + public static string GetDisplayName(Type type, string propertyName) + { + PropertyInfo? prop = type.GetProperty(propertyName); + + if(prop is null) return propertyName; + + DisplayAttribute? displayAttr = prop.GetCustomAttributes(typeof(DisplayAttribute), true) + .OfType() + .FirstOrDefault(); + + return displayAttr?.Name ?? propertyName; + } +} \ No newline at end of file