Add Plot Lines Manage workspace tab

This commit is contained in:
Codex 2026-12-05 18:07:51 +00:00
parent 4bae5d99cd
commit ad61c420a4
9 changed files with 127 additions and 83 deletions

View File

@ -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<IActionResult> 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<IActionResult> 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<IActionResult> Unattributed(int projectId, int? bookId, int? scenarioId)
{
var model = await workspace.GetAsync(projectId, bookId, [], [], scenarioId, false, true);

View File

@ -8,11 +8,8 @@ namespace PlotLine.Controllers;
[Authorize]
public sealed class PlotLinesController(IPlotService plots) : Controller
{
public async Task<IActionResult> 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<IActionResult> Create(int projectId)
{

View File

@ -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]

View File

@ -18,12 +18,10 @@
<h1>Plot Lines <help-icon key="plotLines.workspace" /></h1>
<p class="muted">Follow one line in Focus mode or select several to inspect the weave.</p>
</div>
<div class="button-row">
<a class="btn btn-outline-secondary" asp-controller="PlotLines" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Manage lines</a>
<a class="btn btn-outline-secondary" asp-controller="PlotThreads" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Manage threads</a>
</div>
</div>
<partial name="_PlanningRibbon" model="(Model.Project.ProjectID, Model.SelectedPlotLineIDs.Count == 1 ? (int?)Model.SelectedPlotLineIDs[0] : null, false, Model.PlotLines.Count > 0)" />
<form method="get" asp-action="Index" class="plot-workspace-controls" id="plot-workspace-form">
<input type="hidden" name="projectId" value="@Model.Project.ProjectID" />
<div class="plot-control-row">

View File

@ -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<int>();
async Task RenderLineAsync(PlotLine.Models.PlotLineItem line)
{
if (!displayed.Add(line.PlotLineID))
{
return;
}
<details class="border rounded px-3 py-2 mb-2">
<summary data-planning-line="@line.PlotLineID">
<span class="colour-swatch" style="background-color:@line.Colour"></span>
<strong>@line.PlotLineName</strong>
<small class="muted"> · @(line.BookID.HasValue ? line.BookTitle ?? "Book" : "Project-wide") · @line.PlotImportanceName</small>
</summary>
<div class="button-row my-2">
<a class="btn btn-outline-secondary btn-sm" asp-controller="PlotLines" asp-action="Edit" asp-route-id="@line.PlotLineID" data-planning-edit>Edit plot line</a>
<a class="btn btn-outline-secondary btn-sm" asp-controller="PlotThreads" asp-action="Create" asp-route-projectId="@projectId" asp-route-plotLineId="@line.PlotLineID" data-planning-add-thread>Add thread</a>
<a class="btn btn-outline-secondary btn-sm" asp-controller="Timeline" asp-action="Index" asp-route-projectId="@projectId" asp-route-FocusType="plotline" asp-route-FocusID="@line.PlotLineID">Focus scenes</a>
<form asp-controller="PlotLines" asp-action="Archive" method="post" class="archive-button-form" data-confirm-message="Archive this plot line? You can restore it from Archived Items.">
<input type="hidden" name="id" value="@line.PlotLineID" />
<input type="hidden" name="projectId" value="@projectId" />
<button class="btn btn-outline-danger btn-sm" type="submit">Archive</button>
</form>
</div>
@if (threads[line.PlotLineID].Any())
{
<ul class="mb-2">
@foreach (var thread in threads[line.PlotLineID])
{
<li><a asp-controller="PlotThreads" asp-action="Edit" asp-route-id="@thread.PlotThreadID">@thread.ThreadTitle</a></li>
}
</ul>
}
@foreach (var child in children[line.PlotLineID])
{
await RenderLineAsync(child);
}
</details>
}
}
<div data-pwa-header class="page-heading">
<h1>Plot Lines <help-icon key="plotLines.index" /></h1>
</div>
<partial name="_PlanningRibbon" model="(projectId, (int?)null, true, lines.Count > 0)" />
@if (lines.Count == 0)
{
<p class="muted">No plot lines yet. Add a plot line to start planning.</p>
}
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 {
<script src="~/js/plot-line-manage.js" asp-append-version="true"></script>
}

View File

@ -0,0 +1,15 @@
@model (int ProjectId, int? SelectedLineId, bool Manage, bool HasLines)
<nav class="nav nav-tabs mb-3" aria-label="Plot Lines views">
<a class="nav-link @(!Model.Manage ? "active" : "")" aria-current="@(!Model.Manage ? "page" : null)" asp-controller="PlotLineWorkspace" asp-action="Index" asp-route-projectId="@Model.ProjectId">Visual</a>
<a class="nav-link @(Model.Manage ? "active" : "")" aria-current="@(Model.Manage ? "page" : null)" asp-controller="PlotLineWorkspace" asp-action="Manage" asp-route-projectId="@Model.ProjectId">Manage</a>
</nav>
<div class="button-row mb-3">
<a class="btn btn-primary" asp-controller="PlotLines" asp-action="Create" asp-route-projectId="@Model.ProjectId">Add plot line</a>
@if (Model.HasLines)
{
<a class="btn btn-outline-secondary" id="planning-edit-line"
href="@(Model.SelectedLineId is int id ? Url.Action("Edit", "PlotLines", new { id }) : null)"
hidden="@(!Model.SelectedLineId.HasValue)">Edit plot line</a>
<a class="btn btn-outline-secondary" id="planning-add-thread" asp-controller="PlotThreads" asp-action="Create" asp-route-projectId="@Model.ProjectId" asp-route-plotLineId="@Model.SelectedLineId">Add thread</a>
}
</div>

View File

@ -1,70 +0,0 @@
@model PlotLineListViewModel
@{
ViewData["DesktopLayout"] = "management";
ViewData["Title"] = "Plot Lines";
ViewData["ProjectSection"] = "Threads";
}
<nav data-pwa-identity class="breadcrumb-trail" aria-label="Breadcrumb">
<a asp-controller="Projects" asp-action="Index">Projects</a>
<a asp-controller="Projects" asp-action="Details" asp-route-id="@Model.Project.ProjectID">@Model.Project.ProjectName</a>
<span>Plot lines</span>
</nav>
<partial name="_ProjectSectionNav" model="Model.Project" />
<div data-pwa-header class="page-heading">
<div>
<p class="eyebrow"><a asp-controller="Projects" asp-action="Details" asp-route-id="@Model.Project.ProjectID">@Model.Project.ProjectName</a></p>
<h1>Plot lines <help-icon key="plotLines.index" /></h1>
</div>
<div class="button-row">
<a class="btn btn-primary" asp-action="Create" asp-route-projectId="@Model.Project.ProjectID">Add plot line</a>
</div>
</div>
<section class="list-section">
@if (!Model.PlotLines.Any())
{
<p class="muted">No plot lines yet. Add one to create the first timeline lane.</p>
}
else
{
<div class="table-responsive">
<table class="table align-middle">
<thead>
<tr>
<th>Colour</th>
<th>Name</th>
<th>Type</th>
<th>Importance</th>
<th>Book</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var plotLine in Model.PlotLines)
{
<tr data-pd-context="plot line" data-pd-context-id="@plotLine.PlotLineID" data-pd-context-label="@plotLine.PlotLineName">
<td><span class="colour-swatch" style="background:@plotLine.Colour"></span></td>
<td><a asp-action="Edit" asp-route-id="@plotLine.PlotLineID">@plotLine.PlotLineName</a></td>
<td>@plotLine.PlotLineTypeName</td>
<td>@plotLine.PlotImportanceName</td>
<td>@(plotLine.BookTitle ?? "Project-wide")</td>
<td class="text-end">
<a class="btn btn-outline-secondary btn-sm" asp-controller="Timeline" asp-action="Index" asp-route-ProjectID="@Model.Project.ProjectID" asp-route-FocusType="plotline" asp-route-FocusID="@plotLine.PlotLineID">Focus scenes</a>
<a class="btn btn-outline-secondary btn-sm" asp-controller="PlotThreads" asp-action="Create" asp-route-projectId="@Model.Project.ProjectID" asp-route-plotLineId="@plotLine.PlotLineID">Add thread</a>
<a class="btn btn-outline-secondary btn-sm" asp-action="Edit" asp-route-id="@plotLine.PlotLineID">Edit</a>
<form asp-action="Archive" method="post" class="archive-button-form" data-confirm-message="Archive this plot line?&#10;&#10;This will hide it from active lists and timelines, but the data will be kept and can be restored later.">
<input type="hidden" name="id" value="@plotLine.PlotLineID" />
<input type="hidden" name="projectId" value="@Model.Project.ProjectID" />
<button class="btn btn-outline-danger btn-sm" type="submit">Archive</button>
</form>
</td>
</tr>
}
</tbody>
</table>
</div>
}
</section>

