From f0bc9e23b87f9fee47f179d7855a5d0e796217b2 Mon Sep 17 00:00:00 2001 From: Leon Hoppe Date: Tue, 14 Jan 2025 11:34:57 +0100 Subject: [PATCH 01/17] Added basic configuration --- .idea/.idea.HopFrame/.idea/workspace.xml | 124 +++++++++++- HopFrame.sln | 29 +++ src/HopFrame.Core/Config/DbContextConfig.cs | 37 ++++ src/HopFrame.Core/Config/HopFrameConfig.cs | 27 +++ src/HopFrame.Core/Config/TableConfig.cs | 17 ++ src/HopFrame.Core/HopFrame.Core.csproj | 13 ++ .../ServiceCollectionExtensions.cs | 14 ++ .../Services/IContextExplorer.cs | 8 + .../Implementations/ContextExplorer.cs | 24 +++ src/HopFrame.Web/HopFrame.Web.csproj | 28 +++ .../ServiceCollectionExtensions.cs | 19 ++ src/HopFrame.Web/_Imports.razor | 10 + testing/HopFrame.Testing/Components/App.razor | 20 ++ .../Components/Layout/MainLayout.razor | 26 +++ .../Components/Layout/NavMenu.razor | 19 ++ .../Components/Pages/Counter.razor | 21 ++ .../Components/Pages/Error.razor | 35 ++++ .../Components/Pages/Home.razor | 18 ++ .../Components/Pages/Weather.razor | 48 +++++ .../HopFrame.Testing/Components/Routes.razor | 6 + .../Components/_Imports.razor | 12 ++ testing/HopFrame.Testing/DatabaseContext.cs | 10 + .../HopFrame.Testing/HopFrame.Testing.csproj | 18 ++ testing/HopFrame.Testing/Models/User.cs | 10 + testing/HopFrame.Testing/Program.cs | 41 ++++ .../Properties/launchSettings.json | 23 +++ .../appsettings.Development.json | 8 + testing/HopFrame.Testing/appsettings.json | 9 + testing/HopFrame.Testing/wwwroot/app.css | 191 ++++++++++++++++++ testing/HopFrame.Testing/wwwroot/favicon.ico | Bin 0 -> 15086 bytes 30 files changed, 860 insertions(+), 5 deletions(-) create mode 100644 src/HopFrame.Core/Config/DbContextConfig.cs create mode 100644 src/HopFrame.Core/Config/HopFrameConfig.cs create mode 100644 src/HopFrame.Core/Config/TableConfig.cs create mode 100644 src/HopFrame.Core/HopFrame.Core.csproj create mode 100644 src/HopFrame.Core/ServiceCollectionExtensions.cs create mode 100644 src/HopFrame.Core/Services/IContextExplorer.cs create mode 100644 src/HopFrame.Core/Services/Implementations/ContextExplorer.cs create mode 100644 src/HopFrame.Web/HopFrame.Web.csproj create mode 100644 src/HopFrame.Web/ServiceCollectionExtensions.cs create mode 100644 src/HopFrame.Web/_Imports.razor create mode 100644 testing/HopFrame.Testing/Components/App.razor create mode 100644 testing/HopFrame.Testing/Components/Layout/MainLayout.razor create mode 100644 testing/HopFrame.Testing/Components/Layout/NavMenu.razor create mode 100644 testing/HopFrame.Testing/Components/Pages/Counter.razor create mode 100644 testing/HopFrame.Testing/Components/Pages/Error.razor create mode 100644 testing/HopFrame.Testing/Components/Pages/Home.razor create mode 100644 testing/HopFrame.Testing/Components/Pages/Weather.razor create mode 100644 testing/HopFrame.Testing/Components/Routes.razor create mode 100644 testing/HopFrame.Testing/Components/_Imports.razor create mode 100644 testing/HopFrame.Testing/DatabaseContext.cs create mode 100644 testing/HopFrame.Testing/HopFrame.Testing.csproj create mode 100644 testing/HopFrame.Testing/Models/User.cs create mode 100644 testing/HopFrame.Testing/Program.cs create mode 100644 testing/HopFrame.Testing/Properties/launchSettings.json create mode 100644 testing/HopFrame.Testing/appsettings.Development.json create mode 100644 testing/HopFrame.Testing/appsettings.json create mode 100644 testing/HopFrame.Testing/wwwroot/app.css create mode 100644 testing/HopFrame.Testing/wwwroot/favicon.ico diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml index 57c430c..103fdc8 100644 --- a/.idea/.idea.HopFrame/.idea/workspace.xml +++ b/.idea/.idea.HopFrame/.idea/workspace.xml @@ -1,32 +1,142 @@ + + HopFrame.Testing/HopFrame.Testing.csproj + HopFrame.Testing/HopFrame.Testing.csproj + testing/HopFrame.Testing/HopFrame.Testing.csproj + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + { + "lastFilter": { + "state": "OPENED", + "assignee": { + "type": "org.jetbrains.plugins.gitlab.mergerequest.ui.filters.GitLabMergeRequestsFiltersValue.MergeRequestsMemberFilterValue.MergeRequestsAssigneeFilterValue", + "username": "leon.hoppe", + "fullname": "Leon Hoppe" + } + } +} + { + "selectedUrlAndAccountId": { + "first": "https://git.leon-hoppe.de/leon.hoppe/hopframe.git", + "second": "2d65fdcb-5f13-45ad-a7ba-91dd4a88d6e4" + } +} + { + "associatedIndex": 3 +} - + + + + + + + + + + + + + @@ -36,6 +146,10 @@ diff --git a/HopFrame.sln b/HopFrame.sln index a55ff74..d622867 100644 --- a/HopFrame.sln +++ b/HopFrame.sln @@ -1,8 +1,37 @@  Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{7E4AAFB3-9762-4F42-86DF-5A3194FDC243}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Core", "src\HopFrame.Core\HopFrame.Core.csproj", "{4BFE21C2-EAAC-4662-8B97-500836651B2A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Web", "src\HopFrame.Web\HopFrame.Web.csproj", "{8E59F398-184A-47C9-AAA2-3E0FFD775ABF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{9EB7FDBD-49C2-4872-9666-6F7AEBA541B2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Testing", "testing\HopFrame.Testing\HopFrame.Testing.csproj", "{58490069-51DF-454C-8B54-7FB7D4BDFF81}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {4BFE21C2-EAAC-4662-8B97-500836651B2A} = {7E4AAFB3-9762-4F42-86DF-5A3194FDC243} + {8E59F398-184A-47C9-AAA2-3E0FFD775ABF} = {7E4AAFB3-9762-4F42-86DF-5A3194FDC243} + {58490069-51DF-454C-8B54-7FB7D4BDFF81} = {9EB7FDBD-49C2-4872-9666-6F7AEBA541B2} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4BFE21C2-EAAC-4662-8B97-500836651B2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4BFE21C2-EAAC-4662-8B97-500836651B2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4BFE21C2-EAAC-4662-8B97-500836651B2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4BFE21C2-EAAC-4662-8B97-500836651B2A}.Release|Any CPU.Build.0 = Release|Any CPU + {8E59F398-184A-47C9-AAA2-3E0FFD775ABF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E59F398-184A-47C9-AAA2-3E0FFD775ABF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E59F398-184A-47C9-AAA2-3E0FFD775ABF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E59F398-184A-47C9-AAA2-3E0FFD775ABF}.Release|Any CPU.Build.0 = Release|Any CPU + {58490069-51DF-454C-8B54-7FB7D4BDFF81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58490069-51DF-454C-8B54-7FB7D4BDFF81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58490069-51DF-454C-8B54-7FB7D4BDFF81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58490069-51DF-454C-8B54-7FB7D4BDFF81}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection EndGlobal diff --git a/src/HopFrame.Core/Config/DbContextConfig.cs b/src/HopFrame.Core/Config/DbContextConfig.cs new file mode 100644 index 0000000..b21f8cb --- /dev/null +++ b/src/HopFrame.Core/Config/DbContextConfig.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore; + +namespace HopFrame.Core.Config; + +public class DbContextConfig { + public Type ContextType { get; } + public List Tables { get; init; } = new(); + + public DbContextConfig(Type context) { + ContextType = context; + + foreach (var property in ContextType.GetProperties()) { + if (!property.PropertyType.IsGenericType) continue; + var innerType = property.PropertyType.GenericTypeArguments.First(); + var setType = typeof(DbSet<>).MakeGenericType(innerType); + if (property.PropertyType != setType) continue; + + var table = new TableConfig(this, innerType, property.Name); + Tables.Add(table); + } + } +} + +public class DbContextConfig(Type context) : DbContextConfig(context) where TDbContext : DbContext { + + public DbContextConfig Table(Action> configurator) where TModel : class { + var table = Table(); + configurator.Invoke(table); + return this; + } + + public TableConfig Table() where TModel : class { + var table = Tables.Single(table => table.TableType == typeof(TModel)); + return new TableConfig(table); + } + +} diff --git a/src/HopFrame.Core/Config/HopFrameConfig.cs b/src/HopFrame.Core/Config/HopFrameConfig.cs new file mode 100644 index 0000000..e02d79b --- /dev/null +++ b/src/HopFrame.Core/Config/HopFrameConfig.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; + +namespace HopFrame.Core.Config; + +public class HopFrameConfig { + public List Contexts { get; init; } = new(); + public bool DisplayUserInfo { get; set; } = true; +} + +public class HopFrameConfigurator(HopFrameConfig config) { + public HopFrameConfigurator AddDbContext(Action> configurator) where TDbContext : DbContext { + var context = AddDbContext(); + configurator.Invoke(context); + return this; + } + + public DbContextConfig AddDbContext() where TDbContext : DbContext { + var context = new DbContextConfig(typeof(TDbContext)); + config.Contexts.Add(context); + return context; + } + + public HopFrameConfigurator DisplayUserInfo(bool display) { + config.DisplayUserInfo = display; + return this; + } +} diff --git a/src/HopFrame.Core/Config/TableConfig.cs b/src/HopFrame.Core/Config/TableConfig.cs new file mode 100644 index 0000000..413f6aa --- /dev/null +++ b/src/HopFrame.Core/Config/TableConfig.cs @@ -0,0 +1,17 @@ +namespace HopFrame.Core.Config; + +public class TableConfig(DbContextConfig config, Type tableType, string propertyName) { + public Type TableType { get; } = tableType; + public string PropertyName { get; } = propertyName; + public DbContextConfig ContextConfig { get; } = config; + public bool Ignored { get; set; } +} + +public class TableConfig(TableConfig innerConfig) { + + public TableConfig Ignore() { + innerConfig.Ignored = true; + return this; + } + +} diff --git a/src/HopFrame.Core/HopFrame.Core.csproj b/src/HopFrame.Core/HopFrame.Core.csproj new file mode 100644 index 0000000..ae907a6 --- /dev/null +++ b/src/HopFrame.Core/HopFrame.Core.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/src/HopFrame.Core/ServiceCollectionExtensions.cs b/src/HopFrame.Core/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..13524d1 --- /dev/null +++ b/src/HopFrame.Core/ServiceCollectionExtensions.cs @@ -0,0 +1,14 @@ +using HopFrame.Core.Services; +using HopFrame.Core.Services.Implementations; +using Microsoft.Extensions.DependencyInjection; + +namespace HopFrame.Core; + +public static class ServiceCollectionExtensions { + + public static IServiceCollection AddHopFrameServices(this IServiceCollection services) { + services.AddTransient(); + return services; + } + +} \ No newline at end of file diff --git a/src/HopFrame.Core/Services/IContextExplorer.cs b/src/HopFrame.Core/Services/IContextExplorer.cs new file mode 100644 index 0000000..b74f56e --- /dev/null +++ b/src/HopFrame.Core/Services/IContextExplorer.cs @@ -0,0 +1,8 @@ +using HopFrame.Core.Config; + +namespace HopFrame.Core.Services; + +public interface IContextExplorer { + public IEnumerable GetTableNames(); + public TableConfig? GetTable(string name); +} \ No newline at end of file diff --git a/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs b/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs new file mode 100644 index 0000000..332f9fd --- /dev/null +++ b/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs @@ -0,0 +1,24 @@ +using HopFrame.Core.Config; + +namespace HopFrame.Core.Services.Implementations; + +internal sealed class ContextExplorer(HopFrameConfig config) : IContextExplorer { + public IEnumerable GetTableNames() { + foreach (var context in config.Contexts) { + foreach (var table in context.Tables) { + if (table.Ignored) continue; + yield return table.PropertyName; + } + } + } + + public TableConfig? GetTable(string name) { + foreach (var context in config.Contexts) { + var table = context.Tables.FirstOrDefault(table => table.PropertyName == name); + if (table is not null) + return table; + } + + return null; + } +} \ No newline at end of file diff --git a/src/HopFrame.Web/HopFrame.Web.csproj b/src/HopFrame.Web/HopFrame.Web.csproj new file mode 100644 index 0000000..d2541db --- /dev/null +++ b/src/HopFrame.Web/HopFrame.Web.csproj @@ -0,0 +1,28 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/HopFrame.Web/ServiceCollectionExtensions.cs b/src/HopFrame.Web/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..86c3e51 --- /dev/null +++ b/src/HopFrame.Web/ServiceCollectionExtensions.cs @@ -0,0 +1,19 @@ +using HopFrame.Core; +using HopFrame.Core.Config; +using Microsoft.Extensions.DependencyInjection; + +namespace HopFrame.Web; + +public static class ServiceCollectionExtensions { + + public static IServiceCollection AddHopFrame(this IServiceCollection services, Action configurator) { + var config = new HopFrameConfig(); + configurator.Invoke(new HopFrameConfigurator(config)); + + services.AddSingleton(config); + services.AddHopFrameServices(); + + return services; + } + +} \ No newline at end of file diff --git a/src/HopFrame.Web/_Imports.razor b/src/HopFrame.Web/_Imports.razor new file mode 100644 index 0000000..767bfa2 --- /dev/null +++ b/src/HopFrame.Web/_Imports.razor @@ -0,0 +1,10 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.FluentUI.AspNetCore.Components +@using Icons = Microsoft.FluentUI.AspNetCore.Components.Icons +@using HopFrame.Web diff --git a/testing/HopFrame.Testing/Components/App.razor b/testing/HopFrame.Testing/Components/App.razor new file mode 100644 index 0000000..ccbffb9 --- /dev/null +++ b/testing/HopFrame.Testing/Components/App.razor @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/Layout/MainLayout.razor b/testing/HopFrame.Testing/Components/Layout/MainLayout.razor new file mode 100644 index 0000000..989cce9 --- /dev/null +++ b/testing/HopFrame.Testing/Components/Layout/MainLayout.razor @@ -0,0 +1,26 @@ +@inherits LayoutComponentBase + + + + HopFrame.Testing + + + + +
+ @Body +
+
+
+ + Documentation and demos + + About Blazor + +
+ +
+ An unhandled error has occurred. + Reload + 🗙 +
\ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/Layout/NavMenu.razor b/testing/HopFrame.Testing/Components/Layout/NavMenu.razor new file mode 100644 index 0000000..68ed2db --- /dev/null +++ b/testing/HopFrame.Testing/Components/Layout/NavMenu.razor @@ -0,0 +1,19 @@ +@rendermode InteractiveServer + + + +@code { + private bool expanded = true; +} \ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/Pages/Counter.razor b/testing/HopFrame.Testing/Components/Pages/Counter.razor new file mode 100644 index 0000000..e4f070e --- /dev/null +++ b/testing/HopFrame.Testing/Components/Pages/Counter.razor @@ -0,0 +1,21 @@ +@page "/counter" +@rendermode InteractiveServer + +Counter + +

Counter

+ +
+ Current count: @currentCount +
+ +Click me + +@code { + private int currentCount = 0; + + private void IncrementCount() { + currentCount++; + } + +} \ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/Pages/Error.razor b/testing/HopFrame.Testing/Components/Pages/Error.razor new file mode 100644 index 0000000..06de831 --- /dev/null +++ b/testing/HopFrame.Testing/Components/Pages/Error.razor @@ -0,0 +1,35 @@ +@page "/Error" +@using System.Diagnostics + +Error + +

Error.

+

An error occurred while processing your request.

+ +@if (ShowRequestId) { +

+ Request ID: @RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+ +@code{ + [CascadingParameter] private HttpContext? HttpContext { get; set; } + + private string? RequestId { get; set; } + private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + protected override void OnInitialized() => + RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; + +} \ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/Pages/Home.razor b/testing/HopFrame.Testing/Components/Pages/Home.razor new file mode 100644 index 0000000..fbceb64 --- /dev/null +++ b/testing/HopFrame.Testing/Components/Pages/Home.razor @@ -0,0 +1,18 @@ +@page "/" +@using HopFrame.Core.Services + +Home + +

Hello, world!

+ +Welcome to your new Fluent Blazor app. + +@inject IContextExplorer Explorer + +@code { + + protected override void OnInitialized() { + Console.WriteLine(string.Join(", ", Explorer.GetTableNames())); + } + +} diff --git a/testing/HopFrame.Testing/Components/Pages/Weather.razor b/testing/HopFrame.Testing/Components/Pages/Weather.razor new file mode 100644 index 0000000..b88da70 --- /dev/null +++ b/testing/HopFrame.Testing/Components/Pages/Weather.razor @@ -0,0 +1,48 @@ +@page "/weather" +@attribute [StreamRendering] + +Weather + +

Weather

+ +

This component demonstrates showing data.

+ +@if (forecasts == null) { +

+ Loading... +

+} +else { + + + + + + + +} + +@code { + private IQueryable? forecasts; + + protected override async Task OnInitializedAsync() { + // Simulate asynchronous loading to demonstrate streaming rendering + await Task.Delay(500); + + var startDate = DateOnly.FromDateTime(DateTime.Now); + var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; + forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast { + Date = startDate.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = summaries[Random.Shared.Next(summaries.Length)] + }).AsQueryable(); + } + + private class WeatherForecast { + public DateOnly Date { get; set; } + public int TemperatureC { get; set; } + public string? Summary { get; set; } + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + } + +} \ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/Routes.razor b/testing/HopFrame.Testing/Components/Routes.razor new file mode 100644 index 0000000..ae94e9e --- /dev/null +++ b/testing/HopFrame.Testing/Components/Routes.razor @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/testing/HopFrame.Testing/Components/_Imports.razor b/testing/HopFrame.Testing/Components/_Imports.razor new file mode 100644 index 0000000..eae1177 --- /dev/null +++ b/testing/HopFrame.Testing/Components/_Imports.razor @@ -0,0 +1,12 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.FluentUI.AspNetCore.Components +@using Icons = Microsoft.FluentUI.AspNetCore.Components.Icons +@using Microsoft.JSInterop +@using HopFrame.Testing +@using HopFrame.Testing.Components \ No newline at end of file diff --git a/testing/HopFrame.Testing/DatabaseContext.cs b/testing/HopFrame.Testing/DatabaseContext.cs new file mode 100644 index 0000000..d62cb6d --- /dev/null +++ b/testing/HopFrame.Testing/DatabaseContext.cs @@ -0,0 +1,10 @@ +using HopFrame.Testing.Models; +using Microsoft.EntityFrameworkCore; + +namespace HopFrame.Testing; + +public class DatabaseContext(DbContextOptions options) : DbContext(options) { + + public DbSet Users { get; set; } + +} \ No newline at end of file diff --git a/testing/HopFrame.Testing/HopFrame.Testing.csproj b/testing/HopFrame.Testing/HopFrame.Testing.csproj new file mode 100644 index 0000000..aa6580f --- /dev/null +++ b/testing/HopFrame.Testing/HopFrame.Testing.csproj @@ -0,0 +1,18 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + diff --git a/testing/HopFrame.Testing/Models/User.cs b/testing/HopFrame.Testing/Models/User.cs new file mode 100644 index 0000000..5233569 --- /dev/null +++ b/testing/HopFrame.Testing/Models/User.cs @@ -0,0 +1,10 @@ +namespace HopFrame.Testing.Models; + +public class User { + public required Guid Id { get; init; } + public required string Email { get; init; } + public string? Username { get; set; } + public string? Password { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } +} \ No newline at end of file diff --git a/testing/HopFrame.Testing/Program.cs b/testing/HopFrame.Testing/Program.cs new file mode 100644 index 0000000..cb5cbf4 --- /dev/null +++ b/testing/HopFrame.Testing/Program.cs @@ -0,0 +1,41 @@ +using HopFrame.Testing; +using Microsoft.FluentUI.AspNetCore.Components; +using HopFrame.Testing.Components; +using HopFrame.Testing.Models; +using HopFrame.Web; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents(); +builder.Services.AddFluentUIComponents(); + +builder.Services.AddDbContext(options => { + options.UseInMemoryDatabase("testing"); +}); + +builder.Services.AddHopFrame(options => { + options.AddDbContext() + .Table(table => table.Ignore()); +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) { + app.UseExceptionHandler("/Error", createScopeForErrors: true); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); + +app.UseAntiforgery(); + +app.MapStaticAssets(); +app.MapRazorComponents() + .AddInteractiveServerRenderMode(); + +app.Run(); \ No newline at end of file diff --git a/testing/HopFrame.Testing/Properties/launchSettings.json b/testing/HopFrame.Testing/Properties/launchSettings.json new file mode 100644 index 0000000..4132fdd --- /dev/null +++ b/testing/HopFrame.Testing/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5221", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7180;http://localhost:5221", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } + } diff --git a/testing/HopFrame.Testing/appsettings.Development.json b/testing/HopFrame.Testing/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/testing/HopFrame.Testing/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/testing/HopFrame.Testing/appsettings.json b/testing/HopFrame.Testing/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/testing/HopFrame.Testing/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/testing/HopFrame.Testing/wwwroot/app.css b/testing/HopFrame.Testing/wwwroot/app.css new file mode 100644 index 0000000..288d428 --- /dev/null +++ b/testing/HopFrame.Testing/wwwroot/app.css @@ -0,0 +1,191 @@ +@import '/_content/Microsoft.FluentUI.AspNetCore.Components/css/reboot.css'; + +body { + --body-font: "Segoe UI Variable", "Segoe UI", sans-serif; + font-family: var(--body-font); + font-size: var(--type-ramp-base-font-size); + line-height: var(--type-ramp-base-line-height); + margin: 0; +} + +.navmenu-icon { + display: none; +} + +.main { + min-height: calc(100dvh - 86px); + color: var(--neutral-foreground-rest); + align-items: stretch !important; +} + +.body-content { + align-self: stretch; + height: calc(100dvh - 86px) !important; + display: flex; +} + +.content { + padding: 0.5rem 1.5rem; + align-self: stretch !important; + width: 100%; +} + +.manage { + width: 100dvw; +} + +footer { + background: var(--neutral-layer-4); + color: var(--neutral-foreground-rest); + align-items: center; + padding: 10px 10px; +} + + footer a { + color: var(--neutral-foreground-rest); + text-decoration: none; + } + + footer a:focus { + outline: 1px dashed; + outline-offset: 3px; + } + + footer a:hover { + text-decoration: underline; + } + +.alert { + border: 1px dashed var(--accent-fill-rest); + padding: 5px; +} + + +#blazor-error-ui { + background: lightyellow; + bottom: 0; + box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); + display: none; + left: 0; + padding: 0.6rem 1.25rem 0.7rem 1.25rem; + position: fixed; + width: 100%; + z-index: 1000; + margin: 20px 0; +} + + #blazor-error-ui .dismiss { + cursor: pointer; + position: absolute; + right: 0.75rem; + top: 0.5rem; + } + +.blazor-error-boundary { + background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; + padding: 1rem 1rem 1rem 3.7rem; + color: white; +} + + .blazor-error-boundary::before { + content: "An error has occurred. " + } + +.loading-progress { + position: relative; + display: block; + width: 8rem; + height: 8rem; + margin: 20vh auto 1rem auto; +} + + .loading-progress circle { + fill: none; + stroke: #e0e0e0; + stroke-width: 0.6rem; + transform-origin: 50% 50%; + transform: rotate(-90deg); + } + + .loading-progress circle:last-child { + stroke: #1b6ec2; + stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; + transition: stroke-dasharray 0.05s ease-in-out; + } + +.loading-progress-text { + position: absolute; + text-align: center; + font-weight: bold; + inset: calc(20vh + 3.25rem) 0 auto 0.2rem; +} + + .loading-progress-text:after { + content: var(--blazor-load-percentage-text, "Loading"); + } + +code { + color: #c02d76; +} + +@media (max-width: 600px) { + .header-gutters { + margin: 0.5rem 3rem 0.5rem 1.5rem !important; + } + + [dir="rtl"] .header-gutters { + margin: 0.5rem 1.5rem 0.5rem 3rem !important; + } + + .main { + flex-direction: column !important; + row-gap: 0 !important; + } + + nav.sitenav { + width: 100%; + height: 100%; + } + + #main-menu { + width: 100% !important; + } + + #main-menu > div:first-child:is(.expander) { + display: none; + } + + .navmenu { + width: 100%; + } + + #navmenu-toggle { + appearance: none; + } + + #navmenu-toggle ~ nav { + display: none; + } + + #navmenu-toggle:checked ~ nav { + display: block; + } + + .navmenu-icon { + cursor: pointer; + z-index: 10; + display: block; + position: absolute; + top: 15px; + left: unset; + right: 20px; + width: 20px; + height: 20px; + border: none; + } + + [dir="rtl"] .navmenu-icon { + left: 20px; + right: unset; + } +} diff --git a/testing/HopFrame.Testing/wwwroot/favicon.ico b/testing/HopFrame.Testing/wwwroot/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..e189d8e579e552ab2b3c82a949bccbc5ea00f3ed GIT binary patch literal 15086 zcmeHO33OG}xxSXRYJC=8YhT~%>sqp2t?g55>7>;KUJ^jdYuD;t>%04$efIG0 z>EHjbuf=kirJrTsKnvmlmi0fiSZ=jgECUAk-mkG(Dv)*!Vt#+^n-`o?bHdy;nJmMX5oYCLpS0gU^#FbaM|CxA86yhfyqDvUTyfD?hchV9qBYK09w`PyKHoHi4Ry8WB z+hcYL71aV$fFJ(7`hdD`0S*90yB@n!E8l-q+4=5VW%&bdX>)%$Oh*0h^LpgZ2kVhP z3&eAHCkE@$HxAKbfBUkG`}3RHmQkN8$5-w2bW}E|nkppf6~I2=FTmAbXFpKi4Zu-= zYeClMmZ;m`_(F}n^=}5vqabRrG4Mj zWv(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h#`|7&qK?8c+L!ajwJWqQmxKl=szfE##0f_|H;8M)dmK_}|Ns!%^!`WW*#k zrMwlzd&4^Td>d$Nh73i&oPOp&u36qcpP;25z%!P6hw|UekU`&vP3d&yp*;Emo`fD# zh_hbDeY)NLa=pbUa~am(^{8h!o-gli?syFAp#!MAw>K^cy h>tK_moz~z$C_xJ#cRer_5s?az|L8{mjpJ^y{2w+yQgr|T literal 0 HcmV?d00001 -- 2.49.1 From 313f6e046adc58ec11b41053daac27b18e67dedf Mon Sep 17 00:00:00 2001 From: Leon Hoppe Date: Tue, 14 Jan 2025 12:46:47 +0100 Subject: [PATCH 02/17] Added admin page navigation --- .idea/.idea.HopFrame/.idea/workspace.xml | 65 ++++++++++--------- src/HopFrame.Core/Config/HopFrameConfig.cs | 21 +++++- .../Services/IHopFrameAuthHandler.cs | 6 ++ .../Components/Layout/HopFrameLayout.razor | 48 ++++++++++++++ .../Layout/HopFrameNavigation.razor | 46 +++++++++++++ .../Components/Layout/HopFrameSideMenu.razor | 22 +++++++ .../Components/Pages/HopFrameHome.razor | 8 +++ src/HopFrame.Web/HopFrame.Web.csproj | 4 -- .../ServiceCollectionExtensions.cs | 4 +- src/HopFrame.Web/_Imports.razor | 3 +- src/HopFrame.Web/wwwroot/hopframe.css | 17 +++++ testing/HopFrame.Testing/Program.cs | 9 +-- 12 files changed, 211 insertions(+), 42 deletions(-) create mode 100644 src/HopFrame.Core/Services/IHopFrameAuthHandler.cs create mode 100644 src/HopFrame.Web/Components/Layout/HopFrameLayout.razor create mode 100644 src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor create mode 100644 src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor create mode 100644 src/HopFrame.Web/Components/Pages/HopFrameHome.razor create mode 100644 src/HopFrame.Web/wwwroot/hopframe.css diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml index 103fdc8..c5caf91 100644 --- a/.idea/.idea.HopFrame/.idea/workspace.xml +++ b/.idea/.idea.HopFrame/.idea/workspace.xml @@ -9,37 +9,19 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - + + + + +
\ No newline at end of file diff --git a/src/HopFrame.Core/Config/HopFrameConfig.cs b/src/HopFrame.Core/Config/HopFrameConfig.cs index e02d79b..1c1e676 100644 --- a/src/HopFrame.Core/Config/HopFrameConfig.cs +++ b/src/HopFrame.Core/Config/HopFrameConfig.cs @@ -1,10 +1,14 @@ -using Microsoft.EntityFrameworkCore; +using HopFrame.Core.Services; +using Microsoft.EntityFrameworkCore; namespace HopFrame.Core.Config; public class HopFrameConfig { public List 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() 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; + } } diff --git a/src/HopFrame.Core/Services/IHopFrameAuthHandler.cs b/src/HopFrame.Core/Services/IHopFrameAuthHandler.cs new file mode 100644 index 0000000..f883c7a --- /dev/null +++ b/src/HopFrame.Core/Services/IHopFrameAuthHandler.cs @@ -0,0 +1,6 @@ +namespace HopFrame.Core.Services; + +public interface IHopFrameAuthHandler { + public Task IsAuthenticatedAsync(string? policy); + public Task GetCurrentUserDisplayNameAsync(); +} \ No newline at end of file diff --git a/src/HopFrame.Web/Components/Layout/HopFrameLayout.razor b/src/HopFrame.Web/Components/Layout/HopFrameLayout.razor new file mode 100644 index 0000000..99fe64d --- /dev/null +++ b/src/HopFrame.Web/Components/Layout/HopFrameLayout.razor @@ -0,0 +1,48 @@ +@using HopFrame.Core.Config +@using HopFrame.Core.Services +@inherits LayoutComponentBase + + + + + + + + + + + +
+ @Body +
+
+
+ + Documentation and source code + + + + + + + + +
+ +@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); + } + } + } + +} diff --git a/src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor b/src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor new file mode 100644 index 0000000..0a703b9 --- /dev/null +++ b/src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor @@ -0,0 +1,46 @@ +@using System.Text +@using HopFrame.Core.Config +@using HopFrame.Core.Services + + HopFrame + + + @if (Config.DisplayUserInfo) { + + } + + + +@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(); + } + + +} diff --git a/src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor b/src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor new file mode 100644 index 0000000..78eb38a --- /dev/null +++ b/src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor @@ -0,0 +1,22 @@ +@using HopFrame.Core.Services + + + +
+ + @foreach (var table in Explorer.GetTableNames()) { + + } +
+ +@inject IContextExplorer Explorer diff --git a/src/HopFrame.Web/Components/Pages/HopFrameHome.razor b/src/HopFrame.Web/Components/Pages/HopFrameHome.razor new file mode 100644 index 0000000..b7e9e2e --- /dev/null +++ b/src/HopFrame.Web/Components/Pages/HopFrameHome.razor @@ -0,0 +1,8 @@ +@page "/admin" +@layout HopFrameLayout + +

