From 6fa91d8890135996bf29dc379a8e2b8eb19b2040 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 16:27:46 +0200 Subject: [PATCH 1/9] Added a Minimum Required Permission Level For the component Masu you said it would be possible to handle this in the Components Razor file, but if nothing is shown there will still be an empty space (empty cols are still showing in boostrap, margin on the userdashboard and admindashboard components). I think this would be the best solution --- .../Core/Models/Abstractions/UiComponent.cs | 2 ++ Moonlight/Core/UI/Views/Admin/Index.razor | 25 +++++++++++-------- Moonlight/Core/UI/Views/Index.razor | 10 +++++--- Moonlight/Moonlight.csproj | 1 - 4 files changed, 23 insertions(+), 15 deletions(-) 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/Views/Admin/Index.razor b/Moonlight/Core/UI/Views/Admin/Index.razor index a7c6747a..ab479889 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/Moonlight.csproj b/Moonlight/Moonlight.csproj index 6f369f1d..baf8e518 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -53,7 +53,6 @@ - From 13a49d3306f453a66241121f4aad5726dd5d8dfe Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 17:31:43 +0200 Subject: [PATCH 2/9] Added a permssion requirement to the servercount card --- .../Implementations/UI/Admin/AdminColumns/ServerCount.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); From 7a9708137c433038567a948a2dff8dabb0e8c3f7 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 17:58:29 +0200 Subject: [PATCH 3/9] Fixed a small spacing issue on the admin page --- Moonlight/Core/UI/Views/Admin/Index.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moonlight/Core/UI/Views/Admin/Index.razor b/Moonlight/Core/UI/Views/Admin/Index.razor index ab479889..9d7d9a22 100644 --- a/Moonlight/Core/UI/Views/Admin/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -9,7 +9,7 @@ @attribute [RequirePermission(999)] -
+
@foreach (var column in Columns.OrderBy(x => x.Index)) { if (column.RequiredPermissionLevel <= IdentityService.CurrentUser.Permissions) From fd76a085dc4b981e61fe47755d958f6750628e59 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 18:19:35 +0200 Subject: [PATCH 4/9] Added a cool node status card onto the admin dashboard --- .../UI/Admin/AdminComponents/NodeOverview.cs | 20 ++++++ Moonlight/Features/Servers/ServersFeature.cs | 3 + .../Cards/AdminNodesComponent.razor | 62 +++++++++++++++++++ Moonlight/Moonlight.csproj | 1 - 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Moonlight/Features/Servers/Implementations/UI/Admin/AdminComponents/NodeOverview.cs create mode 100644 Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor 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/ServersFeature.cs b/Moonlight/Features/Servers/ServersFeature.cs index 3c3da663..89956ee5 100644 --- a/Moonlight/Features/Servers/ServersFeature.cs +++ b/Moonlight/Features/Servers/ServersFeature.cs @@ -10,6 +10,7 @@ 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; @@ -100,6 +101,8 @@ public class ServersFeature : MoonlightFeature await pluginService.RegisterImplementation(new NodesDiagnoseAction()); await pluginService.RegisterImplementation(new ServerCount()); + + await pluginService.RegisterImplementation(new NodeOverview()); } 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..c15c218a --- /dev/null +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor @@ -0,0 +1,62 @@ +@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) + { +
+
+ + @(node.Item2 == null ? "offline" : "online") + +
+ @node.Item1.Name + @node.Item1.Fqdn +
+
+
+ } + } + else + { + You dont have any nodes. + } +
+
+
+ +@code { + + private List> Nodes = new(); + + protected override async Task OnInitializedAsync() + { + foreach (var node in NodeRepository.Get().ToList()) + { + SystemStatus? nodeStatus = null; + + try + { + nodeStatus = await NodeService.GetStatus(node); + } + catch (Exception e) + { + // Ignored + } + + Nodes.Add(new Tuple(node, nodeStatus)); + } + } + +} \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index baf8e518..74ddc115 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -74,7 +74,6 @@ - From d107164d7db85469ca77df02ff328d26f2146c6a Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 18:28:45 +0200 Subject: [PATCH 5/9] Improved card ui --- .../Servers/UI/Components/Cards/AdminNodesComponent.razor | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor index c15c218a..67365a4a 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor @@ -8,8 +8,10 @@
-

Nodes Overview

-
+

+ + Nodes Overview +

@if (Nodes.Any()) { From f3a5a8de253b72848c7c24a2a081cd2e25c5dca7 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 20:42:17 +0200 Subject: [PATCH 6/9] Added User Dashboard Informations --- .../Components/UserDashboardServerCount.cs | 20 ++++++++++ Moonlight/Features/Servers/ServersFeature.cs | 4 ++ .../Cards/UserDashboardServerCount.razor | 39 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 Moonlight/Features/Servers/Implementations/UI/UserDashboard/Components/UserDashboardServerCount.cs create mode 100644 Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor 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 89956ee5..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; @@ -14,6 +15,7 @@ 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; @@ -103,6 +105,8 @@ public class ServersFeature : MoonlightFeature 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/UserDashboardServerCount.razor b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor new file mode 100644 index 00000000..952c45ec --- /dev/null +++ b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor @@ -0,0 +1,39 @@ +@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 OnInitializedAsync() + { + + 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 From 09dffe020dad8a91612eb4eb2264e92c9a2250e0 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Wed, 29 May 2024 20:55:23 +0200 Subject: [PATCH 7/9] Improved Nodes Card --- .../Cards/AdminNodesComponent.razor | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor index 67365a4a..191a39ac 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminNodesComponent.razor @@ -9,31 +9,35 @@

- + Nodes Overview

- @if (Nodes.Any()) - { - foreach (var node in Nodes) + + @if (Nodes.Any()) { -
-
- - @(node.Item2 == null ? "offline" : "online") - -
- @node.Item1.Name - @node.Item1.Fqdn -
+ foreach (var node in Nodes) + { + -
+ } } - } - else - { - You dont have any nodes. - } + else + { + You dont have any nodes. + } +
@@ -41,18 +45,20 @@ @code { private List> Nodes = new(); - - protected override async Task OnInitializedAsync() + + 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 (Exception e) + catch { // Ignored } From 20d0e1c8ebab26a0f0f85130c8618cad3bb16fd6 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Thu, 30 May 2024 14:13:42 +0200 Subject: [PATCH 8/9] Used OnAfterRender instead of OnInitialized --- Moonlight/Core/UI/Components/Cards/AdminUserCard.razor | 3 +-- .../Servers/UI/Components/Cards/AdminServersCard.razor | 2 +- .../Servers/UI/Components/Cards/UserDashboardServerCount.razor | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor index c05cad84..3c77403d 100644 --- a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor +++ b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor @@ -11,9 +11,8 @@ private int UserCount; - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { UserCount = UserRepository.Get().Count(); } - } \ 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..0183eda0 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor @@ -11,7 +11,7 @@ private int ServerCount; - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { ServerCount = ServerRepository.Get().Count(); } diff --git a/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor index 952c45ec..7983081f 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor @@ -28,7 +28,7 @@ private int ServerCount = 0; private int NetworksCount = 0; - protected override async Task OnInitializedAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { ServerCount = await ServerRepository.Get().Where(x => x.Owner == IdentityService.CurrentUser).CountAsync(); From ac5890f1152490de877fbf76ba7e79a5c4e3d28d Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Thu, 30 May 2024 18:17:25 +0200 Subject: [PATCH 9/9] Fixed Loading Mistake --- Moonlight/Core/UI/Components/Cards/AdminUserCard.razor | 3 ++- .../Servers/UI/Components/Cards/AdminServersCard.razor | 3 ++- .../UI/Components/Cards/UserDashboardServerCount.razor | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor index 3c77403d..95daa68d 100644 --- a/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor +++ b/Moonlight/Core/UI/Components/Cards/AdminUserCard.razor @@ -13,6 +13,7 @@ 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/Features/Servers/UI/Components/Cards/AdminServersCard.razor b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor index 0183eda0..20f70fa9 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/AdminServersCard.razor @@ -13,7 +13,8 @@ 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 index 7983081f..056172e0 100644 --- a/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor +++ b/Moonlight/Features/Servers/UI/Components/Cards/UserDashboardServerCount.razor @@ -30,10 +30,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { - - ServerCount = await ServerRepository.Get().Where(x => x.Owner == IdentityService.CurrentUser).CountAsync(); - NetworksCount = await NetworkRepository.Get().Where(x => x.User == IdentityService.CurrentUser).CountAsync(); - + 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