From bfa6a73e3fc0800ee2403503fe1f36dca0cccb27 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Wed, 28 Oct 2026 20:25:03 +0000 Subject: [PATCH] Introduce integrated ribbon shell, four account themes and refreshed series dashboard --- PlotLine.Tests/AppearanceTests.cs | 40 ++++ .../Browser/application-toolbar.cjs | 57 ++++-- PlotLine.Tests/Program.cs | 1 + PlotLine.Tests/ToolbarBrowserHost.cs | 29 ++- PlotLine/Controllers/AppearanceController.cs | 26 +++ PlotLine/Data/AppearanceRepository.cs | 29 +++ PlotLine/Program.cs | 1 + PlotLine/Services/ApplicationAppearance.cs | 13 ++ PlotLine/Services/ApplicationRibbon.cs | 58 ++++++ .../Sql/202_UserApplicationAppearance.sql | 33 ++++ PlotLine/Views/Projects/Details.cshtml | 17 +- .../Views/Shared/_ApplicationShell.cshtml | 146 ++++++++++++++ .../Views/Shared/_ApplicationToolbar.cshtml | 12 +- PlotLine/Views/Shared/_Layout.cshtml | 34 +++- PlotLine/wwwroot/css/application-shell.css | 185 ++++++++++++++++++ PlotLine/wwwroot/js/application-navigation.js | 13 ++ PlotLine/wwwroot/js/application-shell.js | 75 +++++++ PlotLine/wwwroot/js/site.js | 2 +- PlotLine/wwwroot/js/site.min.js | 2 +- docs/navigation/application-toolbar.md | 78 +++++--- 20 files changed, 787 insertions(+), 64 deletions(-) create mode 100644 PlotLine.Tests/AppearanceTests.cs create mode 100644 PlotLine/Controllers/AppearanceController.cs create mode 100644 PlotLine/Data/AppearanceRepository.cs create mode 100644 PlotLine/Services/ApplicationAppearance.cs create mode 100644 PlotLine/Services/ApplicationRibbon.cs create mode 100644 PlotLine/Sql/202_UserApplicationAppearance.sql create mode 100644 PlotLine/Views/Shared/_ApplicationShell.cshtml create mode 100644 PlotLine/wwwroot/css/application-shell.css create mode 100644 PlotLine/wwwroot/js/application-shell.js diff --git a/PlotLine.Tests/AppearanceTests.cs b/PlotLine.Tests/AppearanceTests.cs new file mode 100644 index 00000000..5780828c --- /dev/null +++ b/PlotLine.Tests/AppearanceTests.cs @@ -0,0 +1,40 @@ +using PlotLine.Services; +using PlotLine.Data; +using PlotLine.Controllers; +using Microsoft.AspNetCore.Mvc; + +internal static class AppearanceTests +{ + public static void RegistryAndPersistence() + { + if (ApplicationAppearance.Themes.Count != 4 || ApplicationAppearance.IsValid("dark")) throw new Exception("Four explicit theme identifiers required."); + var store = new AppearanceMemoryPreferences(); + var controller = new AppearanceController(new ToolbarTestUser(4), store); + controller.Theme("modern-dark").GetAwaiter().GetResult(); + controller.Theme("warm-light", true).GetAwaiter().GetResult(); + if (store.GetAsync(4).Result.ThemeKey != "modern-dark" || store.GetAsync(5).Result.ThemeKey is not null) throw new Exception("Legacy migration must preserve explicit choices and isolate users."); + controller.Ribbon(true).GetAwaiter().GetResult(); + if (!store.GetAsync(4).Result.RibbonCollapsed || store.GetAsync(4).Result.ThemeKey != "modern-dark") throw new Exception("Ribbon preference must not overwrite theme."); + if (controller.Theme("invalid").Result is not BadRequestResult) throw new Exception("Invalid themes rejected."); + if (ApplicationRibbon.ActiveCategory("StoryCalendar", "Calendar") != "story" || ApplicationRibbon.ActiveCategory("Books", "Overview") != "book") throw new Exception("Category maps feature routes."); + foreach (var command in ApplicationRibbon.Categories.SelectMany(x => x.Groups).SelectMany(x => x.Commands)) + { + _ = ApplicationRibbon.Icon(command.IconKey); + if (command.ToolbarKey is not null && !ToolbarCommands.All.Any(x => x.Key == command.ToolbarKey)) throw new Exception("Registry key invalid."); + var type = typeof(AppearanceController).Assembly.GetType($"PlotLine.Controllers.{command.Controller}Controller"); + if (type is null || !type.GetMethods().Any(x => x.Name == command.Action)) throw new Exception($"Missing destination: {command.Controller}/{command.Action}"); + } + } +} +internal sealed class AppearanceMemoryPreferences : IAppearanceRepository +{ + private readonly System.Collections.Concurrent.ConcurrentDictionary values = new(); + public Task GetAsync(int id) => Task.FromResult(values.GetOrAdd(id, _ => new())); + public Task SaveThemeAsync(int id, string theme, bool onlyIfUnset = false) + { + var value = GetAsync(id).Result; + lock(value) { if (!onlyIfUnset || value.ThemeKey is null) value.ThemeKey = theme; } + return Task.CompletedTask; + } + public Task SaveRibbonAsync(int id, bool collapsed) { GetAsync(id).Result.RibbonCollapsed = collapsed; return Task.CompletedTask; } +} diff --git a/PlotLine.Tests/Browser/application-toolbar.cjs b/PlotLine.Tests/Browser/application-toolbar.cjs index 3bc05260..56ff8b2c 100644 --- a/PlotLine.Tests/Browser/application-toolbar.cjs +++ b/PlotLine.Tests/Browser/application-toolbar.cjs @@ -11,7 +11,7 @@ const assert = require('node:assert/strict'); const visible = () => page.locator('[data-toolbar-key]:visible').evaluateAll(items => items.map(item => item.dataset.toolbarKey)); const open = async () => { await page.locator('#accountMenuButton').click(); - await page.getByRole('button', { name: 'Customise toolbar…', exact: true }).click(); + await page.getByRole('button', { name: 'Customise Quick Access Toolbar…', exact: true }).click(); await page.locator('#customiseToolbar.show').waitFor(); }; const close = async (name) => { @@ -28,11 +28,11 @@ const assert = require('node:assert/strict'); assert.match(await page.locator('[data-toolbar-key="calendar"]').getAttribute('href'), /projectId=7/); assert.match(await page.locator('[data-toolbar-key="review"]').getAttribute('href'), /book\/12\/review-centre/); const chrome = await page.locator('header').boundingBox(); - assert(chrome.height < 100, 'Desktop chrome stays compact'); + assert(chrome.height < 190, 'Desktop chrome stays compact'); await page.screenshot({ path: '/tmp/plotdirector-toolbar-desktop.png' }); - await page.locator('#appStoryMenu').click(); - assert(await page.locator('#appStoryMenu + ul').isVisible()); - assert.match(await page.locator('#appStoryMenu + ul').getByText('Calendar', { exact: true }).getAttribute('href'), /projectId=7/); + await page.getByRole('tab', { name: 'Story', exact: true }).click(); + assert(await page.locator('#ribbon-panel-story').isVisible()); + assert.match(await page.locator('#ribbon-panel-story').getByRole('link', { name: 'Calendar', exact: true }).getAttribute('href'), /projectId=7/); await page.locator('#appProjectMenu').click(); assert.equal(await page.getByText('Switch project…', { exact: true }).getAttribute('href'), '/Projects'); await page.keyboard.press('Escape'); @@ -94,7 +94,7 @@ const assert = require('node:assert/strict'); await close('Save'); assert.deepEqual(await visible(), []); await page.reload(); - assert(await page.locator('[data-toolbar-empty]').isVisible()); + assert(await page.locator('[data-app-toolbar] button').isVisible()); await open(); await page.getByRole('button', { name: 'Restore defaults', exact: true }).click(); await close('Cancel'); @@ -106,21 +106,46 @@ const assert = require('node:assert/strict'); assert.equal(await page.locator('[data-toolbar-key="calendar"]').getAttribute('href'), null); assert.equal(await page.locator('[data-toolbar-key="calendar"]').getAttribute('aria-disabled'), 'true'); await page.setViewportSize({ width: 390, height: 844 }); - await page.locator('.navbar-toggler').click(); - await page.locator('#applicationMenu.collapse.show').waitFor(); await page.locator('#accountMenuButton').click(); - assert(await page.getByRole('button', { name: 'Customise toolbar…', exact: true }).isVisible()); + assert(await page.getByRole('button', { name: 'Customise Quick Access Toolbar…', exact: true }).isVisible()); await page.keyboard.press('Escape'); - await page.locator('.navbar-toggler').click(); - await page.locator('#applicationMenu').waitFor({ state: 'hidden' }); await page.screenshot({ path: '/tmp/plotdirector-toolbar-mobile.png' }); assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), 'Mobile chrome does not overflow viewport'); await page.setViewportSize({ width: 1440, height: 1000 }); - await page.goto(base + '/fixture'); - await page.evaluate(() => { document.documentElement.dataset.theme = 'dark'; document.documentElement.dataset.bsTheme = 'dark'; }); - await page.waitForTimeout(350); // Allow the existing theme colour transition to finish. - await page.screenshot({ path: '/tmp/plotdirector-toolbar-dark.png' }); + await page.goto(base + '/fixture?page=dashboard'); + assert.equal(await page.locator('.dashboard-summary-value').first().textContent(), '2'); + assert.equal(await page.getByRole('tab', { name: 'Project', exact: true }).getAttribute('aria-selected'), 'true'); + for (const theme of ['modern-light','modern-dark','warm-light','warm-dark']) { + const before = page.url(); + await page.locator('#accountMenuButton').click(); + await page.locator(`[data-app-theme-choice="${theme}"]`).click(); + await page.waitForFunction(t => document.documentElement.dataset.appTheme === t && !document.querySelector('[data-app-theme-choice]').disabled, theme); + await page.keyboard.press('Escape'); + assert.equal(page.url(), before); + await page.waitForTimeout(250); + await page.screenshot({ path: `/tmp/plotdirector-shell-${theme}.png` }); + await page.reload(); + assert.equal(await page.locator('html').getAttribute('data-app-theme'), theme); + } + await page.getByRole('tab', { name: 'Project', exact: true }).focus(); + await page.keyboard.press('ArrowRight'); + assert.equal(await page.getByRole('tab', { name: 'Book', exact: true }).getAttribute('aria-selected'), 'true'); + await page.locator('[data-ribbon-collapse]').click(); + await page.waitForFunction(() => !document.querySelector('[data-ribbon-collapse]').disabled); + await page.reload(); + assert(await page.locator('#ribbon-surface').isHidden()); + await page.getByRole('tab', { name: 'World', exact: true }).click(); + assert(await page.locator('#ribbon-panel-world').isVisible()); + assert.match(await page.locator('#ribbon-panel-world').getByRole('link', { name: 'Locations', exact: true }).getAttribute('href'), /projectId=7/); + // Category selection opens a collapsed ribbon temporarily; it does not erase the saved preference. + await page.reload(); + assert(await page.locator('#ribbon-surface').isHidden()); + await page.locator('[data-ribbon-collapse]').click(); + await page.waitForFunction(() => !document.querySelector('[data-ribbon-collapse]').disabled); + await page.setViewportSize({ width: 390, height: 844 }); + assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)); + await page.screenshot({ path: '/tmp/plotdirector-shell-dashboard-mobile.png' }); assert.deepEqual(errors, []); - console.log('PASS application toolbar: real Razor, default/custom order, show/hide, drag/keyboard, cancel/reset, fresh sessions, users, menus, project/book context, CSRF, desktop/mobile/dark'); + console.log('PASS application toolbar: real Razor, default/custom order, show/hide, drag/keyboard, cancel/reset, fresh sessions, users, menus, project/book context, CSRF, desktop/mobile, four themes, theme persistence, ribbon keyboard/collapse, Dashboard'); } finally { await browser.close(); } })().catch(error => { console.error(error); process.exitCode = 1; }); diff --git a/PlotLine.Tests/Program.cs b/PlotLine.Tests/Program.cs index 8fc105d8..05b4d61d 100644 --- a/PlotLine.Tests/Program.cs +++ b/PlotLine.Tests/Program.cs @@ -319,6 +319,7 @@ var tests = new (string Name, Action Test)[] ("Writing Intent route uses canonical story context and planning data", WritingIntentRouteUsesCanonicalStoryContextAndPlanningData), ("Writing Intent client uses shared writing follow helper", WritingIntentClientUsesSharedWritingFollowHelper), ("Obsolete global Word navigation is removed while writing windows remain live", GlobalWordNavigationIsRemoved), + ("Appearance preferences and ribbon destinations", AppearanceTests.RegistryAndPersistence), ("Toolbar preferences, authorisation and contextual routes", ToolbarTests.PreferencesAndRoutes), ("Application navigation resolves authorised project and book context", ApplicationNavigationTests.ContextAndPermissions), ("Writing pair shares canonical follow infrastructure", WritingPairSharesCanonicalFollowInfrastructure), diff --git a/PlotLine.Tests/ToolbarBrowserHost.cs b/PlotLine.Tests/ToolbarBrowserHost.cs index e6bd10b4..4914b8d6 100644 --- a/PlotLine.Tests/ToolbarBrowserHost.cs +++ b/PlotLine.Tests/ToolbarBrowserHost.cs @@ -25,6 +25,8 @@ internal static class ToolbarBrowserHost builder.Services.AddControllersWithViews().AddApplicationPart(typeof(ToolbarController).Assembly); builder.Services.AddSingleton(); builder.Services.AddHttpContextAccessor(); + builder.Services.AddSingleton(); + builder.Services.AddScoped(_ => new ApplicationNavigation(null!, null!, null!)); builder.Services.AddSingleton(); builder.Services.AddScoped(services => new ToolbarTestUser(int.Parse(services.GetRequiredService().HttpContext!.User.FindFirstValue(ClaimTypes.NameIdentifier)!))); var app = builder.Build(); @@ -48,7 +50,10 @@ internal static class ToolbarBrowserHost model.Book = new Book { BookID = 12, ProjectID = 7, BookTitle = "A Distant Shore", BookNumber = 1 }; model.Books = [model.Book, new Book { BookID = 13, ProjectID = 7, BookTitle = "The Return", BookNumber = 2 }]; } - var route = new RouteData(); route.Values["controller"] = "StoryCalendar"; route.Values["action"] = "Index"; + var dashboardPage = context.Request.Query["page"] == "dashboard"; + if (dashboardPage) model.ActiveSection = "Overview"; + var appearance = await context.RequestServices.GetRequiredService().GetAsync(int.Parse(context.User.FindFirstValue(ClaimTypes.NameIdentifier)!)); + var route = new RouteData(); route.Values["controller"] = dashboardPage ? "Projects" : "StoryCalendar"; route.Values["action"] = dashboardPage ? "Details" : "Index"; var action = new ActionContext(context, route, new ActionDescriptor()); async Task Render(string name, object? viewModel = null) { @@ -56,12 +61,13 @@ internal static class ToolbarBrowserHost if (!view.Success) throw new Exception(string.Join(",", view.SearchedLocations)); using var writer = new StringWriter(); var data = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { Model = viewModel ?? model }; + data["ApplicationAppearance"] = appearance; var temp = new TempDataDictionary(context, context.RequestServices.GetRequiredService()); await view.View.RenderAsync(new ViewContext(action, view.View, data, temp, writer, new HtmlHelperOptions())); return writer.ToString(); } - var menu = await Render("Shared/_ApplicationNavigation"); - var toolbar = await Render("Shared/_ApplicationToolbar"); + var menu = await Render("Shared/_ApplicationShell"); + var toolbar = ""; var calendar = new StoryCalendarViewModel { Project = model.Project ?? new(), SelectedBookID = model.Book?.BookID, SelectedMonth = new DateOnly(2026, 10, 1), EarliestStoryDate = new DateOnly(2026, 10, 3), LatestStoryDate = new DateOnly(2026, 10, 3), BookOptions = [new SelectListItem("A Distant Shore", "12"), new SelectListItem("The Return", "13")], @@ -71,9 +77,22 @@ internal static class ToolbarBrowserHost Days = Enumerable.Range(0, 7).Select(day => new StoryCalendarDayViewModel { Date = new DateOnly(2026, 9, 28).AddDays(week * 7 + day), IsInSelectedMonth = week * 7 + day >= 3 }).ToList() }).ToList() }; - var surface = await Render("StoryCalendar/_StoryCalendarSurface", calendar); + var surface = dashboardPage ? "" : await Render("StoryCalendar/_StoryCalendarSurface", calendar); + if (dashboardPage) + { + surface = await Render("Projects/Details", new ProjectDetailViewModel { + Project = model.Project ?? new(), + Summary = new() { TotalBooks = 2, DraftingBooks = 1, PlanningBooks = 1, TotalWords = 68420, CharacterCount = 18, LocationCount = 12, ActivePlotThreadCount = 7, ContinuityWarningCount = 3 }, + SeriesProgress = new() { Percentage = 42, SupportingLine = "68,420 of 160,000 planned words", CalculationLabel = "Word count" }, + Books = [new() { BookID = 12, BookNumber = 1, BookTitle = "A Distant Shore", Subtitle = "The Glass Harbour · Book One", Status = "Drafting", CurrentWordCount = 68420, TargetWordCount = 80000, ProgressPercentage = 85.5m, ChapterCount = 24, SceneCount = 72, UpdatedDate = new DateTime(2026,10,28) }], + RecentActivity = [new() { ActivityType = "Updated", EntityType = "Scene", EntityName = "An unexpected arrival", Description = "Chapter 12 · A change of direction", TimeLabel = "Today", UserLabel = "Fixture Author", IconLabel = "Scene" }], + NeedsAttention = new() { Warnings = [new() { SeverityName = "Review", WarningTypeName = "Chronology", Message = "Check the order of events at the harbour.", LocationLabel = "Book 1 · Chapter 12" }] } + }); + } + var initialTheme = appearance.ThemeKey ?? "warm-light"; + var appearanceScript = ""; context.Response.ContentType = "text/html; charset=utf-8"; - await context.Response.WriteAsync("
" + menu + toolbar + "
" + surface + "
"); + await context.Response.WriteAsync("
" + menu + toolbar + "
" + surface + "
" + appearanceScript + ""); }); await app.RunAsync(); } diff --git a/PlotLine/Controllers/AppearanceController.cs b/PlotLine/Controllers/AppearanceController.cs new file mode 100644 index 00000000..5c306eb8 --- /dev/null +++ b/PlotLine/Controllers/AppearanceController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using PlotLine.Data; +using PlotLine.Services; +namespace PlotLine.Controllers; + +[Authorize] +public sealed class AppearanceController(ICurrentUserService user, IAppearanceRepository preferences) : Controller +{ + [HttpPost, ValidateAntiForgeryToken] + public async Task Theme(string themeKey, bool onlyIfUnset = false) + { + if (user.UserId is not int id) return Unauthorized(); + if (!ModelState.IsValid || !ApplicationAppearance.IsValid(themeKey)) return BadRequest(); + await preferences.SaveThemeAsync(id, themeKey, onlyIfUnset); + return Json(await preferences.GetAsync(id)); + } + [HttpPost, ValidateAntiForgeryToken] + public async Task Ribbon(bool collapsed) + { + if (user.UserId is not int id) return Unauthorized(); + if (!ModelState.IsValid) return BadRequest(); + await preferences.SaveRibbonAsync(id, collapsed); + return Ok(); + } +} diff --git a/PlotLine/Data/AppearanceRepository.cs b/PlotLine/Data/AppearanceRepository.cs new file mode 100644 index 00000000..3b0514b0 --- /dev/null +++ b/PlotLine/Data/AppearanceRepository.cs @@ -0,0 +1,29 @@ +using System.Data; +using Dapper; +using PlotLine.Services; +namespace PlotLine.Data; + +public interface IAppearanceRepository +{ + Task GetAsync(int userId); + Task SaveThemeAsync(int userId, string themeKey, bool onlyIfUnset = false); + Task SaveRibbonAsync(int userId, bool collapsed); +} +public sealed class AppearanceRepository(ISqlConnectionFactory connections) : IAppearanceRepository +{ + public async Task GetAsync(int userId) + { + using var connection = connections.CreateConnection(); + return await connection.QuerySingleOrDefaultAsync("dbo.UserAppearance_Get", new { UserID = userId }, commandType: CommandType.StoredProcedure) ?? new(); + } + public async Task SaveThemeAsync(int userId, string themeKey, bool onlyIfUnset = false) + { + using var connection = connections.CreateConnection(); + await connection.ExecuteAsync("dbo.UserAppearance_SaveTheme", new { UserID = userId, ThemeKey = themeKey, OnlyIfUnset = onlyIfUnset }, commandType: CommandType.StoredProcedure); + } + public async Task SaveRibbonAsync(int userId, bool collapsed) + { + using var connection = connections.CreateConnection(); + await connection.ExecuteAsync("dbo.UserAppearance_SaveRibbon", new { UserID = userId, Collapsed = collapsed }, commandType: CommandType.StoredProcedure); + } +} diff --git a/PlotLine/Program.cs b/PlotLine/Program.cs index e0a82c10..fce64c97 100644 --- a/PlotLine/Program.cs +++ b/PlotLine/Program.cs @@ -113,6 +113,7 @@ public class Program builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/PlotLine/Services/ApplicationAppearance.cs b/PlotLine/Services/ApplicationAppearance.cs new file mode 100644 index 00000000..3a5d497a --- /dev/null +++ b/PlotLine/Services/ApplicationAppearance.cs @@ -0,0 +1,13 @@ +namespace PlotLine.Services; + +public sealed class ApplicationAppearance +{ + public string? ThemeKey { get; set; } + public bool RibbonCollapsed { get; set; } + public static IReadOnlyDictionary Themes { get; } = new Dictionary + { + ["modern-light"] = "Modern Light", ["modern-dark"] = "Modern Dark", + ["warm-light"] = "Warm Light", ["warm-dark"] = "Warm Dark" + }; + public static bool IsValid(string? theme) => theme is not null && Themes.ContainsKey(theme); +} diff --git a/PlotLine/Services/ApplicationRibbon.cs b/PlotLine/Services/ApplicationRibbon.cs new file mode 100644 index 00000000..0d2c143f --- /dev/null +++ b/PlotLine/Services/ApplicationRibbon.cs @@ -0,0 +1,58 @@ +using PlotLine.ViewModels; +namespace PlotLine.Services; + +public sealed record RibbonCommand(string Label, string IconKey, string Controller, string Action, + string Scope = "project", bool OwnerOnly = false, string? ToolbarKey = null) +{ + public bool Available(ApplicationNavigationViewModel model) => (Scope == "global" || model.Project is not null) + && (Scope != "book" && Scope != "chapter" || model.Book is not null) && (!OwnerOnly || model.Project?.IsOwner == true); + public object Values(ApplicationNavigationViewModel model) => Scope switch + { + "global" => new { }, "id" => new { id = model.Project?.ProjectID }, + "book" => new { id = model.Book?.BookID }, "chapter" => new { bookId = model.Book?.BookID }, + _ => new { projectId = model.Project?.ProjectID } + }; + public static RibbonCommand Shortcut(string key) + { + var command = ToolbarCommands.All.Single(x => x.Key == key); + return new(command.Label, key, command.Controller, command.Action, ToolbarKey: key); + } +} +public sealed record RibbonGroup(string Label, params RibbonCommand[] Commands); +public sealed record RibbonCategory(string Key, string Label, params RibbonGroup[] Groups); +public static class ApplicationRibbon +{ + private static RibbonCommand S(string key) => RibbonCommand.Shortcut(key); + public static IReadOnlyList Categories { get; } = [ + new("project", "Project", + new("Workspace", S("overview"), S("projects"), S("writer"), new("Import", "assets", "Imports", "Index", "global")), + new("Project", new("Edit project", "writer", "Projects", "Edit", "id"), new("Add book", "bible", "Books", "Create"), new("Activity", "metrics", "Projects", "Activity", "id")), + new("Manage", new("Collaborators", "characters", "ProjectCollaborators", "Index", OwnerOnly: true), new("Backup", "archive", "Exports", "ProjectBackup", OwnerOnly: true), new("Restore points", "archive", "ProjectRestorePoints", "Index"))), + new("book", "Book", + new("Selected book", new("Book overview", "bible", "Books", "Details", "book"), new("Edit book", "writer", "Books", "Edit", "book"), new("Add chapter", "threads", "Chapters", "Create", "chapter")), + new("Manuscript review", S("review")), new("Library", S("overview"), new("Add book", "bible", "Books", "Create"))), + new("story", "Story", new("Story structure", S("timeline"), S("calendar"), S("threads"), S("point")), new("Analysis & planning", S("review"), S("scenarios"), S("continuity")), new("Writing", S("writer"))), + new("characters", "Characters", new("Cast", S("characters"), S("names")), new("Connections", S("relationships"))), + new("world", "World", new("Setting", S("locations"), S("floorplans")), new("Story world", S("assets"))), + new("tools", "Tools", new("Reference", S("bible")), new("Insights", S("metrics"), S("health"), S("warnings")), new("Organisation", S("archive"))), + new("help", "Help", new RibbonGroup("Support", new("Help Centre", "bible", "Help", "Index", "global"), new("Feature Requests", "review", "FeatureRequests", "Index", "global"))) + ]; + public static string ActiveCategory(string controller, string section) => controller switch + { + "Books" or "Chapters" or "Scenes" => "book", "Help" or "FeatureRequests" => "help", + "Onboarding" => "story", + _ => section switch + { + "Timeline" or "Calendar" or "At This Point" or "Threads" or "Scenarios" or "Continuity Explorer" => "story", + "Characters" or "Names" or "Relationships" => "characters", + "Locations" or "Assets" or "Floor Plans" => "world", + "Story Bible" or "Metrics" or "Health" or "Warnings" or "Archive" => "tools", _ => "project" + } + }; + public static ToolbarCommand Icon(string key) => ToolbarCommands.All.Single(x => x.Key == key); + public static string Tone(string key) => key switch + { + "calendar" or "point" => "calendar", "characters" or "names" => "characters", "locations" or "floorplans" => "locations", + "relationships" => "relationships", "warnings" => "warning", "review" => "review", "bible" or "overview" or "projects" => "books", _ => "planning" + }; +} diff --git a/PlotLine/Sql/202_UserApplicationAppearance.sql b/PlotLine/Sql/202_UserApplicationAppearance.sql new file mode 100644 index 00000000..5da7b930 --- /dev/null +++ b/PlotLine/Sql/202_UserApplicationAppearance.sql @@ -0,0 +1,33 @@ +SET ANSI_NULLS ON; +GO +SET QUOTED_IDENTIFIER ON; +GO +IF COL_LENGTH(N'dbo.AppUser', N'ApplicationThemeKey') IS NULL + ALTER TABLE dbo.AppUser ADD ApplicationThemeKey nvarchar(32) NULL; +IF COL_LENGTH(N'dbo.AppUser', N'RibbonCollapsed') IS NULL + ALTER TABLE dbo.AppUser ADD RibbonCollapsed bit NOT NULL CONSTRAINT DF_AppUser_RibbonCollapsed DEFAULT 0; +GO +CREATE OR ALTER PROCEDURE dbo.UserAppearance_Get @UserID int +AS +BEGIN + SET NOCOUNT ON; + SELECT ApplicationThemeKey AS ThemeKey, RibbonCollapsed FROM dbo.AppUser WHERE UserID = @UserID; +END; +GO +CREATE OR ALTER PROCEDURE dbo.UserAppearance_SaveTheme @UserID int, @ThemeKey nvarchar(32), @OnlyIfUnset bit = 0 +AS +BEGIN + SET NOCOUNT ON; + IF @ThemeKey NOT IN ('modern-light','modern-dark','warm-light','warm-dark') OR @ThemeKey IS NULL + THROW 50001, 'Unknown application theme', 1; + UPDATE dbo.AppUser SET ApplicationThemeKey = @ThemeKey + WHERE UserID = @UserID AND (@OnlyIfUnset = 0 OR ApplicationThemeKey IS NULL); +END; +GO +CREATE OR ALTER PROCEDURE dbo.UserAppearance_SaveRibbon @UserID int, @Collapsed bit +AS +BEGIN + SET NOCOUNT ON; + UPDATE dbo.AppUser SET RibbonCollapsed = @Collapsed WHERE UserID = @UserID; +END; +GO diff --git a/PlotLine/Views/Projects/Details.cshtml b/PlotLine/Views/Projects/Details.cshtml index e5e0a6b8..4d220823 100644 --- a/PlotLine/Views/Projects/Details.cshtml +++ b/PlotLine/Views/Projects/Details.cshtml @@ -2,6 +2,9 @@ @{ ViewData["Title"] = Model.Project.ProjectName; ViewData["ProjectSection"] = "Overview"; + ViewData["ShellClass"] = "pd-dashboard-shell"; + var statIcons = new[] { "bible", "bible", "writer", "threads", "metrics", "characters", "locations", "threads", "warnings" }; + var statIndex = 0; var summaryCards = new[] { @@ -17,6 +20,7 @@ }; } +