6.4 KiB
Authenticated application toolbar
The existing ApplicationNavigation service remains the authority for project/book context. It uses the user-scoped project repository, rejects inaccessible projects and limits book selection to that project's non-archived books. The Bootstrap application menus, account/status controls and mobile menu collapse remain in place. Public navigation and feature page content are unchanged.
_ApplicationToolbar.cshtml renders immediately below the application menu only for authenticated, non-marketing pages. It uses the existing Bootstrap modal/dropdown facilities and theme variables, with small inline SVG icons consistent with the existing codebase (there is no shared icon package). The strip is approximately 40px high; on narrow screens its labelled links scroll horizontally and the existing application menu collapses. Unavailable shortcuts are disabled without an href. Menus remain the comprehensive navigation mechanism.
Command registry
PlotLine/Services/ToolbarCommands.cs defines stable keys, labels, SVG paths, destination controllers/actions, default membership, project/book requirements, route values and active-state detection. Current defaults, in order:
- Overview, Timeline, Calendar, Characters, Threads, Relationships, Review Centre.
Other commands:
- Locations, Assets, Names, At This Point, Scenarios, Floor Plans, Story Bible, Continuity, Metrics, Health, Warnings, Archive, Projects, Writer.
Threads uses the existing PlotThreads destination. There is no independent project-wide Plot Lines or Knowledge landing page to expose. Review Centre uses the existing book review route; it requires a selected book and does not choose one implicitly. Review Centre is also in the Book menu. No new AI or review preparation operation was added. All registered destinations use existing access checks; there are no owner/admin-only toolbar commands. Adding a restricted command must include its visibility/availability check here as well as the destination's normal server-side authorisation.
To add a command, add a ToolbarCommand to All, choose a unique stable key and set the actual MVC destination and section. Supply a 24x24 SVG path; labels remain visible. Set IsDefault if new/default users should see it. Array order determines default order. RouteValues handles project destinations, overview IDs and book review IDs; extend it for a destination with different parameters. Never store URLs in preferences. The registry and rendering partial are separate from the preference model, so future command execution can extend dispatch without changing stored identifiers. No speculative context commands are implemented.
Preferences and migration
Apply PlotLine/Sql/201_UserToolbarPreferences.sql before deploying this code, following the repository's backup and manual migration procedure. This work does not apply it to shared development or production.
The nullable dbo.AppUser.ToolbarCommandKeysJson column is accessed exclusively through dbo.UserToolbar_Get and dbo.UserToolbar_Save and IToolbarPreferenceRepository. It belongs to the existing account row and is removed naturally when the account is deleted. No preference rows are created by rendering a page.
- SQL NULL means follow the current system defaults.
- A JSON array of stable keys is an explicit custom configuration. Array position is display order; membership means enabled and absence means disabled. An empty array deliberately hides every command.
- New commands are never appended to an existing custom array. Removed keys are ignored; remaining order is preserved. Malformed stored JSON falls back to defaults.
- Restore defaults previews current defaults, then Save writes NULL. Cancel (including Escape/backdrop/close) leaves the persisted configuration and toolbar unchanged.
ToolbarController.Saverequires authentication and antiforgery, obtains the user ID from the authenticated identity, validates command keys/duplicates and never accepts a target user ID or URL.- Preferences are loaded from SQL on each authenticated application page, so they survive logout, browser changes and app restarts. Concurrent browser saves use last-save-wins behavior.
The modal uses native drag/drop and named up/down buttons, with no new JavaScript dependencies. It updates the current toolbar only after a successful save, keeps errors in the dialog and prevents closing during the save. Unavailable commands can still be configured for use when the relevant project/book context becomes available.
Active feature and book changes
The existing ApplicationNavigationViewModel.ActiveSection identifies whole features across actions. Registry matching uses it rather than matching URL substrings. Review Centre additionally recognises the Onboarding Story Intelligence action family; ordinary onboarding setup does not activate it. Projects uses the Projects/Index destination explicitly.
application-navigation.js already observes Calendar/At This Point partial replacements. The same hook updates Review Centre's book URL using only a book present in the authorised menu choices, or disables the shortcut when the page shows all books. Project switching continues through the existing project menu.
Validation
dotnet build PlotLine.slnxdotnet run --project PlotLine.Tests/PlotLine.Tests.csproj- In one terminal at the repository root:
dotnet run --project PlotLine.Tests -- --toolbar-browser-host - In
PlotLine.Tests/Browser:npm run test:toolbar
The loopback-only browser host renders the real compiled navigation, toolbar, modal and Calendar surface with isolated fixtures and an in-memory preference repository. It starts no application workers and accesses no live database. Tests cover menu links/project switching, active Calendar, authorised project/book links and asynchronous book changes, show/hide, keyboard/native-drag ordering, cancel/reset, fresh browser sessions and independent identities, CSRF rejection, no-project pages, desktop/mobile and dark theme. Screenshots go to /tmp, never the repository. It does not replace a live authenticated smoke test after deployment.
SQL was separately checked in a disposable verification database: migration applied twice, SQL NULL defaults, ordered/empty preferences, independent user records, retrieval through a fresh repository and restoring defaults. The disposable database was dropped after verification; shared databases were unchanged.