Made Index page Modular
Made Index Page editable with the Plugin System, added greeting Component
This commit is contained in:
parent
769c876dc5
commit
cba98bdf6f
|
@ -9,8 +9,10 @@ using Moonlight.Core.Database;
|
||||||
using Moonlight.Core.Database.Entities;
|
using Moonlight.Core.Database.Entities;
|
||||||
using Moonlight.Core.Implementations.Diagnose;
|
using Moonlight.Core.Implementations.Diagnose;
|
||||||
using Moonlight.Core.Implementations.UI.Admin.AdminColumns;
|
using Moonlight.Core.Implementations.UI.Admin.AdminColumns;
|
||||||
|
using Moonlight.Core.Implementations.UI.Index;
|
||||||
using Moonlight.Core.Interfaces;
|
using Moonlight.Core.Interfaces;
|
||||||
using Moonlight.Core.Interfaces.Ui.Admin;
|
using Moonlight.Core.Interfaces.Ui.Admin;
|
||||||
|
using Moonlight.Core.Interfaces.UI.Index;
|
||||||
using Moonlight.Core.Models;
|
using Moonlight.Core.Models;
|
||||||
using Moonlight.Core.Models.Abstractions;
|
using Moonlight.Core.Models.Abstractions;
|
||||||
using Moonlight.Core.Models.Abstractions.Feature;
|
using Moonlight.Core.Models.Abstractions.Feature;
|
||||||
|
@ -158,8 +160,9 @@ public class CoreFeature : MoonlightFeature
|
||||||
await pluginService.RegisterImplementation<IDiagnoseAction>(new FeatureDiagnoseAction());
|
await pluginService.RegisterImplementation<IDiagnoseAction>(new FeatureDiagnoseAction());
|
||||||
await pluginService.RegisterImplementation<IDiagnoseAction>(new LogDiagnoseAction());
|
await pluginService.RegisterImplementation<IDiagnoseAction>(new LogDiagnoseAction());
|
||||||
|
|
||||||
//Admin Page
|
// UI
|
||||||
await pluginService.RegisterImplementation<IAdminDashboardColumn>(new UserCount());
|
await pluginService.RegisterImplementation<IAdminDashboardColumn>(new UserCount());
|
||||||
|
await pluginService.RegisterImplementation<IIndexPageComponent>(new GreetingMessages());
|
||||||
|
|
||||||
// Startup job services
|
// Startup job services
|
||||||
var startupJobService = app.Services.GetRequiredService<StartupJobService>();
|
var startupJobService = app.Services.GetRequiredService<StartupJobService>();
|
||||||
|
|
20
Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs
Normal file
20
Moonlight/Core/Implementations/UI/Index/GreetingMessages.cs
Normal file
|
@ -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<UiComponent> Get()
|
||||||
|
{
|
||||||
|
var res = new UiComponent()
|
||||||
|
{
|
||||||
|
Component = ComponentHelper.FromType<TimeBasedGreetingMessages>(),
|
||||||
|
Index = int.MinValue
|
||||||
|
};
|
||||||
|
|
||||||
|
return Task.FromResult(res);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Moonlight.Core.Models.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Core.Interfaces.UI.Index;
|
||||||
|
|
||||||
|
public interface IIndexPageComponent
|
||||||
|
{
|
||||||
|
public Task<UiComponent> Get();
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
@using MoonCore.Services
|
||||||
|
@using Moonlight.Core.Configuration
|
||||||
|
@using Moonlight.Core.Services
|
||||||
|
|
||||||
|
@inject IdentityService IdentityService
|
||||||
|
@inject ConfigService<CoreConfiguration> ConfigService
|
||||||
|
|
||||||
|
<div class="card card-body p-8">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<span class="fs-2 fw-semibold">
|
||||||
|
@{
|
||||||
|
var greeting = GetGreetingMessage();
|
||||||
|
}
|
||||||
|
@greeting.Item1
|
||||||
|
<span class="text-info">@IdentityService.CurrentUser.Username</span>
|
||||||
|
@greeting.Item2
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@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 ", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,60 +1,33 @@
|
||||||
@page "/"
|
@page "/"
|
||||||
|
@using Moonlight.Core.Interfaces.UI.Index
|
||||||
|
@using Moonlight.Core.Models.Abstractions
|
||||||
@using Moonlight.Core.Services
|
@using Moonlight.Core.Services
|
||||||
@using MoonCore.Services
|
|
||||||
@using Moonlight.Core.Configuration
|
|
||||||
|
|
||||||
@inject IdentityService IdentityService
|
@inject PluginService PluginService
|
||||||
@inject ConfigService<CoreConfiguration> ConfigService
|
|
||||||
|
|
||||||
<div class="card card-body p-8">
|
<LazyLoader Load="Load">
|
||||||
<div class="d-flex align-items-center">
|
@foreach (var component in Components.OrderBy(x => x.Index))
|
||||||
<span class="fs-2 fw-semibold">
|
{
|
||||||
@{
|
<div class="mb-4">
|
||||||
var greeting = GetGreetingMessage();
|
@component.Component
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
@greeting.Item1
|
</LazyLoader>
|
||||||
<span class="text-info">@IdentityService.CurrentUser.Username</span>
|
|
||||||
@greeting.Item2
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
// For explanation:
|
private List<UiComponent> Components = new();
|
||||||
// The first value is the actual message
|
|
||||||
// end second value is for question marks and so on
|
|
||||||
//
|
private async Task Load(LazyLoader arg)
|
||||||
// and yes, this "feature" is kinda useless but still i wanted to implement
|
|
||||||
// it. - Masu
|
|
||||||
private (string, string) GetGreetingMessage()
|
|
||||||
{
|
{
|
||||||
var config = ConfigService.Get().Customisation;
|
await arg.SetText("Loading...");
|
||||||
|
|
||||||
if (config.DisableTimeBasedGreetingMessages)
|
var implementations = await PluginService.GetImplementations<IIndexPageComponent>();
|
||||||
return ("Welcome back, ", "");
|
|
||||||
|
|
||||||
var time = DateTime.UtcNow.AddHours(config.GreetingTimezoneDifference);
|
foreach (var implementation in implementations)
|
||||||
|
{
|
||||||
if (time.Hour >= 23 || time.Hour < 5)
|
Components.Add(await implementation.Get());
|
||||||
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 ", "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue