From 160de6443b6414ec68ad414e6ba744d5d1f998a2 Mon Sep 17 00:00:00 2001 From: Moritz <101179677+Moritz-Deiaco@users.noreply.github.com> Date: Mon, 13 May 2024 18:38:52 +0200 Subject: [PATCH 1/2] Added Basic Admin Page, will still be adding more in the future --- Moonlight/Core/CoreFeature.cs | 6 ++ Moonlight/Core/UI/Views/Admin/Index.razor | 71 +++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Moonlight/Core/UI/Views/Admin/Index.razor diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index f8513fa..df698bf 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -114,6 +114,12 @@ public class CoreFeature : MoonlightFeature // Define permissions var permissionService = app.Services.GetRequiredService(); + await permissionService.Register(999, new() + { + Name = "See Admin Page", + Description = "Allows access to the admin page and the connected stats (server and user count)" + }); + await permissionService.Register(1000, new() { Name = "Manage users", diff --git a/Moonlight/Core/UI/Views/Admin/Index.razor b/Moonlight/Core/UI/Views/Admin/Index.razor new file mode 100644 index 0000000..45de84b --- /dev/null +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -0,0 +1,71 @@ +@page "/admin" +@using MoonCore.Abstractions +@using Moonlight.Core.Database.Entities +@using Moonlight.Features.Servers.Entities + +@inject Repository ServerRepository +@inject Repository UserRepository + +@attribute [RequirePermission(999)] + + + + + +@* This is just the start of this admin page, there will still be added more during the developement process *@ + +@code { + private List Servers; + private List Users; + + private async Task Load(LazyLoader arg) + { + await Task.Run(() => + { + arg.SetText("Loading Information..."); + Servers = ServerRepository.Get().ToList(); + Users = UserRepository.Get().ToList(); + }); + } +} \ No newline at end of file From d9dd9bbf4d8a49a44172568bf352126ebb25d7a7 Mon Sep 17 00:00:00 2001 From: Moritz <101179677+Moritz-Deiaco@users.noreply.github.com> Date: Tue, 14 May 2024 00:42:00 +0200 Subject: [PATCH 2/2] Optimized it, as Masu wished --- Moonlight/Core/UI/Views/Admin/Index.razor | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Moonlight/Core/UI/Views/Admin/Index.razor b/Moonlight/Core/UI/Views/Admin/Index.razor index 45de84b..2cb5718 100644 --- a/Moonlight/Core/UI/Views/Admin/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -18,7 +18,9 @@
Users
- @Users.Count + + @UserCount +
@@ -38,7 +40,7 @@ Servers - @Servers.Count + @ServerCount
@@ -56,16 +58,16 @@ @* This is just the start of this admin page, there will still be added more during the developement process *@ @code { - private List Servers; - private List Users; + private int ServerCount; + private int UserCount; private async Task Load(LazyLoader arg) { await Task.Run(() => { arg.SetText("Loading Information..."); - Servers = ServerRepository.Get().ToList(); - Users = UserRepository.Get().ToList(); + ServerCount = ServerRepository.Get().Count(); + UserCount = UserRepository.Get().Count(); }); } } \ No newline at end of file