F1 and "?" now open the wiki page of the screen inside the application (/aiuto, mockup 011) from a copy of the wiki shipped next to the program, so help works offline and always matches the installed version. Markdown is converted in-house and fully encoded; images of the repository are served from the copy. KHAEMHAT_HELP_URL sets the online wiki behind "Apri nel wiki"; "Segnala un problema" opens a new issue of that repo. A test checks that every page and menu entry has an existing wiki page. The bell opens a notifications panel (mockup 010) with all/unread filters and mark read. Broadcast notifications are now read per user through sys_notification_reads / notification_reads instead of one shared read_at. The global search asks ISearchProvider implementations through GlobalSearchService after a short pause; the first provider finds help pages and sections, # and @ say which modules will fill them. Escape also closes a side panel when the focus fell out of it. Decisions in ADR 0023. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
289 lines
10 KiB
Plaintext
289 lines
10 KiB
Plaintext
@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
|
|
|
|
@* 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 />
|
|
<KhDrawerHost />
|
|
|
|
<div id="blazor-error-ui" data-nosnippet>
|
|
@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('/'));
|
|
}
|
|
}
|
|
|
|
// F1 and the "?" open the help of the screen in a tab of its own (mockup 011); on a help page they stay there.
|
|
private Task OpenHelpAsync()
|
|
{
|
|
var path = TabService.PathOf("/" + Navigation.ToBaseRelativePath(Navigation.Uri));
|
|
if (!path.StartsWith(Khaemhat.Web.Help.WikiLibrary.BasePath, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
Navigation.NavigateTo(HelpLinks.LocalFor(path));
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|