From 73f66b2f76b57c1bd6ab9fff4b5b0287a65ca004 Mon Sep 17 00:00:00 2001 From: nick Date: Mon, 16 Nov 2026 21:49:26 +0000 Subject: [PATCH] Separate Writer objective choices from recording activities --- PlotLine.Tests/Browser/writer3-focus.cjs | 4 ++-- PlotLine/Views/Shared/_WriterWorkToolbar.cshtml | 6 ++---- PlotLine/Views/Writer/_WriterFocusForm.cshtml | 1 - PlotLine/Views/Writer/_WriterWrite.cshtml | 2 +- PlotLine/wwwroot/js/writer-focus.js | 4 ++-- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/PlotLine.Tests/Browser/writer3-focus.cjs b/PlotLine.Tests/Browser/writer3-focus.cjs index 3c8ed48b..ec3891e1 100644 --- a/PlotLine.Tests/Browser/writer3-focus.cjs +++ b/PlotLine.Tests/Browser/writer3-focus.cjs @@ -5,14 +5,14 @@ let session=null,starts=[],saves=[],blockStart=null;await c.route('**/Writer/Wor await c.route('**/Writer/SaveObjective',async r=>{saves.push(Object.fromEntries(new URLSearchParams(r.request().postData())));assert(saves.at(-1).__RequestVerificationToken);await r.fulfill({status:200,contentType:'text/html',body:'

Working focus saved by fixture

'});}); const p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));const url='http://127.0.0.1:5238/Writer/Write?projectId=7&bookId=12'; await p.goto(url);await p.locator('[data-record-focus]:enabled').waitFor();for(const theme of ['modern-dark','modern-light','warm-dark','plotdirector']){await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);await p.locator('[data-save-focus]').screenshot({animations:'disabled'});const contrast=await p.locator('[data-save-focus]').evaluate(n=>{const lum=s=>s.match(/[\d.]+/g).slice(0,3).map(Number).map(x=>{x/=255;return x<=.04045?x/12.92:((x+.055)/1.055)**2.4}).reduce((v,x,i)=>v+x*[.2126,.7152,.0722][i],0),c=getComputedStyle(n),a=lum(c.color),b=lum(c.backgroundColor);return(Math.max(a,b)+.05)/(Math.min(a,b)+.05)});assert(contrast>=4.5,'Save focus label contrast '+theme);} -assert.equal(await p.locator('select[name=ChapterID]').count(),1);assert.equal(await p.locator('[data-work-start] select').count(),0,'one chapter/activity selection');assert.equal(await p.locator('[data-focus-activity]').count(),1); +assert.equal(await p.locator('select[name=ChapterID]').count(),1);assert.equal(await p.locator('[data-work-start] select').count(),2,'recording choices are separate from working focus');assert.equal(await p.locator('[data-focus-activity]').count(),1); await p.locator('[data-objective-chapter]').selectOption('21');await p.locator('[data-objective-scene]').selectOption('31');await p.locator('[data-objective-chapter]').selectOption('22');assert.equal(await p.locator('[data-objective-scene]').inputValue(),'');assert(await p.locator('[data-objective-scene] option[value="31"]').evaluate(n=>n.disabled));await p.locator('[data-objective-scene]').selectOption('32'); await Promise.all([p.waitForURL('**/Writer/SaveObjective'),p.locator('[data-focus-form]').evaluate(n=>{n.requestSubmit();n.requestSubmit();})]);assert.equal(saves.length,1,'repeated submit saves only once');assert.equal(saves[0].ChapterID,'22');assert.equal(saves[0].SceneID,'32');assert.equal(starts.length,0,'saving never starts recording'); await p.goto(url+'&objective=true');assert.equal(await p.locator('[data-focus-form]').count(),0,'saved focus is read-only by default');assert(await p.getByRole('link',{name:'Change working focus'}).isVisible());await p.locator('[data-record-focus]:enabled').waitFor();let release;blockStart=new Promise(r=>release=r);await p.locator('[data-record-focus]').click();await p.locator('[data-record-focus]').dispatchEvent('click');release();blockStart=null;await p.locator('[data-work-current]:visible').waitFor();assert.equal(starts.length,1);assert.equal(starts[0].chapterId,'21');assert.equal(starts[0].kind,'Editing');assert.equal(saves.length,1,'recording never saves objective');assert(await p.locator('[data-record-focus]').isHidden()); const activeId=session.sessionID;await p.goto(url+'&objective=true&setup=true');await p.locator('[data-work-current]:visible').waitFor();await p.locator('[data-objective-chapter]').selectOption('22');assert.equal(session.sessionID,activeId);assert.equal(session.chapterID,21);assert(await p.locator('[data-record-focus]').isHidden()); session={...session,chapterID:22,chapterTitle:'The harbour',kind:'Writing'};await p.reload();await p.locator('[data-focus-session-difference]:visible').waitFor();assert((await p.locator('[data-focus-session-difference]').textContent()).includes('differs'));assert((await p.locator('[data-work-bound]').textContent()).includes('The harbour')); session=null;await p.goto(url+'&setup=true');await p.locator('[data-record-focus]:enabled').waitFor();await p.locator('[data-focus-activity]').selectOption('Proofreading');await p.locator('[data-record-focus]').click();assert.equal(starts.length,1);assert(await p.locator('[data-record-kind-choice]').isVisible());await p.locator('[data-record-kind]').selectOption('Reading');await p.locator('[data-record-focus]').click();await p.locator('[data-work-current]:visible').waitFor();assert.equal(starts.at(-1).kind,'Reading'); -session=null;await p.goto(url+'&setup=true');await p.locator('[data-record-focus]:enabled').waitFor();await p.locator('[data-focus-activity]').selectOption('AudioReview');assert(await p.locator('[data-save-focus]').isDisabled());await p.locator('[data-record-focus]').click();assert.equal(starts.length,2,'Audio Review requires chapter');await p.locator('[data-objective-chapter]').selectOption('21');await p.locator('[data-record-focus]').click();await p.locator('[data-work-audio]:visible').waitFor();assert.equal(starts.at(-1).kind,'AudioReview'); +session=null;await p.goto(url+'&setup=true');await p.locator('[data-record-focus]:enabled').waitFor();assert.equal(await p.locator('[data-focus-activity] option[value=AudioReview]').count(),0);assert(await p.locator('[data-save-focus]').isEnabled());const recording=p.locator('[data-work-start]');await recording.locator('[name=kind]').selectOption('AudioReview');await recording.locator('[name=chapterId]').selectOption('');await recording.locator('button[type=submit]').click();assert.equal(starts.length,2,'Audio Review requires chapter');await recording.locator('[name=chapterId]').selectOption('21');await recording.locator('button[type=submit]').click();await p.locator('[data-work-audio]:visible').waitFor();assert.equal(starts.at(-1).kind,'AudioReview'); session=null;await p.goto(url+'&setup=true');await p.locator('[data-focus-activity]').selectOption('Editing');await p.locator('[data-plan-focus]').click();await p.waitForURL('**/Writer/ScheduleSetup?*');assert.equal(new URL(p.url()).searchParams.get('bookId'),'12');assert.equal(new URL(p.url()).searchParams.get('focusActivity'),'Editing');assert.equal(saves.length,1);assert.equal(starts.length,3); await p.goto(url+'&setup=true');await p.locator('#appBookMenu').click();await p.locator('[data-app-book-choice="13"]').click();await p.waitForURL('**bookId=13*');assert.equal(await p.locator('[data-objective-chapter] option[value="21"]').count(),0);assert.equal(await p.locator('[data-objective-scene]').inputValue(),'');assert.deepEqual(errors,[]);await c.close();} console.log('PASS unified current work: one selector set, save-only, explicit recording/idempotent repeat, saved display/change, active/mismatched targets, explicit proofreading choice, AudioReview chapter rule, dependent scenes, optional scoped scheduling and book-switch clearing in browser/simulated PWA.');}finally{await b.close()}})().catch(e=>{console.error(e.stack);process.exitCode=1}); diff --git a/PlotLine/Views/Shared/_WriterWorkToolbar.cshtml b/PlotLine/Views/Shared/_WriterWorkToolbar.cshtml index 2d556823..ce4d8781 100644 --- a/PlotLine/Views/Shared/_WriterWorkToolbar.cshtml +++ b/PlotLine/Views/Shared/_WriterWorkToolbar.cshtml @@ -1,15 +1,13 @@ @model PlotLine.Models.WriterWorkToolbar
-
diff --git a/PlotLine/wwwroot/js/writer-focus.js b/PlotLine/wwwroot/js/writer-focus.js index dbeb85ae..9cfe897f 100644 --- a/PlotLine/wwwroot/js/writer-focus.js +++ b/PlotLine/wwwroot/js/writer-focus.js @@ -8,13 +8,13 @@ function render(){const s=selection(),k=kind();if(save)save.disabled=saving||!objectives.includes(s.activity); if(choice)choice.hidden=s.activity!=='Proofreading'||!!active; if(record){record.hidden=!!active;record.disabled=!known||pending;} - if(hint)hint.textContent=active?'':!objectives.includes(s.activity)?'This activity can be recorded as a session; it cannot be saved as a working objective.':s.activity==='Proofreading'?'Choose Editing or Reading review explicitly to record proofreading.':`Optional recording uses the existing ${k} session type. Saving and planning remain separate.`; + if(hint)hint.textContent=active?'':s.activity==='Proofreading'?'Choose Editing or Reading review explicitly to record proofreading.':`Optional recording uses the existing ${k} session type. Saving and planning remain separate.`; const difference=root.querySelector('[data-focus-session-difference]');if(difference){difference.hidden=!active;difference.textContent=active?`Active recording: ${active.kind} · ${active.chapterTitle||'Whole manuscript'}. ${!root.dataset.savedActivity?'No working focus has been saved. ':String(active.chapterID||'')!==String(root.dataset.savedChapter||'')||root.dataset.savedSessionKind!==active.kind?'This differs from your saved working focus. ':''}Changing or saving focus does not retarget this session.`:'';} } root.addEventListener('plotdirector:work-state',e=>{known=true;active=e.detail.session;render();}); root.addEventListener('plotdirector:work-start-finished',()=>{pending=false;render();}); activity?.addEventListener('change',()=>{if(kindChoice)kindChoice.value='';render();});kindChoice?.addEventListener('change',render); - record?.addEventListener('click',()=>{if(active||pending||!known)return;const s=selection(),k=kind();if(!k){message.textContent='Choose a compatible session activity before recording.';kindChoice?.focus();return;}if(k==='AudioReview'&&!s.chapter){message.textContent='Choose a chapter for Audio Review.';chapter?.focus();return;}message.textContent='';pending=true;render();root.querySelector('[data-writer-work]').dispatchEvent(new CustomEvent('plotdirector:record-focus',{detail:{kind:k,chapter:s.chapter}}));}); + record?.addEventListener('click',()=>{if(active||pending||!known)return;const s=selection(),k=kind();if(!k){message.textContent='Choose a compatible session activity before recording.';kindChoice?.focus();return;}message.textContent='';pending=true;render();root.querySelector('[data-writer-work]').dispatchEvent(new CustomEvent('plotdirector:record-focus',{detail:{kind:k,chapter:s.chapter}}));}); form?.addEventListener('submit',e=>{if(e.defaultPrevented)return;if(saving||!objectives.includes(selection().activity)){e.preventDefault();return;}saving=true;render();}); root.querySelector('[data-plan-focus]')?.addEventListener('click',()=>{const url=new URL(root.dataset.planUrl,location.origin);url.searchParams.set('focusActivity',selection().activity);location.assign(url);}); render();