fix: restore dedicated scene creation form and workspace handoff
This commit is contained in:
parent
299500f92a
commit
aa839d3b0b
71
PlotLine.Tests/Browser/scene-creation-acceptance.cjs
Normal file
71
PlotLine.Tests/Browser/scene-creation-acceptance.cjs
Normal file
@ -0,0 +1,71 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const {open} = require('./dev-acceptance.cjs');
|
||||
let session;
|
||||
let stage = 'login';
|
||||
(async () => {
|
||||
try {
|
||||
session = await open();
|
||||
const project = await session.project();
|
||||
const book = await session.create('Books', '?projectId='+project, {BookTitle:'Scene creation acceptance',BookNumber:1});
|
||||
const chapter = await session.create('Chapters','?bookId='+book,{ChapterTitle:'Disposable scene chapter',ChapterNumber:1});
|
||||
const page = session.page;
|
||||
const chapterUrl = '/Chapters/Details/'+chapter;
|
||||
const rows = () => page.locator('a[href^="/Scenes/Edit/"]');
|
||||
stage = 'cancel';
|
||||
await session.goto(chapterUrl);
|
||||
const before = await rows().count();
|
||||
await page.getByRole('link',{name:'Add scene',exact:true}).click();
|
||||
await page.locator('#scene-create-form').waitFor();
|
||||
assert.equal(await page.locator('#ChapterID').inputValue(),String(chapter));
|
||||
assert.equal(await page.locator('#SceneNumber').inputValue(),'1');
|
||||
await page.locator('#SceneTitle').fill('Cancelled scene');
|
||||
await page.getByRole('link',{name:'Cancel',exact:true}).click();
|
||||
await page.reload();
|
||||
assert.equal(await rows().count(),before);
|
||||
stage = 'validation';
|
||||
await page.getByRole('link',{name:'Add scene',exact:true}).click();
|
||||
await page.locator('#scene-create-form').waitFor();
|
||||
await page.getByRole('button',{name:'Create scene',exact:true}).click();
|
||||
assert.equal(await page.locator('#scene-create-form').count(),1);
|
||||
// Bypass only client validation to exercise the server's invalid-model path.
|
||||
await page.locator('#Summary').fill('Preserved after invalid submission');
|
||||
await page.locator('#scene-create-form').evaluate(form=>HTMLFormElement.prototype.submit.call(form));
|
||||
await page.waitForURL('**/Scenes/Save');
|
||||
assert.equal(await page.locator('#Summary').inputValue(),'Preserved after invalid submission');
|
||||
assert.match(await page.locator('[data-valmsg-for="SceneTitle"]').innerText(),/required/i);
|
||||
stage = 'create';
|
||||
await page.locator('#SceneTitle').fill('Persisted acceptance scene');
|
||||
await page.getByRole('button',{name:'Create scene',exact:true}).click();
|
||||
await page.waitForURL('**/Scenes/Edit/*');
|
||||
const sceneUrl = new URL(page.url()).pathname;
|
||||
await page.reload();
|
||||
assert.match(await page.locator('main').innerText(),/Persisted acceptance scene/);
|
||||
await session.goto(chapterUrl);
|
||||
assert.equal(await rows().count(),before+1);
|
||||
const row = page.locator('tr').filter({hasText:'Persisted acceptance scene'});
|
||||
assert.match(await row.innerText(),/1/);
|
||||
stage = 'existing edit';
|
||||
await session.goto(sceneUrl);
|
||||
await page.getByRole('button',{name:'Edit scene details',exact:true}).click();
|
||||
const editor = page.locator('form[data-scene-editor-form]');
|
||||
await editor.locator('[name=SceneTitle]').fill('Edited acceptance scene');
|
||||
await editor.getByRole('button',{name:'Save details',exact:true}).click();
|
||||
await page.locator('[data-scene-editor-overlay]').waitFor({state:'hidden'});
|
||||
await page.reload();
|
||||
assert.match(await page.locator('main').innerText(),/Edited acceptance scene/);
|
||||
stage = 'sequence';
|
||||
await session.goto('/Scenes/Create?chapterId='+chapter);
|
||||
assert.equal(await page.locator('#SceneNumber').inputValue(),'2');
|
||||
await page.getByRole('link',{name:'Cancel',exact:true}).click();
|
||||
await session.close();
|
||||
session = await open();
|
||||
stage = 'fresh login persistence';
|
||||
await session.goto(sceneUrl);
|
||||
assert.match(await session.page.locator('main').innerText(),/Edited acceptance scene/);
|
||||
await session.page.getByRole('button',{name:'Edit scene details',exact:true}).click();
|
||||
assert.equal(await session.page.locator('form[data-scene-editor-form] [name=Summary]').inputValue(),'Preserved after invalid submission');
|
||||
console.log(JSON.stringify({status:'passed',checks:['cancel without mutation','required title client and server validation','field preservation','chapter context and sequence','creation workspace redirect','existing workspace editing','reload and fresh login persistence'],featureUrl:'https://dev.plotdirector.com'+sceneUrl,chapterUrl:'https://dev.plotdirector.com'+chapterUrl}));
|
||||
} finally {
|
||||
if(session) {try {await session.cleanup();console.log('PASS disposable project cleanup');} finally {await session.close();}}
|
||||
}
|
||||
})().catch(()=>{console.error('Scene creation acceptance failed at stage: '+stage+'; no credentials logged.');process.exitCode=1;});
|
||||
@ -15,6 +15,7 @@ using PlotLine.Models;
|
||||
using PlotLine.Services;
|
||||
using PlotLine.ViewModels;
|
||||
|
||||
if(args.Contains("--scene-creation")){await SceneCreationTests.Run();return;}
|
||||
if(args.Contains("--help-visibility")){HelpVisibilityTests.Run();return;}
|
||||
if(args.Contains("--application-domain")){ApplicationDomainBoundaryTests.Run();return;}
|
||||
if(args.Contains("--spatial-context-database")){await SpatialContextDatabaseTests.Run(args.Last());return;}
|
||||
|
||||
50
PlotLine.Tests/SceneCreationTests.cs
Normal file
50
PlotLine.Tests/SceneCreationTests.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PlotLine.Controllers;
|
||||
using PlotLine.Services;
|
||||
using PlotLine.ViewModels;
|
||||
|
||||
internal static class SceneCreationTests
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var saves = 0;
|
||||
var limited = false;
|
||||
var model = new SceneEditViewModel { ChapterID = 42, SceneNumber = 3, SceneTitle = "Draft" };
|
||||
var service = DispatchProxy.Create<ISceneService, StoryPointProxy>();
|
||||
((StoryPointProxy)(object)service).Handler = (method, args) => method switch
|
||||
{
|
||||
"GetCreateAsync" => Task.FromResult<SceneEditViewModel?>((int)args![0]! == 42
|
||||
? new SceneEditViewModel { ChapterID = 42, SceneNumber = 3 } : null),
|
||||
"GetEditAsync" => Task.FromResult<SceneEditViewModel?>(model),
|
||||
"SaveAsync" => Save(),
|
||||
_ => throw new InvalidOperationException(method)
|
||||
};
|
||||
Task<int> Save()
|
||||
{
|
||||
saves++;
|
||||
return limited ? Task.FromException<int>(new SubscriptionLimitException("Scene limit reached")) : Task.FromResult(81);
|
||||
}
|
||||
ScenesController Controller() => new(service, null!, null!, null!, null!, null!, null!, null!, null!);
|
||||
void Check(bool value, string message) { if (!value) throw new Exception(message); }
|
||||
var controller = Controller();
|
||||
Check(await controller.Create(999) is NotFoundResult, "Unknown chapter must not show creation form");
|
||||
Check(await controller.Create(42) is ViewResult { ViewName: "Create", Model: SceneEditViewModel { ChapterID: 42, SceneNumber: 3 } }, "Creation must use dedicated form and chapter defaults");
|
||||
controller.ModelState.AddModelError("SceneTitle", "Required");
|
||||
var invalid = (ViewResult)await controller.Save(model);
|
||||
Check(invalid.ViewName == "Create" && ((SceneEditViewModel)invalid.Model!).SceneTitle == "Draft" && saves == 0, "Invalid creation must preserve fields without saving");
|
||||
limited = true;
|
||||
controller = Controller();
|
||||
var limit = (ViewResult)await controller.Save(model);
|
||||
Check(limit.ViewName == "Create" && !controller.ModelState.IsValid, "Creation limit must return usable form with error");
|
||||
limited = false;
|
||||
controller = Controller();
|
||||
var saved = (RedirectToActionResult)await controller.Save(model);
|
||||
Check(saved.ActionName == "Edit" && (int)saved.RouteValues!["id"]! == 81, "New scene must open persisted workspace");
|
||||
model.SceneID = 81;
|
||||
controller = Controller();
|
||||
controller.ModelState.AddModelError("SceneTitle", "Required");
|
||||
Check(await controller.Save(model) is ViewResult { ViewName: "Edit" }, "Invalid existing edits must retain workspace");
|
||||
Console.WriteLine("PASS scene creation routes, chapter defaults, validation preservation, limits and persisted workspace redirect");
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ public sealed class ScenesController(
|
||||
public async Task<IActionResult> Create(int chapterId)
|
||||
{
|
||||
var model = await scenes.GetCreateAsync(chapterId);
|
||||
return model is null ? NotFound() : View("Edit", model);
|
||||
return model is null ? NotFound() : View("Create", model);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Edit(int id)
|
||||
@ -49,7 +49,7 @@ public sealed class ScenesController(
|
||||
}
|
||||
|
||||
CopyPostedSceneFields(model, hydratedModel);
|
||||
return View("Edit", hydratedModel);
|
||||
return View(model.SceneID == 0 ? "Create" : "Edit", hydratedModel);
|
||||
}
|
||||
|
||||
int sceneId;
|
||||
@ -67,7 +67,12 @@ public sealed class ScenesController(
|
||||
}
|
||||
|
||||
CopyPostedSceneFields(model, createModel);
|
||||
return View("Edit", createModel);
|
||||
return View("Create", createModel);
|
||||
}
|
||||
|
||||
if (model.SceneID == 0)
|
||||
{
|
||||
return RedirectToAction(nameof(Edit), new { id = sceneId });
|
||||
}
|
||||
|
||||
if (TryGetLocalReturnUrl(out var returnUrl))
|
||||
@ -1728,6 +1733,7 @@ public sealed class ScenesController(
|
||||
target.SceneTitle = source.SceneTitle;
|
||||
target.SceneNumber = source.SceneNumber;
|
||||
target.Summary = source.Summary;
|
||||
target.POVCharacterID = source.POVCharacterID;
|
||||
target.TimeModeID = source.TimeModeID;
|
||||
target.StartDateTime = source.StartDateTime;
|
||||
target.EndDateTime = source.EndDateTime;
|
||||
|
||||
@ -22,6 +22,8 @@ Use this page when creating a new story beat, adjusting an existing scene, or ch
|
||||
|
||||
# How To Use It
|
||||
|
||||
From Chapter Details, choose **Add scene** to open the New Scene form for that chapter. Enter a scene title and review the suggested scene number and revision status. **Create scene** saves it and opens the persisted Scene Workspace. **Cancel** returns to Chapter Details without creating a scene. Validation messages keep your entered values in the form so you can correct them.
|
||||
|
||||
Start with the scene title, summary and revision status. Add time, location and point-of-view details when they matter. Record enough continuity information that later scenes can rely on it.
|
||||
|
||||
# Example
|
||||
|
||||
126
PlotLine/Views/Scenes/Create.cshtml
Normal file
126
PlotLine/Views/Scenes/Create.cshtml
Normal file
@ -0,0 +1,126 @@
|
||||
@model SceneEditViewModel
|
||||
@{
|
||||
ViewData["Title"] = "New Scene";
|
||||
ViewData["ProjectSection"] = "Overview";
|
||||
ViewData["ShellClass"] = "plotline-shell-wide";
|
||||
}
|
||||
|
||||
<div data-focus-scene="@Model.SceneID" data-project="@Model.Project?.ProjectID" data-book="@Model.Book?.BookID">
|
||||
<nav data-pwa-identity class="breadcrumb-trail" aria-label="Breadcrumb">
|
||||
<a asp-controller="Projects" asp-action="Index">Projects</a>
|
||||
@if (Model.Project is not null)
|
||||
{
|
||||
<a asp-controller="Projects" asp-action="Details" asp-route-id="@Model.Project.ProjectID">@Model.Project.ProjectName</a>
|
||||
}
|
||||
@if (Model.Book is not null)
|
||||
{
|
||||
<a asp-controller="Books" asp-action="Details" asp-route-id="@Model.Book.BookID">@Model.Book.BookTitle</a>
|
||||
}
|
||||
@if (Model.Chapter is not null)
|
||||
{
|
||||
<a asp-controller="Chapters" asp-action="Details" asp-route-id="@Model.ChapterID">Chapter @Model.Chapter.ChapterNumber</a>
|
||||
}
|
||||
<span>@(Model.SceneID == 0 ? "New scene" : $"Scene {Model.SceneNumber}")</span>
|
||||
</nav>
|
||||
|
||||
@if (Model.Project is not null)
|
||||
{
|
||||
<partial name="_ProjectSectionNav" model="Model.Project" />
|
||||
}
|
||||
|
||||
<div class="page-heading compact">
|
||||
<div>
|
||||
<p class="eyebrow">@Model.Book?.BookTitle / Chapter @Model.Chapter?.ChapterNumber</p>
|
||||
<h1>New Scene <help-icon key="scenes.edit" /></h1>
|
||||
<p>Create the scene, then continue in its Scene Workspace.</p>
|
||||
</div>
|
||||
</div>
|
||||
<section class="edit-panel">
|
||||
<form asp-controller="Scenes" asp-action="Save" method="post" class="pd-record-form" id="scene-create-form">
|
||||
<input asp-for="SceneID" type="hidden" />
|
||||
<input asp-for="ChapterID" type="hidden" />
|
||||
<div asp-validation-summary="All" class="text-danger" role="alert"></div>
|
||||
<fieldset>
|
||||
<legend>Scene details</legend>
|
||||
<div class="form-group"><label asp-for="SceneTitle"></label>
|
||||
<input asp-for="SceneTitle" class="form-control" />
|
||||
<span asp-validation-for="SceneTitle" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="SceneNumber"></label>
|
||||
<input asp-for="SceneNumber" class="form-control" step="0.01" />
|
||||
<span asp-validation-for="SceneNumber" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="RevisionStatusID"></label>
|
||||
<select asp-for="RevisionStatusID" asp-items="Model.RevisionStatuses" class="form-select"></select>
|
||||
<span asp-validation-for="RevisionStatusID" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="Summary"></label>
|
||||
<textarea asp-for="Summary" class="form-control" rows="4"></textarea>
|
||||
<span asp-validation-for="Summary" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="POVCharacterID"></label>
|
||||
<select asp-for="POVCharacterID" asp-items="Model.CharacterOptions" class="form-select"><option value="">None</option></select>
|
||||
<span asp-validation-for="POVCharacterID" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="PrimaryLocationID"></label>
|
||||
<select asp-for="PrimaryLocationID" asp-items="Model.LocationOptions" class="form-select"><option value="">None</option></select>
|
||||
<span asp-validation-for="PrimaryLocationID" class="text-danger"></span></div>
|
||||
</fieldset>
|
||||
<fieldset><legend>Timing</legend>
|
||||
<div class="form-group"><label asp-for="TimeModeID"></label>
|
||||
<select asp-for="TimeModeID" asp-items="Model.TimeModes" class="form-select"></select>
|
||||
<span asp-validation-for="TimeModeID" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="TimeConfidenceID"></label>
|
||||
<select asp-for="TimeConfidenceID" asp-items="Model.TimeConfidences" class="form-select"></select>
|
||||
<span asp-validation-for="TimeConfidenceID" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="StartDateTime"></label>
|
||||
<input asp-for="StartDateTime" class="form-control" type="datetime-local" asp-format="{0:yyyy-MM-ddTHH:mm}" />
|
||||
<span asp-validation-for="StartDateTime" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="EndDateTime"></label>
|
||||
<input asp-for="EndDateTime" class="form-control" type="datetime-local" asp-format="{0:yyyy-MM-ddTHH:mm}" />
|
||||
<span asp-validation-for="EndDateTime" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="DurationAmount"></label>
|
||||
<input asp-for="DurationAmount" class="form-control" step="0.01" />
|
||||
<span asp-validation-for="DurationAmount" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="DurationUnitID"></label>
|
||||
<select asp-for="DurationUnitID" asp-items="Model.DurationUnits" class="form-select"><option value="">None</option></select>
|
||||
<span asp-validation-for="DurationUnitID" class="text-danger"></span></div>
|
||||
<div class="form-group"><label asp-for="RelativeTimeText"></label>
|
||||
<input asp-for="RelativeTimeText" class="form-control" />
|
||||
<span asp-validation-for="RelativeTimeText" class="text-danger"></span></div>
|
||||
</fieldset>
|
||||
<fieldset><legend>Purpose and outcome</legend>
|
||||
@foreach (var purpose in Model.ScenePurposeTypes)
|
||||
{
|
||||
<label class="purpose-check">
|
||||
<input type="checkbox" name="SelectedPurposeTypeIds" value="@purpose.ScenePurposeTypeID" checked="@(Model.SelectedPurposeTypeIds.Contains(purpose.ScenePurposeTypeID))" />
|
||||
<span>@purpose.PurposeName</span>
|
||||
</label>
|
||||
}
|
||||
<div class="form-group"><label asp-for="ScenePurposeNotes"></label><textarea asp-for="ScenePurposeNotes" class="form-control" rows="3"></textarea></div>
|
||||
<div class="form-group"><label asp-for="SceneOutcomeNotes"></label><textarea asp-for="SceneOutcomeNotes" class="form-control" rows="3"></textarea></div>
|
||||
</fieldset>
|
||||
@if (Model.Metrics.Count > 0)
|
||||
{
|
||||
<fieldset><legend>Scene metrics</legend>
|
||||
@for (var index = 0; index < Model.Metrics.Count; index++)
|
||||
{
|
||||
<div class="form-group">
|
||||
<input asp-for="Metrics[index].MetricTypeID" type="hidden" />
|
||||
<input asp-for="Metrics[index].MetricName" type="hidden" />
|
||||
<input asp-for="Metrics[index].MinValue" type="hidden" />
|
||||
<input asp-for="Metrics[index].MaxValue" type="hidden" />
|
||||
<label asp-for="Metrics[index].Value">@Model.Metrics[index].MetricName</label>
|
||||
<input asp-for="Metrics[index].Value" class="form-control" min="@Model.Metrics[index].MinValue" max="@Model.Metrics[index].MaxValue" />
|
||||
<span asp-validation-for="Metrics[index].Value" class="text-danger"></span>
|
||||
<label asp-for="Metrics[index].Notes">@Model.Metrics[index].MetricName notes</label>
|
||||
<input asp-for="Metrics[index].Notes" class="form-control" />
|
||||
</div>
|
||||
}
|
||||
</fieldset>
|
||||
}
|
||||
<div class="button-row">
|
||||
<button type="submit" class="btn btn-primary">Create scene</button>
|
||||
<a class="btn btn-outline-secondary" asp-controller="Chapters" asp-action="Details" asp-route-id="@Model.ChapterID">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user