feat: application shell, localized texts and user preferences (M3, part 1)
The pages built so far now live inside the shell of the mockups instead of the M0 placeholder, every interface text comes from Resources/it-IT, and each user keeps their own look and start page. - Shell: top bar, collapsible side menu with fly-out sub-menus, status bar and tabs that keep each page alive (page type and route values per tab, so a tab never shows another page); at most 12 tabs, least-used clean tab evicted. - One shortcut table with Alt variants for the combinations browsers keep (Ctrl+W, Ctrl+Tab, Ctrl+N); command palette for pages and commands. - ITexts over embedded JSON; tests forbid literal texts in .razor components and check that every key used exists. - User settings in sys_user_settings / user_settings; theme written on the server; profile page with live preview, start page, sessions and shortcuts. - Home, coming-soon pages for later milestones, localized sign-in and error pages; ADR 0020; wiki, CHANGELOG, STATUS and data model updated. Refs #25 #26 #31 #33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c30054e3d
commit
cf6f849cc1
72 files changed
+5785
-259
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Khaemhat.Application.Configuration;
|
||||
using Khaemhat.Application.Instance;
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Core.Common;
|
||||
using Khaemhat.Infrastructure.Logging;
|
||||
@@ -89,6 +90,12 @@ public static class KhaemhatApp
|
||||
}
|
||||
|
||||
app.UseSecurityHeaders();
|
||||
|
||||
// Numbers, dates and texts in Italian (SPEC §10.8); a circuit keeps the culture of the request that opened it.
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions()
|
||||
.SetDefaultCulture(KhaemhatServices.ItalianCulture.Name)
|
||||
.AddSupportedCultures(KhaemhatServices.ItalianCulture.Name)
|
||||
.AddSupportedUICultures(KhaemhatServices.ItalianCulture.Name));
|
||||
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
||||
app.MapHealthEndpoints();
|
||||
app.UseStartingPage();
|
||||
@@ -101,6 +108,7 @@ public static class KhaemhatApp
|
||||
|
||||
app.MapStaticAssets();
|
||||
app.MapSignOut();
|
||||
app.MapCompanySwitch();
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
|
||||
@@ -122,6 +130,35 @@ public static class KhaemhatApp
|
||||
}
|
||||
}
|
||||
|
||||
// POST /session/company: an instance account chooses the company of its session (top bar, SPEC §10.2). The page
|
||||
// is reloaded, so the new circuit starts in the new company.
|
||||
private static void MapCompanySwitch(this IEndpointRouteBuilder endpoints) =>
|
||||
endpoints.MapPost("/session/company", async (HttpContext context, SessionStore sessions, CompanyContextResolver companies, IAntiforgery antiforgery) =>
|
||||
{
|
||||
if (!await antiforgery.IsRequestValidAsync(context).ConfigureAwait(false))
|
||||
{
|
||||
return Results.BadRequest();
|
||||
}
|
||||
|
||||
var actor = SessionCookie.ActorOf(context.User);
|
||||
var cookie = SessionCookie.Read(context);
|
||||
var form = await context.Request.ReadFormAsync(context.RequestAborted).ConfigureAwait(false);
|
||||
var code = form["code"].ToString();
|
||||
if (actor is not { IsInstanceAccount: true } || cookie is null || string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return Results.Forbid();
|
||||
}
|
||||
|
||||
var result = await companies.ResolveAsync(actor, code, context.RequestAborted).ConfigureAwait(false);
|
||||
if (result.Access != CompanyAccess.Granted || result.Company is null)
|
||||
{
|
||||
return Results.Redirect("/");
|
||||
}
|
||||
|
||||
await sessions.SetCompanyAsync(cookie, result.Company.Code, context.RequestAborted).ConfigureAwait(false);
|
||||
return Results.Redirect("/");
|
||||
});
|
||||
|
||||
// POST /logout: closes the session and removes the cookie; a form with the antiforgery token posts here.
|
||||
private static void MapSignOut(this IEndpointRouteBuilder endpoints) =>
|
||||
endpoints.MapPost("/logout", async (HttpContext context, SignInService signIn, IAntiforgery antiforgery) =>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Globalization;
|
||||
using Khaemhat.Application.Audit;
|
||||
using Khaemhat.Application.Configuration;
|
||||
using Khaemhat.Application.Instance;
|
||||
using Khaemhat.Application.Jobs;
|
||||
using Khaemhat.Application.Licensing;
|
||||
using Khaemhat.Application.Localization;
|
||||
using Khaemhat.Application.Modules;
|
||||
using Khaemhat.Application.Notifications;
|
||||
using Khaemhat.Application.Preferences;
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Core.Caching;
|
||||
using Khaemhat.Core.Logging;
|
||||
@@ -21,6 +24,7 @@ using Khaemhat.Infrastructure.Licensing;
|
||||
using Khaemhat.Infrastructure.Logging;
|
||||
using Khaemhat.Infrastructure.Security;
|
||||
using Khaemhat.Web.Security;
|
||||
using Khaemhat.Web.Shell;
|
||||
|
||||
namespace Khaemhat.Web.Hosting;
|
||||
|
||||
@@ -30,6 +34,9 @@ namespace Khaemhat.Web.Hosting;
|
||||
/// </summary>
|
||||
internal static class KhaemhatServices
|
||||
{
|
||||
/// <summary>The culture of the interface and of number and date formats (SPEC §10.8).</summary>
|
||||
internal static readonly CultureInfo ItalianCulture = CultureInfo.GetCultureInfo("it-IT");
|
||||
|
||||
/// <summary>Registers every service of the instance.</summary>
|
||||
/// <param name="services">The container.</param>
|
||||
/// <param name="options">The validated variables.</param>
|
||||
@@ -127,6 +134,16 @@ internal static class KhaemhatServices
|
||||
services.AddSingleton<IScheduledJob, LogRetentionJob>();
|
||||
services.AddSingleton<JobScheduler>();
|
||||
services.AddHostedService<JobSchedulerService>();
|
||||
|
||||
// Interface (SPEC §10): texts, preferences and the per-circuit state of the shell.
|
||||
services.AddSingleton<ITexts>(JsonTextProvider.FromAssembly(typeof(KhaemhatServices).Assembly, ItalianCulture));
|
||||
services.AddSingleton<UserSettingsService>();
|
||||
services.AddScoped<ShellSession>();
|
||||
services.AddScoped<ThemeService>();
|
||||
services.AddScoped<TabService>();
|
||||
services.AddScoped<KeyboardShortcutService>();
|
||||
services.AddScoped<ToastService>();
|
||||
services.AddScoped<DialogService>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ internal static class KhaemhatMiddleware
|
||||
|
||||
return context.Response.WriteAsync(
|
||||
"<!DOCTYPE html><html lang=\"it\"><head><meta charset=\"utf-8\">" + refresh +
|
||||
"<title>Khaemhat</title><link rel=\"stylesheet\" href=\"/app.css\"></head><body><main class=\"kh-construction\"><section class=\"hero\">" +
|
||||
"<img class=\"mark\" src=\"/icon.svg\" alt=\"\" width=\"96\" height=\"96\"><h1>Khaemhat</h1><p class=\"state\">" + WebUtility.HtmlEncode(message) +
|
||||
"<title>Khaemhat</title><link rel=\"stylesheet\" href=\"/app.css\"></head><body><main class=\"kh-unavailable\"><section>" +
|
||||
"<img class=\"mark\" src=\"/icon.svg\" alt=\"\" width=\"96\" height=\"96\"><h1>Khaemhat</h1><p>" + WebUtility.HtmlEncode(message) +
|
||||
"</p></section></main></body></html>",
|
||||
context.RequestAborted);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user