Added theme saving. Added interfaces for overview pages. Renamed sidebar interface function
This commit is contained in:
@@ -8,6 +8,7 @@ public class CoreStartup : IPluginStartup
|
||||
public Task BuildApplication(WebAssemblyHostBuilder builder)
|
||||
{
|
||||
builder.Services.AddSingleton<ISidebarItemProvider, DefaultSidebarItemProvider>();
|
||||
builder.Services.AddSingleton<IOverviewElementProvider, DefaultOverviewElementProvider>();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Moonlight.Client.Interfaces;
|
||||
|
||||
namespace Moonlight.Client.Implementations;
|
||||
|
||||
public class DefaultAdminOverviewElementProvider : IAdminOverviewElementProvider
|
||||
{
|
||||
public void ModifyOverview(List<Type> overviewComponents)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Moonlight.Client.Interfaces;
|
||||
using Moonlight.Client.UI.Components;
|
||||
|
||||
namespace Moonlight.Client.Implementations;
|
||||
|
||||
public class DefaultOverviewElementProvider : IOverviewElementProvider
|
||||
{
|
||||
public void ModifyOverview(List<Type> overviewComponents)
|
||||
{
|
||||
overviewComponents.Add(typeof(WelcomeOverviewElement));
|
||||
}
|
||||
}
|
||||
@@ -5,61 +5,62 @@ namespace Moonlight.Client.Implementations;
|
||||
|
||||
public class DefaultSidebarItemProvider : ISidebarItemProvider
|
||||
{
|
||||
public SidebarItem[] Get()
|
||||
public void ModifySidebar(List<SidebarItem> items)
|
||||
{
|
||||
return
|
||||
[
|
||||
// User
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-chart-no-axes-gantt",
|
||||
Name = "Overview",
|
||||
Path = "/",
|
||||
Priority = 0,
|
||||
RequiresExactMatch = true
|
||||
},
|
||||
|
||||
// Admin
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-chart-no-axes-gantt",
|
||||
Name = "Overview",
|
||||
Group = "Admin",
|
||||
Path = "/admin",
|
||||
Priority = 0,
|
||||
RequiresExactMatch = true,
|
||||
Permission = "admin.overview"
|
||||
},
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-users",
|
||||
Name = "Users",
|
||||
Group = "Admin",
|
||||
Path = "/admin/users",
|
||||
Priority = 1,
|
||||
RequiresExactMatch = false,
|
||||
Permission = "admin.users.read"
|
||||
},
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-key-square",
|
||||
Name = "API",
|
||||
Group = "Admin",
|
||||
Path = "/admin/api",
|
||||
Priority = 2,
|
||||
RequiresExactMatch = false,
|
||||
Permission = "admin.api.read"
|
||||
},
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-settings",
|
||||
Name = "System",
|
||||
Group = "Admin",
|
||||
Path = "/admin/system",
|
||||
Priority = 3,
|
||||
RequiresExactMatch = false,
|
||||
Permission = "admin.system.overview"
|
||||
},
|
||||
];
|
||||
items.AddRange(
|
||||
[
|
||||
// User
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-chart-no-axes-gantt",
|
||||
Name = "Overview",
|
||||
Path = "/",
|
||||
Priority = 0,
|
||||
RequiresExactMatch = true
|
||||
},
|
||||
|
||||
// Admin
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-chart-no-axes-gantt",
|
||||
Name = "Overview",
|
||||
Group = "Admin",
|
||||
Path = "/admin",
|
||||
Priority = 0,
|
||||
RequiresExactMatch = true,
|
||||
Permission = "admin.overview"
|
||||
},
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-users",
|
||||
Name = "Users",
|
||||
Group = "Admin",
|
||||
Path = "/admin/users",
|
||||
Priority = 1,
|
||||
RequiresExactMatch = false,
|
||||
Permission = "admin.users.read"
|
||||
},
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-key-square",
|
||||
Name = "API",
|
||||
Group = "Admin",
|
||||
Path = "/admin/api",
|
||||
Priority = 2,
|
||||
RequiresExactMatch = false,
|
||||
Permission = "admin.api.read"
|
||||
},
|
||||
new SidebarItem()
|
||||
{
|
||||
Icon = "icon-settings",
|
||||
Name = "System",
|
||||
Group = "Admin",
|
||||
Path = "/admin/system",
|
||||
Priority = 3,
|
||||
RequiresExactMatch = false,
|
||||
Permission = "admin.system.overview"
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using MoonCore.Blazor.Tailwind.Fm.Models;
|
||||
using MoonCore.Helpers;
|
||||
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
||||
using Moonlight.Shared.Http.Responses.Admin.Sys.Files;
|
||||
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||
|
||||
namespace Moonlight.Client.Implementations;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Moonlight.Client.Interfaces;
|
||||
|
||||
public interface IAdminOverviewElementProvider
|
||||
{
|
||||
public void ModifyOverview(List<Type> overviewComponents);
|
||||
}
|
||||
6
Moonlight.Client/Interfaces/IOverviewElementProvider.cs
Normal file
6
Moonlight.Client/Interfaces/IOverviewElementProvider.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Moonlight.Client.Interfaces;
|
||||
|
||||
public interface IOverviewElementProvider
|
||||
{
|
||||
public void ModifyOverview(List<Type> overviewComponents);
|
||||
}
|
||||
@@ -4,5 +4,5 @@ namespace Moonlight.Client.Interfaces;
|
||||
|
||||
public interface ISidebarItemProvider
|
||||
{
|
||||
public SidebarItem[] Get();
|
||||
public void ModifySidebar(List<SidebarItem> items);
|
||||
}
|
||||
24
Moonlight.Client/UI/Components/WelcomeOverviewElement.razor
Normal file
24
Moonlight.Client/UI/Components/WelcomeOverviewElement.razor
Normal file
@@ -0,0 +1,24 @@
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
|
||||
<div class="col-span-12 md:col-span-6 xl:col-span-3">
|
||||
<div class="font-medium leading-[1.1] tracking-tight">
|
||||
<div class="animate-shimmer bg-gradient-to-r from-violet-400 via-sky-400 to-purple-400 bg-clip-text font-semibold text-transparent text-3xl" style="animation-duration: 5s; background-size: 200% 100%">
|
||||
Welcome, @(Username)
|
||||
</div>
|
||||
<div class="text-gray-200 text-2xl">What do you want to do today?</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
|
||||
|
||||
private string Username;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var identity = await AuthState;
|
||||
var usernameClaim = identity.User.Claims.ToArray().First(x => x.Type == "username");
|
||||
Username = usernameClaim.Value;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
@using Moonlight.Client.Interfaces
|
||||
@using Moonlight.Client.Models
|
||||
@using Moonlight.Client.Services
|
||||
@using Moonlight.Client.UI.Layouts
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
@@ -129,8 +128,12 @@
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Items = SidebarItemProviders
|
||||
.SelectMany(x => x.Get())
|
||||
var sidebarItems = new List<SidebarItem>();
|
||||
|
||||
foreach (var provider in SidebarItemProviders)
|
||||
provider.ModifySidebar(sidebarItems);
|
||||
|
||||
Items = sidebarItems
|
||||
//.Where(x => x.Permission == null || (x.Permission != null && IdentityService.HasPermission(x.Permission)))
|
||||
.GroupBy(x => x.Group ?? "")
|
||||
.OrderByDescending(x => string.IsNullOrEmpty(x.Key))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Client.Services
|
||||
@using Moonlight.Client.UI.Components
|
||||
@using Moonlight.Shared.Http.Requests.Admin.Sys
|
||||
@using Moonlight.Shared.Misc
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@@ -199,9 +200,13 @@
|
||||
return;
|
||||
}
|
||||
|
||||
await ToastService.Success("Successfully saved theme settings");
|
||||
// Send new variables
|
||||
await ApiClient.Patch("api/admin/system/theme", new UpdateThemeRequest()
|
||||
{
|
||||
Variables = ThemeService.Variables
|
||||
});
|
||||
|
||||
//TODO: Implement saving on the api server
|
||||
await ToastService.Success("Successfully saved theme settings");
|
||||
}
|
||||
|
||||
private async Task Export()
|
||||
|
||||
@@ -1,15 +1,34 @@
|
||||
@page "/admin"
|
||||
@using Moonlight.Client.Services
|
||||
|
||||
@inject DownloadService DownloadService
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Client.Interfaces
|
||||
|
||||
<WButton OnClick="OnClick">Test DownloadService</WButton>
|
||||
@inject IEnumerable<IAdminOverviewElementProvider> ElementProviders
|
||||
|
||||
<div class="grid grid-cols-12">
|
||||
@foreach (var render in Renders)
|
||||
{
|
||||
@render
|
||||
}
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private async Task OnClick(WButton _)
|
||||
private RenderFragment[] Renders;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
await DownloadService.DownloadString("test.txt", "Download seems to be working");
|
||||
var renders = new List<RenderFragment>();
|
||||
|
||||
var elementTypes = new List<Type>();
|
||||
|
||||
foreach (var elementProvider in ElementProviders)
|
||||
elementProvider.ModifyOverview(elementTypes);
|
||||
|
||||
foreach (var elementType in elementTypes)
|
||||
renders.Add(ComponentHelper.FromType(elementType));
|
||||
|
||||
Renders = renders.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
@page "/"
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Client.Interfaces
|
||||
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@inject IEnumerable<IOverviewElementProvider> ElementProviders
|
||||
|
||||
<div class="font-medium leading-[1.1] tracking-tight">
|
||||
<div class="animate-shimmer bg-gradient-to-r from-violet-400 via-sky-400 to-purple-400 bg-clip-text font-semibold text-transparent text-3xl" style="animation-duration: 5s; background-size: 200% 100%">
|
||||
Welcome, @(Username)
|
||||
</div>
|
||||
<div class="text-gray-200 text-2xl">What do you want to do today?</div>
|
||||
<div class="grid grid-cols-12">
|
||||
@foreach (var render in Renders)
|
||||
{
|
||||
@render
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="text-primary-500/10"></div>
|
||||
|
||||
@code
|
||||
{
|
||||
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
|
||||
|
||||
private string Username;
|
||||
private RenderFragment[] Renders;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var identity = await AuthState;
|
||||
var usernameClaim = identity.User.Claims.ToArray().First(x => x.Type == "username");
|
||||
Username = usernameClaim.Value;
|
||||
var renders = new List<RenderFragment>();
|
||||
|
||||
var elementTypes = new List<Type>();
|
||||
|
||||
foreach (var elementProvider in ElementProviders)
|
||||
elementProvider.ModifyOverview(elementTypes);
|
||||
|
||||
foreach (var elementType in elementTypes)
|
||||
renders.Add(ComponentHelper.FromType(elementType));
|
||||
|
||||
Renders = renders.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user