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.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<IDiagnoseAction>(new FeatureDiagnoseAction());
|
||||
await pluginService.RegisterImplementation<IDiagnoseAction>(new LogDiagnoseAction());
|
||||
|
||||
//Admin Page
|
||||
// UI
|
||||
await pluginService.RegisterImplementation<IAdminDashboardColumn>(new UserCount());
|
||||
await pluginService.RegisterImplementation<IIndexPageComponent>(new GreetingMessages());
|
||||
|
||||
// Startup job services
|
||||
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 "/"
|
||||
|
||||
@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<CoreConfiguration> ConfigService
|
||||
@inject PluginService PluginService
|
||||
|
||||
<div class="card card-body p-8">
|
||||
<div class="d-flex align-items-center">
|
||||
<span class="fs-2 fw-semibold">
|
||||
@{
|
||||
var greeting = GetGreetingMessage();
|
||||
<LazyLoader Load="Load">
|
||||
@foreach (var component in Components.OrderBy(x => x.Index))
|
||||
{
|
||||
<div class="mb-4">
|
||||
@component.Component
|
||||
</div>
|
||||
}
|
||||
@greeting.Item1
|
||||
<span class="text-info">@IdentityService.CurrentUser.Username</span>
|
||||
@greeting.Item2
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@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<UiComponent> 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<IIndexPageComponent>();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue