diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index df698bf..ae4bc9c 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -7,6 +7,7 @@ using MoonCoreUI.Services; using Moonlight.Core.Configuration; using Moonlight.Core.Database; using Moonlight.Core.Database.Entities; +using Moonlight.Core.Implementations.AdminColumns; using Moonlight.Core.Implementations.Diagnose; using Moonlight.Core.Interfaces; using Moonlight.Core.Models; @@ -15,6 +16,7 @@ using Moonlight.Core.Models.Abstractions.Feature; using Moonlight.Core.Models.Enums; using Moonlight.Core.Repositories; using Moonlight.Core.Services; +using Moonlight.Core.UI.Components.Cards; namespace Moonlight.Core; @@ -155,6 +157,9 @@ public class CoreFeature : MoonlightFeature await pluginService.RegisterImplementation(new FeatureDiagnoseAction()); await pluginService.RegisterImplementation(new LogDiagnoseAction()); + //Admin Page + await pluginService.RegisterImplementation(new UserCount()); + // Startup job services var startupJobService = app.Services.GetRequiredService(); diff --git a/Moonlight/Core/Implementations/AdminColumns/UserCount.cs b/Moonlight/Core/Implementations/AdminColumns/UserCount.cs new file mode 100644 index 0000000..f4b5461 --- /dev/null +++ b/Moonlight/Core/Implementations/AdminColumns/UserCount.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Components; +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces; +using Moonlight.Core.UI.Components.Cards; + +namespace Moonlight.Core.Implementations.AdminColumns; + +public class UserCount : IAdminDashboardColumn +{ + public Task Get() + { + var res = ComponentHelper.FromType(); + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/IAdminDashboardColumn.cs b/Moonlight/Core/Interfaces/IAdminDashboardColumn.cs new file mode 100644 index 0000000..7e92eab --- /dev/null +++ b/Moonlight/Core/Interfaces/IAdminDashboardColumn.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Components; + +namespace Moonlight.Core.Interfaces; + +public interface IAdminDashboardColumn +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/IAdminDashboardComponent.cs b/Moonlight/Core/Interfaces/IAdminDashboardComponent.cs new file mode 100644 index 0000000..4f1e0e7 --- /dev/null +++ b/Moonlight/Core/Interfaces/IAdminDashboardComponent.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Components; + +namespace Moonlight.Core.Interfaces; + +public interface IAdminDashboardComponent +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/Models/Abstractions/Feature/UiInitContext.cs b/Moonlight/Core/Models/Abstractions/Feature/UiInitContext.cs index c63fbc1..382c690 100644 --- a/Moonlight/Core/Models/Abstractions/Feature/UiInitContext.cs +++ b/Moonlight/Core/Models/Abstractions/Feature/UiInitContext.cs @@ -1,4 +1,9 @@ -using System.Reflection; +using System.ComponentModel; +using System.Reflection; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Options; +using Moonlight.Core.UI.Components.Partials; +using IComponent = Microsoft.AspNetCore.Components.IComponent; namespace Moonlight.Core.Models.Abstractions.Feature; @@ -6,7 +11,9 @@ public class UiInitContext { public List SidebarItems { get; set; } = new(); public List RouteAssemblies { get; set; } = new(); - + public List AdminPageComponents { get; set; } = new(); + public List AdminPageCards { get; set; } = new(); + public void EnablePages() { var assembly = typeof(T).Assembly; diff --git a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor new file mode 100644 index 0000000..c05cad8 --- /dev/null +++ b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor @@ -0,0 +1,19 @@ +@using MoonCore.Abstractions +@using Moonlight.Core.Database.Entities + +@inject Repository UserRepository + + + + + +@code { + + private int UserCount; + + protected override async Task OnInitializedAsync() + { + UserCount = UserRepository.Get().Count(); + } + +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Admin/Index.razor b/Moonlight/Core/UI/Views/Admin/Index.razor index 9a648b4..0b6399a 100644 --- a/Moonlight/Core/UI/Views/Admin/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -1,43 +1,54 @@ @page "/admin" @using MoonCore.Abstractions @using Moonlight.Core.Database.Entities +@using Moonlight.Core.Interfaces +@using Moonlight.Core.Services @using Moonlight.Features.Servers.Entities -@inject Repository ServerRepository -@inject Repository UserRepository +@inject PluginService PluginService @attribute [RequirePermission(999)] -
- - +
+ @foreach(var column in Columns) + { +
+ @column +
+ }
+ @foreach (var component in Components) + { +
+ @component +
+ } -@* 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 List Columns = new(); + private List Components = new(); + private async Task Load(LazyLoader arg) { - await Task.Run(() => - { - arg.SetText("Loading Information..."); - ServerCount = ServerRepository.Get().Count(); - UserCount = UserRepository.Get().Count(); - }); + await arg.SetText("Loading statistics..."); + + var componentImplementations = await PluginService.GetImplementations(); + + foreach (var implementation in componentImplementations) + { + Components.Add(await implementation.Get()); + } + + var columnImplementations = await PluginService.GetImplementations(); + + foreach (var implementation in columnImplementations) + { + Columns.Add(await implementation.Get()); + } + } } \ No newline at end of file diff --git a/Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs b/Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs new file mode 100644 index 0000000..2d743d4 --- /dev/null +++ b/Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Components; +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces; +using Moonlight.Features.Servers.UI.Components.Cards; + +namespace Moonlight.Features.Servers.Implementations.AdminColumns; + +public class ServerCount : IAdminDashboardColumn +{ + public Task Get() + { + var res = ComponentHelper.FromType(); + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/Moonlight/Features/Servers/ServersFeature.cs b/Moonlight/Features/Servers/ServersFeature.cs index acd1445..89e0075 100644 --- a/Moonlight/Features/Servers/ServersFeature.cs +++ b/Moonlight/Features/Servers/ServersFeature.cs @@ -7,9 +7,11 @@ using Moonlight.Core.Services; using Moonlight.Features.Servers.Actions; using Moonlight.Features.Servers.Configuration; using Moonlight.Features.Servers.Http.Middleware; +using Moonlight.Features.Servers.Implementations.AdminColumns; using Moonlight.Features.Servers.Implementations.Diagnose; using Moonlight.Features.Servers.Models.Enums; using Moonlight.Features.Servers.Services; +using Moonlight.Features.Servers.UI.Components.Cards; namespace Moonlight.Features.Servers; @@ -95,6 +97,8 @@ public class ServersFeature : MoonlightFeature var pluginService = app.Services.GetRequiredService(); await pluginService.RegisterImplementation(new NodesDiagnoseAction()); + + await pluginService.RegisterImplementation(new ServerCount()); } public override Task OnUiInitialized(UiInitContext context) diff --git a/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor new file mode 100644 index 0000000..978ff7b --- /dev/null +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor @@ -0,0 +1,19 @@ +@using MoonCore.Abstractions +@using Moonlight.Features.Servers.Entities + +@inject Repository ServerRepository + + + + + +@code { + + private int ServerCount; + + protected override async Task OnInitializedAsync() + { + ServerCount = ServerRepository.Get().Count(); + } + +} \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 1aad123..34bbe64 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -53,6 +53,7 @@ +