diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index ad86ba8..a65c282 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -8,9 +8,12 @@ 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.Implementations.UI.Index; using Moonlight.Core.Interfaces; +using Moonlight.Core.Interfaces.Ui.Admin; +using Moonlight.Core.Interfaces.UI.User; using Moonlight.Core.Models; using Moonlight.Core.Models.Abstractions; using Moonlight.Core.Models.Abstractions.Feature; @@ -160,8 +163,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/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/Implementations/UI/Index/GreetingMessages.cs b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs new file mode 100644 index 0000000..552ec27 --- /dev/null +++ b/Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs @@ -0,0 +1,20 @@ +using MoonCoreUI.Helpers; +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 : IUserDashboardComponent +{ + 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/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/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/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/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/Core/UI/Views/Index.razor b/Moonlight/Core/UI/Views/Index.razor index 80e3838..e36cf09 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.User +@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 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 818be3a..94c9911 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -53,7 +53,7 @@ - + @@ -75,6 +75,7 @@ +