@rig-c/review 2.7.1 → 2.9.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.
- package/docs/PARTS_VIEW.md +103 -66
- package/docs/REVIEW_PACKAGE.md +32 -17
- package/docs/STABILITY.md +85 -4
- package/docs/WORKFLOWS.md +1 -1
- package/package.json +3 -3
- package/src/build.ts +10 -2
- package/src/cli.ts +4 -5
- package/src/correction-handoff.ts +27 -4
- package/src/feedback-export.ts +1 -1
- package/src/front.ts +2 -1
- package/src/handoff.ts +1 -1
- package/src/interview-project.ts +173 -10
- package/src/job-act.ts +101 -33
- package/src/job-api.ts +194 -13
- package/src/job-cli.ts +6 -2
- package/src/job-contract.ts +203 -19
- package/src/job-front.ts +270 -34
- package/src/job-host.ts +123 -1
- package/src/job-session.ts +227 -47
- package/src/job-source.ts +88 -16
- package/src/manifest.ts +9 -0
- package/src/open-workspace-launch.ts +2 -2
- package/src/open.ts +2 -1
- package/src/parts-comment-crops.ts +126 -31
- package/src/parts-comment.ts +321 -28
- package/src/parts-view.ts +485 -89
- package/src/stage-comment.ts +9 -1
- package/src/stage-parts.ts +5 -1
- package/src/versions.ts +7 -7
- package/web/catalog-en.ts +37 -1
- package/web/catalog-ko.ts +37 -1
- package/web/job-session.ts +830 -161
- package/web/parts-page.ts +217 -0
- package/web/parts-render.ts +26 -19
- package/web/parts-viewport-provider.ts +13 -1
- package/web/parts.css +13 -1
- package/web/parts.html +4 -38
- package/web/parts.ts +644 -267
- package/web/stage-comments.ts +77 -23
- package/web/styles.css +10 -2
- package/web/viewport-controller.ts +13 -4
package/web/job-session.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/** Live job window transactions. Every form remains bound to its displayed publication. */
|
|
2
|
-
import
|
|
2
|
+
import { parseControlPart, type ControlPart } from '../src/control.ts';
|
|
3
|
+
import type {
|
|
4
|
+
ActV3,
|
|
5
|
+
DisplayPublicationV3,
|
|
6
|
+
EventV3,
|
|
7
|
+
JobDisplayReceipt,
|
|
8
|
+
JobInterviewDiagnostics,
|
|
9
|
+
JobResult,
|
|
10
|
+
JobUISubmission,
|
|
11
|
+
PendingAskV3,
|
|
12
|
+
JobPanelComposition,
|
|
13
|
+
PanelComponent,
|
|
14
|
+
PanelSlot,
|
|
15
|
+
PartsVerdictValue,
|
|
16
|
+
PublicationV3,
|
|
17
|
+
RecordSource,
|
|
18
|
+
SourceV3,
|
|
19
|
+
UISubmissionV3,
|
|
20
|
+
} from '../src/job-contract.ts';
|
|
3
21
|
import {enCatalog} from './catalog-en.ts';
|
|
4
22
|
import {koCatalog} from './catalog-ko.ts';
|
|
5
23
|
import {t} from './i18n.ts';
|
|
@@ -9,6 +27,9 @@ import {recordJobRigDraw, freezeJobRigCapture, copyJobRigViewport, createJobRigS
|
|
|
9
27
|
import {advancePlayback} from './playback-clock.ts';
|
|
10
28
|
import {presentJobRigViewport, type JobRigPresentation} from './viewport-capture.ts';
|
|
11
29
|
import {CanvasRenderer} from '@rig-c/play';
|
|
30
|
+
import {JOB_PANEL_COMPOSITION_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, parsePanelComposition} from '../src/job-contract.ts';
|
|
31
|
+
import type {PartsSource, PartsHost} from './parts.ts';
|
|
32
|
+
import type {PartsIssue} from '../src/parts-comment.ts';
|
|
12
33
|
|
|
13
34
|
/** Imported runtimes may throw arbitrary prose. Only registered refusal copy reaches the window. */
|
|
14
35
|
export function jobWindowRefusal(error: unknown, fallback = 'JOB_WINDOW_FAILED'): string {
|
|
@@ -20,13 +41,13 @@ export function jobWindowRefusal(error: unknown, fallback = 'JOB_WINDOW_FAILED')
|
|
|
20
41
|
return t(fallback);
|
|
21
42
|
}
|
|
22
43
|
export interface JobWindowTransport {
|
|
23
|
-
readPublication(publicationId: string, signal?: AbortSignal): Promise<JobResult<
|
|
44
|
+
readPublication(publicationId: string, signal?: AbortSignal): Promise<JobResult<DisplayPublicationV3>>;
|
|
24
45
|
acknowledge(input: {
|
|
25
46
|
publicationId: string;
|
|
26
47
|
pageId: string;
|
|
27
48
|
sourceHash: string;
|
|
28
49
|
}, signal: AbortSignal): Promise<JobResult<JobDisplayReceipt>>;
|
|
29
|
-
submit(input:
|
|
50
|
+
submit(input: UISubmissionV3): Promise<JobResult<ActV3>>;
|
|
30
51
|
}
|
|
31
52
|
export interface JobPreparedCommit {
|
|
32
53
|
/** Restore the previous view, including its original forms and route bindings. */
|
|
@@ -36,10 +57,10 @@ export interface JobPreparedCommit {
|
|
|
36
57
|
}
|
|
37
58
|
export interface JobWindowAdapter<Prepared> {
|
|
38
59
|
/** Resolve assets, metadata, forms and publication-pinned routes before returning. */
|
|
39
|
-
prepare(display:
|
|
60
|
+
prepare(display: DisplayPublicationV3, signal: AbortSignal): Promise<Prepared>;
|
|
40
61
|
/** Called immediately before commit, so edits made during preloading are retained. */
|
|
41
62
|
captureDraft(): unknown | null;
|
|
42
|
-
commit(prepared: Prepared, display:
|
|
63
|
+
commit(prepared: Prepared, display: DisplayPublicationV3): JobPreparedCommit;
|
|
43
64
|
painted(prepared: Prepared, signal: AbortSignal): Promise<void>;
|
|
44
65
|
discard(prepared: Prepared): void;
|
|
45
66
|
changed(state: JobWindowState): void;
|
|
@@ -47,19 +68,20 @@ export interface JobWindowAdapter<Prepared> {
|
|
|
47
68
|
export interface JobRetainedDraft {
|
|
48
69
|
readonly publicationId: string;
|
|
49
70
|
readonly sourceHash: string;
|
|
50
|
-
readonly source?:
|
|
71
|
+
readonly source?: SourceV3;
|
|
51
72
|
readonly label: string;
|
|
52
73
|
readonly value: unknown;
|
|
53
74
|
}
|
|
75
|
+
export type JobWindowAsk = PendingAskV3 & {readonly act?: ActV3};
|
|
54
76
|
export interface JobWindowState {
|
|
55
77
|
readonly generation: number;
|
|
56
|
-
readonly displayed:
|
|
78
|
+
readonly displayed: DisplayPublicationV3 | null;
|
|
57
79
|
readonly receipt: JobDisplayReceipt | null;
|
|
58
80
|
readonly preparing: boolean;
|
|
59
81
|
readonly closed: boolean;
|
|
60
82
|
readonly error: string | null;
|
|
61
83
|
readonly previousLabel: string | null;
|
|
62
|
-
readonly pending: readonly
|
|
84
|
+
readonly pending: readonly JobWindowAsk[];
|
|
63
85
|
readonly retainedDrafts: readonly JobRetainedDraft[];
|
|
64
86
|
}
|
|
65
87
|
function unwrap<Value>(result: JobResult<Value>): Value {
|
|
@@ -67,7 +89,10 @@ function unwrap<Value>(result: JobResult<Value>): Value {
|
|
|
67
89
|
throw new Error(result.error.code);
|
|
68
90
|
return result.value;
|
|
69
91
|
}
|
|
70
|
-
function
|
|
92
|
+
function isRecordSource(source: SourceV3): source is RecordSource {
|
|
93
|
+
return source.subject === 'option-set' || source.subject === 'plan';
|
|
94
|
+
}
|
|
95
|
+
function sourceSnapshot(source: unknown): string {
|
|
71
96
|
return JSON.stringify(source, (_key, value: unknown) => {
|
|
72
97
|
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
73
98
|
return value;
|
|
@@ -75,8 +100,9 @@ function sourceSnapshot(source: JobSourceBinding): string {
|
|
|
75
100
|
return Object.fromEntries(Object.keys(record).sort().map(key => [key, record[key]]));
|
|
76
101
|
});
|
|
77
102
|
}
|
|
78
|
-
function assertJobAskSource(ask:
|
|
79
|
-
const source = ask.subject.kind === 'interview-picks'
|
|
103
|
+
function assertJobAskSource(ask: PendingAskV3, display: DisplayPublicationV3): void {
|
|
104
|
+
const source: SourceV3 = ask.subject.kind === 'interview-picks' &&
|
|
105
|
+
!isRecordSource(display.publication.source) && !isRecordSource(ask.source)
|
|
80
106
|
? { ...ask.source, optionSet: display.publication.source.optionSet }
|
|
81
107
|
: ask.source;
|
|
82
108
|
if (sourceSnapshot(source) !== sourceSnapshot(display.publication.source)) {
|
|
@@ -90,9 +116,9 @@ function assertJobAskSource(ask: JobPendingAsk, display: JobDisplayPublication):
|
|
|
90
116
|
|
|
91
117
|
/** Build pending form dependencies off-stage. A failure rejects the candidate before it is displayed. */
|
|
92
118
|
export function prepareJobForms<Form>(
|
|
93
|
-
display:
|
|
94
|
-
asks: readonly
|
|
95
|
-
prepare: (ask:
|
|
119
|
+
display: DisplayPublicationV3,
|
|
120
|
+
asks: readonly PendingAskV3[],
|
|
121
|
+
prepare: (ask: PendingAskV3) => Form,
|
|
96
122
|
): Map<string, Form> {
|
|
97
123
|
const prepared = new Map<string, Form>();
|
|
98
124
|
for (const ask of asks) {
|
|
@@ -105,12 +131,12 @@ export function prepareJobForms<Form>(
|
|
|
105
131
|
|
|
106
132
|
/** C2 publishes the plan mapping in the ask. Legacy checkpoint metadata is optional guidance. */
|
|
107
133
|
export function jobCheckpointContext(
|
|
108
|
-
ask:
|
|
134
|
+
ask: PendingAskV3,
|
|
109
135
|
checkpoints: readonly Pick<Checkpoint, 'id' | 'title' | 'note'>[],
|
|
110
136
|
) {
|
|
111
137
|
if (ask.subject.kind !== 'checkpoint') throw new Error('JOB_ASK_INVALID');
|
|
112
138
|
const checkpointId = ask.subject.checkpointId;
|
|
113
|
-
const planStepId = ask.subject.planStepId ?? checkpointId;
|
|
139
|
+
const planStepId = ('planStepId' in ask.subject ? ask.subject.planStepId : undefined) ?? checkpointId;
|
|
114
140
|
const step = ask.source.plan?.steps.find(item => item.id === planStepId);
|
|
115
141
|
if (!step) throw new Error('JOB_ASK_INVALID');
|
|
116
142
|
const checkpoint = checkpoints.find(item => item.id === checkpointId);
|
|
@@ -127,17 +153,26 @@ export function createJobWindow<Prepared>(options: {
|
|
|
127
153
|
pageId: string;
|
|
128
154
|
transport: JobWindowTransport;
|
|
129
155
|
adapter: JobWindowAdapter<Prepared>;
|
|
156
|
+
previousDisplayed?: {
|
|
157
|
+
readonly publicationId: string;
|
|
158
|
+
readonly label: string;
|
|
159
|
+
readonly previousLabel: string | null;
|
|
160
|
+
} | null;
|
|
161
|
+
initialRetainedDrafts?: readonly JobRetainedDraft[];
|
|
130
162
|
}) {
|
|
131
163
|
const { transport, adapter, pageId } = options;
|
|
132
|
-
const pending = new Map<string,
|
|
133
|
-
const rigAttempts = new WeakSet<
|
|
164
|
+
const pending = new Map<string, JobWindowAsk>();
|
|
165
|
+
const rigAttempts = new WeakSet<UISubmissionV3>();
|
|
134
166
|
const retainedDrafts: JobRetainedDraft[] = [];
|
|
167
|
+
let initialDrafts: readonly JobRetainedDraft[] | null = options.initialRetainedDrafts
|
|
168
|
+
? [...options.initialRetainedDrafts] : null;
|
|
135
169
|
let generation = 0;
|
|
136
|
-
let displayed:
|
|
170
|
+
let displayed: DisplayPublicationV3 | null = null;
|
|
137
171
|
let receipt: JobDisplayReceipt | null = null;
|
|
138
172
|
let preparing = false;
|
|
139
173
|
let closed = false;
|
|
140
|
-
let error: string | null
|
|
174
|
+
let error: string | null;
|
|
175
|
+
error = null;
|
|
141
176
|
let previousLabel: string | null = null;
|
|
142
177
|
let intent = 0;
|
|
143
178
|
let stopped = false;
|
|
@@ -150,7 +185,7 @@ export function createJobWindow<Prepared>(options: {
|
|
|
150
185
|
};
|
|
151
186
|
}
|
|
152
187
|
function changed(): void { adapter.changed(state()); }
|
|
153
|
-
function replace(publication:
|
|
188
|
+
function replace(publication: PublicationV3): Promise<void> {
|
|
154
189
|
if (stopped)
|
|
155
190
|
return Promise.resolve();
|
|
156
191
|
const revision = ++intent;
|
|
@@ -166,14 +201,16 @@ export function createJobWindow<Prepared>(options: {
|
|
|
166
201
|
let prepared: Prepared | undefined;
|
|
167
202
|
let committed: JobPreparedCommit | undefined;
|
|
168
203
|
try {
|
|
169
|
-
if (publication.visual.status !== 'available')
|
|
204
|
+
if (publication.visual.status !== 'available' && !isRecordSource(publication.source))
|
|
170
205
|
throw new Error(publication.visual.code);
|
|
171
206
|
const candidate = unwrap(await transport.readPublication(publication.publicationId, abort.signal));
|
|
172
207
|
if (candidate.publication.publicationId !== publication.publicationId ||
|
|
173
208
|
candidate.publication.source.sourceHash !== publication.source.sourceHash ||
|
|
174
209
|
candidate.publication.instanceKey !== publication.instanceKey ||
|
|
175
210
|
candidate.publication.generation !== publication.generation ||
|
|
176
|
-
sourceSnapshot(candidate.publication.source) !== sourceSnapshot(publication.source)
|
|
211
|
+
sourceSnapshot(candidate.publication.source) !== sourceSnapshot(publication.source) ||
|
|
212
|
+
(publication.interview !== undefined &&
|
|
213
|
+
sourceSnapshot(candidate.publication.interview) !== sourceSnapshot(publication.interview))) {
|
|
177
214
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
178
215
|
}
|
|
179
216
|
prepared = await adapter.prepare(candidate, abort.signal);
|
|
@@ -194,16 +231,42 @@ export function createJobWindow<Prepared>(options: {
|
|
|
194
231
|
acknowledged.pageId !== pageId || !acknowledged.displayedNonce) {
|
|
195
232
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
196
233
|
}
|
|
234
|
+
if (initialDrafts) {
|
|
235
|
+
for (const item of initialDrafts) {
|
|
236
|
+
if (item.publicationId !== candidate.publication.publicationId &&
|
|
237
|
+
!retainedDrafts.some(existing => existing.publicationId === item.publicationId)) {
|
|
238
|
+
retainedDrafts.push(structuredClone(item));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
initialDrafts = null;
|
|
242
|
+
}
|
|
243
|
+
for (let index = retainedDrafts.length - 1; index >= 0; index--) {
|
|
244
|
+
if (retainedDrafts[index]?.publicationId === candidate.publication.publicationId)
|
|
245
|
+
retainedDrafts.splice(index, 1);
|
|
246
|
+
}
|
|
197
247
|
if (displayed && draft !== null) {
|
|
198
|
-
|
|
248
|
+
const nextDraft: JobRetainedDraft = {
|
|
199
249
|
publicationId: displayed.publication.publicationId,
|
|
200
250
|
sourceHash: displayed.publication.source.sourceHash,
|
|
201
251
|
source: structuredClone(displayed.publication.source),
|
|
202
252
|
label: displayed.publication.label,
|
|
203
253
|
value: structuredClone(draft),
|
|
204
|
-
}
|
|
254
|
+
};
|
|
255
|
+
const existing = retainedDrafts.findIndex(item => item.publicationId === nextDraft.publicationId);
|
|
256
|
+
if (existing >= 0) retainedDrafts[existing] = nextDraft;
|
|
257
|
+
else retainedDrafts.push(nextDraft);
|
|
258
|
+
}
|
|
259
|
+
if (displayed) {
|
|
260
|
+
previousLabel = displayed.publication.label;
|
|
261
|
+
}
|
|
262
|
+
else if (options.previousDisplayed) {
|
|
263
|
+
previousLabel = options.previousDisplayed.publicationId === candidate.publication.publicationId
|
|
264
|
+
? options.previousDisplayed.previousLabel
|
|
265
|
+
: options.previousDisplayed.label;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
previousLabel = null;
|
|
205
269
|
}
|
|
206
|
-
previousLabel = displayed?.publication.label ?? null;
|
|
207
270
|
displayed = candidate;
|
|
208
271
|
receipt = acknowledged;
|
|
209
272
|
const cleanup = committed;
|
|
@@ -232,7 +295,7 @@ export function createJobWindow<Prepared>(options: {
|
|
|
232
295
|
});
|
|
233
296
|
return queue;
|
|
234
297
|
}
|
|
235
|
-
function event(value:
|
|
298
|
+
function event(value: EventV3): void {
|
|
236
299
|
if (stopped || value.jobId !== options.jobId)
|
|
237
300
|
return;
|
|
238
301
|
generation = Math.max(generation, value.generation);
|
|
@@ -246,19 +309,20 @@ export function createJobWindow<Prepared>(options: {
|
|
|
246
309
|
void replace(value.publication);
|
|
247
310
|
}
|
|
248
311
|
else if (value.type === 'pending') {
|
|
249
|
-
pending.
|
|
312
|
+
const previous = pending.get(value.ask.askId);
|
|
313
|
+
pending.set(value.ask.askId, previous?.act ? {...value.ask, status: 'answered', act: previous.act} : value.ask);
|
|
250
314
|
}
|
|
251
315
|
else if (value.type === 'act') {
|
|
252
316
|
const ask = pending.get(value.act.askId);
|
|
253
317
|
if (ask)
|
|
254
|
-
pending.set(ask.askId, { ...ask, status: 'answered' });
|
|
318
|
+
pending.set(ask.askId, { ...ask, status: 'answered', act: value.act });
|
|
255
319
|
}
|
|
256
320
|
else if (value.type === 'closed') {
|
|
257
321
|
closed = true;
|
|
258
322
|
}
|
|
259
323
|
changed();
|
|
260
324
|
}
|
|
261
|
-
async function submit(input:
|
|
325
|
+
async function submit(input: UISubmissionV3): Promise<JobResult<ActV3>> {
|
|
262
326
|
if (closed)
|
|
263
327
|
return { ok: false, error: { code: 'JOB_CLOSED', message: 'JOB_CLOSED' } };
|
|
264
328
|
const ask = pending.get(input.askId);
|
|
@@ -272,10 +336,46 @@ export function createJobWindow<Prepared>(options: {
|
|
|
272
336
|
}
|
|
273
337
|
// The backend authenticates the actual Request and validates the semantic value.
|
|
274
338
|
if (input.capture !== undefined) rigAttempts.add(input);
|
|
275
|
-
|
|
339
|
+
const result = await transport.submit(input);
|
|
340
|
+
if (result.ok && ask) {
|
|
341
|
+
pending.set(ask.askId, {...ask, status: 'answered', act: result.value});
|
|
342
|
+
changed();
|
|
343
|
+
}
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
async function submitParts(input: UISubmissionV3, signoffSubmissionId: string): Promise<JobResult<ActV3>> {
|
|
347
|
+
const publicationId = input.publicationId;
|
|
348
|
+
const ask = pending.get(input.askId);
|
|
349
|
+
if (!displayed || displayed.publication.publicationId !== publicationId || !ask ||
|
|
350
|
+
ask.subject.kind !== 'parts-verdict') throw new Error('JOB_ACT_SOURCE_STALE');
|
|
351
|
+
assertJobAskSource(ask, displayed);
|
|
352
|
+
const previous = ask.act;
|
|
353
|
+
const value = (previous?.kind === 'parts-verdict' ? previous.value : input.value) as PartsVerdictValue;
|
|
354
|
+
const signoff = [...pending.values()].find(item => item.publicationId === publicationId &&
|
|
355
|
+
item.subject.kind === 'signoff' && item.subject.stage === 'parts-review' && item.status === 'pending');
|
|
356
|
+
if (value.verdict === 'approved' && !signoff) throw new Error('JOB_PARTS_SIGNOFF_MISSING');
|
|
357
|
+
let result: JobResult<ActV3>;
|
|
358
|
+
if (ask.status === 'pending') {
|
|
359
|
+
result = await submit(input);
|
|
360
|
+
if (!result.ok) return result;
|
|
361
|
+
} else {
|
|
362
|
+
if (!previous || previous.kind !== 'parts-verdict' || previous.schema !== JOB_PARTS_VERDICT_ACT_SCHEMA ||
|
|
363
|
+
value.verdict !== 'approved') throw new Error('JOB_ACT_SOURCE_STALE');
|
|
364
|
+
result = {ok: true, value: previous};
|
|
365
|
+
}
|
|
366
|
+
if (value.verdict !== 'approved') return result;
|
|
367
|
+
// Recheck after the first durable write. A replacement never inherits this signoff.
|
|
368
|
+
const latest = state();
|
|
369
|
+
if (latest.displayed?.publication.publicationId !== publicationId || !latest.receipt || !signoff)
|
|
370
|
+
throw new Error('JOB_ACT_SOURCE_STALE');
|
|
371
|
+
assertJobAskSource(signoff, latest.displayed);
|
|
372
|
+
return submit({kind: 'signoff', publicationId, pageId: input.pageId, askId: signoff.askId,
|
|
373
|
+
expectedGeneration: latest.generation, displayedNonce: latest.receipt.displayedNonce,
|
|
374
|
+
submissionId: signoffSubmissionId,
|
|
375
|
+
value: {stage: 'parts-review', decision: 'approved', words: value.words}});
|
|
276
376
|
}
|
|
277
377
|
return {
|
|
278
|
-
event, replace, submit, state, refresh: changed,
|
|
378
|
+
event, replace, submit, submitParts, state, refresh: changed,
|
|
279
379
|
settled: () => queue,
|
|
280
380
|
stop() { stopped = true; ++intent; controller?.abort(); },
|
|
281
381
|
};
|
|
@@ -334,7 +434,7 @@ export function jobWindowAccess(href: string, storage: Pick<Storage, 'getItem' |
|
|
|
334
434
|
};
|
|
335
435
|
}
|
|
336
436
|
/** Resolve only the publication's explicit immutable instance routes. */
|
|
337
|
-
export function jobPublicationRoutes(display:
|
|
437
|
+
export function jobPublicationRoutes(display: DisplayPublicationV3, origin: string) {
|
|
338
438
|
const key = display.publication.instanceKey;
|
|
339
439
|
if (!/^[a-f0-9]{64}$/.test(key))
|
|
340
440
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
@@ -408,7 +508,7 @@ export function createJobWindowTransport(access: JobWindowAccess, fetcher: typeo
|
|
|
408
508
|
};
|
|
409
509
|
}
|
|
410
510
|
/** Bounded newline events. Reconnects resume after the last fully parsed event. */
|
|
411
|
-
export async function* jobWindowEvents(access: JobWindowAccess, after: string | null, signal: AbortSignal, fetcher: typeof fetch = fetch): AsyncGenerator<
|
|
511
|
+
export async function* jobWindowEvents(access: JobWindowAccess, after: string | null, signal: AbortSignal, fetcher: typeof fetch = fetch): AsyncGenerator<EventV3> {
|
|
412
512
|
const path = 'events' + (after === null ? '' : '?after=' + encodeURIComponent(after));
|
|
413
513
|
const response = await fetcher(access.route(path), { signal, headers: access.headers() });
|
|
414
514
|
if (!response.ok || !response.body)
|
|
@@ -431,7 +531,7 @@ export async function* jobWindowEvents(access: JobWindowAccess, after: string |
|
|
|
431
531
|
while (newline >= 0) {
|
|
432
532
|
if (newline > limit)
|
|
433
533
|
throw new Error('JOB_BODY_LIMIT');
|
|
434
|
-
const event = JSON.parse(buffered.slice(0, newline)) as
|
|
534
|
+
const event = JSON.parse(buffered.slice(0, newline)) as EventV3;
|
|
435
535
|
if (!event || event.jobId !== access.jobId || typeof event.cursor !== 'string' ||
|
|
436
536
|
!Number.isSafeInteger(event.generation) || event.generation < 0 ||
|
|
437
537
|
!['published', 'pending', 'act', 'closed'].includes(event.type))
|
|
@@ -454,7 +554,7 @@ export function startJobWindowEvents(options: {
|
|
|
454
554
|
access: JobWindowAccess;
|
|
455
555
|
signal: AbortSignal;
|
|
456
556
|
member: boolean;
|
|
457
|
-
event(value:
|
|
557
|
+
event(value: EventV3): void;
|
|
458
558
|
refused(error: unknown): void;
|
|
459
559
|
fetcher?: typeof fetch;
|
|
460
560
|
}) {
|
|
@@ -512,6 +612,7 @@ import type { FeedbackCatalog } from '../src/feedback-validation.ts';
|
|
|
512
612
|
import type { InterviewQuestion } from '../src/interview-project.ts';
|
|
513
613
|
export interface JobInspectionMetadata {
|
|
514
614
|
manifest: ReviewManifest;
|
|
615
|
+
recordSource?: undefined;
|
|
515
616
|
sourceHash: string;
|
|
516
617
|
reviewedSource: ReviewedSource;
|
|
517
618
|
setsHash?: string;
|
|
@@ -531,6 +632,24 @@ export interface JobInspectionMetadata {
|
|
|
531
632
|
};
|
|
532
633
|
feedbackCatalog: Pick<FeedbackCatalog, 'slots'>;
|
|
533
634
|
}
|
|
635
|
+
export interface JobRecordInspectionMetadata {
|
|
636
|
+
manifest?: undefined;
|
|
637
|
+
recordSource: RecordSource;
|
|
638
|
+
sourceHash: string;
|
|
639
|
+
reviewedSource?: undefined;
|
|
640
|
+
setsHash?: undefined;
|
|
641
|
+
initialAnimation?: null;
|
|
642
|
+
direction?: undefined;
|
|
643
|
+
referenceHashes?: undefined;
|
|
644
|
+
sourcePainting?: undefined;
|
|
645
|
+
capabilities: {
|
|
646
|
+
interview?: boolean;
|
|
647
|
+
preRig?: boolean;
|
|
648
|
+
playback: boolean;
|
|
649
|
+
};
|
|
650
|
+
feedbackCatalog: Pick<FeedbackCatalog, 'slots'>;
|
|
651
|
+
}
|
|
652
|
+
export type JobInspectionMetadataV3 = JobInspectionMetadata | JobRecordInspectionMetadata;
|
|
534
653
|
type JobInterview = {
|
|
535
654
|
questions: (Omit<InterviewQuestion, 'images'> & {
|
|
536
655
|
images: {
|
|
@@ -538,23 +657,9 @@ type JobInterview = {
|
|
|
538
657
|
url: string;
|
|
539
658
|
}[];
|
|
540
659
|
})[];
|
|
660
|
+
interview?: JobInterviewDiagnostics | null;
|
|
541
661
|
};
|
|
542
|
-
|
|
543
|
-
sourceHash: string;
|
|
544
|
-
rigSize: [
|
|
545
|
-
number,
|
|
546
|
-
number
|
|
547
|
-
] | null;
|
|
548
|
-
items: {
|
|
549
|
-
name: string;
|
|
550
|
-
index: number;
|
|
551
|
-
x: number;
|
|
552
|
-
y: number;
|
|
553
|
-
w: number;
|
|
554
|
-
h: number;
|
|
555
|
-
imageHash?: string;
|
|
556
|
-
}[];
|
|
557
|
-
}
|
|
662
|
+
type JobPartsInventory = Awaited<ReturnType<PartsSource['view']>>;
|
|
558
663
|
interface JobReferenceView {
|
|
559
664
|
id: string;
|
|
560
665
|
label: string;
|
|
@@ -564,6 +669,43 @@ interface JobReferenceView {
|
|
|
564
669
|
seek(time: number, signal: AbortSignal): Promise<void>;
|
|
565
670
|
}
|
|
566
671
|
|
|
672
|
+
/** Read composition at the host boundary. Unknown IDs remain local to their slot. */
|
|
673
|
+
export function resolveJobPanels(metadata: JobInspectionMetadataV3, source: SourceV3) {
|
|
674
|
+
const parts: JobPanelComposition = {schema: JOB_PANEL_COMPOSITION_SCHEMA, left: ['parts.list'],
|
|
675
|
+
stage: ['parts.canvas'], toolbar: ['parts.layers'], side: ['parts.issues', 'act.submit']};
|
|
676
|
+
const stage: PanelComponent = source.subject === 'image-set' ? 'images.set' :
|
|
677
|
+
isRecordSource(source) ? source.subject === 'plan' ? 'plan.body' : 'interview.picks' :
|
|
678
|
+
source.direction ? 'scene.composite' : 'rig.playback';
|
|
679
|
+
const fallback: JobPanelComposition = metadata.capabilities.preRig ? parts :
|
|
680
|
+
{schema: JOB_PANEL_COMPOSITION_SCHEMA, stage: [stage], side: ['act.submit']};
|
|
681
|
+
const raw: unknown = metadata.manifest?.panels;
|
|
682
|
+
if (raw === undefined) return {composition: fallback, invalid: false};
|
|
683
|
+
try { return {composition: parsePanelComposition(raw), invalid: false}; }
|
|
684
|
+
catch { return {composition: fallback, invalid: true}; }
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** Derived only from finalized asks, including cursor replay after reload. */
|
|
688
|
+
export function jobPartsReviewState(asks: readonly JobWindowAsk[], publicationId: string) {
|
|
689
|
+
const bound = asks.filter(ask => ask.publicationId === publicationId);
|
|
690
|
+
const verdict = bound.filter(ask => ask.subject.kind === 'parts-verdict').at(-1);
|
|
691
|
+
const act = verdict?.act;
|
|
692
|
+
if (act?.kind !== 'parts-verdict' || act.schema !== JOB_PARTS_VERDICT_ACT_SCHEMA) return 'reviewing';
|
|
693
|
+
if (act.value.verdict === 'changes-requested') return 'sent';
|
|
694
|
+
const approved = bound.some(ask => ask.subject.kind === 'signoff' && ask.subject.stage === 'parts-review' &&
|
|
695
|
+
ask.act?.kind === 'signoff' && ask.act.value.decision === 'approved');
|
|
696
|
+
return approved ? 'approved' : 'retry-signoff';
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/** A declared painting identity takes precedence over manifest reference order. */
|
|
700
|
+
export function jobPartsPainting(prepared: Pick<JobPreparedInspection, 'metadata' | 'display' | 'references'>) {
|
|
701
|
+
const declared = prepared.metadata.sourcePainting;
|
|
702
|
+
if (declared) return prepared.references.find(reference => reference.id === declared.id) ?? null;
|
|
703
|
+
const source = prepared.display.publication.source;
|
|
704
|
+
if (isRecordSource(source)) return null;
|
|
705
|
+
const painting = source.parts?.images.find(image => image.role === 'painting');
|
|
706
|
+
return painting ? prepared.references.find(reference => reference.label === painting.role + ' ' + painting.path) ?? null : null;
|
|
707
|
+
}
|
|
708
|
+
|
|
567
709
|
/** A reference stays off-stage until its seek matches the latest inspection time. */
|
|
568
710
|
export function createJobReferenceSelection<Reference extends Pick<JobReferenceView, 'seek'>>(options: {
|
|
569
711
|
current(): {owner: object | null; time: number};
|
|
@@ -606,11 +748,12 @@ export function createJobReferenceSelection<Reference extends Pick<JobReferenceV
|
|
|
606
748
|
}
|
|
607
749
|
|
|
608
750
|
export interface JobPreparedInspection {
|
|
609
|
-
display:
|
|
610
|
-
metadata:
|
|
751
|
+
display: DisplayPublicationV3;
|
|
752
|
+
metadata: JobInspectionMetadataV3;
|
|
611
753
|
interview: JobInterview | null;
|
|
612
754
|
parts: JobPartsInventory | null;
|
|
613
755
|
partImages: Map<string, HTMLImageElement>;
|
|
756
|
+
partPages?: Map<number, HTMLImageElement>;
|
|
614
757
|
interviewImages: Map<string, HTMLImageElement>;
|
|
615
758
|
imageSetImages?: readonly HTMLImageElement[];
|
|
616
759
|
references: JobReferenceView[];
|
|
@@ -683,12 +826,21 @@ function mediaReady(media: HTMLVideoElement, name: 'loadeddata' | 'seeked', sign
|
|
|
683
826
|
});
|
|
684
827
|
}
|
|
685
828
|
/** Prepare the real published Play model, references and every form dependency off-stage. */
|
|
686
|
-
export async function prepareJobInspection(display:
|
|
829
|
+
export async function prepareJobInspection(display: DisplayPublicationV3, signal: AbortSignal): Promise<JobPreparedInspection> {
|
|
687
830
|
const routes = jobPublicationRoutes(display, location.origin);
|
|
688
|
-
const metadata = await jobJson<
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
(metadata.
|
|
831
|
+
const metadata = await jobJson<JobInspectionMetadataV3>(routes.api('review'), signal);
|
|
832
|
+
const publishedSource = display.publication.source;
|
|
833
|
+
if (isRecordSource(publishedSource)) {
|
|
834
|
+
if (!metadata.recordSource || metadata.manifest !== undefined || metadata.reviewedSource !== undefined ||
|
|
835
|
+
metadata.sourceHash !== publishedSource.sourceHash ||
|
|
836
|
+
sourceSnapshot(metadata.recordSource) !== sourceSnapshot(publishedSource)) {
|
|
837
|
+
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
else if (!metadata.manifest || !metadata.reviewedSource ||
|
|
841
|
+
metadata.manifest.id !== publishedSource.package.id ||
|
|
842
|
+
metadata.manifest.revision !== publishedSource.package.revision ||
|
|
843
|
+
(metadata.reviewedSource.rig?.sha256 ?? null) !== (publishedSource.model?.sha256 ?? null)) {
|
|
692
844
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
693
845
|
}
|
|
694
846
|
const objectUrls: string[] = [];
|
|
@@ -740,15 +892,22 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
740
892
|
}
|
|
741
893
|
try {
|
|
742
894
|
const interview = metadata.capabilities.interview ? await jobJson<JobInterview>(routes.api('interview'), signal) : null;
|
|
895
|
+
if (interview?.interview !== undefined && display.publication.interview !== undefined &&
|
|
896
|
+
sourceSnapshot(interview.interview) !== sourceSnapshot(display.publication.interview)) {
|
|
897
|
+
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
898
|
+
}
|
|
743
899
|
const parts = metadata.capabilities.preRig ? await jobJson<JobPartsInventory>(routes.api('stage-parts'), signal) : null;
|
|
900
|
+
if (metadata.sourceHash !== publishedSource.sourceHash || parts && parts.sourceHash !== publishedSource.sourceHash)
|
|
901
|
+
throw new Error('JOB_SOURCE_MISMATCH');
|
|
744
902
|
const references: JobReferenceView[] = [];
|
|
745
903
|
const partImages = new Map<string, HTMLImageElement>();
|
|
746
904
|
const interviewImages = new Map<string, HTMLImageElement>();
|
|
905
|
+
const partPages = new Map<number, HTMLImageElement>();
|
|
747
906
|
const preload: Promise<void>[] = [];
|
|
748
907
|
const imageSetImages: HTMLImageElement[] = [];
|
|
749
908
|
const source = display.publication.source;
|
|
750
909
|
if (source.subject === 'image-set') {
|
|
751
|
-
if (metadata.sourceHash !== source.sourceHash || metadata.manifest
|
|
910
|
+
if (metadata.sourceHash !== source.sourceHash || metadata.manifest?.model)
|
|
752
911
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
753
912
|
const canonical = source.imageSet.images.map(({role, name, sha256}) => ({role, name, sha256}));
|
|
754
913
|
if (source.imageSet.images.length < 2 || source.imageSet.images.length > 8 ||
|
|
@@ -761,10 +920,13 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
761
920
|
}));
|
|
762
921
|
}
|
|
763
922
|
}
|
|
764
|
-
for (const reference of metadata.manifest
|
|
923
|
+
for (const reference of metadata.manifest?.references ?? []) {
|
|
924
|
+
if (reference.id === metadata.sourcePainting?.id) continue;
|
|
765
925
|
preload.push((async () => {
|
|
766
926
|
if (reference.type === 'image') {
|
|
767
|
-
const
|
|
927
|
+
const painting = !isRecordSource(source) ? source.parts?.images.find(entry =>
|
|
928
|
+
entry.role === 'painting' && reference.label === entry.role + ' ' + entry.path) : null;
|
|
929
|
+
const element = await image(routes.asset(reference.path), painting?.sha256 ?? metadata.referenceHashes?.[reference.id]);
|
|
768
930
|
element.alt = reference.label;
|
|
769
931
|
references.push({ id: reference.id, label: reference.label, element,
|
|
770
932
|
width: element.naturalWidth, height: element.naturalHeight, seek: async () => { } });
|
|
@@ -869,6 +1031,10 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
869
1031
|
preload.push(image(routes.api('stage-parts/image/' + part.index), part.imageHash)
|
|
870
1032
|
.then(element => { element.alt = part.name; partImages.set(part.name, element); }));
|
|
871
1033
|
}
|
|
1034
|
+
for (const page of parts?.pages ?? []) {
|
|
1035
|
+
preload.push(image(routes.api('stage-parts/page/' + page.index))
|
|
1036
|
+
.then(element => { partPages.set(page.index, element); }));
|
|
1037
|
+
}
|
|
872
1038
|
for (const question of interview?.questions ?? [])
|
|
873
1039
|
for (const asset of question.images) {
|
|
874
1040
|
preload.push(image(routes.instance(asset.url)).then(element => { element.alt = asset.name; interviewImages.set(asset.url, element); }));
|
|
@@ -877,10 +1043,10 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
877
1043
|
const failed = preloaded.find(result => result.status === 'rejected');
|
|
878
1044
|
if (failed?.status === 'rejected')
|
|
879
1045
|
throw failed.reason;
|
|
880
|
-
if (metadata.manifest
|
|
1046
|
+
if (metadata.manifest?.model) {
|
|
881
1047
|
const runtime = await import('@rig-c/play');
|
|
882
1048
|
const modelUrl = routes.asset(metadata.manifest.model);
|
|
883
|
-
const modelHash = metadata.reviewedSource
|
|
1049
|
+
const modelHash = metadata.reviewedSource!.rig!.sha256;
|
|
884
1050
|
const setsUrl = metadata.manifest.sets ? routes.asset(metadata.manifest.sets) : null;
|
|
885
1051
|
const checkedFetch = new Proxy(fetch, { apply: async (_target, _receiver, args: Parameters<typeof fetch>) => {
|
|
886
1052
|
const url = String(args[0]);
|
|
@@ -909,15 +1075,15 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
909
1075
|
};
|
|
910
1076
|
resetToSetup();
|
|
911
1077
|
}
|
|
912
|
-
if (!player && !references.length && !partImages.size && !imageSetImages.length)
|
|
1078
|
+
if (!isRecordSource(source) && !player && !references.length && !partImages.size && !imageSetImages.length)
|
|
913
1079
|
throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
914
1080
|
if (signal.aborted)
|
|
915
1081
|
throw new Error('JOB_PRELOAD_CANCELLED');
|
|
916
1082
|
// Preloads can finish out of order. Restore the producer's declared display order.
|
|
917
|
-
const order = [metadata.sourcePainting?.id, ...metadata.manifest
|
|
1083
|
+
const order = [metadata.sourcePainting?.id, ...(metadata.manifest?.references.map(reference => reference.id) ?? [])];
|
|
918
1084
|
references.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
|
|
919
1085
|
return {
|
|
920
|
-
display, metadata, interview, parts, partImages, interviewImages, imageSetImages, references, assets, rigRoot,
|
|
1086
|
+
display, metadata, interview, parts, partImages, partPages, interviewImages, imageSetImages, references, assets, rigRoot,
|
|
921
1087
|
get rigPresentation() { return rigPresentation; },
|
|
922
1088
|
set rigPresentation(value) {
|
|
923
1089
|
clearRigPresentation();
|
|
@@ -986,34 +1152,213 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
986
1152
|
host.replaceChildren(header, notice, workspace);
|
|
987
1153
|
let current: JobPreparedInspection | null = null;
|
|
988
1154
|
let currentElement: HTMLElement | null = null;
|
|
989
|
-
|
|
990
|
-
|
|
1155
|
+
type SavedCameraState = Pick<
|
|
1156
|
+
ReturnType<typeof createViewportState>,
|
|
1157
|
+
'cameraSync' | 'activeCamera' | 'zoom' | 'cameraCenter' | 'referenceZoom' | 'referenceCenter'
|
|
1158
|
+
>;
|
|
1159
|
+
type SavedJobWindowState = {
|
|
1160
|
+
publicationId: string;
|
|
1161
|
+
label: string;
|
|
1162
|
+
sourceHash: string;
|
|
1163
|
+
previousLabel: string | null;
|
|
1164
|
+
compatibilityNotice?: boolean;
|
|
1165
|
+
animation?: string;
|
|
1166
|
+
time?: number;
|
|
1167
|
+
loop?: boolean;
|
|
1168
|
+
selectedPart?: string;
|
|
1169
|
+
partMode?: 'context' | 'solo';
|
|
1170
|
+
selectedReference?: string;
|
|
1171
|
+
panel?: string;
|
|
1172
|
+
partIdentity?: unknown;
|
|
1173
|
+
camera?: unknown;
|
|
1174
|
+
};
|
|
1175
|
+
const parseSavedPoint = (raw: unknown): { x: number; y: number } | null | undefined => {
|
|
1176
|
+
if (raw === null) return null;
|
|
1177
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return undefined;
|
|
1178
|
+
const point = raw as Record<string, unknown>;
|
|
1179
|
+
return typeof point.x === 'number' && Number.isFinite(point.x) &&
|
|
1180
|
+
typeof point.y === 'number' && Number.isFinite(point.y)
|
|
1181
|
+
? { x: point.x, y: point.y }
|
|
1182
|
+
: undefined;
|
|
1183
|
+
};
|
|
1184
|
+
const parseSavedCamera = (raw: unknown): SavedCameraState | null => {
|
|
1185
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
1186
|
+
const value = raw as Record<string, unknown>;
|
|
1187
|
+
const cameraCenter = parseSavedPoint(value.cameraCenter);
|
|
1188
|
+
const referenceCenter = parseSavedPoint(value.referenceCenter);
|
|
1189
|
+
if (typeof value.cameraSync !== 'boolean' ||
|
|
1190
|
+
(value.activeCamera !== 'rig' && value.activeCamera !== 'reference') ||
|
|
1191
|
+
typeof value.zoom !== 'number' || !Number.isFinite(value.zoom) || value.zoom < 0.25 || value.zoom > 8 ||
|
|
1192
|
+
typeof value.referenceZoom !== 'number' || !Number.isFinite(value.referenceZoom) || value.referenceZoom < 0.25 || value.referenceZoom > 8 ||
|
|
1193
|
+
cameraCenter === undefined || referenceCenter === undefined) {
|
|
1194
|
+
return null;
|
|
1195
|
+
}
|
|
1196
|
+
return {
|
|
1197
|
+
cameraSync: value.cameraSync,
|
|
1198
|
+
activeCamera: value.activeCamera,
|
|
1199
|
+
zoom: value.zoom,
|
|
1200
|
+
cameraCenter,
|
|
1201
|
+
referenceZoom: value.referenceZoom,
|
|
1202
|
+
referenceCenter,
|
|
1203
|
+
};
|
|
1204
|
+
};
|
|
1205
|
+
const parseSavedPartIdentity = (raw: unknown): ControlPart | null => {
|
|
1206
|
+
try {
|
|
1207
|
+
return parseControlPart(raw);
|
|
1208
|
+
}
|
|
1209
|
+
catch {
|
|
1210
|
+
return null;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
const parseSavedDraftRecord = (raw: unknown): JobRetainedDraft | null => {
|
|
1214
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
1215
|
+
const draft = raw as Record<string, unknown>;
|
|
1216
|
+
if (!Array.isArray(draft.forms) || !draft.forms.length ||
|
|
1217
|
+
typeof draft.publicationId !== 'string' || !draft.publicationId ||
|
|
1218
|
+
typeof draft.sourceHash !== 'string' || !draft.sourceHash ||
|
|
1219
|
+
typeof draft.label !== 'string' || !draft.label ||
|
|
1220
|
+
!draft.source || typeof draft.source !== 'object' || Array.isArray(draft.source) ||
|
|
1221
|
+
(draft.source as { sourceHash?: unknown }).sourceHash !== draft.sourceHash) {
|
|
1222
|
+
return null;
|
|
1223
|
+
}
|
|
1224
|
+
const forms = draft.forms.filter((item: unknown): item is { askId: string; value: unknown } =>
|
|
1225
|
+
!!item && typeof item === 'object' && !Array.isArray(item) &&
|
|
1226
|
+
typeof (item as { askId?: unknown }).askId === 'string' && !!(item as { askId: string }).askId);
|
|
1227
|
+
if (!forms.length) return null;
|
|
1228
|
+
return {
|
|
1229
|
+
publicationId: draft.publicationId,
|
|
1230
|
+
sourceHash: draft.sourceHash,
|
|
1231
|
+
source: draft.source as SourceV3,
|
|
1232
|
+
label: draft.label,
|
|
1233
|
+
value: forms.map(item => ({ askId: item.askId, value: item.value })),
|
|
1234
|
+
};
|
|
1235
|
+
};
|
|
1236
|
+
const localWindowKey = 'rig-review-job-window/1:' + access.jobId;
|
|
1237
|
+
let savedWindow: SavedJobWindowState | null = null;
|
|
1238
|
+
try {
|
|
1239
|
+
const parsed = JSON.parse(localStorage.getItem(localWindowKey) ?? 'null');
|
|
1240
|
+
if (parsed && typeof parsed.publicationId === 'string' && typeof parsed.label === 'string' &&
|
|
1241
|
+
typeof parsed.sourceHash === 'string') {
|
|
1242
|
+
savedWindow = parsed as SavedJobWindowState;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
catch { /* Invalid saved window state falls back to defaults. */ }
|
|
1246
|
+
const initialRetainedDrafts: JobRetainedDraft[] = [];
|
|
1247
|
+
try {
|
|
1248
|
+
const draftPrefix = 'rig-review-job-draft/1:' + access.jobId + ':';
|
|
1249
|
+
for (let index = 0; index < localStorage.length; index++) {
|
|
1250
|
+
const key = localStorage.key(index);
|
|
1251
|
+
if (!key?.startsWith(draftPrefix)) continue;
|
|
1252
|
+
try {
|
|
1253
|
+
const parsedDraft = parseSavedDraftRecord(JSON.parse(localStorage.getItem(key) ?? 'null'));
|
|
1254
|
+
if (parsedDraft) initialRetainedDrafts.push(parsedDraft);
|
|
1255
|
+
}
|
|
1256
|
+
catch { /* Ignore malformed draft entries without dropping sibling drafts. */ }
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
catch { /* In-memory standing state remains active when storage is unavailable. */ }
|
|
1260
|
+
const previousDisplayed = savedWindow ? {
|
|
1261
|
+
publicationId: savedWindow.publicationId,
|
|
1262
|
+
label: savedWindow.label,
|
|
1263
|
+
previousLabel: typeof savedWindow.previousLabel === 'string' ? savedWindow.previousLabel : null,
|
|
1264
|
+
} : null;
|
|
1265
|
+
let animation = typeof savedWindow?.animation === 'string' ? savedWindow.animation : '';
|
|
1266
|
+
let time = typeof savedWindow?.time === 'number' && Number.isFinite(savedWindow.time) && savedWindow.time >= 0
|
|
1267
|
+
? savedWindow.time : 0;
|
|
991
1268
|
let playing = false;
|
|
992
|
-
let loop = true;
|
|
1269
|
+
let loop = typeof savedWindow?.loop === 'boolean' ? savedWindow.loop : true;
|
|
993
1270
|
let playbackCarry = 0;
|
|
994
1271
|
let rafHandle = 0;
|
|
995
1272
|
let lastFrameTime = 0;
|
|
996
|
-
let
|
|
997
|
-
let
|
|
998
|
-
let
|
|
999
|
-
let
|
|
1000
|
-
let
|
|
1273
|
+
let inPlaybackStep = false;
|
|
1274
|
+
let lastRunningSaveMs: number | null = null;
|
|
1275
|
+
let lastSavedWindowJson: string | null = null;
|
|
1276
|
+
let selectedPart = typeof savedWindow?.selectedPart === 'string' ? savedWindow.selectedPart : '';
|
|
1277
|
+
let partMode: 'context' | 'solo' = savedWindow?.partMode === 'solo' ? 'solo' : 'context';
|
|
1278
|
+
let selectedReference = typeof savedWindow?.selectedReference === 'string' ? savedWindow.selectedReference : '';
|
|
1279
|
+
let panel = typeof savedWindow?.panel === 'string' && ['1', '2', '3', '4'].includes(savedWindow.panel)
|
|
1280
|
+
? savedWindow.panel : '3';
|
|
1281
|
+
let restoredPartIdentity: ControlPart | null = parseSavedPartIdentity(savedWindow?.partIdentity);
|
|
1282
|
+
let restoredCamera: SavedCameraState | null = parseSavedCamera(savedWindow?.camera);
|
|
1283
|
+
let compatibilityNotice = Boolean(savedWindow?.compatibilityNotice);
|
|
1001
1284
|
type JobForm = {
|
|
1002
1285
|
form: HTMLFormElement;
|
|
1003
1286
|
fieldset: HTMLFieldSetElement;
|
|
1004
|
-
read: () =>
|
|
1287
|
+
read: () => UISubmissionV3['value'];
|
|
1005
1288
|
submissionId: string;
|
|
1006
1289
|
dirty: boolean;
|
|
1290
|
+
submitting: boolean;
|
|
1007
1291
|
rigSubmission: ReturnType<typeof createJobRigSubmission>;
|
|
1008
1292
|
};
|
|
1009
1293
|
type PreparedWindow = JobPreparedInspection & {
|
|
1010
1294
|
element: HTMLElement;
|
|
1011
1295
|
forms: Map<string, JobForm>;
|
|
1012
1296
|
};
|
|
1297
|
+
const partsPanels = new WeakMap<JobPreparedInspection, {
|
|
1298
|
+
slots: {left: HTMLElement; stage: HTMLElement; toolbar: HTMLElement; side: HTMLElement};
|
|
1299
|
+
composition: JobPanelComposition;
|
|
1300
|
+
output?: Parameters<PartsHost['register']>[0];
|
|
1301
|
+
issues: PartsIssue[];
|
|
1302
|
+
legacy: unknown;
|
|
1303
|
+
dispose?: () => void;
|
|
1304
|
+
}>();
|
|
1013
1305
|
const forms = new Map<string, JobForm>();
|
|
1014
1306
|
const drawn = new WeakMap<JobPreparedInspection, JobRigDraw>();
|
|
1015
1307
|
let drawGeneration = 0;
|
|
1016
1308
|
const viewportState = createViewportState();
|
|
1309
|
+
if (restoredCamera) {
|
|
1310
|
+
Object.assign(viewportState, restoredCamera, { cameraRestoring: false });
|
|
1311
|
+
}
|
|
1312
|
+
function saveWindowState(nowMs?: number): void {
|
|
1313
|
+
if (!current)
|
|
1314
|
+
return;
|
|
1315
|
+
if (inPlaybackStep && nowMs === undefined)
|
|
1316
|
+
return;
|
|
1317
|
+
const state = window.state();
|
|
1318
|
+
if (state.displayed?.publication.publicationId !== current.display.publication.publicationId)
|
|
1319
|
+
return;
|
|
1320
|
+
if (nowMs !== undefined) {
|
|
1321
|
+
if (lastRunningSaveMs === null) {
|
|
1322
|
+
lastRunningSaveMs = nowMs;
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
if (nowMs - lastRunningSaveMs < 1000)
|
|
1326
|
+
return;
|
|
1327
|
+
lastRunningSaveMs = nowMs;
|
|
1328
|
+
}
|
|
1329
|
+
try {
|
|
1330
|
+
const serialized = JSON.stringify({
|
|
1331
|
+
publicationId: current.display.publication.publicationId,
|
|
1332
|
+
label: current.display.publication.label,
|
|
1333
|
+
sourceHash: current.display.publication.source.sourceHash,
|
|
1334
|
+
previousLabel: state.previousLabel,
|
|
1335
|
+
compatibilityNotice,
|
|
1336
|
+
animation,
|
|
1337
|
+
time,
|
|
1338
|
+
loop,
|
|
1339
|
+
selectedPart,
|
|
1340
|
+
partMode,
|
|
1341
|
+
selectedReference,
|
|
1342
|
+
panel,
|
|
1343
|
+
partIdentity: current.inspection?.value() ?? null,
|
|
1344
|
+
camera: {
|
|
1345
|
+
cameraSync: viewportState.cameraSync,
|
|
1346
|
+
activeCamera: viewportState.activeCamera,
|
|
1347
|
+
zoom: viewportState.zoom,
|
|
1348
|
+
cameraCenter: viewportState.cameraCenter
|
|
1349
|
+
? { x: viewportState.cameraCenter.x, y: viewportState.cameraCenter.y } : null,
|
|
1350
|
+
referenceZoom: viewportState.referenceZoom,
|
|
1351
|
+
referenceCenter: viewportState.referenceCenter
|
|
1352
|
+
? { x: viewportState.referenceCenter.x, y: viewportState.referenceCenter.y } : null,
|
|
1353
|
+
},
|
|
1354
|
+
});
|
|
1355
|
+
if (serialized === lastSavedWindowJson)
|
|
1356
|
+
return;
|
|
1357
|
+
localStorage.setItem(localWindowKey, serialized);
|
|
1358
|
+
lastSavedWindowJson = serialized;
|
|
1359
|
+
}
|
|
1360
|
+
catch { /* Standing state stays in memory when storage is unavailable. */ }
|
|
1361
|
+
}
|
|
1017
1362
|
const el = <Element extends HTMLElement = HTMLElement>(id: string): Element => {
|
|
1018
1363
|
const element = workspace.querySelector<HTMLElement>('#' + id);
|
|
1019
1364
|
if (!element)
|
|
@@ -1034,6 +1379,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1034
1379
|
canonicalControls(controller);
|
|
1035
1380
|
const fit = el('fit');
|
|
1036
1381
|
fit.textContent = t(fit.textContent ?? 'Fit');
|
|
1382
|
+
saveWindowState();
|
|
1037
1383
|
};
|
|
1038
1384
|
const viewport = createViewportController(provider, viewportState);
|
|
1039
1385
|
const renderViewport = provider.render;
|
|
@@ -1130,8 +1476,10 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1130
1476
|
playing = false;
|
|
1131
1477
|
playbackCarry = 0;
|
|
1132
1478
|
lastFrameTime = 0;
|
|
1479
|
+
lastRunningSaveMs = null;
|
|
1133
1480
|
targetPlayer?.pause();
|
|
1134
1481
|
syncTransportControls();
|
|
1482
|
+
saveWindowState();
|
|
1135
1483
|
}
|
|
1136
1484
|
function presentCurrentFrame(owner: JobPreparedInspection): void {
|
|
1137
1485
|
if (!owner.player) return;
|
|
@@ -1192,13 +1540,25 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1192
1540
|
}
|
|
1193
1541
|
const clock = workspace.querySelector<HTMLInputElement>('#job-time');
|
|
1194
1542
|
if (clock) clock.value = playbackTimeLabel(clip.duration, activeEntry.trackTime);
|
|
1195
|
-
|
|
1196
|
-
|
|
1543
|
+
inPlaybackStep = true;
|
|
1544
|
+
try {
|
|
1545
|
+
syncTransportControls();
|
|
1546
|
+
presentCurrentFrame(expectedOwner);
|
|
1547
|
+
}
|
|
1548
|
+
finally {
|
|
1549
|
+
inPlaybackStep = false;
|
|
1550
|
+
}
|
|
1551
|
+
if (playing) {
|
|
1552
|
+
saveWindowState(now);
|
|
1553
|
+
} else {
|
|
1554
|
+
lastRunningSaveMs = null;
|
|
1555
|
+
saveWindowState();
|
|
1556
|
+
}
|
|
1197
1557
|
if (playing && current === expectedOwner && current.player === expectedPlayer && hubVisible) {
|
|
1198
1558
|
armPlayback(expectedOwner, expectedPlayer);
|
|
1199
1559
|
}
|
|
1200
1560
|
}
|
|
1201
|
-
function copyRigVerdict(ask:
|
|
1561
|
+
function copyRigVerdict(ask: PendingAskV3, owner: JobPreparedInspection) {
|
|
1202
1562
|
if (owner !== current || ask.publicationId !== owner.display.publication.publicationId) {
|
|
1203
1563
|
throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
1204
1564
|
}
|
|
@@ -1234,7 +1594,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1234
1594
|
});
|
|
1235
1595
|
let unbindNavigation: (() => void) | null = null;
|
|
1236
1596
|
let resize: ResizeObserver | null = null;
|
|
1237
|
-
function localDraftKey(display:
|
|
1597
|
+
function localDraftKey(display: DisplayPublicationV3): string {
|
|
1238
1598
|
return 'rig-review-job-draft/1:' + access.jobId + ':' + display.publication.publicationId + ':' + display.publication.source.sourceHash;
|
|
1239
1599
|
}
|
|
1240
1600
|
function saveDraft(): void {
|
|
@@ -1275,7 +1635,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1275
1635
|
parent.append(inputLabel(key, input));
|
|
1276
1636
|
return input;
|
|
1277
1637
|
}
|
|
1278
|
-
function formFor(ask:
|
|
1638
|
+
function formFor(ask: PendingAskV3, prepared: JobPreparedInspection): JobForm {
|
|
1279
1639
|
if (ask.publicationId !== prepared.display.publication.publicationId)
|
|
1280
1640
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
1281
1641
|
assertJobAskSource(ask, prepared.display);
|
|
@@ -1288,13 +1648,33 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1288
1648
|
source.textContent = prepared.display.publication.label + ' · ' + ask.source.sourceHash;
|
|
1289
1649
|
fields.append(source);
|
|
1290
1650
|
const note = textArea(fields, 'interview.note');
|
|
1291
|
-
let read: () =>
|
|
1651
|
+
let read: () => UISubmissionV3['value'];
|
|
1292
1652
|
let submitKey = 'Submit review';
|
|
1293
1653
|
const subject = ask.subject;
|
|
1294
1654
|
if (subject.kind === 'interview-picks') {
|
|
1295
1655
|
const question = prepared.interview?.questions.find(item => item.set.id === subject.setId && item.set.question === subject.questionId);
|
|
1296
1656
|
if (!question || !question.editable) throw new Error('JOB_ASK_INVALID');
|
|
1297
1657
|
if (question.ref.sha256 !== ask.source.optionSet?.sha256) throw new Error('JOB_ACT_SOURCE_STALE');
|
|
1658
|
+
const interviewState = prepared.interview?.interview ?? prepared.display.publication.interview ?? null;
|
|
1659
|
+
const inspectionRecord = interviewState?.records.find(
|
|
1660
|
+
item => item.timeKind === 'inspection' &&
|
|
1661
|
+
item.questionId === subject.questionId &&
|
|
1662
|
+
item.setId === subject.setId &&
|
|
1663
|
+
item.record.endsWith('.pending_options'),
|
|
1664
|
+
);
|
|
1665
|
+
const legacyDiagnostic = inspectionRecord
|
|
1666
|
+
? interviewState?.diagnostics.find(
|
|
1667
|
+
item => item.code === 'INTERVIEW_OPTIONS_SCENE_LEGACY' &&
|
|
1668
|
+
item.record === inspectionRecord.record &&
|
|
1669
|
+
item.at === inspectionRecord.at,
|
|
1670
|
+
)
|
|
1671
|
+
: undefined;
|
|
1672
|
+
if (legacyDiagnostic) {
|
|
1673
|
+
const legacyNotice = node('p', 'INTERVIEW_OPTIONS_SCENE_LEGACY');
|
|
1674
|
+
legacyNotice.dataset.jobInterviewWarning = legacyDiagnostic.code;
|
|
1675
|
+
legacyNotice.dataset.record = legacyDiagnostic.record;
|
|
1676
|
+
fields.prepend(legacyNotice);
|
|
1677
|
+
}
|
|
1298
1678
|
const heading = node('h3');
|
|
1299
1679
|
heading.textContent = question.set.question;
|
|
1300
1680
|
fields.prepend(heading);
|
|
@@ -1343,7 +1723,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1343
1723
|
submitKey = 'interview.save';
|
|
1344
1724
|
}
|
|
1345
1725
|
else if (subject.kind === 'checkpoint') {
|
|
1346
|
-
const checkpoint = jobCheckpointContext(ask, prepared.metadata.manifest
|
|
1726
|
+
const checkpoint = jobCheckpointContext(ask, prepared.metadata.manifest?.checkpoints ?? []);
|
|
1347
1727
|
const heading = node('h3');
|
|
1348
1728
|
heading.textContent = checkpoint.title;
|
|
1349
1729
|
fields.prepend(heading);
|
|
@@ -1361,32 +1741,13 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1361
1741
|
submitKey = 'job.saveCheckpoint';
|
|
1362
1742
|
}
|
|
1363
1743
|
else if (subject.kind === 'parts-verdict') {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
const legend = node('legend');
|
|
1372
|
-
legend.textContent = part.name;
|
|
1373
|
-
group.append(legend);
|
|
1374
|
-
const partOutcome = selectValues(['pending', 'clean', 'flagged'], ['Pending', 'Clean', 'Flagged']);
|
|
1375
|
-
const meshOutcome = selectValues(['pending', 'clean', 'flagged'], ['Pending', 'Clean', 'Flagged']);
|
|
1376
|
-
partOutcome.name = 'parts.' + part.name + '.outcome';
|
|
1377
|
-
meshOutcome.name = 'mesh.' + part.name + '.outcome';
|
|
1378
|
-
group.append(inputLabel('Parts', partOutcome));
|
|
1379
|
-
const partNote = textArea(group, 'Note', 'parts.' + part.name + '.note');
|
|
1380
|
-
group.append(inputLabel('Mesh', meshOutcome));
|
|
1381
|
-
const meshNote = textArea(group, 'Note', 'mesh.' + part.name + '.note');
|
|
1382
|
-
fields.append(group);
|
|
1383
|
-
return { partId: part.name, partOutcome, meshOutcome, partNote, meshNote };
|
|
1384
|
-
});
|
|
1385
|
-
read = () => ({ verdict: verdict.value as 'pending' | 'approved' | 'changes-requested', words: note.value,
|
|
1386
|
-
parts: parts.map(part => ({ partId: part.partId,
|
|
1387
|
-
part: { outcome: part.partOutcome.value as 'pending' | 'clean' | 'flagged', note: part.partNote.value },
|
|
1388
|
-
mesh: { outcome: part.meshOutcome.value as 'pending' | 'clean' | 'flagged', note: part.meshNote.value } })) });
|
|
1389
|
-
submitKey = 'job.savePartsVerdict';
|
|
1744
|
+
read = () => {
|
|
1745
|
+
const panel = partsPanels.get(prepared);
|
|
1746
|
+
if (panel?.legacy) throw new Error('JOB_PARTS_LEGACY_DRAFT');
|
|
1747
|
+
if (!panel?.output) throw new Error('JOB_PANEL_OUTPUT_MISSING');
|
|
1748
|
+
return {...panel.output.value(), words: note.value};
|
|
1749
|
+
};
|
|
1750
|
+
submitKey = 'job.partsApprove';
|
|
1390
1751
|
}
|
|
1391
1752
|
else if (subject.kind === 'review-verdict') {
|
|
1392
1753
|
const verdict = selectValues(['pending', 'approved', 'changes-requested'], ['Pending', 'Approved', 'Changes requested']);
|
|
@@ -1421,6 +1782,22 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1421
1782
|
read = () => ({ stage: subject.stage, decision: 'approved', words: note.value });
|
|
1422
1783
|
submitKey = 'job.signoff';
|
|
1423
1784
|
}
|
|
1785
|
+
else if (subject.kind === 'reopen') {
|
|
1786
|
+
if (
|
|
1787
|
+
!('record' in ask.source) ||
|
|
1788
|
+
ask.source.subject !== 'plan' ||
|
|
1789
|
+
typeof subject.stage !== 'string' ||
|
|
1790
|
+
!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(subject.stage) ||
|
|
1791
|
+
!ask.source.subjects.some(candidate => candidate.kind === 'reopen' && candidate.stage === subject.stage)
|
|
1792
|
+
) {
|
|
1793
|
+
throw new Error('JOB_ASK_INVALID');
|
|
1794
|
+
}
|
|
1795
|
+
const stage = node('p');
|
|
1796
|
+
stage.textContent = subject.stage;
|
|
1797
|
+
fields.append(stage);
|
|
1798
|
+
read = () => ({ stage: subject.stage, words: note.value });
|
|
1799
|
+
submitKey = 'job.reopen';
|
|
1800
|
+
}
|
|
1424
1801
|
else {
|
|
1425
1802
|
throw new Error('JOB_ACT_KIND_DISABLED');
|
|
1426
1803
|
}
|
|
@@ -1431,14 +1808,21 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1431
1808
|
status.setAttribute('role', 'status');
|
|
1432
1809
|
form.append(status);
|
|
1433
1810
|
const entry: JobForm = { form, fieldset: fields, read, submissionId: crypto.randomUUID(), dirty: false,
|
|
1434
|
-
rigSubmission: createJobRigSubmission() };
|
|
1811
|
+
submitting: false, rigSubmission: createJobRigSubmission() };
|
|
1812
|
+
const signoffSubmissionId = crypto.randomUUID();
|
|
1435
1813
|
try {
|
|
1436
1814
|
const saved = JSON.parse(localStorage.getItem(localDraftKey(prepared.display)) ?? 'null');
|
|
1437
1815
|
if (saved?.publicationId === prepared.display.publication.publicationId &&
|
|
1438
1816
|
saved?.sourceHash === prepared.display.publication.source.sourceHash) {
|
|
1817
|
+
assertJobAskSource({...ask, source: saved.source}, prepared.display);
|
|
1439
1818
|
const original = saved.forms?.find((item: {
|
|
1440
1819
|
askId: string;
|
|
1441
1820
|
}) => item.askId === ask.askId);
|
|
1821
|
+
if (subject.kind === 'parts-verdict') {
|
|
1822
|
+
const panel = partsPanels.get(prepared);
|
|
1823
|
+
if (panel && Array.isArray(original?.value?.issues)) panel.issues = structuredClone(original.value.issues);
|
|
1824
|
+
else if (panel && original?.value?.parts) panel.legacy = original.value;
|
|
1825
|
+
}
|
|
1442
1826
|
for (const input of form.querySelectorAll<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>('input[name],textarea[name],select[name]')) {
|
|
1443
1827
|
const restored = original?.controls?.find((item: {
|
|
1444
1828
|
name: string;
|
|
@@ -1464,28 +1848,35 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1464
1848
|
try {
|
|
1465
1849
|
const input = { kind: subject.kind, publicationId: ask.publicationId,
|
|
1466
1850
|
askId: ask.askId, pageId, displayedNonce: receipt.displayedNonce,
|
|
1467
|
-
expectedGeneration: state.generation, submissionId: entry.submissionId, value: read() } as
|
|
1851
|
+
expectedGeneration: state.generation, submissionId: entry.submissionId, value: read() } as UISubmissionV3;
|
|
1468
1852
|
const activeAsk = state.pending.find(item => item.askId === ask.askId);
|
|
1469
1853
|
if (!activeAsk) throw new Error('JOB_ASK_INVALID');
|
|
1470
1854
|
const pending = subject.kind === 'review-verdict' && subject.stage === 'rig-review'
|
|
1471
|
-
? entry.rigSubmission.prepare(input, () => copyRigVerdict(activeAsk, prepared)) : Promise.resolve(input);
|
|
1855
|
+
? entry.rigSubmission.prepare(input as JobUISubmission, () => copyRigVerdict(activeAsk, prepared)) : Promise.resolve(input);
|
|
1856
|
+
entry.submitting = true;
|
|
1472
1857
|
fields.disabled = true;
|
|
1473
1858
|
const frozen = await pending;
|
|
1474
1859
|
if (entry.submissionId !== frozen.submissionId) throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
1475
|
-
|
|
1860
|
+
if (subject.kind === 'parts-verdict') window.refresh();
|
|
1861
|
+
const result = subject.kind === 'parts-verdict'
|
|
1862
|
+
? await window.submitParts(frozen, signoffSubmissionId) : await window.submit(frozen);
|
|
1476
1863
|
if (!result.ok)
|
|
1477
1864
|
throw new Error(result.error.code);
|
|
1865
|
+
entry.submitting = false;
|
|
1478
1866
|
entry.dirty = false;
|
|
1479
1867
|
entry.rigSubmission.reset();
|
|
1480
1868
|
status.dataset.jobText = 'job.saved';
|
|
1481
1869
|
status.textContent = t('job.saved');
|
|
1482
1870
|
saveDraft();
|
|
1871
|
+
if (subject.kind === 'parts-verdict') window.refresh();
|
|
1483
1872
|
}
|
|
1484
1873
|
catch (error) {
|
|
1874
|
+
entry.submitting = false;
|
|
1485
1875
|
status.dataset.jobText = error instanceof Error && Object.hasOwn(enCatalog, error.message) && Object.hasOwn(koCatalog, error.message)
|
|
1486
1876
|
? error.message : 'JOB_ACT_INVALID';
|
|
1487
1877
|
status.textContent = jobWindowRefusal(error, 'JOB_ACT_INVALID');
|
|
1488
1878
|
fields.disabled = false;
|
|
1879
|
+
if (subject.kind === 'parts-verdict') window.refresh();
|
|
1489
1880
|
}
|
|
1490
1881
|
};
|
|
1491
1882
|
return entry;
|
|
@@ -1496,11 +1887,17 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1496
1887
|
const host = workspace.querySelector<HTMLElement>('[data-job-forms]');
|
|
1497
1888
|
if (!host)
|
|
1498
1889
|
return;
|
|
1890
|
+
const partsPanel = partsPanels.get(current);
|
|
1891
|
+
const partsState = jobPartsReviewState(state.pending, current.display.publication.publicationId);
|
|
1892
|
+
const activeParts = state.pending.filter(ask => ask.publicationId === current!.display.publication.publicationId &&
|
|
1893
|
+
ask.subject.kind === 'parts-verdict').at(-1);
|
|
1499
1894
|
for (const ask of state.pending) {
|
|
1500
1895
|
if (ask.publicationId !== current.display.publication.publicationId)
|
|
1501
1896
|
continue;
|
|
1897
|
+
if (partsPanel && ask.subject.kind === 'signoff' && ask.subject.stage === 'parts-review') continue;
|
|
1898
|
+
if (partsPanel && ask.subject.kind === 'parts-verdict' && ask !== activeParts) continue;
|
|
1502
1899
|
let entry = forms.get(ask.askId);
|
|
1503
|
-
if (!entry && ask.status === 'pending') {
|
|
1900
|
+
if (!entry && (ask.status === 'pending' || partsPanel && ask === activeParts)) {
|
|
1504
1901
|
try {
|
|
1505
1902
|
entry = formFor(ask, current);
|
|
1506
1903
|
forms.set(ask.askId, entry);
|
|
@@ -1512,8 +1909,146 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1512
1909
|
host.append(refusal);
|
|
1513
1910
|
}
|
|
1514
1911
|
}
|
|
1515
|
-
if (entry)
|
|
1516
|
-
|
|
1912
|
+
if (entry) {
|
|
1913
|
+
const partsAsk = partsPanel && ask.subject.kind === 'parts-verdict';
|
|
1914
|
+
entry.fieldset.disabled = entry.submitting || (ask.status !== 'pending' && !(partsAsk && partsState === 'retry-signoff')) ||
|
|
1915
|
+
state.preparing || state.closed || !state.receipt || !access.capability;
|
|
1916
|
+
if (partsAsk) {
|
|
1917
|
+
const button = entry.form.querySelector<HTMLButtonElement>('button[type=submit]')!;
|
|
1918
|
+
const signoff = state.pending.some(item => item.publicationId === ask.publicationId && item.status === 'pending' &&
|
|
1919
|
+
item.subject.kind === 'signoff' && item.subject.stage === 'parts-review');
|
|
1920
|
+
button.dataset.jobText = partsState === 'retry-signoff' ? 'job.partsRetrySignoff' :
|
|
1921
|
+
partsPanel.issues.length ? 'job.partsRequestFixes' : 'job.partsApprove';
|
|
1922
|
+
button.textContent = t(button.dataset.jobText, [partsPanel.issues.length]);
|
|
1923
|
+
button.disabled = !partsPanel.output || !!partsPanel.legacy ||
|
|
1924
|
+
(partsState === 'retry-signoff' || !partsPanel.issues.length) && !signoff;
|
|
1925
|
+
const status = entry.form.querySelector<HTMLElement>('[role=status]')!;
|
|
1926
|
+
if (!partsPanel.output) {
|
|
1927
|
+
status.dataset.jobText = 'JOB_PANEL_OUTPUT_MISSING';
|
|
1928
|
+
status.textContent = t('JOB_PANEL_OUTPUT_MISSING') + ' · ' + ask.subject.kind;
|
|
1929
|
+
} else if (status.dataset.jobText === 'JOB_PANEL_OUTPUT_MISSING') {
|
|
1930
|
+
delete status.dataset.jobText;
|
|
1931
|
+
status.textContent = '';
|
|
1932
|
+
}
|
|
1933
|
+
const words = entry.form.querySelector<HTMLTextAreaElement>('textarea[name=note]');
|
|
1934
|
+
if (words) words.disabled = ask.status !== 'pending';
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
async function mountJobParts(prepared: JobPreparedInspection, signal: AbortSignal): Promise<void> {
|
|
1940
|
+
const panel = partsPanels.get(prepared)!;
|
|
1941
|
+
const [{mountPartsWorkspace}, {parsePartsIssue}] = await Promise.all([
|
|
1942
|
+
import('./parts.ts'), import('../src/parts-comment.ts'),
|
|
1943
|
+
]);
|
|
1944
|
+
if (signal.aborted) throw new Error('JOB_PRELOAD_CANCELLED');
|
|
1945
|
+
const finalized = window.state().pending.filter(ask =>
|
|
1946
|
+
ask.publicationId === prepared.display.publication.publicationId && ask.subject.kind === 'parts-verdict').at(-1)?.act;
|
|
1947
|
+
if (finalized?.kind === 'parts-verdict') {
|
|
1948
|
+
if (finalized.schema === JOB_PARTS_VERDICT_ACT_SCHEMA) panel.issues = [...finalized.value.issues];
|
|
1949
|
+
else panel.legacy = finalized.value;
|
|
1950
|
+
}
|
|
1951
|
+
panel.issues = panel.issues.map(issue => parsePartsIssue(issue, true, false, false));
|
|
1952
|
+
const routes = jobPublicationRoutes(prepared.display, location.origin);
|
|
1953
|
+
const painting = jobPartsPainting(prepared);
|
|
1954
|
+
const lifetime = new AbortController();
|
|
1955
|
+
let rejectPreparation!: (error: unknown) => void;
|
|
1956
|
+
const preparationCancelled = new Promise<never>((_resolve, reject) => {rejectPreparation = reject;});
|
|
1957
|
+
void preparationCancelled.catch(() => {});
|
|
1958
|
+
let mounted: ReturnType<typeof mountPartsWorkspace> | undefined;
|
|
1959
|
+
const cancelPreparation = () => {lifetime.abort(); rejectPreparation(new Error('JOB_PRELOAD_CANCELLED'));};
|
|
1960
|
+
signal.addEventListener('abort', cancelPreparation, {once: true});
|
|
1961
|
+
panel.dispose = () => {
|
|
1962
|
+
signal.removeEventListener('abort', cancelPreparation);
|
|
1963
|
+
lifetime.abort();
|
|
1964
|
+
const instance = mounted;
|
|
1965
|
+
mounted = undefined;
|
|
1966
|
+
instance?.dispose();
|
|
1967
|
+
};
|
|
1968
|
+
const source: PartsSource = {
|
|
1969
|
+
async view() {
|
|
1970
|
+
const view = await jobJson<JobPartsInventory>(routes.api('stage-parts'), lifetime.signal);
|
|
1971
|
+
if (current !== prepared || lifetime.signal.aborted ||
|
|
1972
|
+
view.sourceHash !== prepared.display.publication.source.sourceHash)
|
|
1973
|
+
throw new Error('JOB_ACT_SOURCE_STALE');
|
|
1974
|
+
return {...view, readOnly: false};
|
|
1975
|
+
},
|
|
1976
|
+
async image(index) {
|
|
1977
|
+
const item = prepared.parts?.items.find(item => item.index === index);
|
|
1978
|
+
const image = item && prepared.partImages.get(item.name);
|
|
1979
|
+
if (!image) throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
1980
|
+
return image;
|
|
1981
|
+
},
|
|
1982
|
+
async page(index) {
|
|
1983
|
+
const page = prepared.partPages?.get(index);
|
|
1984
|
+
if (!page) throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
1985
|
+
return page;
|
|
1986
|
+
},
|
|
1987
|
+
painting: () => painting?.element instanceof HTMLImageElement ? Promise.resolve(painting.element) : null,
|
|
1988
|
+
async crop(issue) {
|
|
1989
|
+
if (current !== prepared || lifetime.signal.aborted) throw new Error('JOB_ACT_SOURCE_STALE');
|
|
1990
|
+
const response = await fetch(routes.api('stage-parts/comment'), {
|
|
1991
|
+
method: 'POST', signal: lifetime.signal, headers: access.headers({'Content-Type': 'application/json'}),
|
|
1992
|
+
body: JSON.stringify(issue),
|
|
1993
|
+
});
|
|
1994
|
+
const value = await response.json();
|
|
1995
|
+
if (!response.ok) throw new Error(value?.error?.code ?? 'PARTS_COMMENT_UNAVAILABLE');
|
|
1996
|
+
if (current !== prepared || lifetime.signal.aborted) throw new Error('JOB_ACT_SOURCE_STALE');
|
|
1997
|
+
return parsePartsIssue(value.comment);
|
|
1998
|
+
},
|
|
1999
|
+
};
|
|
2000
|
+
const host: PartsHost = {
|
|
2001
|
+
initial: () => panel.issues,
|
|
2002
|
+
changed(issues) {
|
|
2003
|
+
if (current !== prepared || lifetime.signal.aborted) return;
|
|
2004
|
+
panel.issues = issues;
|
|
2005
|
+
for (const [askId, entry] of forms) {
|
|
2006
|
+
if (window.state().pending.find(ask => ask.askId === askId)?.subject.kind !== 'parts-verdict') continue;
|
|
2007
|
+
entry.dirty = true;
|
|
2008
|
+
entry.submissionId = crypto.randomUUID();
|
|
2009
|
+
}
|
|
2010
|
+
saveDraft(); window.refresh();
|
|
2011
|
+
},
|
|
2012
|
+
register(output) {
|
|
2013
|
+
if (current !== prepared || lifetime.signal.aborted) return;
|
|
2014
|
+
if (output.kind === 'parts-verdict' && panel.composition.side?.includes('parts.issues')) panel.output = output;
|
|
2015
|
+
window.refresh();
|
|
2016
|
+
},
|
|
2017
|
+
locked() {
|
|
2018
|
+
if (lifetime.signal.aborted || panel.legacy || window.state().closed) return 'sent';
|
|
2019
|
+
if (current !== prepared || [...forms.values()].some(entry => entry.submitting)) return 'sent';
|
|
2020
|
+
const phase = jobPartsReviewState(window.state().pending, prepared.display.publication.publicationId);
|
|
2021
|
+
return phase === 'reviewing' ? 'open' : phase;
|
|
2022
|
+
},
|
|
2023
|
+
};
|
|
2024
|
+
try {
|
|
2025
|
+
mounted = mountPartsWorkspace(panel.slots, source, host, {defaultView: 'assembled'});
|
|
2026
|
+
if (panel.legacy) {
|
|
2027
|
+
const legacy = node('p', 'JOB_PARTS_LEGACY_DRAFT');
|
|
2028
|
+
const rows = node('pre');
|
|
2029
|
+
rows.className = 'job-source';
|
|
2030
|
+
rows.textContent = JSON.stringify(panel.legacy, null, 2);
|
|
2031
|
+
panel.slots.side.append(legacy, rows);
|
|
2032
|
+
}
|
|
2033
|
+
await Promise.race([mounted.ready, preparationCancelled]);
|
|
2034
|
+
panel.slots.toolbar.querySelector<HTMLButtonElement>('#fit')?.click();
|
|
2035
|
+
await new Promise<void>((resolve, reject) => {
|
|
2036
|
+
let frame = 0;
|
|
2037
|
+
const cancelled = () => {
|
|
2038
|
+
signal.removeEventListener('abort', cancelled);
|
|
2039
|
+
cancelAnimationFrame(frame);
|
|
2040
|
+
reject(new Error('JOB_PRELOAD_CANCELLED'));
|
|
2041
|
+
};
|
|
2042
|
+
signal.addEventListener('abort', cancelled, {once: true});
|
|
2043
|
+
frame = requestAnimationFrame(() => {frame = requestAnimationFrame(() => {
|
|
2044
|
+
signal.removeEventListener('abort', cancelled);
|
|
2045
|
+
resolve();
|
|
2046
|
+
});});
|
|
2047
|
+
if (signal.aborted) cancelled();
|
|
2048
|
+
});
|
|
2049
|
+
if (signal.aborted) throw new Error('JOB_PRELOAD_CANCELLED');
|
|
2050
|
+
} finally {
|
|
2051
|
+
signal.removeEventListener('abort', cancelPreparation);
|
|
1517
2052
|
}
|
|
1518
2053
|
}
|
|
1519
2054
|
function build(prepared: JobPreparedInspection): HTMLElement {
|
|
@@ -1532,9 +2067,54 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1532
2067
|
sourceBinding.textContent = JSON.stringify(prepared.display.publication.source, null, 2);
|
|
1533
2068
|
binding.append(bindingTitle, sourceBinding);
|
|
1534
2069
|
sidebar.append(binding);
|
|
2070
|
+
if (prepared.metadata.capabilities.preRig) {
|
|
2071
|
+
const {composition, invalid} = resolveJobPanels(prepared.metadata, prepared.display.publication.source);
|
|
2072
|
+
root.dataset.jobPartsWorkspace = '';
|
|
2073
|
+
const stage = node('section');
|
|
2074
|
+
stage.className = 'job-stage';
|
|
2075
|
+
const toolbar = node('div');
|
|
2076
|
+
toolbar.className = 'viewbar pv-toolbar';
|
|
2077
|
+
const canvas = node('div');
|
|
2078
|
+
canvas.className = 'job-parts-stage';
|
|
2079
|
+
const left = node('div');
|
|
2080
|
+
const side = node('div');
|
|
2081
|
+
sidebar.prepend(left);
|
|
2082
|
+
const formsHost = node('section');
|
|
2083
|
+
formsHost.className = 'job-forms';
|
|
2084
|
+
formsHost.dataset.jobForms = '';
|
|
2085
|
+
formsHost.append(side);
|
|
2086
|
+
const slots = {left, stage: canvas, toolbar, side};
|
|
2087
|
+
stage.append(toolbar, canvas);
|
|
2088
|
+
root.append(sidebar, stage, formsHost);
|
|
2089
|
+
const components: Record<PanelComponent, PanelSlot | null> = {
|
|
2090
|
+
'parts.list': 'left', 'parts.canvas': 'stage', 'parts.layers': 'toolbar', 'parts.issues': 'side',
|
|
2091
|
+
'act.submit': 'side', 'interview.picks': null, 'plan.body': null, 'rig.playback': null,
|
|
2092
|
+
'scene.composite': null, 'images.set': null,
|
|
2093
|
+
};
|
|
2094
|
+
for (const slot of ['left', 'stage', 'toolbar', 'side'] as const) {
|
|
2095
|
+
const entries = composition[slot] ?? [];
|
|
2096
|
+
slots[slot].hidden = !entries.some(id => components[id] === slot && id !== 'act.submit');
|
|
2097
|
+
for (const id of entries) {
|
|
2098
|
+
if (components[id] === slot) continue;
|
|
2099
|
+
const refusal = node('p');
|
|
2100
|
+
refusal.textContent = t(Object.hasOwn(components, id) ? 'JOB_PANEL_UNAVAILABLE' : 'JOB_PANEL_UNKNOWN', [id]);
|
|
2101
|
+
slots[slot].after(refusal);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
if (invalid) formsHost.prepend(node('p', 'JOB_PANELS_INVALID'));
|
|
2105
|
+
const history = node('div');
|
|
2106
|
+
history.className = 'job-history';
|
|
2107
|
+
history.dataset.jobHistory = '';
|
|
2108
|
+
formsHost.append(history);
|
|
2109
|
+
const panel = {slots, composition, issues: [] as PartsIssue[], legacy: null, dispose: undefined as (() => void) | undefined};
|
|
2110
|
+
partsPanels.set(prepared, panel);
|
|
2111
|
+
const dispose = prepared.dispose;
|
|
2112
|
+
prepared.dispose = () => {try {panel.dispose?.();} finally {dispose();}};
|
|
2113
|
+
return root;
|
|
2114
|
+
}
|
|
1535
2115
|
const parts = node('select');
|
|
1536
2116
|
parts.id = 'job-part';
|
|
1537
|
-
parts.disabled = !prepared.metadata.manifest
|
|
2117
|
+
parts.disabled = !prepared.metadata.manifest?.model || prepared.metadata.feedbackCatalog.slots === null;
|
|
1538
2118
|
const whole = node('option', 'job.wholeRig');
|
|
1539
2119
|
whole.value = '';
|
|
1540
2120
|
parts.append(whole);
|
|
@@ -1568,16 +2148,6 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1568
2148
|
if (current === prepared && next) void referenceSelection.select(next);
|
|
1569
2149
|
};
|
|
1570
2150
|
sidebar.append(inputLabel('Reference', referenceSelect));
|
|
1571
|
-
const images = node('div');
|
|
1572
|
-
images.className = 'job-part-images';
|
|
1573
|
-
for (const [name, image] of prepared.partImages) {
|
|
1574
|
-
const label = node('label');
|
|
1575
|
-
const title = node('span');
|
|
1576
|
-
title.textContent = name;
|
|
1577
|
-
label.append(title, image);
|
|
1578
|
-
images.append(label);
|
|
1579
|
-
}
|
|
1580
|
-
sidebar.append(images);
|
|
1581
2151
|
const stage = node('section');
|
|
1582
2152
|
stage.className = 'job-stage';
|
|
1583
2153
|
const controls = node('div');
|
|
@@ -1654,6 +2224,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1654
2224
|
playing = true;
|
|
1655
2225
|
playbackCarry = 0;
|
|
1656
2226
|
lastFrameTime = 0;
|
|
2227
|
+
lastRunningSaveMs = null;
|
|
1657
2228
|
const clockInput = workspace.querySelector<HTMLInputElement>('#job-time');
|
|
1658
2229
|
if (clockInput) clockInput.value = playbackTimeLabel(clip.duration, current.player.time);
|
|
1659
2230
|
syncTransportControls();
|
|
@@ -1686,9 +2257,11 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1686
2257
|
if (!playing) current.player.pause();
|
|
1687
2258
|
syncTransportControls();
|
|
1688
2259
|
presentCurrentFrame(current);
|
|
2260
|
+
saveWindowState();
|
|
1689
2261
|
if (playing && hubVisible) armPlayback(current, current.player);
|
|
1690
2262
|
} else {
|
|
1691
2263
|
syncTransportControls();
|
|
2264
|
+
saveWindowState();
|
|
1692
2265
|
}
|
|
1693
2266
|
};
|
|
1694
2267
|
const clock = node('input');
|
|
@@ -1713,10 +2286,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1713
2286
|
time = value;
|
|
1714
2287
|
pose();
|
|
1715
2288
|
};
|
|
1716
|
-
|
|
1717
|
-
panels.id = 'job-panel';
|
|
1718
|
-
panels.onchange = () => { panel = panels.value; showPanel(); };
|
|
1719
|
-
transport.append(clips, playButton, inputLabel('Repeat', loopInput), inputLabel('job.time', clock), panels);
|
|
2289
|
+
transport.append(clips, playButton, inputLabel('Repeat', loopInput), inputLabel('job.time', clock));
|
|
1720
2290
|
const numeric = node('pre');
|
|
1721
2291
|
numeric.id = 'view-coordinates';
|
|
1722
2292
|
numeric.hidden = true;
|
|
@@ -1775,6 +2345,36 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1775
2345
|
if (child instanceof HTMLElement && child !== identity && child !== binding) child.hidden = true;
|
|
1776
2346
|
}
|
|
1777
2347
|
}
|
|
2348
|
+
else if (source.subject === 'option-set' || source.subject === 'plan') {
|
|
2349
|
+
const summary = node('section');
|
|
2350
|
+
summary.dataset.jobRecord = source.subject;
|
|
2351
|
+
const recordLine = node('p');
|
|
2352
|
+
recordLine.className = 'job-source';
|
|
2353
|
+
recordLine.textContent = source.record.path + ' · ' + source.record.sha256;
|
|
2354
|
+
summary.append(recordLine);
|
|
2355
|
+
if (source.subject === 'option-set') {
|
|
2356
|
+
const optionLine = node('p');
|
|
2357
|
+
optionLine.className = 'job-source';
|
|
2358
|
+
optionLine.textContent = source.selection.questionId + ' · ' + source.optionSet.id + ' · ' + source.optionSetFile.path + ' · ' + source.optionSet.sha256;
|
|
2359
|
+
summary.append(optionLine);
|
|
2360
|
+
}
|
|
2361
|
+
else {
|
|
2362
|
+
const list = node('ol');
|
|
2363
|
+
list.className = 'job-source';
|
|
2364
|
+
for (const step of source.plan.steps) {
|
|
2365
|
+
const item = node('li');
|
|
2366
|
+
item.textContent = step.id + ' · ' + step.hash;
|
|
2367
|
+
list.append(item);
|
|
2368
|
+
}
|
|
2369
|
+
summary.append(list);
|
|
2370
|
+
}
|
|
2371
|
+
stage.prepend(summary);
|
|
2372
|
+
controls.hidden = pair.hidden = transport.hidden = true;
|
|
2373
|
+
controls.style.display = pair.style.display = transport.style.display = 'none';
|
|
2374
|
+
for (const child of sidebar.children) {
|
|
2375
|
+
if (child instanceof HTMLElement && child !== identity && child !== binding) child.hidden = true;
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
1778
2378
|
const formsHost = node('section');
|
|
1779
2379
|
formsHost.className = 'job-forms';
|
|
1780
2380
|
formsHost.dataset.jobForms = '';
|
|
@@ -1785,10 +2385,43 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1785
2385
|
direction.dataset.jobDirection = '';
|
|
1786
2386
|
if (prepared.metadata.direction)
|
|
1787
2387
|
direction.textContent = t('job.metadata') + '\n' + JSON.stringify(prepared.metadata.direction, null, 2);
|
|
2388
|
+
const interviewDiagnostics = node('section');
|
|
2389
|
+
interviewDiagnostics.className = 'job-interview-diagnostics';
|
|
2390
|
+
interviewDiagnostics.dataset.jobInterviewDiagnostics = '';
|
|
2391
|
+
const interviewState = prepared.interview?.interview ?? prepared.display.publication.interview ?? null;
|
|
2392
|
+
if (interviewState && (interviewState.diagnostics.length > 0 || interviewState.records.some(record => record.timeKind !== 'inspection'))) {
|
|
2393
|
+
interviewDiagnostics.append(node('h3', 'interview.history'));
|
|
2394
|
+
for (const diagnostic of interviewState.diagnostics) {
|
|
2395
|
+
const item = node('div');
|
|
2396
|
+
item.dataset.jobInterviewDiagnostic = diagnostic.code;
|
|
2397
|
+
item.dataset.severity = diagnostic.severity;
|
|
2398
|
+
item.dataset.record = diagnostic.record;
|
|
2399
|
+
const summary = node('p', diagnostic.code);
|
|
2400
|
+
const detail = node('pre');
|
|
2401
|
+
detail.className = 'job-source';
|
|
2402
|
+
detail.textContent = JSON.stringify(diagnostic, null, 2);
|
|
2403
|
+
item.append(summary, detail);
|
|
2404
|
+
interviewDiagnostics.append(item);
|
|
2405
|
+
}
|
|
2406
|
+
for (const record of interviewState.records) {
|
|
2407
|
+
if (record.timeKind === 'inspection') continue;
|
|
2408
|
+
const item = node('div');
|
|
2409
|
+
item.dataset.jobInterviewRecord = record.record;
|
|
2410
|
+
item.dataset.timeKind = record.timeKind;
|
|
2411
|
+
const detail = node('pre');
|
|
2412
|
+
detail.className = 'job-source';
|
|
2413
|
+
detail.textContent = JSON.stringify(record, null, 2);
|
|
2414
|
+
item.append(detail);
|
|
2415
|
+
interviewDiagnostics.append(item);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
else {
|
|
2419
|
+
interviewDiagnostics.hidden = true;
|
|
2420
|
+
}
|
|
1788
2421
|
const history = node('div');
|
|
1789
2422
|
history.className = 'job-history';
|
|
1790
2423
|
history.dataset.jobHistory = '';
|
|
1791
|
-
formsHost.append(direction, history);
|
|
2424
|
+
formsHost.append(direction, interviewDiagnostics, history);
|
|
1792
2425
|
root.append(sidebar, stage, formsHost);
|
|
1793
2426
|
return root;
|
|
1794
2427
|
}
|
|
@@ -1809,13 +2442,8 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1809
2442
|
}
|
|
1810
2443
|
function showPanel(): void {
|
|
1811
2444
|
const direction = workspace.querySelector<HTMLElement>('[data-job-direction]');
|
|
1812
|
-
if (direction)
|
|
1813
|
-
|
|
1814
|
-
for (const [askId, entry] of forms) {
|
|
1815
|
-
const ask = window.state().pending.find(item => item.askId === askId);
|
|
1816
|
-
entry.form.hidden = current?.display.publication.source.subject !== 'image-set' &&
|
|
1817
|
-
panel === '2' && ask?.subject.kind !== 'interview-picks';
|
|
1818
|
-
}
|
|
2445
|
+
if (direction) direction.hidden = !current?.metadata.direction;
|
|
2446
|
+
saveWindowState();
|
|
1819
2447
|
}
|
|
1820
2448
|
function pose(seekReference = true): void {
|
|
1821
2449
|
if (!current)
|
|
@@ -1879,12 +2507,16 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1879
2507
|
function announceHubFrame(): void {
|
|
1880
2508
|
if (hubIncarnation) globalThis.parent.postMessage({...hubBinding(), schema: JOB_HUB_READY}, location.origin);
|
|
1881
2509
|
}
|
|
1882
|
-
const window = createJobWindow({ jobId: access.jobId, pageId, transport,
|
|
2510
|
+
const window = createJobWindow({ jobId: access.jobId, pageId, transport,
|
|
2511
|
+
previousDisplayed, initialRetainedDrafts,
|
|
2512
|
+
adapter: {
|
|
1883
2513
|
async prepare(display, signal): Promise<PreparedWindow> {
|
|
1884
2514
|
const inspection = await prepareJobInspection(display, signal);
|
|
1885
2515
|
try {
|
|
1886
2516
|
const element = build(inspection);
|
|
1887
|
-
const
|
|
2517
|
+
const asks = window.state().pending.filter(ask => !(partsPanels.has(inspection) &&
|
|
2518
|
+
ask.subject.kind === 'signoff' && ask.subject.stage === 'parts-review'));
|
|
2519
|
+
const preparedForms = prepareJobForms(display, asks, ask => formFor(ask, inspection));
|
|
1888
2520
|
return Object.assign(inspection, { element, forms: preparedForms });
|
|
1889
2521
|
}
|
|
1890
2522
|
catch (error) {
|
|
@@ -1895,7 +2527,9 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1895
2527
|
captureDraft() { saveDraft(); const dirty = [...forms].filter(([, item]) => item.dirty); return dirty.length ? dirty.map(([askId, item]) => ({ askId, value: item.read() })) : null; },
|
|
1896
2528
|
commit(prepared, display) {
|
|
1897
2529
|
// Pending asks can arrive while assets load. Finish their forms before the visible replacement.
|
|
1898
|
-
const
|
|
2530
|
+
const asks = window.state().pending.filter(ask => !(partsPanels.has(prepared) &&
|
|
2531
|
+
ask.subject.kind === 'signoff' && ask.subject.stage === 'parts-review'));
|
|
2532
|
+
const nextForms = prepareJobForms(display, asks,
|
|
1899
2533
|
ask => prepared.forms.get(ask.askId) ?? formFor(ask, prepared));
|
|
1900
2534
|
const root = prepared.element;
|
|
1901
2535
|
const formHost = root.querySelector<HTMLElement>('[data-job-forms]');
|
|
@@ -1906,9 +2540,13 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1906
2540
|
stopPlayback(previous?.player);
|
|
1907
2541
|
const previousElement = currentElement;
|
|
1908
2542
|
const previousForms = new Map(forms);
|
|
1909
|
-
const
|
|
1910
|
-
|
|
1911
|
-
|
|
2543
|
+
const restoringCamera = Boolean(previous || restoredCamera);
|
|
2544
|
+
const navigation = { animation, time, loop, selectedPart, partMode, selectedReference, panel,
|
|
2545
|
+
partIdentity: previous ? (previous.inspection?.value() ?? null) : restoredPartIdentity,
|
|
2546
|
+
camera: structuredClone(viewportState) };
|
|
2547
|
+
compatibilityNotice = Boolean(!previous &&
|
|
2548
|
+
savedWindow?.publicationId === display.publication.publicationId &&
|
|
2549
|
+
savedWindow.compatibilityNotice);
|
|
1912
2550
|
if (animation && !prepared.assets?.animations.some(item => item.name === animation && time <= item.duration)) {
|
|
1913
2551
|
animation = '';
|
|
1914
2552
|
time = 0;
|
|
@@ -1930,6 +2568,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1930
2568
|
currentElement = previousElement;
|
|
1931
2569
|
animation = navigation.animation;
|
|
1932
2570
|
time = navigation.time;
|
|
2571
|
+
loop = navigation.loop;
|
|
1933
2572
|
selectedPart = navigation.selectedPart;
|
|
1934
2573
|
partMode = navigation.partMode;
|
|
1935
2574
|
selectedReference = navigation.selectedReference;
|
|
@@ -1939,7 +2578,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1939
2578
|
forms.set(id, item);
|
|
1940
2579
|
workspace.replaceChildren(...(previousElement ? [previousElement] : []));
|
|
1941
2580
|
Object.assign(viewportState, navigation.camera);
|
|
1942
|
-
if (current) {
|
|
2581
|
+
if (current && !partsPanels.has(current)) {
|
|
1943
2582
|
el<HTMLSelectElement>('job-reference').value = selectedReference;
|
|
1944
2583
|
syncTransportControls();
|
|
1945
2584
|
viewport.fitCamera();
|
|
@@ -1951,17 +2590,29 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1951
2590
|
forms.clear();
|
|
1952
2591
|
for (const [id, entry] of nextForms) forms.set(id, entry);
|
|
1953
2592
|
workspace.replaceChildren(root);
|
|
2593
|
+
if (partsPanels.has(prepared)) {
|
|
2594
|
+
updateForms(window.state());
|
|
2595
|
+
return {rollback, finalize() {
|
|
2596
|
+
unbindNavigation?.(); resize?.disconnect();
|
|
2597
|
+
unbindNavigation = null; resize = null;
|
|
2598
|
+
previous?.dispose();
|
|
2599
|
+
title.textContent = display.publication.source.package?.id ?? display.publication.label;
|
|
2600
|
+
}};
|
|
2601
|
+
}
|
|
1954
2602
|
el<HTMLSelectElement>('job-part').value = selectedPart;
|
|
1955
2603
|
el<HTMLInputElement>('job-solo').checked = partMode === 'solo';
|
|
1956
2604
|
el<HTMLSelectElement>('job-reference').value = selectedReference;
|
|
1957
2605
|
el<HTMLSelectElement>('job-animation').value = animation;
|
|
1958
|
-
el<
|
|
2606
|
+
el<HTMLInputElement>('job-loop').checked = loop;
|
|
1959
2607
|
el('rig-empty').hidden = !!prepared.player;
|
|
1960
|
-
Object.assign(viewportState, navigation.camera, { cameraRestoring:
|
|
2608
|
+
Object.assign(viewportState, navigation.camera, { cameraRestoring: restoringCamera });
|
|
1961
2609
|
showReference();
|
|
1962
2610
|
pose(false);
|
|
1963
2611
|
if (selectedPart) {
|
|
1964
2612
|
try {
|
|
2613
|
+
if (!navigation.partIdentity || navigation.partIdentity.slot !== selectedPart) {
|
|
2614
|
+
throw new Error('PART_IDENTITY_UNAVAILABLE');
|
|
2615
|
+
}
|
|
1965
2616
|
prepared.inspection?.assertIdentity(navigation.partIdentity);
|
|
1966
2617
|
}
|
|
1967
2618
|
catch {
|
|
@@ -1980,12 +2631,15 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1980
2631
|
return {
|
|
1981
2632
|
rollback,
|
|
1982
2633
|
finalize() {
|
|
2634
|
+
restoredPartIdentity = null;
|
|
2635
|
+
restoredCamera = null;
|
|
2636
|
+
savedWindow = null;
|
|
1983
2637
|
unbindNavigation?.();
|
|
1984
2638
|
resize?.disconnect();
|
|
1985
2639
|
unbindNavigation = nextUnbind;
|
|
1986
2640
|
resize = nextResize;
|
|
1987
2641
|
previous?.dispose();
|
|
1988
|
-
title.textContent = display.publication.source.package.
|
|
2642
|
+
title.textContent = display.publication.source.package?.id ?? display.publication.label;
|
|
1989
2643
|
},
|
|
1990
2644
|
};
|
|
1991
2645
|
}
|
|
@@ -1995,6 +2649,10 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1995
2649
|
}
|
|
1996
2650
|
},
|
|
1997
2651
|
async painted(prepared, signal) {
|
|
2652
|
+
if (partsPanels.has(prepared)) {
|
|
2653
|
+
await mountJobParts(prepared, signal);
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
1998
2656
|
for (const image of prepared.imageSetImages ?? []) {
|
|
1999
2657
|
if (!image.isConnected || !image.complete || !image.naturalWidth || !image.naturalHeight)
|
|
2000
2658
|
throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
@@ -2018,11 +2676,20 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
2018
2676
|
notice.textContent = t('job.closed');
|
|
2019
2677
|
else if (state.preparing)
|
|
2020
2678
|
notice.textContent = t('job.preparing');
|
|
2021
|
-
else if (state.displayed)
|
|
2679
|
+
else if (state.displayed && current && partsPanels.has(current)) {
|
|
2680
|
+
const panel = partsPanels.get(current)!;
|
|
2681
|
+
const sending = [...forms.values()].some(entry => entry.submitting);
|
|
2682
|
+
const phase = sending ? 'sending' : jobPartsReviewState(state.pending, state.displayed.publication.publicationId);
|
|
2683
|
+
notice.dataset.jobPartsState = phase;
|
|
2684
|
+
notice.textContent = state.displayed.publication.label + ' · ' + t('job.parts.' + phase, [panel.issues.length]);
|
|
2685
|
+
}
|
|
2686
|
+
else if (state.displayed) {
|
|
2687
|
+
delete notice.dataset.jobPartsState;
|
|
2022
2688
|
notice.textContent = state.previousLabel
|
|
2023
2689
|
? t('job.updated', [state.previousLabel, state.displayed.publication.label]) : state.displayed.publication.label;
|
|
2024
|
-
|
|
2025
|
-
|
|
2690
|
+
if (compatibilityNotice)
|
|
2691
|
+
notice.textContent += ' · ' + t('job.incompatible');
|
|
2692
|
+
}
|
|
2026
2693
|
if (state.closed) {
|
|
2027
2694
|
const wasPlaying = playing;
|
|
2028
2695
|
stopPlayback();
|
|
@@ -2040,18 +2707,19 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
2040
2707
|
const key = localStorage.key(index);
|
|
2041
2708
|
if (!key?.startsWith(prefix))
|
|
2042
2709
|
continue;
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2710
|
+
try {
|
|
2711
|
+
const parsedDraft = parseSavedDraftRecord(JSON.parse(localStorage.getItem(key) ?? 'null'));
|
|
2712
|
+
if (!parsedDraft || parsedDraft.publicationId === state.displayed?.publication.publicationId)
|
|
2713
|
+
continue;
|
|
2714
|
+
retained.set(parsedDraft.publicationId, parsedDraft);
|
|
2715
|
+
}
|
|
2716
|
+
catch { /* Ignore malformed draft entries without dropping sibling drafts. */ }
|
|
2050
2717
|
}
|
|
2051
2718
|
}
|
|
2052
2719
|
catch { /* In-memory retained evidence remains available. */ }
|
|
2053
2720
|
history.textContent = [...retained.values()].map(draft => t('job.retained', [draft.label]) + '\n' + draft.sourceHash + '\n' + JSON.stringify(draft.value, null, 2)).join('\n');
|
|
2054
2721
|
}
|
|
2722
|
+
saveWindowState();
|
|
2055
2723
|
pauseHiddenHubFrame(); announceHubFrame();
|
|
2056
2724
|
if (state.receipt && !state.preparing) events?.displayed();
|
|
2057
2725
|
},
|
|
@@ -2060,7 +2728,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
2060
2728
|
for (const element of host.querySelectorAll<HTMLElement>('[data-job-text]'))
|
|
2061
2729
|
element.textContent = t(element.dataset.jobText!);
|
|
2062
2730
|
languages.setAttribute('aria-label', t('interview.language'));
|
|
2063
|
-
if (current)
|
|
2731
|
+
if (current && !partsPanels.has(current))
|
|
2064
2732
|
viewport.renderCameraControls();
|
|
2065
2733
|
window.refresh();
|
|
2066
2734
|
});
|
|
@@ -2089,7 +2757,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
2089
2757
|
resolution?.removeEventListener('change', resolutionChanged);
|
|
2090
2758
|
resolution = globalThis.matchMedia(`(resolution:${globalThis.devicePixelRatio || 1}dppx)`);
|
|
2091
2759
|
resolution.addEventListener('change', resolutionChanged);
|
|
2092
|
-
if (current) {
|
|
2760
|
+
if (current && !partsPanels.has(current)) {
|
|
2093
2761
|
drawn.delete(current);
|
|
2094
2762
|
current.rigPresentation = undefined;
|
|
2095
2763
|
viewport.fitCamera();
|
|
@@ -2101,6 +2769,7 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
2101
2769
|
resolution?.removeEventListener('change', resolutionChanged);
|
|
2102
2770
|
globalThis.removeEventListener('message', hubVisibility);
|
|
2103
2771
|
saveDraft();
|
|
2772
|
+
saveWindowState();
|
|
2104
2773
|
referenceSelection.cancel();
|
|
2105
2774
|
abort.abort();
|
|
2106
2775
|
window.stop();
|