diff --git a/Moonlight/Core/Models/Abstractions/UiComponent.cs b/Moonlight/Core/Models/Abstractions/UiComponent.cs index 60329f63..f994bad4 100644 --- a/Moonlight/Core/Models/Abstractions/UiComponent.cs +++ b/Moonlight/Core/Models/Abstractions/UiComponent.cs @@ -7,4 +7,6 @@ public class UiComponent public required RenderFragment Component { get; set; } public int Index { get; set; } = 0; + + public int RequiredPermissionLevel { get; set; } = 0; } \ No newline at end of file diff --git a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor index c05cad84..95daa68d 100644 --- a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor +++ b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor @@ -11,9 +11,9 @@ private int UserCount; - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { - UserCount = UserRepository.Get().Count(); + if (firstRender) + 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 a7c6747a..9d7d9a22 100644 --- a/Moonlight/Core/UI/Views/Admin/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -1,30 +1,33 @@ @page "/admin" -@using MoonCore.Abstractions -@using Moonlight.Core.Database.Entities -@using Moonlight.Core.Interfaces @using Moonlight.Core.Interfaces.Ui.Admin @using Moonlight.Core.Models.Abstractions @using Moonlight.Core.Services -@using Moonlight.Features.Servers.Entities @inject PluginService PluginService +@inject IdentityService IdentityService @attribute [RequirePermission(999)] -
- @foreach(var column in Columns.OrderBy(x => x.Index)) +
+ @foreach (var column in Columns.OrderBy(x => x.Index)) { -
- @column.Component -
+ if (column.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) + { +
+ @column.Component +
+ } }
@foreach (var component in Components.OrderBy(x => x.Index)) { -
- @component.Component -
+ if (component.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) + { +
+ @component.Component +
+ } } diff --git a/Moonlight/Core/UI/Views/Index.razor b/Moonlight/Core/UI/Views/Index.razor index e36cf092..acef82a3 100644 --- a/Moonlight/Core/UI/Views/Index.razor +++ b/Moonlight/Core/UI/Views/Index.razor @@ -4,13 +4,17 @@ @using Moonlight.Core.Services @inject PluginService PluginService +@inject IdentityService IdentityService @foreach (var component in Components.OrderBy(x => x.Index)) { -
- @component.Component -
+ if (component.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) + { +
+ @component.Component +
+ } }
diff --git a/Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs b/Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs index fa18e6d2..3e7928ae 100644 --- a/Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs +++ b/Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs @@ -11,7 +11,8 @@ public class ServerCount : IAdminDashboardColumn { var res = new UiComponent() { - Component = ComponentHelper.FromType() + Component = ComponentHelper.FromType(), + RequiredPermissionLevel = 5000 }; return Task.FromResult(res); diff --git a/Moonlight/Features/Servers/Implementations/UI/Admin/AdminComponents/NodeOverview.cs b/Moonlight/Features/Servers/Implementations/UI/Admin/AdminComponents/NodeOverview.cs new file mode 100644 index 00000000..cd5116c8 --- /dev/null +++ b/Moonlight/Features/Servers/Implementations/UI/Admin/AdminComponents/NodeOverview.cs @@ -0,0 +1,20 @@ +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces.Ui.Admin; +using Moonlight.Core.Models.Abstractions; +using Moonlight.Features.Servers.UI.Components.Cards; + +namespace Moonlight.Features.Servers.Implementations.UI.Admin.AdminComponents; + +public class NodeOverview : IAdminDashboardComponent +{ + public Task Get() + { + var res = new UiComponent() + { + Component = ComponentHelper.FromType(), + RequiredPermissionLevel = 5001 + }; + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/Moonlight/Features/Servers/Implementations/UI/UserDashboard/Components/UserDashboardServerCount.cs b/Moonlight/Features/Servers/Implementations/UI/UserDashboard/Components/UserDashboardServerCount.cs new file mode 100644 index 00000000..5a10fee5 --- /dev/null +++ b/Moonlight/Features/Servers/Implementations/UI/UserDashboard/Components/UserDashboardServerCount.cs @@ -0,0 +1,20 @@ +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces.UI.User; +using Moonlight.Core.Models.Abstractions; +using Moonlight.Features.Servers.UI.Components.Cards; + +namespace Moonlight.Features.Servers.Implementations.UI.UserDashboard.Components; + +public class UserDashboardServerCount : IUserDashboardComponent +{ + public Task Get() + { + var res = new UiComponent() + { + Component = ComponentHelper.FromType(), + Index = int.MinValue + 100 + }; + + 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 3c3da663..8ebf44f7 100644 --- a/Moonlight/Features/Servers/ServersFeature.cs +++ b/Moonlight/Features/Servers/ServersFeature.cs @@ -3,6 +3,7 @@ using MoonCore.Services; using Moonlight.Core.Configuration; using Moonlight.Core.Interfaces; using Moonlight.Core.Interfaces.Ui.Admin; +using Moonlight.Core.Interfaces.UI.User; using Moonlight.Core.Models.Abstractions.Feature; using Moonlight.Core.Services; using Moonlight.Features.Servers.Actions; @@ -10,9 +11,11 @@ using Moonlight.Features.Servers.Configuration; using Moonlight.Features.Servers.Http.Middleware; using Moonlight.Features.Servers.Implementations.Diagnose; using Moonlight.Features.Servers.Implementations.UI.Admin.AdminColumns; +using Moonlight.Features.Servers.Implementations.UI.Admin.AdminComponents; using Moonlight.Features.Servers.Models.Enums; using Moonlight.Features.Servers.Services; using Moonlight.Features.Servers.UI.Components.Cards; +using UserDashboardServerCount = Moonlight.Features.Servers.Implementations.UI.UserDashboard.Components.UserDashboardServerCount; namespace Moonlight.Features.Servers; @@ -100,6 +103,10 @@ public class ServersFeature : MoonlightFeature await pluginService.RegisterImplementation(new NodesDiagnoseAction()); await pluginService.RegisterImplementation(new ServerCount()); + + await pluginService.RegisterImplementation(new NodeOverview()); + + await pluginService.RegisterImplementation(new UserDashboardServerCount()); } public override Task OnUiInitialized(UiInitContext context) diff --git a/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor new file mode 100644 index 00000000..191a39ac --- /dev/null +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor @@ -0,0 +1,70 @@ +@using MoonCore.Abstractions +@using Moonlight.Features.Servers.Api.Resources +@using Moonlight.Features.Servers.Entities +@using Moonlight.Features.Servers.Services + +@inject NodeService NodeService +@inject Repository NodeRepository + +
+
+

+ + Nodes Overview +

+
+ + @if (Nodes.Any()) + { + foreach (var node in Nodes) + { + + } + } + else + { + You dont have any nodes. + } + +
+
+
+ +@code { + + private List> Nodes = new(); + + private async Task Load(LazyLoader arg) + { + foreach (var node in NodeRepository.Get().ToList()) + { + SystemStatus? nodeStatus = null; + + await arg.SetText("Fetching Nodes..."); + + try + { + nodeStatus = await NodeService.GetStatus(node); + } + catch + { + // Ignored + } + + Nodes.Add(new Tuple(node, nodeStatus)); + } + } + +} \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor index 978ff7b6..20f70fa9 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor @@ -11,9 +11,10 @@ private int ServerCount; - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { - ServerCount = ServerRepository.Get().Count(); + if (firstRender) + ServerCount = ServerRepository.Get().Count(); } } \ No newline at end of file diff --git a/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor new file mode 100644 index 00000000..056172e0 --- /dev/null +++ b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor @@ -0,0 +1,40 @@ +@using Microsoft.EntityFrameworkCore +@using MoonCore.Abstractions +@using Moonlight.Core.Services +@using Moonlight.Features.Servers.Entities + +@inject Repository ServerRepository +@inject Repository NetworkRepository +@inject IdentityService IdentityService + +
+ + + +
+ +@code { + + private int ServerCount = 0; + private int NetworksCount = 0; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + ServerCount = await ServerRepository.Get().Where(x => x.Owner == IdentityService.CurrentUser).CountAsync(); + NetworksCount = await NetworkRepository.Get().Where(x => x.User == IdentityService.CurrentUser).CountAsync(); + } + } + +} \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 88b2155f..56df0bc8 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -53,7 +53,6 @@ - @@ -75,7 +74,6 @@ -