View File

@ -10,7 +10,7 @@
<nav data-pwa-identity class="breadcrumb-trail" aria-label="Breadcrumb">
<a asp-controller="Projects" asp-action="Index">Projects</a>
<a asp-controller="Projects" asp-action="Details" asp-route-id="@Model.Project.ProjectID">@Model.Project.ProjectName</a>
<a asp-action="Index" asp-route-projectId="@Model.ProjectID">Plot threads</a>
<a asp-controller="PlotLineWorkspace" asp-action="Manage" asp-route-projectId="@Model.ProjectID">Plot threads</a>
<span>@ViewData["Title"]</span>
</nav>
@ -23,7 +23,7 @@
<h1>@ViewData["Title"] <help-icon key="plotThreads.edit" /></h1>
</div>
<div class="button-row">
<a class="btn btn-outline-secondary" data-pwa-icon="close" asp-action="Index" asp-route-projectId="@Model.ProjectID">Cancel</a>
<a class="btn btn-outline-secondary" data-pwa-icon="close" asp-controller="PlotLineWorkspace" asp-action="Manage" asp-route-projectId="@Model.ProjectID">Cancel</a>
@if (Model.PlotThreadID > 0)
{
<form asp-action="Archive" method="post" class="archive-button-form" data-confirm-message="Archive this plot thread?&#10;&#10;This will hide it from active lists and timelines, but the data will be kept and can be restored later.">

View File

@ -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));
});
})();