Added admin page navigation

This commit is contained in:
2025-01-14 12:46:47 +01:00
parent f0bc9e23b8
commit 313f6e046a
12 changed files with 211 additions and 42 deletions

View File

@@ -0,0 +1,48 @@
@using HopFrame.Core.Config
@using HopFrame.Core.Services
@inherits LayoutComponentBase
<link rel="stylesheet" type='text/css' href="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/devicon.min.css" />
<link rel="stylesheet" href="/_content/HopFrame.Web/hopframe.css"/>
<FluentDesignTheme Mode="DesignThemeModes.Dark" />
<FluentLayout Class="hopframe-outer">
<HopFrameNavigation />
<FluentStack Orientation="Orientation.Horizontal" Width="100%" Class="hopframe-main">
<HopFrameSideMenu />
<FluentBodyContent>
<div class="hopframe-content">
@Body
</div>
</FluentBodyContent>
</FluentStack>
<FluentFooter>
<a href="https://git.leon-hoppe.de/leon.hoppe/hopframe" target="_blank">Documentation and source code</a>
<FluentSpacer/>
<a href="https://git.leon-hoppe.de/leon.hoppe/" target="_blank" style="margin-right: 0.25rem; text-decoration: none">
<i class="devicon-gitlab-plain"></i>
</a>
<a href="https://github.com/leonhoppe" target="_blank" style="text-decoration: none">
<i class="devicon-github-original"></i>
</a>
</FluentFooter>
</FluentLayout>
@inject IServiceProvider Provider
@inject HopFrameConfig Config
@inject NavigationManager Navigator
@code {
protected override async Task OnInitializedAsync() {
if (!string.IsNullOrEmpty(Config.BasePolicy)) {
var handler = Provider.GetService(Config.AuthHandler!) as IHopFrameAuthHandler;
var authorized = await handler!.IsAuthenticatedAsync(Config.BasePolicy);
if (!authorized) {
Navigator.NavigateTo((Config.LoginPageRewrite ?? "/login") + "?redirect=" + Navigator.Uri);
}
}
}
}

View File

@@ -0,0 +1,46 @@
@using System.Text
@using HopFrame.Core.Config
@using HopFrame.Core.Services
<FluentHeader Class="hopframe-header">
<a href="/admin" style="text-decoration: none; color: @Color.Neutral.ToAttributeValue()">HopFrame</a>
<FluentSpacer/>
@if (Config.DisplayUserInfo) {
<FluentPersona Name="@_displayName" Initials="@_initials" ImageSize="32px" TextPosition="TextPosition.Start"/>
}
</FluentHeader>
@inject HopFrameConfig Config
@inject IServiceProvider Provider
@code {
private string? _displayName;
private string? _initials;
protected override async Task OnInitializedAsync() {
if (Config.DisplayUserInfo) {
var handler = Provider.GetService(Config.AuthHandler!) as IHopFrameAuthHandler;
_displayName = await handler!.GetCurrentUserDisplayNameAsync();
_initials = GetInitials(_displayName);
}
}
private static string GetInitials(string input) {
if (string.IsNullOrEmpty(input))
return string.Empty;
StringBuilder initials = new StringBuilder();
string[] words = input.Split([' ', '.', '_'], StringSplitOptions.RemoveEmptyEntries);
foreach (string word in words) {
if (!string.IsNullOrEmpty(word) && char.IsLetter(word[0]))
initials.Append(word[0]);
}
return initials.ToString().ToUpper();
}
}

View File

@@ -0,0 +1,22 @@
@using HopFrame.Core.Services
<FluentAppBar Orientation="Orientation.Vertical" Style="background-color: var(--neutral-layer-2); height: auto">
<FluentAppBarItem Href="/admin"
Match="NavLinkMatch.All"
IconActive="new Icons.Filled.Size24.Grid()"
IconRest="new Icons.Regular.Size24.Grid()"
Text="Dashboard"
Style="margin-top: 0.25rem"/>
<br>
@foreach (var table in Explorer.GetTableNames()) {
<FluentAppBarItem Href="@("/admin/" + table)"
Match="NavLinkMatch.All"
IconActive="new Icons.Filled.Size24.Database()"
IconRest="new Icons.Regular.Size24.Database()"
Text="@table"
Style="margin-top: 0.25rem"/>
}
</FluentAppBar>
@inject IContextExplorer Explorer

View File

@@ -0,0 +1,8 @@
@page "/admin"
@layout HopFrameLayout
<h3>HopFrameHome</h3>
@code {
}

View File

@@ -17,10 +17,6 @@
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.11.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HopFrame.Core\HopFrame.Core.csproj" />
</ItemGroup>

View File

@@ -9,10 +9,12 @@ public static class ServiceCollectionExtensions {
public static IServiceCollection AddHopFrame(this IServiceCollection services, Action<HopFrameConfigurator> configurator) {
var config = new HopFrameConfig();
configurator.Invoke(new HopFrameConfigurator(config));
return AddHopFrame(services, config);
}
public static IServiceCollection AddHopFrame(this IServiceCollection services, HopFrameConfig config) {
services.AddSingleton(config);
services.AddHopFrameServices();
return services;
}

View File

@@ -7,4 +7,5 @@
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.FluentUI.AspNetCore.Components
@using Icons = Microsoft.FluentUI.AspNetCore.Components.Icons
@using HopFrame.Web
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
@using HopFrame.Web.Components.Layout

View File

@@ -0,0 +1,17 @@
.hopframe-header {
background-color: var(--neutral-layer-4) !important;
border-bottom: calc(var(--stroke-width) * 2px) solid var(--accent-fill-rest) !important;
color: var(--neutral-foreground-rest) !important;
}
.hopframe-content {
padding: 0.5rem 1.5rem;
align-self: stretch !important;
width: 100%;
}
.hopframe-main {
min-height: calc(100dvh - 86px);
color: var(--neutral-foreground-rest);
align-items: stretch !important;
}