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,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<html lang="it" @attributes="RootAttributes">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -10,6 +10,10 @@
|
||||
<link rel="icon" href="icon.svg" type="image/svg+xml" />
|
||||
<link rel="apple-touch-icon" href="icon-256.png" />
|
||||
<ResourcePreloader />
|
||||
<link rel="stylesheet" href="@Assets["css/tokens.css"]" />
|
||||
<link rel="stylesheet" href="@Assets["css/components.css"]" />
|
||||
<link rel="stylesheet" href="@Assets["css/interactive.css"]" />
|
||||
<link rel="stylesheet" href="@Assets["css/print.css"]" />
|
||||
<link rel="stylesheet" href="@Assets["app.css"]" />
|
||||
<link rel="stylesheet" href="@Assets["Khaemhat.Web.styles.css"]" />
|
||||
@* No <ImportMap />: it is an inline script, and the content security policy allows none (no JS modules yet). *@
|
||||
@@ -20,6 +24,7 @@
|
||||
<Routes @rendermode="PageRenderMode" />
|
||||
<ReconnectModal />
|
||||
<script src="@Assets["_framework/blazor.web.js"]"></script>
|
||||
<script src="@Assets["js/khaemhat.js"]"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -28,6 +33,21 @@
|
||||
[CascadingParameter]
|
||||
private HttpContext HttpContext { get; set; } = default!;
|
||||
|
||||
private IReadOnlyDictionary<string, object> RootAttributes { get; set; } = new Dictionary<string, object>();
|
||||
|
||||
// The sign-in pages are static server-rendered forms (they set the cookie); everything else is interactive.
|
||||
private IComponentRenderMode? PageRenderMode => HttpContext.AcceptsInteractiveRouting() ? InteractiveServer : null;
|
||||
|
||||
[Inject]
|
||||
private UserSettingsService Settings { get; set; } = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// The theme of the signed-in user is written on the server, so the first paint already has the right colours;
|
||||
// before sign-in the system theme applies (data-theme="auto").
|
||||
var actor = SessionCookie.ActorOf(HttpContext.User);
|
||||
var preferences = actor is null ? null : await Settings.GetPreferencesAsync(actor, HttpContext.RequestAborted);
|
||||
RootAttributes = ThemeService.RootAttributes(preferences).ToDictionary(a => a.Key, a => (object)a.Value);
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,25 @@
|
||||
@using Khaemhat.Core.Common
|
||||
@inject ProductVersion Version
|
||||
|
||||
@* Mockups 001-003: brand panel on the left, the form on the right. Texts move to the it-IT resources in M3. *@
|
||||
@* Mockups 001-003: brand panel on the left, the form on the right. *@
|
||||
<div class="kh-auth">
|
||||
<aside class="brand">
|
||||
<aside class="side">
|
||||
<div class="brand-top">
|
||||
<img class="mark" src="icon.svg" alt="" width="56" height="56" />
|
||||
<h2>Khaemhat</h2>
|
||||
<p>Gestionale ERP + CRM per PMI italiane: documenti, magazzino, contabilità e fatturazione elettronica in un'unica applicazione web.</p>
|
||||
<h2>@T["Common.ProductName"]</h2>
|
||||
<p>@T["Auth.Brand.Tagline"]</p>
|
||||
</div>
|
||||
<ul class="features">
|
||||
<li><strong>Contabilità italiana completa</strong> prima nota, IVA, registri, bilancio CEE</li>
|
||||
<li><strong>Fatturazione elettronica</strong> SDI, conservazione, bollo, autofatture</li>
|
||||
<li><strong>CRM</strong> lead, opportunità, attività, campagne</li>
|
||||
<li><strong>Più aziende</strong> un database per azienda, backup integrati</li>
|
||||
<li><strong>@T["Auth.Brand.Feature1Title"]</strong> @T["Auth.Brand.Feature1Text"]</li>
|
||||
<li><strong>@T["Auth.Brand.Feature2Title"]</strong> @T["Auth.Brand.Feature2Text"]</li>
|
||||
<li><strong>@T["Auth.Brand.Feature3Title"]</strong> @T["Auth.Brand.Feature3Text"]</li>
|
||||
<li><strong>@T["Auth.Brand.Feature4Title"]</strong> @T["Auth.Brand.Feature4Text"]</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<main class="panel">
|
||||
<main class="form-side">
|
||||
<section class="card">
|
||||
@Body
|
||||
</section>
|
||||
<footer>Khaemhat @Version.Version · <a href="https://gitea.encke-hake.ts.net/BalboSoft/Khaemhat/wiki">Documentazione</a></footer>
|
||||
<footer>@T.Format("Auth.Brand.Footer", Version.Version) · <a href="@HelpLinks.DefaultBaseUrl">@T["Common.Documentation"]</a></footer>
|
||||
</main>
|
||||
</div>
|
||||
@@ -1,9 +1,281 @@
|
||||
@inherits LayoutComponentBase
|
||||
@using System.Text.Json
|
||||
@using Khaemhat.Application.Preferences
|
||||
@implements IAsyncDisposable
|
||||
@inject ShellSession Session
|
||||
@inject TabService Tabs
|
||||
@inject ThemeService Theme
|
||||
@inject KeyboardShortcutService Shortcuts
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject NavigationManager Navigation
|
||||
@inject IJSRuntime Js
|
||||
|
||||
@Body
|
||||
@* The shell of SPEC §10.2 (mockups 004, 007, 013): top bar, collapsible menu, tab area, status bar. Every page opened
|
||||
becomes a tab; its component stays alive while the tab is open (hidden when another tab is active), so going back
|
||||
to a tab finds it as it was left. *@
|
||||
<PageTitle>@ActiveTitle · @T["Common.ProductName"]</PageTitle>
|
||||
<a class="skip" href="#kh-main">@T["Shell.SkipToContent"]</a>
|
||||
<div class="app @(_collapsed ? "collapsed" : null)">
|
||||
<TopBar OnSearch="() => _searchOpen = true" OnHelp="OpenHelpAsync" />
|
||||
<KhSideMenu Collapsed="_collapsed" OnToggle="ToggleMenuAsync" />
|
||||
<main class="main" id="kh-main">
|
||||
<div class="tabs-strip" role="tablist" aria-label="@T["Shell.Tabs.Label"]">
|
||||
@foreach (var tab in Tabs.Tabs)
|
||||
{
|
||||
var active = tab == Tabs.Active;
|
||||
var item = MenuCatalog.Find(tab.Path);
|
||||
var title = TitleOf(tab, item);
|
||||
<div class="wtab @(active ? "active" : null)" @key="tab.Id" role="presentation">
|
||||
<a class="tt" role="tab" href="@tab.Url.TrimStart('/')" aria-selected="@active" aria-controls="@("pane-" + tab.Id)" title="@title">
|
||||
@title
|
||||
</a>
|
||||
@if (tab.IsModified)
|
||||
{
|
||||
<span class="mod" title="@T["Shell.Tabs.Modified"]" aria-label="@T["Shell.Tabs.Modified"]">●</span>
|
||||
}
|
||||
<button type="button" class="x" aria-label="@T.Format("Shell.Tabs.Close", title)" title="@T["Shell.Tabs.CloseHint"]"
|
||||
@onclick="() => CloseTabAsync(tab)"><KhIcon Name="x" Class="sm" /></button>
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="wtab add" aria-label="@T["Shell.Tabs.New"]" title="@T["Shell.Tabs.New"]" @onclick="() => _searchOpen = true">
|
||||
<KhIcon Name="plus" Class="sm" />
|
||||
</button>
|
||||
</div>
|
||||
@foreach (var tab in Tabs.Tabs)
|
||||
{
|
||||
<div class="tabpane" id="@("pane-" + tab.Id)" role="tabpanel" hidden="@(tab != Tabs.Active)" @key="tab.Id">
|
||||
<CascadingValue Value="tab" IsFixed="true">
|
||||
<div class="content">@tab.Content</div>
|
||||
</CascadingValue>
|
||||
</div>
|
||||
}
|
||||
</main>
|
||||
<KhStatusBar />
|
||||
</div>
|
||||
<KhCommandPalette Open="_searchOpen" OpenChanged="open => _searchOpen = open" OnToggleMenu="ToggleMenuAsync" />
|
||||
<KhToastHost />
|
||||
<KhDialogHost />
|
||||
|
||||
<div id="blazor-error-ui" data-nosnippet>
|
||||
Si è verificato un errore imprevisto.
|
||||
<a href="." class="reload">Ricarica</a>
|
||||
@T["Shell.Error.Unexpected"]
|
||||
<a href="." class="reload">@T["Shell.Error.Reload"]</a>
|
||||
<span class="dismiss">×</span>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool _collapsed;
|
||||
private bool _searchOpen;
|
||||
private bool _unloadGuard;
|
||||
private string _savedTabs = string.Empty;
|
||||
private bool _startHandled;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
_collapsed = Session.Preferences.MenuCollapsed ?? false;
|
||||
Tabs.Changed += OnTabsChanged;
|
||||
Session.Changed += OnSessionChanged;
|
||||
Shortcuts.ShellPressed += OnShortcutAsync;
|
||||
}
|
||||
|
||||
/// <summary>The page being shown and its route values, given by <c>Routes.razor</c>.</summary>
|
||||
[CascadingParameter]
|
||||
public RouteData? Route { get; set; }
|
||||
|
||||
private string ActiveTitle => Tabs.Active is { } tab ? TitleOf(tab, MenuCatalog.Find(tab.Path)) : T["Shell.Tabs.Untitled"];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
var url = "/" + Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||
if (Tabs.Open(url, Route is null ? Body : PageOf(Route)) == TabOpenResult.Refused)
|
||||
{
|
||||
Toasts.Show(ToastKind.Warning, T["Shell.Tabs.LimitTitle"], T.Format("Shell.Tabs.LimitText", TabService.MaxTabs));
|
||||
if (Tabs.Active is { } active)
|
||||
{
|
||||
Navigation.NavigateTo(active.Url.TrimStart('/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Shortcuts.StartAsync();
|
||||
if (Session.Preferences.MenuCollapsed is null && await Js.InvokeAsync<int>("khaemhat.viewportWidth") < 1100)
|
||||
{
|
||||
_collapsed = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
await ApplyStartPageAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
Tabs.Changed -= OnTabsChanged;
|
||||
Session.Changed -= OnSessionChanged;
|
||||
Shortcuts.ShellPressed -= OnShortcutAsync;
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
// Body always draws the current page; a tab needs its own page, so it keeps the page type and a copy of the route values.
|
||||
private static RenderFragment PageOf(RouteData route)
|
||||
{
|
||||
var type = route.PageType;
|
||||
var values = route.RouteValues.ToArray();
|
||||
return builder =>
|
||||
{
|
||||
builder.OpenComponent(0, type);
|
||||
foreach (var (name, value) in values)
|
||||
{
|
||||
builder.AddComponentParameter(1, name, value);
|
||||
}
|
||||
|
||||
builder.CloseComponent();
|
||||
};
|
||||
}
|
||||
|
||||
private string TitleOf(KhTab tab, MenuItem? item) =>
|
||||
tab.Title ?? (item is not null && item.Href.Equals(tab.Path, StringComparison.OrdinalIgnoreCase) ? T[item.Key] : T["Shell.Tabs.Untitled"]);
|
||||
|
||||
// After sign-in the home page may give way to the start page chosen in the preferences (SPEC §10.3).
|
||||
private async Task ApplyStartPageAsync()
|
||||
{
|
||||
if (_startHandled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_startHandled = true;
|
||||
if (Tabs.Tabs.Count != 1 || Tabs.Active?.Path != "/")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var preferences = Session.Preferences;
|
||||
string? target = null;
|
||||
if (preferences.StartPage == StartPage.Page && preferences.StartPath is { } path)
|
||||
{
|
||||
target = path;
|
||||
}
|
||||
else if (preferences.StartPage == StartPage.LastTab && await Session.ReadSettingAsync(PreferenceKeys.OpenTabs) is { } json)
|
||||
{
|
||||
target = ReadActiveTab(json);
|
||||
}
|
||||
|
||||
if (target is not null && UserPreferences.IsLocalPath(target) && TabService.PathOf(target) != "/")
|
||||
{
|
||||
Navigation.NavigateTo(target.TrimStart('/'));
|
||||
}
|
||||
}
|
||||
|
||||
private static string? ReadActiveTab(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var document = JsonDocument.Parse(json);
|
||||
return document.RootElement.TryGetProperty("active", out var active) ? active.GetString() : null;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ToggleMenuAsync()
|
||||
{
|
||||
_collapsed = !_collapsed;
|
||||
await Session.SavePreferencesAsync(Session.Preferences with { MenuCollapsed = _collapsed });
|
||||
}
|
||||
|
||||
private async Task CloseTabAsync(KhTab tab)
|
||||
{
|
||||
if (tab.IsModified)
|
||||
{
|
||||
var title = TitleOf(tab, MenuCatalog.Find(tab.Path));
|
||||
var confirmed = await Dialogs.ConfirmAsync(new ConfirmRequest(
|
||||
T["Shell.Tabs.CloseModifiedTitle"], T.Format("Shell.Tabs.CloseModifiedText", title), T["Shell.Tabs.CloseModifiedConfirm"], T["Common.Cancel"], Danger: true));
|
||||
if (!confirmed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Tabs.Close(tab) is { } next)
|
||||
{
|
||||
Navigation.NavigateTo(next.TrimStart('/'));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenHelpAsync()
|
||||
{
|
||||
var path = TabService.PathOf(Navigation.ToBaseRelativePath(Navigation.Uri));
|
||||
await Js.InvokeVoidAsync("khaemhat.openWindow", HelpLinks.UrlFor(HelpLinks.DefaultBaseUrl, path));
|
||||
}
|
||||
|
||||
private async Task OnShortcutAsync(string command)
|
||||
{
|
||||
await InvokeAsync(async () =>
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case KeyboardShortcuts.Commands.ToggleMenu:
|
||||
await ToggleMenuAsync();
|
||||
break;
|
||||
case KeyboardShortcuts.Commands.Search:
|
||||
_searchOpen = true;
|
||||
break;
|
||||
case KeyboardShortcuts.Commands.Help:
|
||||
await OpenHelpAsync();
|
||||
break;
|
||||
case KeyboardShortcuts.Commands.CloseTab when Tabs.Active is { } active:
|
||||
await CloseTabAsync(active);
|
||||
break;
|
||||
case KeyboardShortcuts.Commands.NextTab when Tabs.Neighbour(1) is { } next:
|
||||
Navigation.NavigateTo(next.Url.TrimStart('/'));
|
||||
break;
|
||||
case KeyboardShortcuts.Commands.PreviousTab when Tabs.Neighbour(-1) is { } previous:
|
||||
Navigation.NavigateTo(previous.Url.TrimStart('/'));
|
||||
break;
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
});
|
||||
}
|
||||
|
||||
private void OnSessionChanged() => _ = InvokeAsync(StateHasChanged);
|
||||
|
||||
private void OnTabsChanged() => _ = InvokeAsync(async () =>
|
||||
{
|
||||
StateHasChanged();
|
||||
if (Tabs.HasModified != _unloadGuard)
|
||||
{
|
||||
_unloadGuard = Tabs.HasModified;
|
||||
await Js.InvokeVoidAsync("khaemhat.setUnloadGuard", _unloadGuard);
|
||||
}
|
||||
|
||||
await SaveTabsAsync();
|
||||
});
|
||||
|
||||
// The open tabs and the active one, for the "last tab" start page.
|
||||
private async Task SaveTabsAsync()
|
||||
{
|
||||
var json = JsonSerializer.Serialize(new { active = Tabs.Active?.Url, tabs = Tabs.Tabs.Select(t => t.Url).ToArray() });
|
||||
if (json == _savedTabs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_savedTabs = json;
|
||||
await Session.SaveSettingAsync(PreferenceKeys.OpenTabs, json);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#blazor-error-ui {
|
||||
color-scheme: light only;
|
||||
background: lightyellow;
|
||||
background: #FADEDC;
|
||||
color: #1E2733;
|
||||
bottom: 0;
|
||||
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
|
||||
box-sizing: border-box;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script type="module" src="@Assets["Components/Layout/ReconnectModal.razor.js"]"></script>
|
||||
<script type="module" src="@Assets["Components/Layout/ReconnectModal.razor.js"]"></script>
|
||||
|
||||
<dialog id="components-reconnect-modal" data-nosnippet>
|
||||
<div class="components-reconnect-container">
|
||||
@@ -7,25 +7,25 @@
|
||||
<div></div>
|
||||
</div>
|
||||
<p class="components-reconnect-first-attempt-visible">
|
||||
Rejoining the server...
|
||||
@T["Shell.Reconnect.First"]
|
||||
</p>
|
||||
<p class="components-reconnect-repeated-attempt-visible">
|
||||
Rejoin failed... trying again in <span id="components-seconds-to-next-attempt"></span> seconds.
|
||||
@T["Shell.Reconnect.Repeated"] <span id="components-seconds-to-next-attempt"></span> @T["Shell.Reconnect.Seconds"]
|
||||
</p>
|
||||
<p class="components-reconnect-failed-visible">
|
||||
Failed to rejoin.<br />Please retry or reload the page.
|
||||
@T["Shell.Reconnect.Failed"]<br />@T["Shell.Reconnect.FailedHint"]
|
||||
</p>
|
||||
<button id="components-reconnect-button" class="components-reconnect-failed-visible">
|
||||
Retry
|
||||
@T["Shell.Reconnect.Retry"]
|
||||
</button>
|
||||
<p class="components-pause-visible">
|
||||
The session has been paused by the server.
|
||||
@T["Shell.Reconnect.Paused"]
|
||||
</p>
|
||||
<p class="components-resume-failed-visible">
|
||||
Failed to resume the session.<br />Please retry or reload the page.
|
||||
@T["Shell.Reconnect.ResumeFailed"]<br />@T["Shell.Reconnect.FailedHint"]
|
||||
</p>
|
||||
<button id="components-resume-button" class="components-pause-visible components-resume-failed-visible">
|
||||
Resume
|
||||
@T["Shell.Reconnect.Resume"]
|
||||
</button>
|
||||
</div>
|
||||
</dialog>
|
||||
@@ -1,12 +1,11 @@
|
||||
@page "/accesso-negato"
|
||||
@attribute [ExcludeFromInteractiveRouting]
|
||||
@layout AuthLayout
|
||||
<KhPageTitle Text="@T["Pages.AccessDenied.PageTitle"]" />
|
||||
|
||||
<PageTitle>Khaemhat · accesso negato</PageTitle>
|
||||
|
||||
<main class="kh-construction">
|
||||
<section class="hero">
|
||||
<h1>Accesso negato</h1>
|
||||
<p class="lead">Il tuo profilo non ha il permesso per questa pagina, oppure il modulo non è compreso nella licenza.</p>
|
||||
<ul class="links"><li><a href="/">Torna alla pagina iniziale</a></li></ul>
|
||||
</section>
|
||||
</main>
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="lock" Class="lg" />
|
||||
<h1>@T["Pages.AccessDenied.Title"]</h1>
|
||||
<p class="lead">@T["Pages.AccessDenied.Lead"]</p>
|
||||
<a class="btn" href="./">@T["Common.BackHome"]</a>
|
||||
</div>
|
||||
@@ -0,0 +1,76 @@
|
||||
@page "/anagrafiche/{*Rest}"
|
||||
@page "/crm/{*Rest}"
|
||||
@page "/vendite/{*Rest}"
|
||||
@page "/acquisti/{*Rest}"
|
||||
@page "/magazzino/{*Rest}"
|
||||
@page "/contabilita/{*Rest}"
|
||||
@page "/scadenzario/{*Rest}"
|
||||
@page "/fatturazione-elettronica/{*Rest}"
|
||||
@page "/cespiti/{*Rest}"
|
||||
@page "/servizi/{*Rest}"
|
||||
@page "/canali/{*Rest}"
|
||||
@page "/report/{*Rest}"
|
||||
@page "/tabelle/{*Rest}"
|
||||
@page "/automazioni/{*Rest}"
|
||||
@page "/amministrazione/{*Rest}"
|
||||
@attribute [Authorize]
|
||||
@inject ShellSession Session
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@* The menu shows every area the licence and the permissions allow (SPEC §10.2); the areas of later milestones land
|
||||
here, which says when they arrive and what they will hold. Each real page replaces its route as it is built. *@
|
||||
<KhPageTitle Text="@Title" Icon="@(Area?.Icon)" />
|
||||
|
||||
@if (Area is null || !Session.CanSee(Area))
|
||||
{
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="lock" Class="lg" />
|
||||
<h1>@T["Pages.AccessDenied.Title"]</h1>
|
||||
<p class="lead">@T["Pages.AccessDenied.Lead"]</p>
|
||||
<a class="btn" href="./">@T["Common.BackHome"]</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="@Area.Icon" Class="lg" />
|
||||
<h1>@Title</h1>
|
||||
<p class="lead">@(Area.Milestone is { } milestone ? T.Format("Pages.ComingSoon.Lead", milestone) : T["Pages.ComingSoon.LeadUnknown"])</p>
|
||||
@if (Area.Children.Count > 0)
|
||||
{
|
||||
<p class="muted">@T["Pages.ComingSoon.Areas"]</p>
|
||||
<ul class="kh-chips">
|
||||
@foreach (var child in Area.Children)
|
||||
{
|
||||
<li class="chip">@T[child.Key]</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<div class="kh-actions">
|
||||
<a class="btn" href="./">@T["Common.BackHome"]</a>
|
||||
<a class="btn ghost" href="@(HelpLinks.DefaultBaseUrl + "Roadmap")" target="_blank" rel="noopener">@T["Pages.ComingSoon.Roadmap"]</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>The rest of the address, after the area.</summary>
|
||||
[Parameter]
|
||||
public string? Rest { get; set; }
|
||||
|
||||
private MenuItem? Area { get; set; }
|
||||
|
||||
private MenuItem? Entry { get; set; }
|
||||
|
||||
private string Title => Entry is null ? T["Pages.ComingSoon.Title"] : T[Entry.Key];
|
||||
|
||||
// A tab keeps its page alive and has one address, so the address is read once.
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
var path = "/" + Navigation.ToBaseRelativePath(Navigation.Uri).Split('?', '#')[0];
|
||||
Area = MenuCatalog.FindArea(path);
|
||||
Entry = MenuCatalog.Find(path);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
@page "/Error"
|
||||
@attribute [ExcludeFromInteractiveRouting]
|
||||
@layout AuthLayout
|
||||
@using System.Diagnostics
|
||||
|
||||
@* The error code shown to people is the trace id, the same one written in the log (SPEC §9.5). *@
|
||||
<PageTitle>Khaemhat · errore</PageTitle>
|
||||
<PageTitle>@T["Pages.Error.PageTitle"] · @T["Common.ProductName"]</PageTitle>
|
||||
|
||||
<main class="kh-construction">
|
||||
<section class="hero">
|
||||
<h1>Si è verificato un errore</h1>
|
||||
<p class="lead">La richiesta non è stata completata. Se il problema si ripete, comunica all'amministratore il codice qui sotto.</p>
|
||||
@if (!string.IsNullOrEmpty(TraceId))
|
||||
{
|
||||
<p class="build">Codice errore: <code>@TraceId</code></p>
|
||||
}
|
||||
<ul class="links"><li><a href="/">Torna alla pagina iniziale</a></li></ul>
|
||||
</section>
|
||||
</main>
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="alert" Class="lg" />
|
||||
<h1>@T["Pages.Error.Title"]</h1>
|
||||
<p class="lead">@T["Pages.Error.Lead"]</p>
|
||||
@if (!string.IsNullOrEmpty(TraceId))
|
||||
{
|
||||
<p class="muted">@T["Pages.Error.Code"] <code>@TraceId</code></p>
|
||||
}
|
||||
<a class="btn" href="./">@T["Common.BackHome"]</a>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
|
||||
@@ -1,42 +1,102 @@
|
||||
@page "/"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Licensing
|
||||
@using Khaemhat.Core.Common
|
||||
@inject ProductVersion Version
|
||||
@inject ILicenseGate Licenses
|
||||
@using Khaemhat.Application.Modules
|
||||
@inject ShellSession Session
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* Placeholder until the shell of M3 (SPEC §20): who is signed in, in which company, with which licence. Texts move to
|
||||
the it-IT resources with the localization of M3. *@
|
||||
<PageTitle>Khaemhat</PageTitle>
|
||||
@* The home page of SPEC §10.2 until the widget dashboard of mockup 004 (issue #30): who is signed in, the licence,
|
||||
the company and the areas the user can open, with the milestone of those still to come. *@
|
||||
<KhPageTitle Text="@T["Pages.Home.Title"]" Icon="home" />
|
||||
|
||||
<main class="kh-construction">
|
||||
<section class="hero">
|
||||
<img class="mark" src="icon.svg" alt="" width="96" height="96" />
|
||||
<h1>Khaemhat <span class="ver">v @Version.MajorMinor</span></h1>
|
||||
<AuthorizeView>
|
||||
<p class="lead">Benvenuto, <strong>@context.User.FindFirst(SessionCookie.DisplayNameClaim)?.Value</strong>
|
||||
(@LevelLabel(context.User.FindFirst(SessionCookie.LevelClaim)?.Value))
|
||||
@if (context.User.FindFirst(SessionCookie.CompanyClaim)?.Value is { } company)
|
||||
{
|
||||
<span> · azienda <strong>@company</strong></span>
|
||||
}
|
||||
</p>
|
||||
</AuthorizeView>
|
||||
<p class="state">Accesso, utenti, ruoli, licenze e log sono pronti; le schermate di lavoro arrivano con l'interfaccia della milestone 3.
|
||||
Licenza: @(Licenses.Current.Kind == LicenseKind.Trial ? "prova" : Licenses.Current.Licensee) · moduli @string.Join(", ", Licenses.Current.Modules.Order())</p>
|
||||
<form method="post" action="/logout" class="links">
|
||||
<AntiforgeryToken />
|
||||
<button type="submit" class="kh-btn ghost">Esci</button>
|
||||
</form>
|
||||
<p class="build">Versione @Version.Full</p>
|
||||
</section>
|
||||
</main>
|
||||
<div class="phead">
|
||||
<div>
|
||||
<h1>@Greeting</h1>
|
||||
<div class="sub">@T.Format("Pages.Home.Today", Today)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cols cols-3 kh-home-tiles">
|
||||
<div class="tile acc">
|
||||
<div class="t"><KhIcon Name="key" Class="sm" /> @T["Pages.Home.LicenseTile"]</div>
|
||||
<div class="v">@(License.Kind == LicenseKind.Trial ? T["Pages.Home.LicenseTrial"] : T["Pages.Home.LicenseFull"])</div>
|
||||
<div class="d">@LicenseDetail</div>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<div class="t"><KhIcon Name="layers" Class="sm" /> @T["Pages.Home.ModulesTile"]</div>
|
||||
<div class="v">@T.Format("Pages.Home.ModulesText", License.Modules.Count, ModuleRegistry.Default.Modules.Count)</div>
|
||||
<div class="d">@(License.Modules.Count == 0 ? T["Pages.Home.ModulesNone"] : string.Join(" · ", License.Modules.Order(StringComparer.Ordinal)))</div>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<div class="t"><KhIcon Name="building" Class="sm" /> @T["Pages.Home.CompanyTile"]</div>
|
||||
<div class="v">@(Session.Company?.Name ?? T["Pages.Home.CompanyNone"])</div>
|
||||
<div class="d">@Session.Company?.Code</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="panel" aria-labelledby="kh-home-areas">
|
||||
<div class="ph"><KhIcon Name="grid" /> <span id="kh-home-areas">@T["Pages.Home.AreasTitle"]</span></div>
|
||||
<div class="pb">
|
||||
<p class="muted">@T["Pages.Home.AreasHint"]</p>
|
||||
<div class="kh-areas">
|
||||
@foreach (var area in Areas)
|
||||
{
|
||||
<a class="kh-area" href="@area.Href.TrimStart('/')">
|
||||
<span class="ico-box"><KhIcon Name="@area.Icon" /></span>
|
||||
<span class="grow">@T[area.Key]</span>
|
||||
@if (area.Milestone is { } milestone)
|
||||
{
|
||||
<span class="badge gray">@T.Format("Pages.Home.Coming", milestone)</span>
|
||||
}
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="callout info"><KhIcon Name="info" /> <span>@T["Pages.Home.DashboardSoon"]</span></div>
|
||||
|
||||
@code {
|
||||
private static string LevelLabel(string? level) => level switch
|
||||
private LicenseState License => Session.Licenses.Current;
|
||||
|
||||
private IEnumerable<MenuItem> Areas =>
|
||||
MenuCatalog.Sections.SelectMany(s => s.Items).Where(i => i.Href != "/" && Session.CanSee(i));
|
||||
|
||||
private string Today => Clock.GetLocalNow().ToString("dddd d MMMM yyyy", T.Culture);
|
||||
|
||||
private string Greeting
|
||||
{
|
||||
"SuperUser" => "super utente",
|
||||
"Administrator" => "amministratore",
|
||||
_ => "utente",
|
||||
};
|
||||
get
|
||||
{
|
||||
var key = Clock.GetLocalNow().Hour switch
|
||||
{
|
||||
< 13 => "Pages.Home.Greeting",
|
||||
< 18 => "Pages.Home.GreetingAfternoon",
|
||||
_ => "Pages.Home.GreetingEvening",
|
||||
};
|
||||
return T.Format(key, FirstName);
|
||||
}
|
||||
}
|
||||
|
||||
private string FirstName => Session.DisplayName.Split(' ', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? Session.DisplayName;
|
||||
|
||||
private string LicenseDetail
|
||||
{
|
||||
get
|
||||
{
|
||||
var parts = new List<string>();
|
||||
if (License.Licensee is { Length: > 0 } licensee)
|
||||
{
|
||||
parts.Add(T.Format("Pages.Home.LicenseLicensee", licensee));
|
||||
}
|
||||
|
||||
parts.Add(License.DaysLeft(Clock.GetUtcNow().UtcDateTime) is { } days
|
||||
? T.Format("Pages.Home.LicenseDaysLeft", days)
|
||||
: T["Pages.Home.LicenseUnlimited"]);
|
||||
return string.Join(" · ", parts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task OnInitializedAsync() => Session.EnsureLoadedAsync();
|
||||
}
|
||||
@@ -12,10 +12,10 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject TimeProvider Clock
|
||||
|
||||
<PageTitle>Accedi · Khaemhat</PageTitle>
|
||||
<PageTitle>@T["Auth.Login.Title"] · @T["Common.ProductName"]</PageTitle>
|
||||
|
||||
<h1>Accedi</h1>
|
||||
<p class="sub">Scegli l'azienda e inserisci le credenziali.</p>
|
||||
<h1>@T["Auth.Login.Title"]</h1>
|
||||
<p class="sub">@T["Auth.Login.Subtitle"]</p>
|
||||
|
||||
@foreach (var message in Errors)
|
||||
{
|
||||
@@ -23,24 +23,24 @@
|
||||
}
|
||||
|
||||
<EditForm Model="Input" method="post" FormName="login" OnSubmit="SubmitAsync" class="kh-form">
|
||||
<label for="company">Azienda</label>
|
||||
<label for="company">@T["Auth.Login.Company"]</label>
|
||||
<InputSelect id="company" @bind-Value="Input.CompanyCode">
|
||||
<option value="">Nessuna (account di istanza)</option>
|
||||
<option value="">@T["Auth.Login.NoCompany"]</option>
|
||||
@foreach (var company in AvailableCompanies)
|
||||
{
|
||||
<option value="@company.Code">@company.Name (@company.Code)</option>
|
||||
<option value="@company.Code">@T.Format("Auth.Login.CompanyOption", company.Name, company.Code)</option>
|
||||
}
|
||||
</InputSelect>
|
||||
|
||||
<label for="user">Nome utente</label>
|
||||
<label for="user">@T["Auth.Login.UserName"]</label>
|
||||
<InputText id="user" @bind-Value="Input.UserName" autocomplete="username" autofocus required />
|
||||
|
||||
<label for="password">Password</label>
|
||||
<label for="password">@T["Auth.Login.Password"]</label>
|
||||
<InputText id="password" type="password" @bind-Value="Input.Password" autocomplete="current-password" required />
|
||||
|
||||
<label class="check"><InputCheckbox @bind-Value="Input.Remember" /> Ricordami su questo dispositivo</label>
|
||||
<label class="check"><InputCheckbox @bind-Value="Input.Remember" /> @T["Auth.Login.Remember"]</label>
|
||||
|
||||
<button type="submit" class="kh-btn primary">Accedi</button>
|
||||
<button type="submit" class="kh-btn primary">@T["Auth.Login.Submit"]</button>
|
||||
</EditForm>
|
||||
|
||||
@if (TrialNotice is not null)
|
||||
@@ -77,11 +77,11 @@
|
||||
var license = Licenses.Current;
|
||||
if (license.Kind == LicenseKind.Trial)
|
||||
{
|
||||
TrialNotice = $"Licenza in modalità prova: restano {license.DaysLeft(Clock.GetUtcNow().UtcDateTime)} giorni, con i moduli Base e Contabilità e {license.MaxConcurrentUsers} utenti collegati.";
|
||||
TrialNotice = T.Format("Auth.Login.Trial", license.DaysLeft(Clock.GetUtcNow().UtcDateTime), license.MaxConcurrentUsers);
|
||||
}
|
||||
else if (license.Status != LicenseStatus.Valid)
|
||||
{
|
||||
TrialNotice = "La licenza è scaduta: rivolgiti all'amministratore.";
|
||||
TrialNotice = T["Auth.Login.Expired"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
Input.Password = null;
|
||||
if (!result.Succeeded || result.Cookie is null)
|
||||
{
|
||||
Errors = LoginFlow.Messages(result.Error);
|
||||
Errors = LoginFlow.Messages(T, Policy, result.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject TimeProvider Clock
|
||||
|
||||
<PageTitle>Cambio password · Khaemhat</PageTitle>
|
||||
<PageTitle>@T["Auth.PasswordChange.PageTitle"] · @T["Common.ProductName"]</PageTitle>
|
||||
|
||||
<h1>Scegli una nuova password</h1>
|
||||
<p class="sub">Al primo accesso, o dopo una password provvisoria, serve una password personale.</p>
|
||||
<h1>@T["Auth.PasswordChange.Title"]</h1>
|
||||
<p class="sub">@T["Auth.PasswordChange.Subtitle"]</p>
|
||||
|
||||
@foreach (var message in Errors)
|
||||
{
|
||||
@@ -18,22 +18,22 @@
|
||||
}
|
||||
|
||||
<EditForm Model="Input" method="post" FormName="password-change" OnSubmit="SubmitAsync" class="kh-form">
|
||||
<label for="current">Password attuale o provvisoria</label>
|
||||
<label for="current">@T["Auth.PasswordChange.Current"]</label>
|
||||
<InputText id="current" type="password" @bind-Value="Input.Current" autocomplete="current-password" autofocus required />
|
||||
|
||||
<label for="new">Nuova password</label>
|
||||
<label for="new">@T["Auth.PasswordChange.New"]</label>
|
||||
<InputText id="new" type="password" @bind-Value="Input.New" autocomplete="new-password" required />
|
||||
|
||||
<label for="confirm">Ripeti la nuova password</label>
|
||||
<label for="confirm">@T["Auth.PasswordChange.Confirm"]</label>
|
||||
<InputText id="confirm" type="password" @bind-Value="Input.Confirm" autocomplete="new-password" required />
|
||||
|
||||
<ul class="kh-rules">
|
||||
<li>Almeno @Policy.MinimumLength caratteri</li>
|
||||
<li>Almeno tre tipi tra minuscole, maiuscole, cifre e simboli</li>
|
||||
<li>Diversa dal nome utente e dalle ultime @Policy.HistorySize password</li>
|
||||
<li>@T.Format("Auth.PasswordChange.RuleLength", Policy.MinimumLength)</li>
|
||||
<li>@T["Auth.PasswordChange.RuleKinds"]</li>
|
||||
<li>@T.Format("Auth.PasswordChange.RuleHistory", Policy.HistorySize)</li>
|
||||
</ul>
|
||||
|
||||
<button type="submit" class="kh-btn primary">Salva e continua</button>
|
||||
<button type="submit" class="kh-btn primary">@T["Auth.PasswordChange.Submit"]</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
if (!string.Equals(Input.New, Input.Confirm, StringComparison.Ordinal))
|
||||
{
|
||||
Errors = ["Le due nuove password non coincidono."];
|
||||
Errors = [T["Auth.PasswordChange.Mismatch"]];
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
@@ -79,7 +79,7 @@
|
||||
Clear();
|
||||
if (!result.Succeeded || result.Cookie is null)
|
||||
{
|
||||
Errors = LoginFlow.Messages(result.Error);
|
||||
Errors = LoginFlow.Messages(T, Policy, result.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject TimeProvider Clock
|
||||
|
||||
<PageTitle>Verifica in due passaggi · Khaemhat</PageTitle>
|
||||
<PageTitle>@T["Auth.Totp.Title"] · @T["Common.ProductName"]</PageTitle>
|
||||
|
||||
<h1>Verifica in due passaggi</h1>
|
||||
<p class="sub">Inserisci il codice a 6 cifre dell'app di autenticazione.</p>
|
||||
<h1>@T["Auth.Totp.Title"]</h1>
|
||||
<p class="sub">@T["Auth.Totp.Subtitle"]</p>
|
||||
|
||||
@foreach (var message in Errors)
|
||||
{
|
||||
@@ -18,15 +18,15 @@
|
||||
}
|
||||
|
||||
<EditForm Model="Input" method="post" FormName="totp" OnSubmit="SubmitAsync" class="kh-form">
|
||||
<label for="code">Codice</label>
|
||||
<label for="code">@T["Auth.Totp.Code"]</label>
|
||||
<InputText id="code" class="otp" @bind-Value="Input.Code" inputmode="numeric" autocomplete="one-time-code" maxlength="20" autofocus required />
|
||||
<div class="row">
|
||||
<button type="submit" class="kh-btn primary">Verifica</button>
|
||||
<span class="hint">Oppure un codice di recupero (XXXX-XXXX)</span>
|
||||
<button type="submit" class="kh-btn primary">@T["Auth.Totp.Submit"]</button>
|
||||
<span class="hint">@T["Auth.Totp.RecoveryHint"]</span>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<div class="kh-alert info">Il codice cambia ogni 30 secondi. L'autenticazione a due fattori è obbligatoria per amministratori e super utente.</div>
|
||||
<div class="kh-alert info">@T["Auth.Totp.Info"]</div>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
@@ -64,7 +64,7 @@
|
||||
Input.Code = null;
|
||||
if (!result.Succeeded || result.Cookie is null)
|
||||
{
|
||||
Errors = LoginFlow.Messages(result.Error);
|
||||
Errors = LoginFlow.Messages(T, Policy, result.Error);
|
||||
if (result.Error == SecurityErrors.AccountLocked)
|
||||
{
|
||||
SessionCookie.Clear(HttpContext);
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject TimeProvider Clock
|
||||
|
||||
<PageTitle>Configura la verifica in due passaggi · Khaemhat</PageTitle>
|
||||
<PageTitle>@T["Auth.TotpSetup.PageTitle"] · @T["Common.ProductName"]</PageTitle>
|
||||
|
||||
@if (RecoveryCodes is not null)
|
||||
{
|
||||
<h1>Codici di recupero</h1>
|
||||
<p class="sub">Conservali in un luogo sicuro: ognuno vale una volta sola, al posto del codice dell'app, se perdi il telefono. Non verranno mostrati di nuovo.</p>
|
||||
<h1>@T["Auth.TotpSetup.RecoveryTitle"]</h1>
|
||||
<p class="sub">@T["Auth.TotpSetup.RecoveryText"]</p>
|
||||
<ul class="kh-codes">
|
||||
@foreach (var recovery in RecoveryCodes)
|
||||
{
|
||||
<li><code>@recovery</code></li>
|
||||
}
|
||||
</ul>
|
||||
<a class="kh-btn primary" href="@NextUrl">Ho salvato i codici, continua</a>
|
||||
<a class="kh-btn primary" href="@NextUrl">@T["Auth.TotpSetup.RecoveryDone"]</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h1>Configura la verifica in due passaggi</h1>
|
||||
<p class="sub">Aggiungi l'account a un'app di autenticazione (Google Authenticator, Microsoft Authenticator, Aegis, 2FAS...) e inserisci il primo codice.</p>
|
||||
<h1>@T["Auth.TotpSetup.Title"]</h1>
|
||||
<p class="sub">@T["Auth.TotpSetup.Subtitle"]</p>
|
||||
|
||||
@foreach (var message in Errors)
|
||||
{
|
||||
@@ -34,17 +34,17 @@ else
|
||||
@if (Setup is not null)
|
||||
{
|
||||
<dl class="kh-secret">
|
||||
<dt>Chiave da inserire nell'app</dt>
|
||||
<dt>@T["Auth.TotpSetup.Secret"]</dt>
|
||||
<dd><code>@Grouped(Setup.Secret)</code></dd>
|
||||
<dt>Sul telefono</dt>
|
||||
<dd><a href="@Setup.ProvisioningUri">Apri nell'app di autenticazione</a></dd>
|
||||
<dt>@T["Auth.TotpSetup.Phone"]</dt>
|
||||
<dd><a href="@Setup.ProvisioningUri">@T["Auth.TotpSetup.OpenInApp"]</a></dd>
|
||||
</dl>
|
||||
}
|
||||
|
||||
<EditForm Model="Input" method="post" FormName="totp-setup" OnSubmit="SubmitAsync" class="kh-form">
|
||||
<label for="code">Primo codice dell'app</label>
|
||||
<label for="code">@T["Auth.TotpSetup.FirstCode"]</label>
|
||||
<InputText id="code" class="otp" @bind-Value="Input.Code" inputmode="numeric" autocomplete="one-time-code" maxlength="6" autofocus required />
|
||||
<button type="submit" class="kh-btn primary">Attiva</button>
|
||||
<button type="submit" class="kh-btn primary">@T["Auth.TotpSetup.Submit"]</button>
|
||||
</EditForm>
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ else
|
||||
Input.Code = null;
|
||||
if (!result.Succeeded || result.Cookie is null || codes is null)
|
||||
{
|
||||
Errors = LoginFlow.Messages(result.Error);
|
||||
Errors = LoginFlow.Messages(T, Policy, result.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
@page "/not-found"
|
||||
@layout MainLayout
|
||||
<KhPageTitle Text="@T["Pages.NotFound.PageTitle"]" />
|
||||
|
||||
<PageTitle>Khaemhat · pagina non trovata</PageTitle>
|
||||
|
||||
<main class="kh-construction">
|
||||
<section class="hero">
|
||||
<h1>Pagina non trovata</h1>
|
||||
<p class="lead">L'indirizzo richiesto non esiste.</p>
|
||||
<ul class="links"><li><a href="/">Torna alla pagina iniziale</a></li></ul>
|
||||
</section>
|
||||
</main>
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="search" Class="lg" />
|
||||
<h1>@T["Pages.NotFound.Title"]</h1>
|
||||
<p class="lead">@T["Pages.NotFound.Lead"]</p>
|
||||
<a class="btn" href="./">@T["Common.BackHome"]</a>
|
||||
</div>
|
||||
@@ -0,0 +1,393 @@
|
||||
@page "/profilo"
|
||||
@attribute [Authorize]
|
||||
@using System.Globalization
|
||||
@using Khaemhat.Application.Preferences
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Web.Security
|
||||
@implements IAsyncDisposable
|
||||
@inject ShellSession Session
|
||||
@inject ThemeService Theme
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject SessionStore Sessions
|
||||
@inject AuthenticationStateProvider Authentication
|
||||
|
||||
@* "Il mio profilo" (SPEC §10.6, §11.12, mockup 008). Every change is shown at once on the page (preview) and kept only
|
||||
with Save; leaving the page without saving puts the saved preferences back. *@
|
||||
<KhPageTitle Text="@T["Pages.Profile.Title"]" Icon="user" />
|
||||
|
||||
<div class="phead">
|
||||
<div>
|
||||
<h1>@T["Pages.Profile.Title"]</h1>
|
||||
<div class="sub">@T["Pages.Profile.Subtitle"]</div>
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
@if (_section is AppearanceSection or StartSection)
|
||||
{
|
||||
<div class="toolbar">
|
||||
<button type="button" class="btn ghost" @onclick="DefaultsAsync">@T["Pages.Profile.Defaults"]</button>
|
||||
<button type="button" class="btn" disabled="@(!IsModified)" @onclick="UndoAsync"><KhIcon Name="undo" /> @T["Pages.Profile.Undo"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(!IsModified)" @onclick="SaveAsync"><KhIcon Name="save" /> @T["Pages.Profile.Save"]</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<section class="panel">
|
||||
<div class="tabs i" role="tablist">
|
||||
@foreach (var (id, icon, key) in Sections)
|
||||
{
|
||||
<a class="tab @(id == _section ? "active" : null)" role="tab" aria-selected="@(id == _section)" href="@("profilo?scheda=" + id)">
|
||||
<KhIcon Name="@icon" /> @T[key]
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
@switch (_section)
|
||||
{
|
||||
case AppearanceSection:
|
||||
<div class="fgroups">
|
||||
<fieldset class="fgroup wide">
|
||||
<legend class="fgh"><KhIcon Name="contrast" /> @T["Pages.Profile.Theme"]</legend>
|
||||
<div class="kh-choices">
|
||||
@foreach (var theme in Enum.GetValues<ThemeMode>())
|
||||
{
|
||||
<button type="button" class="themecard @(Draft.Theme == theme ? "on" : null)" aria-pressed="@(Draft.Theme == theme)"
|
||||
@onclick="() => ChangeAsync(Draft with { Theme = theme })">
|
||||
<span class="pv kh-pv-@UserPreferences.ThemeName(theme)" aria-hidden="true">
|
||||
<span class="tb"></span><span class="sb"></span>
|
||||
<span class="ct"><i></i><i></i><i></i></span>
|
||||
</span>
|
||||
<span class="lbl">
|
||||
@if (Draft.Theme == theme)
|
||||
{
|
||||
<KhIcon Name="check-circle" Class="sm" />
|
||||
}
|
||||
@T["Pages.Profile.Theme." + theme]
|
||||
@if (theme == ThemeMode.Auto)
|
||||
{
|
||||
<span class="muted">@T["Pages.Profile.Theme.AutoHint"]</span>
|
||||
}
|
||||
</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="fgroup wide">
|
||||
<legend class="fgh"><KhIcon Name="palette" /> @T["Pages.Profile.Accent"]</legend>
|
||||
<div class="swatches kh-choices">
|
||||
@foreach (var accent in UserPreferences.Accents)
|
||||
{
|
||||
<button type="button" class="sw @(Draft.Accent == accent ? "on" : null)" aria-pressed="@(Draft.Accent == accent)"
|
||||
@onclick="() => ChangeAsync(Draft with { Accent = accent })">
|
||||
<span class="c kh-acc-@accent" aria-hidden="true"><i></i></span>
|
||||
<span class="n">
|
||||
@if (Draft.Accent == accent)
|
||||
{
|
||||
<KhIcon Name="check" Class="sm" />
|
||||
}
|
||||
@T["Pages.Profile.Accent." + accent]
|
||||
</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="fgroup">
|
||||
<legend class="fgh"><KhIcon Name="columns" /> @T["Pages.Profile.Density"]</legend>
|
||||
<div class="kh-seg" role="radiogroup" aria-label="@T["Pages.Profile.Density"]">
|
||||
@foreach (var density in Enum.GetValues<Density>())
|
||||
{
|
||||
<button type="button" role="radio" class="@(Draft.Density == density ? "on" : null)" aria-checked="@(Draft.Density == density)"
|
||||
@onclick="() => ChangeAsync(Draft with { Density = density })">@T["Pages.Profile.Density." + density]</button>
|
||||
}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="fgroup">
|
||||
<legend class="fgh"><KhIcon Name="edit" /> @T["Pages.Profile.TextSize"]</legend>
|
||||
<div class="kh-seg" role="radiogroup" aria-label="@T["Pages.Profile.TextSize"]">
|
||||
@foreach (var size in UserPreferences.TextSizes)
|
||||
{
|
||||
<button type="button" role="radio" class="@(Draft.TextSize == size ? "on" : null)" aria-checked="@(Draft.TextSize == size)"
|
||||
@onclick="() => ChangeAsync(Draft with { TextSize = size })">@T.Format("Pages.Profile.TextSize.Value", size)</button>
|
||||
}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="fgroup">
|
||||
<legend class="fgh"><KhIcon Name="sidebar" /> @T["Pages.Profile.Menu"]</legend>
|
||||
<div class="kh-seg" role="radiogroup" aria-label="@T["Pages.Profile.Menu"]">
|
||||
@foreach (var (value, key) in MenuChoices)
|
||||
{
|
||||
<button type="button" role="radio" class="@(Draft.MenuCollapsed == value ? "on" : null)" aria-checked="@(Draft.MenuCollapsed == value)"
|
||||
@onclick="() => ChangeAsync(Draft with { MenuCollapsed = value })">@T[key]</button>
|
||||
}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="fgroup wide">
|
||||
<legend class="fgh"><KhIcon Name="settings" /> @T["Pages.Profile.Options"]</legend>
|
||||
<div class="kh-switches">
|
||||
<KhSwitchRow Label="@T["Pages.Profile.Options.TabularNumbers"]" Hint="@T["Pages.Profile.Options.TabularNumbersHint"]"
|
||||
Value="Draft.TabularNumbers" ValueChanged="v => ChangeAsync(Draft with { TabularNumbers = v })" />
|
||||
<KhSwitchRow Label="@T["Pages.Profile.Options.ReducedMotion"]" Hint="@T["Pages.Profile.Options.ReducedMotionHint"]"
|
||||
Value="Draft.ReducedMotion" ValueChanged="v => ChangeAsync(Draft with { ReducedMotion = v })" />
|
||||
<KhSwitchRow Label="@T["Pages.Profile.Options.Tooltips"]" Hint="@T["Pages.Profile.Options.TooltipsHint"]"
|
||||
Value="Draft.Tooltips" ValueChanged="v => ChangeAsync(Draft with { Tooltips = v })" />
|
||||
<KhSwitchRow Label="@T["Pages.Profile.Options.RowHover"]" Hint="@T["Pages.Profile.Options.RowHoverHint"]"
|
||||
Value="Draft.RowHover" ValueChanged="v => ChangeAsync(Draft with { RowHover = v })" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="callout info kh-inset"><KhIcon Name="info" /> <span>@T["Pages.Profile.Preview"]</span></div>
|
||||
break;
|
||||
|
||||
case StartSection:
|
||||
<div class="fgroups">
|
||||
<fieldset class="fgroup wide">
|
||||
<legend class="fgh"><KhIcon Name="home" /> @T["Pages.Profile.Start"]</legend>
|
||||
<div class="kh-radios" role="radiogroup" aria-label="@T["Pages.Profile.Start"]">
|
||||
@foreach (var start in Enum.GetValues<StartPage>())
|
||||
{
|
||||
<label class="chk">
|
||||
<input type="radio" name="kh-start" checked="@(Draft.StartPage == start)"
|
||||
@onchange="() => ChangeAsync(Draft with { StartPage = start })" />
|
||||
@T["Pages.Profile.Start." + start]
|
||||
</label>
|
||||
}
|
||||
</div>
|
||||
@if (Draft.StartPage == StartPage.Page)
|
||||
{
|
||||
<div class="f kh-pick">
|
||||
<label for="kh-start-path">@T["Pages.Profile.Start.PagePick"]</label>
|
||||
<select id="kh-start-path" class="kh-input" value="@Draft.StartPath"
|
||||
@onchange="e => ChangeAsync(Draft with { StartPath = e.Value as string })">
|
||||
@foreach (var item in StartChoices)
|
||||
{
|
||||
<option value="@item.Href">@T[item.Key]</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
<KhSwitchRow Label="@T["Pages.Profile.Start.ShowDashboard"]" Value="Draft.ShowDashboard"
|
||||
ValueChanged="v => ChangeAsync(Draft with { ShowDashboard = v })" />
|
||||
</fieldset>
|
||||
</div>
|
||||
break;
|
||||
|
||||
case SessionsSection:
|
||||
<div class="pb">
|
||||
<p class="muted">@T["Pages.Profile.Sessions.Intro"]</p>
|
||||
<table class="kh-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Pages.Profile.Sessions.Device"]</th>
|
||||
<th scope="col">@T["Pages.Profile.Sessions.Address"]</th>
|
||||
<th scope="col">@T["Pages.Profile.Sessions.Company"]</th>
|
||||
<th scope="col">@T["Pages.Profile.Sessions.SignedIn"]</th>
|
||||
<th scope="col">@T["Pages.Profile.Sessions.LastSeen"]</th>
|
||||
<th scope="col"><span class="sr-only">@T["Pages.Profile.Sessions.Revoke"]</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in _sessions)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<KhIcon Name="monitor" Class="sm" /> @DeviceOf(item.UserAgent)
|
||||
@if (item.Id == _currentSessionId)
|
||||
{
|
||||
<span class="badge green">@T["Pages.Profile.Sessions.Current"]</span>
|
||||
}
|
||||
</td>
|
||||
<td class="mono">@item.IpAddress</td>
|
||||
<td>@(item.CompanyCode ?? T["Pages.Profile.Sessions.InstanceAccount"])</td>
|
||||
<td class="kh-nowrap">@T.DateTime(item.CreatedAt, TimeZoneInfo.Local)</td>
|
||||
<td class="kh-nowrap">@T.DateTime(item.LastSeenAt, TimeZoneInfo.Local)</td>
|
||||
<td>
|
||||
@if (item.Id != _currentSessionId)
|
||||
{
|
||||
<button type="button" class="btn danger" @onclick="() => RevokeAsync(item)"><KhIcon Name="logout" /> @T["Pages.Profile.Sessions.Revoke"]</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@if (_sessions.Any(s => s.Id != _currentSessionId))
|
||||
{
|
||||
<div><button type="button" class="btn danger" @onclick="RevokeOthersAsync"><KhIcon Name="logout" /> @T["Pages.Profile.Sessions.RevokeOthers"]</button></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="muted">@T["Pages.Profile.Sessions.None"]</p>
|
||||
}
|
||||
</div>
|
||||
break;
|
||||
|
||||
default:
|
||||
<div class="pb">
|
||||
@foreach (var scope in Enum.GetValues<ShortcutScope>())
|
||||
{
|
||||
<h2 class="kh-h2">@T["Pages.Profile.Shortcuts." + scope]</h2>
|
||||
<table class="kh-table">
|
||||
<thead><tr><th scope="col">@T["Pages.Profile.Shortcuts.Keys"]</th><th scope="col">@T["Pages.Profile.Shortcuts.Action"]</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var shortcut in KeyboardShortcuts.All.Where(s => s.Scope == scope))
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@foreach (var keys in shortcut.Keys)
|
||||
{
|
||||
<kbd>@keys</kbd>
|
||||
}
|
||||
</td>
|
||||
<td>@T[shortcut.TextKey]</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
<p class="muted">@T["Pages.Profile.Shortcuts.BrowserNote"]</p>
|
||||
</div>
|
||||
break;
|
||||
}
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private const string AppearanceSection = "aspetto";
|
||||
private const string StartSection = "pagina-iniziale";
|
||||
private const string ShortcutsSection = "scorciatoie";
|
||||
private const string SessionsSection = "sessioni";
|
||||
|
||||
private static readonly (string Id, string Icon, string Key)[] Sections =
|
||||
[
|
||||
(AppearanceSection, "palette", "Pages.Profile.Tabs.Appearance"),
|
||||
(StartSection, "home", "Pages.Profile.Tabs.Start"),
|
||||
(SessionsSection, "monitor", "Pages.Profile.Tabs.Sessions"),
|
||||
(ShortcutsSection, "keyboard", "Pages.Profile.Tabs.Shortcuts"),
|
||||
];
|
||||
|
||||
private static readonly (bool? Value, string Key)[] MenuChoices =
|
||||
[
|
||||
(null, "Pages.Profile.Menu.Auto"),
|
||||
(false, "Pages.Profile.Menu.Expanded"),
|
||||
(true, "Pages.Profile.Menu.Collapsed"),
|
||||
];
|
||||
|
||||
private string _section = AppearanceSection;
|
||||
private IReadOnlyList<SessionSummary> _sessions = [];
|
||||
private SessionOwner? _owner;
|
||||
private long _currentSessionId;
|
||||
|
||||
/// <summary>The section: <c>aspetto</c>, <c>pagina-iniziale</c>, <c>sessioni</c>, <c>scorciatoie</c>.</summary>
|
||||
[SupplyParameterFromQuery(Name = "scheda")]
|
||||
public string? Section { get; set; }
|
||||
|
||||
/// <summary>The tab of the page, to show the modified mark.</summary>
|
||||
[CascadingParameter]
|
||||
public KhTab? Tab { get; set; }
|
||||
|
||||
private UserPreferences Draft { get; set; } = UserPreferences.Default;
|
||||
|
||||
private bool IsModified => Draft != Session.Preferences;
|
||||
|
||||
private IEnumerable<MenuItem> StartChoices => MenuCatalog.All.Where(i => i.Milestone is null && Session.CanSee(i));
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
Draft = Session.Preferences;
|
||||
var user = (await Authentication.GetAuthenticationStateAsync()).User;
|
||||
_owner = SessionCookie.OwnerOf(user);
|
||||
_ = long.TryParse(user.FindFirst(SessionCookie.SessionIdClaim)?.Value, NumberStyles.None, CultureInfo.InvariantCulture, out _currentSessionId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_section = Sections.Any(s => s.Id == Section) ? Section! : AppearanceSection;
|
||||
if (_section == SessionsSection)
|
||||
{
|
||||
await LoadSessionsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadSessionsAsync() =>
|
||||
_sessions = _owner is null ? [] : await Sessions.ListAsync(_owner);
|
||||
|
||||
private async Task RevokeAsync(SessionSummary item)
|
||||
{
|
||||
if (_owner is null || !await Dialogs.ConfirmAsync(new(T["Pages.Profile.Sessions.RevokeTitle"], T["Pages.Profile.Sessions.RevokeText"],
|
||||
T["Pages.Profile.Sessions.Revoke"], T["Common.Cancel"], Danger: true)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Sessions.RevokeAsync(_owner, item.Id, "user");
|
||||
Toasts.Show(ToastKind.Success, T["Pages.Profile.Sessions.Revoked"]);
|
||||
await LoadSessionsAsync();
|
||||
}
|
||||
|
||||
private async Task RevokeOthersAsync()
|
||||
{
|
||||
if (_owner is null || !await Dialogs.ConfirmAsync(new(T["Pages.Profile.Sessions.RevokeTitle"], T["Pages.Profile.Sessions.RevokeOthersText"],
|
||||
T["Pages.Profile.Sessions.RevokeOthers"], T["Common.Cancel"], Danger: true)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var count = await Sessions.RevokeAllAsync(_owner, "user", _currentSessionId);
|
||||
Toasts.Show(ToastKind.Success, T.Format("Pages.Profile.Sessions.RevokedMany", count));
|
||||
await LoadSessionsAsync();
|
||||
}
|
||||
|
||||
// A short name of the browser and system from the user agent: enough to recognise a device, not a full parser.
|
||||
private static readonly (string Marker, string Name)[] Browsers = [("Edg/", "Edge"), ("OPR/", "Opera"), ("Firefox/", "Firefox"), ("Chrome/", "Chrome"), ("Safari/", "Safari")];
|
||||
private static readonly string[] Systems = ["Windows", "Android", "iPhone", "iPad", "Mac OS", "Linux"];
|
||||
|
||||
private string DeviceOf(string? userAgent)
|
||||
{
|
||||
var browser = userAgent is null ? null : Browsers.FirstOrDefault(b => userAgent.Contains(b.Marker, StringComparison.Ordinal)).Name;
|
||||
var system = userAgent is null ? null : Systems.FirstOrDefault(s => userAgent.Contains(s, StringComparison.Ordinal));
|
||||
return browser is null && system is null
|
||||
? T["Pages.Profile.Sessions.Unknown"]
|
||||
: string.Join(" · ", new[] { browser, system }.Where(x => x is not null));
|
||||
}
|
||||
|
||||
private async Task ChangeAsync(UserPreferences next)
|
||||
{
|
||||
if (next.StartPage == StartPage.Page && !UserPreferences.IsLocalPath(next.StartPath))
|
||||
{
|
||||
next = next with { StartPath = StartChoices.FirstOrDefault()?.Href ?? "/" };
|
||||
}
|
||||
|
||||
Draft = next;
|
||||
Tab?.SetModified(IsModified);
|
||||
await Theme.PreviewAsync(Draft);
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
await Theme.ApplyAsync(Draft);
|
||||
Draft = Session.Preferences;
|
||||
Tab?.SetModified(false);
|
||||
Toasts.Show(ToastKind.Success, T["Pages.Profile.Saved"], T["Pages.Profile.SavedText"]);
|
||||
}
|
||||
|
||||
private Task UndoAsync() => ChangeAsync(Session.Preferences);
|
||||
|
||||
private Task DefaultsAsync() => ChangeAsync(UserPreferences.Default);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
// Closing the tab without saving: the page goes back to the saved look.
|
||||
if (IsModified)
|
||||
{
|
||||
await Theme.PreviewAsync(Session.Preferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
|
||||
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)">
|
||||
<NotAuthorized>
|
||||
<RedirectToLogin />
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
@* The layout keeps a page alive for each tab, so it needs the page and its parameters, not only the body. *@
|
||||
<CascadingValue Value="routeData">
|
||||
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)">
|
||||
<NotAuthorized>
|
||||
<RedirectToLogin />
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
</CascadingValue>
|
||||
<FocusOnNavigate RouteData="routeData" Selector="h1" />
|
||||
</Found>
|
||||
</Router>
|
||||
@@ -0,0 +1,46 @@
|
||||
@inject ShellSession Session
|
||||
|
||||
@* The company of the session (SPEC §10.2). Instance accounts choose it from the list: the choice is posted to
|
||||
/session/company, which updates the session and reloads the application in the new company. *@
|
||||
@if (Session.SwitchableCompanies.Count > 0)
|
||||
{
|
||||
<div class="pop">
|
||||
<button type="button" class="company" aria-haspopup="menu" aria-expanded="@Open" @onclick="() => OpenChanged.InvokeAsync(!Open)">
|
||||
<KhIcon Name="building" />
|
||||
<span>@(Session.Company?.Name ?? T["Shell.Company.None"])</span>
|
||||
<KhIcon Name="chevron-down" Class="sm" />
|
||||
</button>
|
||||
@if (Open)
|
||||
{
|
||||
<div class="popmenu left" role="menu">
|
||||
<div class="fh">@T["Shell.Company.Switch"]</div>
|
||||
@foreach (var company in Session.SwitchableCompanies)
|
||||
{
|
||||
<form method="post" action="session/company">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="code" value="@company.Code" />
|
||||
<button type="submit" role="menuitem" class="mi @(company.Code == Session.Company?.Code ? "on" : null)">
|
||||
<KhIcon Name="building" />
|
||||
<span class="grow">@company.Name</span>
|
||||
<span class="k">@company.Code</span>
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else if (Session.Company is { } company)
|
||||
{
|
||||
<div class="company" title="@company.Code"><KhIcon Name="building" /><span>@company.Name</span></div>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>Whether the list is open.</summary>
|
||||
[Parameter]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>Opens or closes the list.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<bool> OpenChanged { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
@inject ShellSession Session
|
||||
@inject NavigationManager Navigation
|
||||
@inject ThemeService Theme
|
||||
|
||||
@* The global search of SPEC §10.2 (Ctrl+K, mockup 009). Today it finds pages of the menu and commands (prefix >);
|
||||
records (parties, items, documents with #, people with @) join as their modules arrive, through
|
||||
GlobalSearchService. Arrows move, Enter opens, Escape closes. *@
|
||||
@if (Open)
|
||||
{
|
||||
<div class="overlay" @onclick="CloseAsync">
|
||||
<div class="dialog palette" role="dialog" aria-modal="true" aria-label="@T["Shell.Search.Title"]" @onclick:stopPropagation="true">
|
||||
<div class="pin">
|
||||
<KhIcon Name="search" Class="lg" />
|
||||
<input @ref="_input" class="palette-input" type="search" placeholder="@T["Shell.Search.Placeholder"]" aria-label="@T["Shell.Search.Title"]"
|
||||
aria-controls="kh-palette-hits" aria-activedescendant="@(Hits.Count > 0 ? "kh-hit-" + _selected : null)"
|
||||
value="@_query" @oninput="OnInput" @onkeydown="OnKeyDownAsync" autocomplete="off" />
|
||||
<span class="kbdhint"><kbd>@T["Shell.Keys.Escape"]</kbd></span>
|
||||
</div>
|
||||
<div id="kh-palette-hits" role="listbox" class="hits">
|
||||
@if (Hits.Count == 0)
|
||||
{
|
||||
<div class="grp">@T["Shell.Search.NoResults"]</div>
|
||||
}
|
||||
@{
|
||||
string? group = null;
|
||||
var index = 0;
|
||||
}
|
||||
@foreach (var hit in Hits)
|
||||
{
|
||||
if (hit.Group != group)
|
||||
{
|
||||
group = hit.Group;
|
||||
<div class="grp">@T[group]</div>
|
||||
}
|
||||
|
||||
var i = index++;
|
||||
<button type="button" id="@("kh-hit-" + i)" role="option" aria-selected="@(i == _selected)" class="hit @(i == _selected ? "on" : null)"
|
||||
@onclick="() => RunAsync(hit)" @onmouseover="() => _selected = i">
|
||||
<KhIcon Name="@hit.Icon" />
|
||||
<span>@hit.Title</span>
|
||||
@if (hit.Hint is not null)
|
||||
{
|
||||
<span class="k">@hit.Hint</span>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<div class="df palette-foot">
|
||||
<span class="kbdhint"><kbd>↑</kbd><kbd>↓</kbd> @T["Shell.Search.Move"]</span>
|
||||
<span class="kbdhint"><kbd>↵</kbd> @T["Shell.Search.Open"]</span>
|
||||
<span class="kbdhint"><kbd>></kbd> @T["Shell.Search.Commands"]</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private sealed record Hit(string Group, string Icon, string Title, string? Hint, Func<Task> Run);
|
||||
|
||||
private ElementReference _input;
|
||||
private string _query = string.Empty;
|
||||
private int _selected;
|
||||
private bool _focus;
|
||||
|
||||
/// <summary>Whether the search is open.</summary>
|
||||
[Parameter]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>Opens or closes it.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<bool> OpenChanged { get; set; }
|
||||
|
||||
/// <summary>Collapses or expands the menu (command).</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnToggleMenu { get; set; }
|
||||
|
||||
private List<Hit> Hits { get; set; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (Open && !_focus && Hits.Count == 0)
|
||||
{
|
||||
_query = string.Empty;
|
||||
_selected = 0;
|
||||
_focus = true;
|
||||
Hits = Search(_query);
|
||||
}
|
||||
else if (!Open)
|
||||
{
|
||||
Hits = [];
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (_focus && Open)
|
||||
{
|
||||
_focus = false;
|
||||
await _input.FocusAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInput(ChangeEventArgs e)
|
||||
{
|
||||
_query = e.Value?.ToString() ?? string.Empty;
|
||||
_selected = 0;
|
||||
Hits = Search(_query);
|
||||
}
|
||||
|
||||
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
||||
{
|
||||
switch (e.Key)
|
||||
{
|
||||
case "ArrowDown":
|
||||
_selected = Hits.Count == 0 ? 0 : (_selected + 1) % Hits.Count;
|
||||
break;
|
||||
case "ArrowUp":
|
||||
_selected = Hits.Count == 0 ? 0 : (_selected - 1 + Hits.Count) % Hits.Count;
|
||||
break;
|
||||
case "Enter" when Hits.Count > 0:
|
||||
await RunAsync(Hits[Math.Min(_selected, Hits.Count - 1)]);
|
||||
break;
|
||||
case "Escape":
|
||||
await CloseAsync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAsync(Hit hit)
|
||||
{
|
||||
await CloseAsync();
|
||||
await hit.Run();
|
||||
}
|
||||
|
||||
private Task CloseAsync()
|
||||
{
|
||||
Hits = [];
|
||||
return OpenChanged.InvokeAsync(false);
|
||||
}
|
||||
|
||||
private List<Hit> Search(string query)
|
||||
{
|
||||
var text = query.Trim();
|
||||
var commandsOnly = text.StartsWith('>');
|
||||
if (commandsOnly)
|
||||
{
|
||||
text = text[1..].Trim();
|
||||
}
|
||||
|
||||
var hits = new List<Hit>();
|
||||
if (!commandsOnly)
|
||||
{
|
||||
foreach (var item in MenuCatalog.All.Where(Session.CanSee))
|
||||
{
|
||||
var title = T[item.Key];
|
||||
var area = MenuCatalog.FindArea(item.Href);
|
||||
var label = area is not null && area != item ? T[area.Key] + " · " + title : title;
|
||||
if (Matches(label, text))
|
||||
{
|
||||
hits.Add(new Hit("Shell.Search.Pages", item.Icon, label, null, () => Go(item.Href)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var command in Commands())
|
||||
{
|
||||
if (Matches(command.Title, text))
|
||||
{
|
||||
hits.Add(command);
|
||||
}
|
||||
}
|
||||
|
||||
return [.. hits.Take(30)];
|
||||
}
|
||||
|
||||
private IEnumerable<Hit> Commands()
|
||||
{
|
||||
yield return new Hit("Shell.Search.CommandsGroup", "moon", T["Shell.Commands.ToggleTheme"], null, () => Theme.ToggleDarkAsync());
|
||||
yield return new Hit("Shell.Search.CommandsGroup", "sidebar", T["Shell.Commands.ToggleMenu"], KeyboardShortcuts.KeysOf(KeyboardShortcuts.Commands.ToggleMenu),
|
||||
() => OnToggleMenu.InvokeAsync());
|
||||
yield return new Hit("Shell.Search.CommandsGroup", "palette", T["Shell.Commands.Appearance"], null, () => Go("/profilo?scheda=aspetto"));
|
||||
yield return new Hit("Shell.Search.CommandsGroup", "user", T["Shell.Commands.Profile"], null, () => Go("/profilo"));
|
||||
yield return new Hit("Shell.Search.CommandsGroup", "monitor", T["Shell.User.Sessions"], null, () => Go("/profilo?scheda=sessioni"));
|
||||
yield return new Hit("Shell.Search.CommandsGroup", "keyboard", T["Shell.Commands.Shortcuts"], null, () => Go("/profilo?scheda=scorciatoie"));
|
||||
}
|
||||
|
||||
private Task Go(string href)
|
||||
{
|
||||
Navigation.NavigateTo(href.TrimStart('/'));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static bool Matches(string title, string text) =>
|
||||
text.Length == 0 || text.Split(' ', StringSplitOptions.RemoveEmptyEntries).All(word => title.Contains(word, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
@using Khaemhat.Core.Common
|
||||
@implements IDisposable
|
||||
@inject ShellSession Session
|
||||
@inject NavigationManager Navigation
|
||||
@inject ProductVersion Version
|
||||
|
||||
@* The side menu of SPEC §10.2 (mockups 004, 007, 013). Expanded: icon and text, sub-entries of the active module.
|
||||
Collapsed to 60 px: icons only, the name as tooltip, sub-entries in a pop-up on hover or keyboard focus. *@
|
||||
<nav class="sidebar" aria-label="@T["Shell.Menu.Label"]">
|
||||
<div class="navscroll">
|
||||
@foreach (var section in Sections)
|
||||
{
|
||||
<div class="sec">@T[section.Key]</div>
|
||||
<div class="nav">
|
||||
@foreach (var item in section.Items)
|
||||
{
|
||||
var active = item == _activeArea;
|
||||
var children = item.Children.Where(Session.CanSee).ToList();
|
||||
<div class="item">
|
||||
<a href="@Href(item)" class="@(active ? "active" : null)" aria-current="@(active && _path == item.Href ? "page" : null)"
|
||||
title="@(Collapsed ? T[item.Key] : null)">
|
||||
<KhIcon Name="@item.Icon" />
|
||||
<span>@T[item.Key]</span>
|
||||
</a>
|
||||
@if (Collapsed && children.Count > 0)
|
||||
{
|
||||
<div class="flyout" role="group" aria-label="@T[item.Key]">
|
||||
<div class="fh">@T[item.Key]</div>
|
||||
@foreach (var child in children)
|
||||
{
|
||||
<a class="fi @(child == _activeItem ? "on" : null)" href="@Href(child)">@T[child.Key]</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (active && !Collapsed && children.Count > 0)
|
||||
{
|
||||
<div class="nav sub">
|
||||
@foreach (var child in children)
|
||||
{
|
||||
<a href="@Href(child)" class="@(child == _activeItem ? "active" : null)" aria-current="@(child == _activeItem ? "page" : null)">
|
||||
<span>@T[child.Key]</span>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<button type="button" class="toggle" aria-expanded="@(!Collapsed)" aria-keyshortcuts="Control+B" @onclick="OnToggle"
|
||||
title="@(Collapsed ? ExpandLabel : null)">
|
||||
<KhIcon Name="@(Collapsed ? "chevron-right" : "chevron-left")" />
|
||||
<span>@(Collapsed ? ExpandLabel : T["Shell.Menu.Collapse"])</span>
|
||||
</button>
|
||||
<div class="foot">
|
||||
@T.Format("Shell.Menu.Footer", Version.Version)<br />
|
||||
@T.Format("Shell.Menu.FiscalYear", DateTime.Today.Year)
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@code {
|
||||
private string _path = "/";
|
||||
private MenuItem? _activeArea;
|
||||
private MenuItem? _activeItem;
|
||||
|
||||
/// <summary>Whether the menu is collapsed to icons.</summary>
|
||||
[Parameter]
|
||||
public bool Collapsed { get; set; }
|
||||
|
||||
/// <summary>Collapses or expands the menu.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnToggle { get; set; }
|
||||
|
||||
private string ExpandLabel => T["Shell.Menu.Expand"];
|
||||
|
||||
private IEnumerable<MenuSection> Sections =>
|
||||
MenuCatalog.Sections
|
||||
.Select(s => new MenuSection(s.Key, [.. s.Items.Where(Session.CanSee)]))
|
||||
.Where(s => s.Items.Count > 0);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Navigation.LocationChanged += OnLocationChanged;
|
||||
Session.Changed += OnSessionChanged;
|
||||
Locate(Navigation.Uri);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Navigation.LocationChanged -= OnLocationChanged;
|
||||
Session.Changed -= OnSessionChanged;
|
||||
}
|
||||
|
||||
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
||||
{
|
||||
Locate(e.Location);
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private void OnSessionChanged() => _ = InvokeAsync(StateHasChanged);
|
||||
|
||||
private void Locate(string uri)
|
||||
{
|
||||
_path = TabService.PathOf(Navigation.ToBaseRelativePath(uri));
|
||||
_activeArea = MenuCatalog.FindArea(_path);
|
||||
_activeItem = MenuCatalog.Find(_path);
|
||||
}
|
||||
|
||||
private static string Href(MenuItem item) => item.Href == "/" ? "./" : item.Href.TrimStart('/');
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
@using System.Diagnostics
|
||||
@using Khaemhat.Core.Caching
|
||||
@using Khaemhat.Core.Common
|
||||
@implements IDisposable
|
||||
@inject ShellSession Session
|
||||
@inject ProductVersion Version
|
||||
@inject ICacheProvider Cache
|
||||
@inject IJSRuntime Js
|
||||
|
||||
@* The status bar of SPEC §10.2: company, fiscal year, user and level, connection and latency, cache, full version.
|
||||
The warehouse joins in M6 with the warehouses table. Latency is the round trip of the circuit, every 30 s. *@
|
||||
<footer class="statusbar" aria-label="@T["Shell.Status.Label"]">
|
||||
<span class="item">@(Session.Company?.Name ?? T["Shell.Company.None"])</span>
|
||||
<span class="item">@T.Format("Shell.Menu.FiscalYear", DateTime.Today.Year)</span>
|
||||
<span class="item">@Session.DisplayName · @T[Session.LevelKey]</span>
|
||||
<span class="sp"></span>
|
||||
<span class="item" title="@T["Shell.Status.ConnectionHint"]">
|
||||
<span class="live @(_latency is null ? "warn" : null)"></span>
|
||||
@(_latency is { } ms ? T.Format("Shell.Status.Connected", ms) : T["Shell.Status.Connecting"])
|
||||
</span>
|
||||
<span class="item">@(Cache.IsDistributed ? T["Shell.Status.Redis"] : T["Shell.Status.LocalCache"])</span>
|
||||
<span class="item" title="@Version.Full">@T.Format("Shell.Status.Version", Version.Version, ShortRevision)</span>
|
||||
</footer>
|
||||
|
||||
@code {
|
||||
private long? _latency;
|
||||
private Timer? _timer;
|
||||
|
||||
private string ShortRevision => Version.Revision.Length > 7 ? Version.Revision[..7] : Version.Revision;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized() => Session.Changed += OnChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
_timer = new Timer(_ => _ = InvokeAsync(MeasureAsync), null, TimeSpan.Zero, TimeSpan.FromSeconds(30));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Session.Changed -= OnChanged;
|
||||
_timer?.Dispose();
|
||||
}
|
||||
|
||||
private void OnChanged() => _ = InvokeAsync(StateHasChanged);
|
||||
|
||||
private async Task MeasureAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var watch = Stopwatch.StartNew();
|
||||
await Js.InvokeAsync<bool>("khaemhat.ping");
|
||||
_latency = watch.ElapsedMilliseconds;
|
||||
}
|
||||
catch (JSDisconnectedException)
|
||||
{
|
||||
_latency = null;
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
_latency = null;
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
@using Khaemhat.Application.Notifications
|
||||
@using Khaemhat.Application.Preferences
|
||||
@using Khaemhat.Core.Common
|
||||
@implements IDisposable
|
||||
@inject ShellSession Session
|
||||
@inject ThemeService Theme
|
||||
@inject TabService Tabs
|
||||
@inject NavigationManager Navigation
|
||||
@inject ProductVersion Version
|
||||
@inject NotificationDispatcher Notifications
|
||||
|
||||
@* The dark top bar of SPEC §10.2 (mockups 004, 007): brand, company, search, new, recent, notifications, quick theme,
|
||||
help, user menu. Only one pop-up is open at a time; clicking outside closes it. *@
|
||||
<header class="topbar">
|
||||
<div class="brand">
|
||||
<a href="/" title="@T["Shell.TopBar.Home"]">
|
||||
<span class="mark"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="icons/sprite.svg#brand"></use></svg></span>
|
||||
<span class="txt">@T["Common.ProductName"]</span>
|
||||
</a>
|
||||
<span class="ver">@Version.MajorMinor</span>
|
||||
</div>
|
||||
|
||||
<CompanySwitcher Open="@(_open == Popup.Company)" OpenChanged="open => Toggle(Popup.Company, open)" />
|
||||
|
||||
<button type="button" class="gsearch" @onclick="OnSearch" aria-keyshortcuts="Control+K">
|
||||
<KhIcon Name="search" />
|
||||
<span class="ph">@T["Shell.TopBar.SearchPlaceholder"]</span>
|
||||
<kbd>@T["Shell.TopBar.SearchKeys"]</kbd>
|
||||
</button>
|
||||
|
||||
<div class="right">
|
||||
<div class="pop">
|
||||
<button type="button" class="tbtn" aria-haspopup="menu" aria-expanded="@(_open == Popup.Recent)" aria-label="@T["Shell.TopBar.Recent"]"
|
||||
@onclick="() => Toggle(Popup.Recent)">
|
||||
<KhIcon Name="history" /><span class="tip">@T["Shell.TopBar.Recent"]</span>
|
||||
</button>
|
||||
@if (_open == Popup.Recent)
|
||||
{
|
||||
<div class="popmenu" role="menu">
|
||||
<div class="fh">@T["Shell.TopBar.Recent"]</div>
|
||||
@if (Tabs.Recent.Count == 0)
|
||||
{
|
||||
<div class="mi muted">@T["Shell.TopBar.NoRecent"]</div>
|
||||
}
|
||||
@foreach (var url in Tabs.Recent)
|
||||
{
|
||||
var item = MenuCatalog.Find(TabService.PathOf(url));
|
||||
<a class="mi" role="menuitem" href="@Relative(url)" @onclick="Close">
|
||||
<KhIcon Name="@(item?.Icon ?? "file")" />
|
||||
<span class="grow">@(item is null ? url : T[item.Key])</span>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="pop">
|
||||
<button type="button" class="tbtn" aria-haspopup="menu" aria-expanded="@(_open == Popup.Notifications)"
|
||||
aria-label="@T.Format("Shell.TopBar.NotificationsCount", _unread.Count)" @onclick="ToggleNotificationsAsync">
|
||||
<KhIcon Name="bell" />
|
||||
@if (_unread.Count > 0)
|
||||
{
|
||||
<span class="dot"></span>
|
||||
}
|
||||
<span class="tip">@T["Shell.TopBar.Notifications"]</span>
|
||||
</button>
|
||||
@if (_open == Popup.Notifications)
|
||||
{
|
||||
<div class="popmenu notif" role="menu">
|
||||
<div class="fh">@T["Shell.TopBar.Notifications"]</div>
|
||||
@if (_unread.Count == 0)
|
||||
{
|
||||
<div class="mi muted">@T["Shell.TopBar.NoNotifications"]</div>
|
||||
}
|
||||
@foreach (var n in _unread)
|
||||
{
|
||||
<a class="mi" role="menuitem" href="@(n.Link is { } link && UserPreferences.IsLocalPath(link) ? link.TrimStart('/') : "#")" @onclick="Close">
|
||||
<KhIcon Name="@SeverityIcon(n.Severity)" />
|
||||
<span class="grow"><b>@n.Title</b>@if (n.Body is not null) {<br /><span class="muted small">@n.Body</span>}</span>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<button type="button" class="tbtn" aria-label="@ThemeLabel" @onclick="Theme.ToggleDarkAsync">
|
||||
<KhIcon Name="@(Session.Preferences.Theme == ThemeMode.Dark ? "sun" : "moon")" /><span class="tip">@ThemeLabel</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="tbtn" aria-label="@T["Shell.TopBar.Help"]" aria-keyshortcuts="F1" @onclick="OnHelp">
|
||||
<KhIcon Name="help" /><span class="tip">@T["Shell.TopBar.Help"] <kbd>@KeyboardShortcuts.KeysOf(KeyboardShortcuts.Commands.Help)</kbd></span>
|
||||
</button>
|
||||
|
||||
<UserMenu Open="@(_open == Popup.User)" OpenChanged="open => Toggle(Popup.User, open)" />
|
||||
</div>
|
||||
</header>
|
||||
@if (_open is not null)
|
||||
{
|
||||
<div class="scrim" @onclick="Close"></div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum Popup
|
||||
{
|
||||
Company,
|
||||
Recent,
|
||||
Notifications,
|
||||
User,
|
||||
}
|
||||
|
||||
private Popup? _open;
|
||||
private IReadOnlyList<(string Title, string? Body, string? Link, Khaemhat.Core.Instance.NotificationSeverity Severity)> _unread = [];
|
||||
|
||||
/// <summary>Opens the global search.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnSearch { get; set; }
|
||||
|
||||
/// <summary>Opens the help of the page.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnHelp { get; set; }
|
||||
|
||||
private string ThemeLabel => Session.Preferences.Theme == ThemeMode.Dark ? T["Shell.TopBar.ThemeLight"] : T["Shell.TopBar.ThemeDark"];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Session.Changed += OnChanged;
|
||||
Tabs.Changed += OnChanged;
|
||||
await LoadNotificationsAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Session.Changed -= OnChanged;
|
||||
Tabs.Changed -= OnChanged;
|
||||
}
|
||||
|
||||
private void OnChanged() => _ = InvokeAsync(StateHasChanged);
|
||||
|
||||
private void Toggle(Popup popup, bool? open = null) => _open = (open ?? _open != popup) ? popup : null;
|
||||
|
||||
private void Close() => _open = null;
|
||||
|
||||
private async Task ToggleNotificationsAsync()
|
||||
{
|
||||
Toggle(Popup.Notifications);
|
||||
if (_open == Popup.Notifications)
|
||||
{
|
||||
await LoadNotificationsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadNotificationsAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (actor.SystemUserId is { } systemUser)
|
||||
{
|
||||
_unread = [.. (await Notifications.UnreadForInstanceAsync(systemUser)).Select(n => (n.Title, n.Body, n.Link, n.Severity))];
|
||||
}
|
||||
else if (actor is { CompanyCode: { } company, CompanyUserId: { } user })
|
||||
{
|
||||
_unread = [.. (await Notifications.UnreadForUserAsync(company, user)).Select(n => (n.Title, n.Body, n.Link, n.Severity))];
|
||||
}
|
||||
}
|
||||
|
||||
private static string Relative(string url) => url.TrimStart('/');
|
||||
|
||||
private static string SeverityIcon(Khaemhat.Core.Instance.NotificationSeverity severity) => severity switch
|
||||
{
|
||||
Khaemhat.Core.Instance.NotificationSeverity.Error => "x-circle",
|
||||
Khaemhat.Core.Instance.NotificationSeverity.Warning => "alert",
|
||||
Khaemhat.Core.Instance.NotificationSeverity.Success => "check-circle",
|
||||
_ => "info",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
@inject ShellSession Session
|
||||
|
||||
@* The user box of the top bar (mockup 004): initials, name, level; the menu opens the profile and signs out. *@
|
||||
<div class="pop">
|
||||
<button type="button" class="userbox" aria-haspopup="menu" aria-expanded="@Open" @onclick="() => OpenChanged.InvokeAsync(!Open)">
|
||||
<span class="avatar" aria-hidden="true">@Session.Initials</span>
|
||||
<span class="who">
|
||||
<span class="nm">@Session.DisplayName</span><br />
|
||||
<span class="rl">@T[Session.LevelKey]</span>
|
||||
</span>
|
||||
<KhIcon Name="chevron-down" Class="sm" />
|
||||
</button>
|
||||
@if (Open)
|
||||
{
|
||||
<div class="popmenu" role="menu">
|
||||
<div class="fh">@Session.DisplayName</div>
|
||||
<a class="mi" role="menuitem" href="profilo" @onclick="() => OpenChanged.InvokeAsync(false)"><KhIcon Name="user" /><span class="grow">@T["Shell.User.Profile"]</span></a>
|
||||
<a class="mi" role="menuitem" href="profilo?scheda=aspetto" @onclick="() => OpenChanged.InvokeAsync(false)"><KhIcon Name="palette" /><span class="grow">@T["Shell.User.Appearance"]</span></a>
|
||||
<a class="mi" role="menuitem" href="profilo?scheda=sessioni" @onclick="() => OpenChanged.InvokeAsync(false)"><KhIcon Name="monitor" /><span class="grow">@T["Shell.User.Sessions"]</span></a>
|
||||
<hr />
|
||||
<form method="post" action="logout">
|
||||
<AntiforgeryToken />
|
||||
<button type="submit" role="menuitem" class="mi"><KhIcon Name="logout" /><span class="grow">@T["Shell.User.SignOut"]</span></button>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>Whether the menu is open.</summary>
|
||||
[Parameter]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>Opens or closes the menu.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<bool> OpenChanged { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
@implements IDisposable
|
||||
@inject DialogService Dialogs
|
||||
|
||||
@* The confirmation dialog of SPEC §10.7 (KhConfirm): modal, Escape cancels, the cancelling button has the focus. *@
|
||||
@if (Dialogs.Current is { } request)
|
||||
{
|
||||
<div class="overlay" @onkeydown="OnKeyDown">
|
||||
<div class="dialog confirm" role="alertdialog" aria-modal="true" aria-labelledby="kh-confirm-title" aria-describedby="kh-confirm-text">
|
||||
<div class="dh"><KhIcon Name="@(request.Danger ? "alert" : "help")" /><span id="kh-confirm-title" class="grow">@request.Title</span></div>
|
||||
<div class="db" id="kh-confirm-text">@request.Text</div>
|
||||
<div class="df">
|
||||
<button type="button" class="btn" @ref="_cancel" @onclick="() => Dialogs.Answer(false)">@request.CancelText</button>
|
||||
<button type="button" class="btn @(request.Danger ? "danger" : "primary")" @onclick="() => Dialogs.Answer(true)">@request.ConfirmText</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private ElementReference _cancel;
|
||||
private bool _focus;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized() => Dialogs.Changed += OnChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose() => Dialogs.Changed -= OnChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (_focus && Dialogs.Current is not null)
|
||||
{
|
||||
_focus = false;
|
||||
await _cancel.FocusAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnChanged()
|
||||
{
|
||||
_focus = Dialogs.Current is not null;
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private void OnKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Escape")
|
||||
{
|
||||
Dialogs.Answer(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
@* An icon of icons/sprite.svg (SPEC §10.8). Decorative: the text next to it, or the tooltip, carries the meaning. *@
|
||||
<svg class="i @Class" aria-hidden="true" focusable="false"><use href="@("icons/sprite.svg#" + Name)"></use></svg>
|
||||
|
||||
@code {
|
||||
/// <summary>The symbol id in the sprite.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Extra classes: <c>lg</c>, <c>sm</c>.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
@* Sets the title of the tab that holds the page (SPEC §10.2); the layout writes the browser title from the active
|
||||
tab. Outside a tab (sign-in pages) it writes the browser title itself. *@
|
||||
@if (Tab is null)
|
||||
{
|
||||
<PageTitle>@Text · @T["Common.ProductName"]</PageTitle>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>The tab of the page, given by the tab host.</summary>
|
||||
[CascadingParameter]
|
||||
public KhTab? Tab { get; set; }
|
||||
|
||||
/// <summary>The title.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The icon of the tab, or <see langword="null"/> for the menu icon.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet() => Tab?.SetTitle(Text, Icon);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
@* An on/off option with its label and a short explanation (mockup 008). The whole row is the switch. *@
|
||||
<button type="button" class="kh-switch-row" role="switch" aria-checked="@Value" @onclick="() => ValueChanged.InvokeAsync(!Value)">
|
||||
<span class="grow">
|
||||
<span class="t">@Label</span>
|
||||
@if (!string.IsNullOrEmpty(Hint))
|
||||
{
|
||||
<span class="s">@Hint</span>
|
||||
}
|
||||
</span>
|
||||
<span class="switch @(Value ? "on" : null)" aria-hidden="true"></span>
|
||||
</button>
|
||||
|
||||
@code {
|
||||
/// <summary>The label.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Label { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The explanation under the label.</summary>
|
||||
[Parameter]
|
||||
public string? Hint { get; set; }
|
||||
|
||||
/// <summary>Whether the option is on.</summary>
|
||||
[Parameter]
|
||||
public bool Value { get; set; }
|
||||
|
||||
/// <summary>Raised with the new value.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<bool> ValueChanged { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
@implements IDisposable
|
||||
@inject ToastService Toasts
|
||||
|
||||
@* The toasts of SPEC §10.7, bottom right, announced to screen readers. Each one goes away after six seconds. *@
|
||||
<div class="toasts" role="status" aria-live="polite">
|
||||
@foreach (var toast in Toasts.Toasts)
|
||||
{
|
||||
<div class="toast @KindClass(toast.Kind)" @key="toast.Id">
|
||||
<KhIcon Name="@KindIcon(toast.Kind)" />
|
||||
<div class="grow">
|
||||
<div class="tt">@toast.Title</div>
|
||||
@if (toast.Text is not null)
|
||||
{
|
||||
<div class="muted">@toast.Text</div>
|
||||
}
|
||||
</div>
|
||||
<button type="button" title="@T["Common.Close"]" aria-label="@T["Common.Close"]" @onclick="() => Toasts.Dismiss(toast.Id)"><KhIcon Name="x" Class="sm" /></button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private readonly HashSet<Guid> _timed = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized() => Toasts.Changed += OnChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose() => Toasts.Changed -= OnChanged;
|
||||
|
||||
private void OnChanged()
|
||||
{
|
||||
foreach (var toast in Toasts.Toasts.Where(t => _timed.Add(t.Id)))
|
||||
{
|
||||
_ = DismissLaterAsync(toast.Id);
|
||||
}
|
||||
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task DismissLaterAsync(Guid id)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(6));
|
||||
_timed.Remove(id);
|
||||
await InvokeAsync(() => Toasts.Dismiss(id));
|
||||
}
|
||||
|
||||
private static string KindClass(ToastKind kind) => kind switch
|
||||
{
|
||||
ToastKind.Success => "ok",
|
||||
ToastKind.Warning => "warn",
|
||||
ToastKind.Error => "err",
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
private static string KindIcon(ToastKind kind) => kind switch
|
||||
{
|
||||
ToastKind.Success => "check-circle",
|
||||
ToastKind.Warning => "alert",
|
||||
ToastKind.Error => "x-circle",
|
||||
_ => "info",
|
||||
};
|
||||
}
|
||||
@@ -13,3 +13,9 @@
|
||||
@using Khaemhat.Web.Components.Layout
|
||||
@using Khaemhat.Core.Security
|
||||
@using Khaemhat.Web.Security
|
||||
@using Khaemhat.Application.Localization
|
||||
@using Khaemhat.Application.Preferences
|
||||
@using Khaemhat.Web.Shell
|
||||
@using Khaemhat.Web.Components.Shell
|
||||
@using Khaemhat.Web.Components.Ui
|
||||
@inject ITexts T
|
||||
Reference in new issue
Block a user