HopFrameHome

+ +@code { + +} \ No newline at end of file diff --git a/src/HopFrame.Web/HopFrame.Web.csproj b/src/HopFrame.Web/HopFrame.Web.csproj index d2541db..c137722 100644 --- a/src/HopFrame.Web/HopFrame.Web.csproj +++ b/src/HopFrame.Web/HopFrame.Web.csproj @@ -17,10 +17,6 @@ - - - - diff --git a/src/HopFrame.Web/ServiceCollectionExtensions.cs b/src/HopFrame.Web/ServiceCollectionExtensions.cs index 86c3e51..c68c7a4 100644 --- a/src/HopFrame.Web/ServiceCollectionExtensions.cs +++ b/src/HopFrame.Web/ServiceCollectionExtensions.cs @@ -9,10 +9,12 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddHopFrame(this IServiceCollection services, Action 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; } diff --git a/src/HopFrame.Web/_Imports.razor b/src/HopFrame.Web/_Imports.razor index 767bfa2..4a8dc26 100644 --- a/src/HopFrame.Web/_Imports.razor +++ b/src/HopFrame.Web/_Imports.razor @@ -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 diff --git a/src/HopFrame.Web/wwwroot/hopframe.css b/src/HopFrame.Web/wwwroot/hopframe.css new file mode 100644 index 0000000..40f6b2b --- /dev/null +++ b/src/HopFrame.Web/wwwroot/hopframe.css @@ -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; +} diff --git a/testing/HopFrame.Testing/Program.cs b/testing/HopFrame.Testing/Program.cs index cb5cbf4..1133beb 100644 --- a/testing/HopFrame.Testing/Program.cs +++ b/testing/HopFrame.Testing/Program.cs @@ -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(options => { }); builder.Services.AddHopFrame(options => { - options.AddDbContext() - .Table(table => table.Ignore()); + options.DisplayUserInfo(false); + options.AddDbContext(); }); var app = builder.Build(); @@ -36,6 +36,7 @@ app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() - .AddInteractiveServerRenderMode(); + .AddInteractiveServerRenderMode() + .AddAdditionalAssemblies(typeof(HopFrameHome).Assembly); app.Run(); \ No newline at end of file -- 2.49.1 From 6115dcf8e1e2ebaa6cdcd534c63519361f0366cc Mon Sep 17 00:00:00 2001 From: Leon Hoppe Date: Tue, 14 Jan 2025 14:05:15 +0100 Subject: [PATCH 03/17] Added database loading logic --- .idea/.idea.HopFrame/.idea/workspace.xml | 41 ++++++++++++------- .../Services/IContextExplorer.cs | 3 +- src/HopFrame.Core/Services/ITableManager.cs | 5 +++ .../Implementations/ContextExplorer.cs | 22 ++++++++-- .../Services/Implementations/TableManager.cs | 15 +++++++ .../Components/Layout/HopFrameLayout.razor | 12 +++--- .../Layout/HopFrameNavigation.razor | 12 +++--- .../Components/Pages/Home.razor | 15 ++++++- testing/HopFrame.Testing/DatabaseContext.cs | 10 ++++- testing/HopFrame.Testing/Models/Post.cs | 17 ++++++++ testing/HopFrame.Testing/Models/User.cs | 4 ++ testing/HopFrame.Testing/Program.cs | 6 ++- .../HopFrame.Testing/Services/AuthService.cs | 12 ++++++ 13 files changed, 139 insertions(+), 35 deletions(-) create mode 100644 src/HopFrame.Core/Services/ITableManager.cs create mode 100644 src/HopFrame.Core/Services/Implementations/TableManager.cs create mode 100644 testing/HopFrame.Testing/Models/Post.cs create mode 100644 testing/HopFrame.Testing/Services/AuthService.cs diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml index c5caf91..bbde447 100644 --- a/.idea/.idea.HopFrame/.idea/workspace.xml +++ b/.idea/.idea.HopFrame/.idea/workspace.xml @@ -9,18 +9,19 @@