Added admin page navigation
This commit is contained in:
65
.idea/.idea.HopFrame/.idea/workspace.xml
generated
65
.idea/.idea.HopFrame/.idea/workspace.xml
generated
@@ -9,37 +9,19 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/DbContextConfig.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/HopFrameConfig.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/HopFrame.Core.csproj" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/ServiceCollectionExtensions.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/IContextExplorer.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/HopFrame.Web.csproj" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/ServiceCollectionExtensions.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/_Imports.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/App.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Layout/MainLayout.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Layout/NavMenu.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Pages/Counter.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Pages/Error.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Pages/Home.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Pages/Weather.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Routes.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/_Imports.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/DatabaseContext.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/HopFrame.Testing.csproj" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/User.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Properties/launchSettings.json" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/appsettings.Development.json" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/appsettings.json" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/wwwroot/app.css" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/wwwroot/favicon.ico" afterDir="false" />
|
||||
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="Added basic configuration">
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/IHopFrameAuthHandler.cs" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Layout/HopFrameLayout.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameHome.razor" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/HopFrame.Web/wwwroot/hopframe.css" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/HopFrame.sln" beforeDir="false" afterPath="$PROJECT_DIR$/HopFrame.sln" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/HopFrameConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/HopFrameConfig.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/HopFrame.Web.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/HopFrame.Web.csproj" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/ServiceCollectionExtensions.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/ServiceCollectionExtensions.cs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/_Imports.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/_Imports.razor" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -49,6 +31,13 @@
|
||||
<component name="DpaMonitoringSettings">
|
||||
<option name="firstShow" value="false" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="CSS File" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
@@ -73,6 +62,7 @@
|
||||
"second": "2d65fdcb-5f13-45ad-a7ba-91dd4a88d6e4"
|
||||
}
|
||||
}</component>
|
||||
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 3
|
||||
}</component>
|
||||
@@ -92,6 +82,7 @@
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "feature/setup",
|
||||
"list.type.of.created.stylesheet": "CSS",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
@@ -149,15 +140,27 @@
|
||||
<workItem from="1736788853462" duration="780000" />
|
||||
<workItem from="1736845367516" duration="283000" />
|
||||
<workItem from="1736845655122" duration="165000" />
|
||||
<workItem from="1736845825812" duration="5047000" />
|
||||
<workItem from="1736845825812" duration="9326000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Added basic configuration">
|
||||
<option name="closed" value="true" />
|
||||
<created>1736850899254</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1736850899254</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
|
||||
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||
<MESSAGE value="Added basic configuration" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Added basic configuration" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,10 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using HopFrame.Core.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HopFrame.Core.Config;
|
||||
|
||||
public class HopFrameConfig {
|
||||
public List<DbContextConfig> Contexts { get; init; } = new();
|
||||
public bool DisplayUserInfo { get; set; } = true;
|
||||
public Type? AuthHandler { get; set; }
|
||||
public string? BasePolicy { get; set; }
|
||||
public string? LoginPageRewrite { get; set; }
|
||||
}
|
||||
|
||||
public class HopFrameConfigurator(HopFrameConfig config) {
|
||||
@@ -24,4 +28,19 @@ public class HopFrameConfigurator(HopFrameConfig config) {
|
||||
config.DisplayUserInfo = display;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HopFrameConfigurator SetAuthHandler<TAuthHandler>() where TAuthHandler : IHopFrameAuthHandler {
|
||||
config.AuthHandler = typeof(TAuthHandler);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HopFrameConfigurator SetBasePolicy(string basePolicy) {
|
||||
config.BasePolicy = basePolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HopFrameConfigurator SetLoginPage(string url) {
|
||||
config.LoginPageRewrite = url;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
6
src/HopFrame.Core/Services/IHopFrameAuthHandler.cs
Normal file
6
src/HopFrame.Core/Services/IHopFrameAuthHandler.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace HopFrame.Core.Services;
|
||||
|
||||
public interface IHopFrameAuthHandler {
|
||||
public Task<bool> IsAuthenticatedAsync(string? policy);
|
||||
public Task<string> GetCurrentUserDisplayNameAsync();
|
||||
}
|
||||
48
src/HopFrame.Web/Components/Layout/HopFrameLayout.razor
Normal file
48
src/HopFrame.Web/Components/Layout/HopFrameLayout.razor
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
46
src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor
Normal file
46
src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
22
src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor
Normal file
22
src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor
Normal 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
|
||||
8
src/HopFrame.Web/Components/Pages/HopFrameHome.razor
Normal file
8
src/HopFrame.Web/Components/Pages/HopFrameHome.razor
Normal file
@@ -0,0 +1,8 @@
|
||||
@page "/admin"
|
||||
@layout HopFrameLayout
|
||||
|
||||
<h3>HopFrameHome</h3>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
17
src/HopFrame.Web/wwwroot/hopframe.css
Normal file
17
src/HopFrame.Web/wwwroot/hopframe.css
Normal 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;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using HopFrame.Testing;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
using HopFrame.Testing.Components;
|
||||
using HopFrame.Testing.Models;
|
||||
using HopFrame.Web;
|
||||
using HopFrame.Web.Components.Pages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -17,8 +17,8 @@ builder.Services.AddDbContext<DatabaseContext>(options => {
|
||||
});
|
||||
|
||||
builder.Services.AddHopFrame(options => {
|
||||
options.AddDbContext<DatabaseContext>()
|
||||
.Table<User>(table => table.Ignore());
|
||||
options.DisplayUserInfo(false);
|
||||
options.AddDbContext<DatabaseContext>();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
@@ -36,6 +36,7 @@ app.UseAntiforgery();
|
||||
|
||||
app.MapStaticAssets();
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
.AddInteractiveServerRenderMode()
|
||||
.AddAdditionalAssemblies(typeof(HopFrameHome).Assembly);
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user