diff --git a/PlotLine/Controllers/PlotLineWorkspaceController.cs b/PlotLine/Controllers/PlotLineWorkspaceController.cs index 40c9929b..32962f0a 100644 --- a/PlotLine/Controllers/PlotLineWorkspaceController.cs +++ b/PlotLine/Controllers/PlotLineWorkspaceController.cs @@ -5,7 +5,7 @@ using PlotLine.Services; namespace PlotLine.Controllers; [Authorize] -public sealed class PlotLineWorkspaceController(IPlotLineWorkspaceService workspace) : Controller +public sealed class PlotLineWorkspaceController(IPlotLineWorkspaceService workspace, IPlotService plots) : Controller { public async Task Index( int projectId, @@ -19,6 +19,18 @@ public sealed class PlotLineWorkspaceController(IPlotLineWorkspaceService worksp return model is null ? NotFound() : Request.Headers["X-Plot-Map"] == "true" ? PartialView("_NarrativeMap", model) : View(model); } + public async Task Manage(int projectId) + { + var lines = await plots.GetPlotLinesAsync(projectId); + if (lines is null) + { + return NotFound(); + } + + var threads = await plots.GetPlotThreadsAsync(projectId); + return threads is null ? NotFound() : View((lines, threads)); + } + public async Task Unattributed(int projectId, int? bookId, int? scenarioId) { var model = await workspace.GetAsync(projectId, bookId, [], [], scenarioId, false, true); diff --git a/PlotLine/Controllers/PlotLinesController.cs b/PlotLine/Controllers/PlotLinesController.cs index bf1b28cc..d859b3ba 100644 --- a/PlotLine/Controllers/PlotLinesController.cs +++ b/PlotLine/Controllers/PlotLinesController.cs @@ -8,11 +8,8 @@ namespace PlotLine.Controllers; [Authorize] public sealed class PlotLinesController(IPlotService plots) : Controller { - public async Task Index(int projectId) - { - var model = await plots.GetPlotLinesAsync(projectId); - return model is null ? NotFound() : View(model); - } + public IActionResult Index(int projectId) => + RedirectToAction("Manage", "PlotLineWorkspace", new { projectId }); public async Task Create(int projectId) { diff --git a/PlotLine/Controllers/PlotThreadsController.cs b/PlotLine/Controllers/PlotThreadsController.cs index bee8f442..cc9f7cbc 100644 --- a/PlotLine/Controllers/PlotThreadsController.cs +++ b/PlotLine/Controllers/PlotThreadsController.cs @@ -36,7 +36,7 @@ public sealed class PlotThreadsController(IPlotService plots) : Controller } await plots.SavePlotThreadAsync(model); - return RedirectToAction(nameof(Index), new { projectId = model.ProjectID }); + return RedirectToAction("Manage", "PlotLineWorkspace", new { projectId = model.ProjectID }); } [HttpPost] diff --git a/PlotLine/Views/PlotLineWorkspace/Index.cshtml b/PlotLine/Views/PlotLineWorkspace/Index.cshtml index f9283cf5..fe80f289 100644 --- a/PlotLine/Views/PlotLineWorkspace/Index.cshtml +++ b/PlotLine/Views/PlotLineWorkspace/Index.cshtml @@ -18,12 +18,10 @@

Plot Lines

Follow one line in Focus mode or select several to inspect the weave.

- + +
diff --git a/PlotLine/Views/PlotLineWorkspace/Manage.cshtml b/PlotLine/Views/PlotLineWorkspace/Manage.cshtml new file mode 100644 index 00000000..64b465e9 --- /dev/null +++ b/PlotLine/Views/PlotLineWorkspace/Manage.cshtml @@ -0,0 +1,75 @@ +@model (PlotLineListViewModel Lines, PlotThreadListViewModel Threads) +@{ + ViewData["Title"] = "Plot Lines"; + ViewData["ProjectSection"] = "Plot Lines"; + var projectId = Model.Lines.Project.ProjectID; + var lines = Model.Lines.PlotLines; + var lineIds = lines.Select(line => line.PlotLineID).ToHashSet(); + var children = lines.ToLookup(line => line.ParentPlotLineID); + var threads = Model.Threads.PlotThreads.ToLookup(thread => thread.PlotLineID); + var displayed = new HashSet(); + + async Task RenderLineAsync(PlotLine.Models.PlotLineItem line) + { + if (!displayed.Add(line.PlotLineID)) + { + return; + } +
+ + + @line.PlotLineName + · @(line.BookID.HasValue ? line.BookTitle ?? "Book" : "Project-wide") · @line.PlotImportanceName + +
+ Edit plot line + Add thread + Focus scenes + + + + + +
+ @if (threads[line.PlotLineID].Any()) + { + + } + @foreach (var child in children[line.PlotLineID]) + { + await RenderLineAsync(child); + } +
+ } +} + +
+

Plot Lines

+
+ + + +@if (lines.Count == 0) +{ +

No plot lines yet. Add a plot line to start planning.

+} +else +{ + @foreach (var line in lines.Where(line => line.ParentPlotLineID is not int parent || !lineIds.Contains(parent))) + { + await RenderLineAsync(line); + } + @foreach (var line in lines.Where(line => !displayed.Contains(line.PlotLineID))) + { + await RenderLineAsync(line); + } +} + +@section Scripts { + +} diff --git a/PlotLine/Views/PlotLineWorkspace/_PlanningRibbon.cshtml b/PlotLine/Views/PlotLineWorkspace/_PlanningRibbon.cshtml new file mode 100644 index 00000000..5a7c408e --- /dev/null +++ b/PlotLine/Views/PlotLineWorkspace/_PlanningRibbon.cshtml @@ -0,0 +1,15 @@ +@model (int ProjectId, int? SelectedLineId, bool Manage, bool HasLines) + +
+ Add plot line + @if (Model.HasLines) + { + + Add thread + } +
diff --git a/PlotLine/Views/PlotLines/Index.cshtml b/PlotLine/Views/PlotLines/Index.cshtml deleted file mode 100644 index 5076f7d4..00000000 --- a/PlotLine/Views/PlotLines/Index.cshtml +++ /dev/null @@ -1,70 +0,0 @@ -@model PlotLineListViewModel -@{ - ViewData["DesktopLayout"] = "management"; - ViewData["Title"] = "Plot Lines"; - ViewData["ProjectSection"] = "Threads"; -} - - - - - -
-
-

@Model.Project.ProjectName

-

Plot lines

-
- -
- -
- @if (!Model.PlotLines.Any()) - { -

No plot lines yet. Add one to create the first timeline lane.

- } - else - { -
- - - - - - - - - - - - - @foreach (var plotLine in Model.PlotLines) - { - - - - - - - - - } - -
ColourNameTypeImportanceBook
@plotLine.PlotLineName@plotLine.PlotLineTypeName@plotLine.PlotImportanceName@(plotLine.BookTitle ?? "Project-wide") - Focus scenes - Add thread - Edit -
- - - -
-
-
- } -
diff --git a/PlotLine/Views/PlotThreads/Edit.cshtml b/PlotLine/Views/PlotThreads/Edit.cshtml index 31fdde64..a223c31c 100644 --- a/PlotLine/Views/PlotThreads/Edit.cshtml +++ b/PlotLine/Views/PlotThreads/Edit.cshtml @@ -10,7 +10,7 @@ @@ -23,7 +23,7 @@

@ViewData["Title"]

- Cancel + Cancel @if (Model.PlotThreadID > 0) {
diff --git a/PlotLine/wwwroot/js/plot-line-manage.js b/PlotLine/wwwroot/js/plot-line-manage.js new file mode 100644 index 00000000..ef8c2f56 --- /dev/null +++ b/PlotLine/wwwroot/js/plot-line-manage.js @@ -0,0 +1,17 @@ +(() => { + const editLine = document.getElementById("planning-edit-line"); + const addThread = document.getElementById("planning-add-thread"); + + document.querySelectorAll("[data-planning-line]").forEach(summary => { + const actions = summary.nextElementSibling; + const editUrl = actions.querySelector("[data-planning-edit]").href; + const addThreadUrl = actions.querySelector("[data-planning-add-thread]").href; + + summary.addEventListener("click", () => { + editLine.href = editUrl; + editLine.hidden = false; + addThread.href = addThreadUrl; + }); + summary.addEventListener("dblclick", () => window.location.assign(editUrl)); + }); +})();