@rig-c/review 4.0.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,7 +113,6 @@ export function createJobRigScreen(options: {
113
113
  if (!options.formDependencies) throw new Error('JOB_ACT_KIND_DISABLED');
114
114
  const inspection = await prepareJobInspection(display, signal);
115
115
  try {
116
- const forms = prepareJobForms(display, options.window.state().pending, ask => formFor(ask, inspection, options.formDependencies!));
117
116
  let previous = display.publication.previousPublicationId, picture:JobRigScreenPrepared|null = null;
118
117
  const jobId=jobPublicationRoutes(display,location.origin).jobId;
119
118
  const seen = new Set([display.publication.publicationId]);
@@ -140,6 +139,7 @@ export function createJobRigScreen(options: {
140
139
  picture = {jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints:new Set(),parts};
141
140
  }
142
141
  if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
142
+ const forms = prepareJobForms(display, options.window.state().pending, ask => formFor(ask, inspection, {...options.formDependencies!,interviewMainView:!!picture}),!!picture);
143
143
  return {jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints:new Set(),record:{inspection,forms,picture}};
144
144
  } catch(error) {inspection.dispose();throw error;}
145
145
  }
@@ -285,7 +285,7 @@ export function createJobRigScreen(options: {
285
285
  function refreshRecordForms():void {
286
286
  const record=mounted?.record??mounted?.modals,deps=options.formDependencies;if(!record||!deps)return;
287
287
  const state=options.window.state(),display=record.inspection.display;
288
- const next=prepareJobForms(display,state.pending.filter(ask=>ask.subject.kind!=='parts-verdict'&&ask.subject.kind!=='review-verdict'&&jobRigScreenAsk(display,ask,mounted!.checkpoints)),ask=>record.forms.get(ask.askId)??formFor(ask,record.inspection,deps));
288
+ const next=prepareJobForms(display,state.pending.filter(ask=>ask.subject.kind!=='parts-verdict'&&ask.subject.kind!=='review-verdict'&&jobRigScreenAsk(display,ask,mounted!.checkpoints)),ask=>{const previous=record.forms.get(ask.askId),saved=state.pending.find(item=>item.askId===ask.askId);if(previous&&saved?.act?.kind==='interview-picks'&&ask.status==='answered'&&!previous.submitting&&previous.form.dataset.interviewAnswered!=='true'){previous.dispose?.();return formFor(saved,record.inspection,{...deps,interviewMainView:!!mounted?.record?.picture});}return previous??formFor(saved??ask,record.inspection,{...deps,interviewMainView:!!mounted?.record?.picture});},!!mounted?.record?.picture);
289
289
  for(const [id,entry]of next)record.forms.set(id,entry);
290
290
  for(const [id,entry]of record.forms){const ask=state.pending.find(ask=>ask.askId===id);entry.fieldset.disabled=entry.submitting||ask?.status!=='pending'||state.preparing||state.closed||!state.receipt||!options.access.capability;}
291
291
  screen?.recordForms?.([...record.forms.values()].map(entry=>entry.form));
@@ -329,7 +329,7 @@ export function createJobRigScreen(options: {
329
329
  /** Unsupported asks stay on the shared screen with a named explanation. */
330
330
  changed(state: {readonly pending: readonly PendingAskV3[]; readonly closed: boolean; readonly preparing?:boolean; readonly error?:string|null; readonly errorOrigin?:string; readonly previousLabel?:string|null; readonly displayed?:DisplayPublicationV3|null}): void {
331
331
  if (!mounted) return;
332
- if(mounted.record){refreshRecordForms();if(mounted.refusal){screen?.message(options.translate('job.refusal.'+mounted.refusal),true);const notice=document.getElementById('message');if(notice)notice.title=mounted.refusal;}if(state.closed)screen?.message(options.translate('job.closed'),true);return;}
332
+ if(mounted.record){screen?.pendingSubjects?.(pendingSubjects());refreshRecordForms();if(mounted.refusal){screen?.message(options.translate('job.refusal.'+mounted.refusal),true);const notice=document.getElementById('message');if(notice)notice.title=mounted.refusal;}if(state.closed)screen?.message(options.translate('job.closed'),true);return;}
333
333
  const refusal=jobRigScreenRefusal(mounted.display,state.pending,mounted.checkpoints);
334
334
  if(refusal){screen?.message(options.translate('job.refusal.'+refusal),true);const notice=document.getElementById('message');if(notice)notice.title=refusal;return;}
335
335
  screen?.pendingSubjects?.(pendingSubjects());
@@ -130,10 +130,11 @@ export function prepareJobForms<Form>(
130
130
  display: DisplayPublicationV3,
131
131
  asks: readonly PendingAskV3[],
132
132
  prepare: (ask: PendingAskV3) => Form,
133
+ answeredInterviews = false,
133
134
  ): Map<string, Form> {
134
135
  const prepared = new Map<string, Form>();
135
136
  for (const ask of asks) {
136
- if (ask.publicationId !== display.publication.publicationId || ask.status !== 'pending') continue;
137
+ if (ask.publicationId !== display.publication.publicationId || ask.status !== 'pending' && !(answeredInterviews && ask.status === 'answered' && ask.subject.kind === 'interview-picks')) continue;
137
138
  assertJobAskSource(ask, display);
138
139
  prepared.set(ask.askId, prepare(ask));
139
140
  }
@@ -1321,6 +1322,7 @@ export function createJobFormHelpers(node: JobFormNode, t: typeof import('./i18n
1321
1322
 
1322
1323
  /** The answer builder owns no page shell, transport or draft collection. */
1323
1324
  export interface JobFormDependencies {
1325
+ interviewMainView?:boolean;
1324
1326
  node: JobFormNode;
1325
1327
  translate: typeof import('./i18n.ts').t;
1326
1328
  helpers: ReturnType<typeof createJobFormHelpers> & {
@@ -1339,7 +1341,7 @@ export interface JobFormDependencies {
1339
1341
  }
1340
1342
 
1341
1343
  /** Build the existing answer form with explicit host dependencies. */
1342
- function formFor(ask: PendingAskV3, prepared: JobPreparedInspection, deps: JobFormDependencies): JobForm {
1344
+ function formFor(ask: JobWindowAsk, prepared: JobPreparedInspection, deps: JobFormDependencies): JobForm {
1343
1345
  const {node, translate: t, helpers: {selectValues, imageGallery, planTextList, planStepText, assertJobAskSource, jobCheckpointContext},
1344
1346
  draftStorage, localDraftKey, saveDraft, window, access, pageId} = deps;
1345
1347
  if (ask.publicationId !== prepared.display.publication.publicationId)
@@ -1370,9 +1372,14 @@ export interface JobFormDependencies {
1370
1372
  let disposeInterview:(()=>void)|undefined;
1371
1373
  let interviewForm:ReturnType<typeof createInterviewForm>|undefined;
1372
1374
  if (subject.kind === 'interview-picks') {
1373
- const question = prepared.interview?.questions.find(item => item.set.id === subject.setId && item.set.question === subject.questionId);
1375
+ let question:InterviewDisplayQuestion|undefined = prepared.interview?.questions.find(item => item.set.id === subject.setId && item.set.question === subject.questionId);
1374
1376
  if (!question || !question.editable) throw new Error('JOB_ASK_INVALID');
1375
1377
  if (question.ref.sha256 !== ask.source.optionSet?.sha256) throw new Error('JOB_ACT_SOURCE_STALE');
1378
+ if(ask.status==='answered'&&ask.act?.kind==='interview-picks'){
1379
+ const value=ask.act.value;
1380
+ const picks=value.selections.map(selection=>({ask:selection.itemId,option_id:selection.optionId,...(selection.otherText!==null?{other_text:selection.otherText}:{})}));
1381
+ question={...question,saved:interviewPicksRecord(question.ref,picks,value.note,ask.act.at)};
1382
+ }
1376
1383
  const interviewState = prepared.interview?.interview ?? prepared.display.publication.interview ?? null;
1377
1384
  const inspectionRecord = interviewState?.records.find(
1378
1385
  item => item.timeKind === 'inspection' &&
@@ -1393,7 +1400,7 @@ export interface JobFormDependencies {
1393
1400
  legacyNotice.dataset.record = legacyDiagnostic.record;
1394
1401
  fields.prepend(legacyNotice);
1395
1402
  }
1396
- interviewForm=createInterviewForm({question,id:'interview-answer-'+ask.askId,node,form,fieldset:fields,source,
1403
+ interviewForm=createInterviewForm({question,id:'interview-answer-'+ask.askId,node,form,fieldset:fields,source,mainView:deps.interviewMainView,
1397
1404
  images:question.images.map(image=>({name:image.name,src:jobPublicationRoutes(prepared.display,location.origin).instance(image.url)})),answered:ask.status==='answered'});
1398
1405
  disposeInterview=interviewForm.dispose;read=interviewForm.read;
1399
1406
  submitKey = 'interview.save';
@@ -1417,58 +1424,9 @@ export interface JobFormDependencies {
1417
1424
  (JSON.stringify(evidence.packet) !== JSON.stringify(declared) || evidence.packet.planStepId !== checkpoint.step.id)) {
1418
1425
  throw new Error('CHECKPOINT_EVIDENCE_INVALID');
1419
1426
  }
1420
- if (evidence) {
1421
- const section = node('section');
1422
- section.dataset.jobCheckpointEvidence = subject.checkpointId;
1423
- section.append(node('h4', 'job.checkpointEvidence'));
1424
- section.append(imageGallery(evidence.packet.tiles.map((tile, index) => ({name: tile.label,
1425
- sha256: tile.sha256, element: evidence.images[index]?.cloneNode(true) as HTMLImageElement})), true));
1426
- const tableHost = node('div');
1427
- tableHost.style.overflow = 'auto';
1428
- tableHost.style.maxHeight = '50dvh';
1429
- const table = node('table');
1430
- table.dataset.jobCheckpointTable = '';
1431
- const caption = node('caption', 'job.checkpointTable');
1432
- if (evidence.packet.table.label !== undefined) {
1433
- delete caption.dataset.jobText;
1434
- caption.textContent = evidence.packet.table.label;
1435
- caption.setAttribute('translate', 'no');
1436
- }
1437
- const head = node('thead');
1438
- head.setAttribute('translate', 'no');
1439
- const columns = node('tr');
1440
- for (const column of evidence.table.columns) {
1441
- const cell = node('th');
1442
- cell.scope = 'col';
1443
- cell.textContent = column;
1444
- columns.append(cell);
1445
- }
1446
- head.append(columns);
1447
- const body = node('tbody');
1448
- body.setAttribute('translate', 'no');
1449
- for (const row of evidence.table.rows) {
1450
- const cells = node('tr');
1451
- for (const value of row) {
1452
- const cell = node('td');
1453
- cell.textContent = String(value);
1454
- cells.append(cell);
1455
- }
1456
- body.append(cells);
1457
- }
1458
- table.append(caption, head, body);
1459
- tableHost.append(table);
1460
- const routes = node('pre');
1461
- routes.textContent = evidence.packet.routesText;
1462
- routes.setAttribute('translate', 'no');
1463
- const recommendation = node('pre');
1464
- recommendation.textContent = evidence.packet.recommendationText;
1465
- recommendation.setAttribute('translate', 'no');
1466
- section.append(tableHost, node('h4', 'job.checkpointRoutes'), routes,
1467
- node('h4', 'job.checkpointRecommendation'), recommendation);
1468
- fields.append(section, node('p', 'job.checkpointRouteMapping'));
1469
- }
1470
1427
  const outcome = selectValues(['', 'pass', 'fail'], ['Pending', 'Pass', 'job.fail']);
1471
1428
  outcome.required = true;
1429
+ outcome.hidden = true;
1472
1430
  outcome.name = 'outcome';
1473
1431
  fields.append(outcome);
1474
1432
  read = () => ({ checkpointId: subject.checkpointId, outcome: outcome.value as 'pass' | 'fail', words: commentWords() });
@@ -1500,6 +1458,14 @@ export interface JobFormDependencies {
1500
1458
  }
1501
1459
  const submit = interviewForm?.submit??node('button', submitKey);
1502
1460
  submit.type = 'submit';
1461
+ submit.classList.add('primary');
1462
+ if(subject.kind==='checkpoint'){
1463
+ submit.dataset.jobText='Pass';submit.textContent=t('Pass');
1464
+ submit.onclick=()=>{form.querySelector<HTMLSelectElement>('select[name=outcome]')!.value='pass';form.dispatchEvent(new Event('input'));};
1465
+ const fail=node('button','job.fail');fail.type='submit';
1466
+ fail.onclick=()=>{form.querySelector<HTMLSelectElement>('select[name=outcome]')!.value='fail';form.dispatchEvent(new Event('input'));};
1467
+ fields.append(fail);
1468
+ }
1503
1469
  fields.append(submit);
1504
1470
  const status = interviewForm?.status??node('p');
1505
1471
  status.setAttribute('role', 'status');
@@ -1509,7 +1475,8 @@ export interface JobFormDependencies {
1509
1475
  if(disposeInterview)form.addEventListener('job-form-dispose',disposeInterview);
1510
1476
  try {
1511
1477
  const saved = JSON.parse(draftStorage().getItem(localDraftKey(prepared.display)) ?? 'null');
1512
- if (saved?.publicationId === prepared.display.publication.publicationId &&
1478
+ // A finalized answer is read back from its act; a local draft never overrides it.
1479
+ if (ask.status !== 'answered' && saved?.publicationId === prepared.display.publication.publicationId &&
1513
1480
  saved?.sourceHash === prepared.display.publication.source.sourceHash) {
1514
1481
  assertJobAskSource({...ask, source: saved.source}, prepared.display);
1515
1482
  const original = saved.forms?.find((item: {
@@ -1566,6 +1533,7 @@ export interface JobFormDependencies {
1566
1533
  status.textContent = t('job.saved');
1567
1534
  if(subject.kind==='interview-picks'){form.dataset.interviewAnswered='true';form.dispatchEvent(new Event('change'));}
1568
1535
  saveDraft();
1536
+ form.dispatchEvent(new Event('job-answer-saved',{bubbles:true}));
1569
1537
  }
1570
1538
  catch (error) {
1571
1539
  entry.submitting = false;
@@ -1609,13 +1577,15 @@ export async function joinedInterviewForms(access:InstanceAccess,present:(forms:
1609
1577
  entry.form.onsubmit=async event=>{
1610
1578
  event.preventDefault();if(!question.editable||!access.capability||entry!.fieldset.disabled||!entry!.form.reportValidity())return;
1611
1579
  answer.fieldset.disabled=true;
1580
+ let saved=false;
1612
1581
  try{
1613
1582
  const value=answer.read(),picks=value.selections.map(selection=>({ask:selection.itemId,option_id:selection.optionId,...(selection.otherText!==null?{other_text:selection.otherText}:{})}));
1614
1583
  const record=interviewPicksRecord(question.ref,picks,answer.retainedNote,new Date().toISOString());
1615
1584
  await request('/api/interview/picks',record);
1616
- question.saved=record;answer.form.dataset.interviewAnswered='true';answer.status.dataset.jobText='interview.saved';answer.status.textContent=t('interview.saved');answer.form.dispatchEvent(new Event('change'));
1585
+ question.saved=record;answer.form.dataset.interviewAnswered='true';answer.status.dataset.jobText='interview.saved';answer.status.textContent=t('interview.saved');answer.form.dispatchEvent(new Event('change'));saved=true;
1617
1586
  }catch(error){const code=error instanceof Error?error.message.split(':')[0]:'';answer.status.dataset.jobText=interviewErrors[code]??'interview.failed';answer.status.textContent=t(answer.status.dataset.jobText);}
1618
1587
  finally{answer.fieldset.disabled=!question.editable||!access.capability;}
1588
+ if(saved)answer.form.dispatchEvent(new Event('job-answer-saved',{bubbles:true}));
1619
1589
  };
1620
1590
  forms.set(index,entry);
1621
1591
  }
@@ -1673,7 +1643,7 @@ export async function mountJobScreen(host:HTMLElement):Promise<()=>void> {
1673
1643
  window:{state:()=>window.state(),submit:input=>window.submit(input)},readPublication:(id,signal)=>transport.readPublication(id,signal),
1674
1644
  routes:display=>jobPublicationRoutes(display,location.origin),load:async()=>(await import('./main.ts')).mountRigScreen()});
1675
1645
  let bootstrapNotice:HTMLElement|null=null;
1676
- const report=(error:unknown,fallback?:string)=>{if(rigScreen.mounted()){rigScreen.report(error,fallback);return;}if(!bootstrapNotice){bootstrapNotice=node('p');bootstrapNotice.setAttribute('role','status');host.append(bootstrapNotice);}bootstrapNotice.textContent=jobWindowRefusal(error,fallback);};
1646
+ const report=(error:unknown,fallback?:string)=>{if(rigScreen.mounted()){rigScreen.report(error,fallback);return;}if(!bootstrapNotice){bootstrapNotice=node('p');bootstrapNotice.setAttribute('role','status');bootstrapNotice.setAttribute('translate','no');host.prepend(bootstrapNotice);}bootstrapNotice.textContent=jobWindowRefusal(error,fallback);const code=error instanceof Error?error.message:error;bootstrapNotice.title=typeof code==='string'&&/^[A-Z][A-Z0-9_]*$/.test(code)&&Object.hasOwn(enCatalog,code)&&Object.hasOwn(koCatalog,code)?code:fallback??'JOB_WINDOW_FAILED';};
1677
1647
  const window=createJobWindow<JobRigScreenPrepared|null>({jobId:access.jobId,pageId,transport,adapter:{
1678
1648
  async prepare(display,signal){return rigScreen.prepare(display,signal);},
1679
1649
  captureDraft(){drafts.saveDraft();const forms=modalState()?.forms;const dirty=forms?[...forms].filter(([,entry])=>entry.dirty):[];return dirty.length?dirty.map(([askId,entry])=>({askId,value:entry.read()})):null;},