浏览代码

Merge pull request #406 from Moonlight-Panel/v2_AddAdminPage

Added Basic Admin Page, will still be adding more in the future
Masu Baumgartner 1 年之前
父节点
当前提交
45e81c98bf
共有 2 个文件被更改,包括 79 次插入0 次删除
  1. 6 0
      Moonlight/Core/CoreFeature.cs
  2. 73 0
      Moonlight/Core/UI/Views/Admin/Index.razor

+ 6 - 0
Moonlight/Core/CoreFeature.cs

@@ -114,6 +114,12 @@ public class CoreFeature : MoonlightFeature
         // Define permissions
         var permissionService = app.Services.GetRequiredService<PermissionService>();
 
+        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",

+ 73 - 0
Moonlight/Core/UI/Views/Admin/Index.razor

@@ -0,0 +1,73 @@
+@page "/admin"
+@using MoonCore.Abstractions
+@using Moonlight.Core.Database.Entities
+@using Moonlight.Features.Servers.Entities
+
+@inject Repository<Server> ServerRepository
+@inject Repository<User> UserRepository
+
+@attribute [RequirePermission(999)]
+
+<LazyLoader Load="Load">
+    <div class="row">
+        <div class="col-12 col-lg-6 col-xl">
+            <a class="mt-4 card" href="/admin/servers">
+                <div class="card-body">
+                    <div class="row align-items-center gx-0">
+                        <div class="col">
+                            <h6 class="text-uppercase text-muted mb-2">
+                                Users
+                            </h6>
+                            <span class="h2 mb-0">
+                                @UserCount
+                            </span>
+                        </div>
+                        <div class="col-auto">
+                            <span class="h2 text-muted mb-0">
+                                <i class="text-primary bx bxs-group bx-lg"></i>
+                            </span>
+                        </div>
+                    </div>
+                </div>
+            </a>
+        </div>
+        <div class="col-12 col-lg-6 col-xl">
+            <a class="mt-4 card" href="/admin/users">
+                <div class="card-body">
+                    <div class="row align-items-center gx-0">
+                        <div class="col">
+                            <h6 class="text-uppercase text-muted mb-2">
+                                Servers
+                            </h6>
+                            <span class="h2 mb-0">
+                                @ServerCount
+                            </span>
+                        </div>
+                        <div class="col-auto">
+                            <span class="h2 text-muted mb-0">
+                                <i class="text-primary bx bx-server bx-lg"></i>
+                            </span>
+                        </div>
+                    </div>
+                </div>
+            </a>
+        </div>  
+    </div>
+</LazyLoader>
+
+@* This is just the start of this admin page, there will still be added more during the developement process *@
+
+@code {
+    private int ServerCount;
+    private int UserCount;
+
+    private async Task Load(LazyLoader arg)
+    {
+        await Task.Run(() =>
+        {
+            arg.SetText("Loading Information...");
+            ServerCount = ServerRepository.Get().Count();
+            UserCount = UserRepository.Get().Count();
+        });
+    }
+}