From 769c876dc5c3aca8f57f1c3f5787bf238bd51f62 Mon Sep 17 00:00:00 2001 From: Moritz <101179677+Moritz-Deiaco@users.noreply.github.com> Date: Sun, 19 May 2024 14:27:45 +0200 Subject: [PATCH 1/3] Added a way to sort the admin components with an index --- Moonlight/Core/CoreFeature.cs | 3 ++- .../Implementations/AdminColumns/UserCount.cs | 16 --------------- .../UI/Admin/AdminColumns/UserCount.cs | 20 +++++++++++++++++++ .../Core/Interfaces/IAdminDashboardColumn.cs | 8 -------- .../Interfaces/IAdminDashboardComponent.cs | 8 -------- .../UI/Admin/IAdminDashboardColumn.cs | 8 ++++++++ .../UI/Admin/IAdminDashboardComponent.cs | 8 ++++++++ .../Core/Models/Abstractions/UiComponent.cs | 10 ++++++++++ Moonlight/Core/UI/Views/Admin/Index.razor | 14 +++++++------ .../AdminColumns/ServerCount.cs | 16 --------------- .../UI/Admin/AdminColumns/ServerCount.cs | 19 ++++++++++++++++++ Moonlight/Features/Servers/ServersFeature.cs | 3 ++- Moonlight/Moonlight.csproj | 3 ++- 13 files changed, 79 insertions(+), 57 deletions(-) delete mode 100644 Moonlight/Core/Implementations/AdminColumns/UserCount.cs create mode 100644 Moonlight/Core/Implementations/UI/Admin/AdminColumns/UserCount.cs delete mode 100644 Moonlight/Core/Interfaces/IAdminDashboardColumn.cs delete mode 100644 Moonlight/Core/Interfaces/IAdminDashboardComponent.cs create mode 100644 Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardColumn.cs create mode 100644 Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardComponent.cs create mode 100644 Moonlight/Core/Models/Abstractions/UiComponent.cs delete mode 100644 Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs create mode 100644 Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index ae4bc9c..3f8cbda 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -7,9 +7,10 @@ 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.Implementations.UI.Admin.AdminColumns; using Moonlight.Core.Interfaces; +using Moonlight.Core.Interfaces.Ui.Admin; using Moonlight.Core.Models; using Moonlight.Core.Models.Abstractions; using Moonlight.Core.Models.Abstractions.Feature; diff --git a/Moonlight/Core/Implementations/AdminColumns/UserCount.cs b/Moonlight/Core/Implementations/AdminColumns/UserCount.cs deleted file mode 100644 index f4b5461..0000000 --- a/Moonlight/Core/Implementations/AdminColumns/UserCount.cs +++ /dev/null @@ -1,16 +0,0 @@ -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/Implementations/UI/Admin/AdminColumns/UserCount.cs b/Moonlight/Core/Implementations/UI/Admin/AdminColumns/UserCount.cs new file mode 100644 index 0000000..328cb07 --- /dev/null +++ b/Moonlight/Core/Implementations/UI/Admin/AdminColumns/UserCount.cs @@ -0,0 +1,20 @@ +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces.Ui.Admin; +using Moonlight.Core.Models.Abstractions; +using Moonlight.Core.UI.Components.Cards; + +namespace Moonlight.Core.Implementations.UI.Admin.AdminColumns; + +public class UserCount : IAdminDashboardColumn +{ + public Task Get() + { + var res = new UiComponent() + { + Component = ComponentHelper.FromType(), + Index = int.MinValue + }; + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/IAdminDashboardColumn.cs b/Moonlight/Core/Interfaces/IAdminDashboardColumn.cs deleted file mode 100644 index 7e92eab..0000000 --- a/Moonlight/Core/Interfaces/IAdminDashboardColumn.cs +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 4f1e0e7..0000000 --- a/Moonlight/Core/Interfaces/IAdminDashboardComponent.cs +++ /dev/null @@ -1,8 +0,0 @@ -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/Interfaces/UI/Admin/IAdminDashboardColumn.cs b/Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardColumn.cs new file mode 100644 index 0000000..e47db08 --- /dev/null +++ b/Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardColumn.cs @@ -0,0 +1,8 @@ +using Moonlight.Core.Models.Abstractions; + +namespace Moonlight.Core.Interfaces.Ui.Admin; + +public interface IAdminDashboardColumn +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardComponent.cs b/Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardComponent.cs new file mode 100644 index 0000000..52a3937 --- /dev/null +++ b/Moonlight/Core/Interfaces/UI/Admin/IAdminDashboardComponent.cs @@ -0,0 +1,8 @@ +using Moonlight.Core.Models.Abstractions; + +namespace Moonlight.Core.Interfaces.Ui.Admin; + +public interface IAdminDashboardComponent +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/Models/Abstractions/UiComponent.cs b/Moonlight/Core/Models/Abstractions/UiComponent.cs new file mode 100644 index 0000000..60329f6 --- /dev/null +++ b/Moonlight/Core/Models/Abstractions/UiComponent.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Components; + +namespace Moonlight.Core.Models.Abstractions; + +public class UiComponent +{ + public required RenderFragment Component { get; set; } + + public int Index { 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 0b6399a..a7c6747 100644 --- a/Moonlight/Core/UI/Views/Admin/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Index.razor @@ -2,6 +2,8 @@ @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 @@ -11,17 +13,17 @@
- @foreach(var column in Columns) + @foreach(var column in Columns.OrderBy(x => x.Index)) {
- @column + @column.Component
}
- @foreach (var component in Components) + @foreach (var component in Components.OrderBy(x => x.Index)) {
- @component + @component.Component
}
@@ -29,8 +31,8 @@ @code { - private List Columns = new(); - private List Components = new(); + private List Columns = new(); + private List Components = new(); private async Task Load(LazyLoader arg) { diff --git a/Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs b/Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs deleted file mode 100644 index 2d743d4..0000000 --- a/Moonlight/Features/Servers/Implementations/AdminColumns/ServerCount.cs +++ /dev/null @@ -1,16 +0,0 @@ -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/Implementations/UI/Admin/AdminColumns/ServerCount.cs b/Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs new file mode 100644 index 0000000..fa18e6d --- /dev/null +++ b/Moonlight/Features/Servers/Implementations/UI/Admin/AdminColumns/ServerCount.cs @@ -0,0 +1,19 @@ +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.AdminColumns; + +public class ServerCount : IAdminDashboardColumn +{ + public Task Get() + { + var res = new UiComponent() + { + Component = 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 89e0075..3c3da66 100644 --- a/Moonlight/Features/Servers/ServersFeature.cs +++ b/Moonlight/Features/Servers/ServersFeature.cs @@ -2,13 +2,14 @@ using MoonCore.Helpers; using MoonCore.Services; using Moonlight.Core.Configuration; using Moonlight.Core.Interfaces; +using Moonlight.Core.Interfaces.Ui.Admin; using Moonlight.Core.Models.Abstractions.Feature; 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.Implementations.UI.Admin.AdminColumns; using Moonlight.Features.Servers.Models.Enums; using Moonlight.Features.Servers.Services; using Moonlight.Features.Servers.UI.Components.Cards; diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 34bbe64..d706b91 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -53,7 +53,7 @@ - + @@ -75,6 +75,7 @@ + From cba98bdf6ff9a736276c1ff376220b508361dbd1 Mon Sep 17 00:00:00 2001 From: Moritz <101179677+Moritz-Deiaco@users.noreply.github.com> Date: Mon, 20 May 2024 09:07:06 +0200 Subject: [PATCH 2/3] Made Index page Modular Made Index Page editable with the Plugin System, added greeting Component --- Moonlight/Core/CoreFeature.cs | 5 +- .../UI/Index/GreetingMessages.cs | 20 ++++++ .../UI/Index/IIndexPageComponent.cs | 8 +++ .../Cards/TimeBasedGreetingMessages.razor | 57 +++++++++++++++ Moonlight/Core/UI/Views/Index.razor | 71 ++++++------------- 5 files changed, 111 insertions(+), 50 deletions(-) create mode 100644 Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs create mode 100644 Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs create mode 100644 Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index 3f8cbda..25ada45 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -9,8 +9,10 @@ using Moonlight.Core.Database; using Moonlight.Core.Database.Entities; using Moonlight.Core.Implementations.Diagnose; using Moonlight.Core.Implementations.UI.Admin.AdminColumns; +using Moonlight.Core.Implementations.UI.Index; using Moonlight.Core.Interfaces; using Moonlight.Core.Interfaces.Ui.Admin; +using Moonlight.Core.Interfaces.UI.Index; using Moonlight.Core.Models; using Moonlight.Core.Models.Abstractions; using Moonlight.Core.Models.Abstractions.Feature; @@ -158,8 +160,9 @@ public class CoreFeature : MoonlightFeature await pluginService.RegisterImplementation(new FeatureDiagnoseAction()); await pluginService.RegisterImplementation(new LogDiagnoseAction()); - //Admin Page + // UI await pluginService.RegisterImplementation(new UserCount()); + await pluginService.RegisterImplementation(new GreetingMessages()); // Startup job services var startupJobService = app.Services.GetRequiredService(); diff --git a/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs new file mode 100644 index 0000000..a0c5c0e --- /dev/null +++ b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs @@ -0,0 +1,20 @@ +using MoonCoreUI.Helpers; +using Moonlight.Core.Interfaces.UI.Index; +using Moonlight.Core.Models.Abstractions; +using Moonlight.Core.UI.Components.Cards; + +namespace Moonlight.Core.Implementations.UI.Index; + +public class GreetingMessages : IIndexPageComponent +{ + public Task Get() + { + var res = new UiComponent() + { + Component = ComponentHelper.FromType(), + Index = int.MinValue + }; + + return Task.FromResult(res); + } +} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs b/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs new file mode 100644 index 0000000..50ae397 --- /dev/null +++ b/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs @@ -0,0 +1,8 @@ +using Moonlight.Core.Models.Abstractions; + +namespace Moonlight.Core.Interfaces.UI.Index; + +public interface IIndexPageComponent +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor b/Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor new file mode 100644 index 0000000..0d62e63 --- /dev/null +++ b/Moonlight/Core/UI/Components/Cards/TimeBasedGreetingMessages.razor @@ -0,0 +1,57 @@ +@using MoonCore.Services +@using Moonlight.Core.Configuration +@using Moonlight.Core.Services + +@inject IdentityService IdentityService +@inject ConfigService ConfigService + +
+
+ + @{ + var greeting = GetGreetingMessage(); + } + @greeting.Item1 + @IdentityService.CurrentUser.Username + @greeting.Item2 + +
+
+ +@code { + // For explanation: + // The first value is the actual message + // end second value is for question marks and so on + // + // and yes, this "feature" is kinda useless but still i wanted to implement + // it. - Masu + private (string, string) GetGreetingMessage() + { + var config = ConfigService.Get().Customisation; + + if (config.DisableTimeBasedGreetingMessages) + return ("Welcome back, ", ""); + + var time = DateTime.UtcNow.AddHours(config.GreetingTimezoneDifference); + + if (time.Hour >= 23 || time.Hour < 5) + return ("\ud83d\ude34 Still awake, ", "?"); + + if (time.Hour >= 5 && time.Hour < 10) + return ("\ud83d\ude04 Good morning, ", ""); + + if (time.Hour >= 10 && time.Hour < 14) + return ("\u2600\ufe0f Have a nice day, ", ""); + + if (time.Hour >= 14 && time.Hour < 16) + return ("\ud83d\ude03 Good afternoon, ", ""); + + if (time.Hour >= 16 && time.Hour < 22) + return ("\ud83c\udf25\ufe0f Have a nice evening, ", ""); + + if (time.Hour >= 22 && time.Hour < 23) + return ("\ud83c\udf19 Sleep well, ", ""); + + return ("Welcome back ", ""); + } +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Index.razor b/Moonlight/Core/UI/Views/Index.razor index 80e3838..bc43335 100644 --- a/Moonlight/Core/UI/Views/Index.razor +++ b/Moonlight/Core/UI/Views/Index.razor @@ -1,60 +1,33 @@ @page "/" - +@using Moonlight.Core.Interfaces.UI.Index +@using Moonlight.Core.Models.Abstractions @using Moonlight.Core.Services -@using MoonCore.Services -@using Moonlight.Core.Configuration -@inject IdentityService IdentityService -@inject ConfigService ConfigService - -
-
- - @{ - var greeting = GetGreetingMessage(); - } - @greeting.Item1 - @IdentityService.CurrentUser.Username - @greeting.Item2 - -
-
+@inject PluginService PluginService + + @foreach (var component in Components.OrderBy(x => x.Index)) + { +
+ @component.Component +
+ } +
+ @code { - // For explanation: - // The first value is the actual message - // end second value is for question marks and so on - // - // and yes, this "feature" is kinda useless but still i wanted to implement - // it. - Masu - private (string, string) GetGreetingMessage() + private List Components = new(); + + + private async Task Load(LazyLoader arg) { - var config = ConfigService.Get().Customisation; + await arg.SetText("Loading..."); - if (config.DisableTimeBasedGreetingMessages) - return ("Welcome back, ", ""); + var implementations = await PluginService.GetImplementations(); - var time = DateTime.UtcNow.AddHours(config.GreetingTimezoneDifference); - - if (time.Hour >= 23 || time.Hour < 5) - return ("\ud83d\ude34 Still awake, ", "?"); - - if (time.Hour >= 5 && time.Hour < 10) - return ("\ud83d\ude04 Good morning, ", ""); - - if (time.Hour >= 10 && time.Hour < 14) - return ("\u2600\ufe0f Have a nice day, ", ""); - - if (time.Hour >= 14 && time.Hour < 16) - return ("\ud83d\ude03 Good afternoon, ", ""); - - if (time.Hour >= 16 && time.Hour < 22) - return ("\ud83c\udf25\ufe0f Have a nice evening, ", ""); - - if (time.Hour >= 22 && time.Hour < 23) - return ("\ud83c\udf19 Sleep well, ", ""); - - return ("Welcome back ", ""); + foreach (var implementation in implementations) + { + Components.Add(await implementation.Get()); + } } } \ No newline at end of file From 6eedc8aba99646984f4035a0b6e54dfeae6375cd Mon Sep 17 00:00:00 2001 From: Moritz <101179677+Moritz-Deiaco@users.noreply.github.com> Date: Tue, 21 May 2024 14:12:46 +0200 Subject: [PATCH 3/3] Renamed the Implementation --- Moonlight/Core/CoreFeature.cs | 4 ++-- .../Core/Implementations/UI/Index/GreetingMessages.cs | 4 ++-- Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs | 8 -------- .../Core/Interfaces/UI/User/IUserDashboardComponent.cs | 8 ++++++++ Moonlight/Core/UI/Views/Index.razor | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs create mode 100644 Moonlight/Core/Interfaces/UI/User/IUserDashboardComponent.cs diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index 25ada45..22156ab 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -12,7 +12,7 @@ using Moonlight.Core.Implementations.UI.Admin.AdminColumns; using Moonlight.Core.Implementations.UI.Index; using Moonlight.Core.Interfaces; using Moonlight.Core.Interfaces.Ui.Admin; -using Moonlight.Core.Interfaces.UI.Index; +using Moonlight.Core.Interfaces.UI.User; using Moonlight.Core.Models; using Moonlight.Core.Models.Abstractions; using Moonlight.Core.Models.Abstractions.Feature; @@ -162,7 +162,7 @@ public class CoreFeature : MoonlightFeature // UI await pluginService.RegisterImplementation(new UserCount()); - await pluginService.RegisterImplementation(new GreetingMessages()); + await pluginService.RegisterImplementation(new GreetingMessages()); // Startup job services var startupJobService = app.Services.GetRequiredService(); diff --git a/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs index a0c5c0e..552ec27 100644 --- a/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs +++ b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs @@ -1,11 +1,11 @@ using MoonCoreUI.Helpers; -using Moonlight.Core.Interfaces.UI.Index; +using Moonlight.Core.Interfaces.UI.User; using Moonlight.Core.Models.Abstractions; using Moonlight.Core.UI.Components.Cards; namespace Moonlight.Core.Implementations.UI.Index; -public class GreetingMessages : IIndexPageComponent +public class GreetingMessages : IUserDashboardComponent { public Task Get() { diff --git a/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs b/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs deleted file mode 100644 index 50ae397..0000000 --- a/Moonlight/Core/Interfaces/UI/Index/IIndexPageComponent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Moonlight.Core.Models.Abstractions; - -namespace Moonlight.Core.Interfaces.UI.Index; - -public interface IIndexPageComponent -{ - public Task Get(); -} \ No newline at end of file diff --git a/Moonlight/Core/Interfaces/UI/User/IUserDashboardComponent.cs b/Moonlight/Core/Interfaces/UI/User/IUserDashboardComponent.cs new file mode 100644 index 0000000..0f2570d --- /dev/null +++ b/Moonlight/Core/Interfaces/UI/User/IUserDashboardComponent.cs @@ -0,0 +1,8 @@ +using Moonlight.Core.Models.Abstractions; + +namespace Moonlight.Core.Interfaces.UI.User; + +public interface IUserDashboardComponent +{ + public Task Get(); +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Index.razor b/Moonlight/Core/UI/Views/Index.razor index bc43335..e36cf09 100644 --- a/Moonlight/Core/UI/Views/Index.razor +++ b/Moonlight/Core/UI/Views/Index.razor @@ -1,5 +1,5 @@ @page "/" -@using Moonlight.Core.Interfaces.UI.Index +@using Moonlight.Core.Interfaces.UI.User @using Moonlight.Core.Models.Abstractions @using Moonlight.Core.Services @@ -23,7 +23,7 @@ { await arg.SetText("Loading..."); - var implementations = await PluginService.GetImplementations(); + var implementations = await PluginService.GetImplementations(); foreach (var implementation in implementations) {