@astl/player 0.1.4 → 0.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.
- package/CHANGELOG.md +18 -0
- package/dist/attempt/controller.d.ts +11 -1
- package/dist/attempt/controller.d.ts.map +1 -1
- package/dist/attempt/controller.js +11 -3
- package/dist/attempt/controller.js.map +1 -1
- package/dist/messages/help/en.json +3 -1
- package/dist/messages/help/pl.json +3 -1
- package/dist/player/help.d.ts +22 -9
- package/dist/player/help.d.ts.map +1 -1
- package/dist/player/help.js +138 -30
- package/dist/player/help.js.map +1 -1
- package/dist/player/player.d.ts +4 -4
- package/dist/player/player.d.ts.map +1 -1
- package/dist/player/player.js +57 -31
- package/dist/player/player.js.map +1 -1
- package/package.json +3 -3
- package/src/attempt/controller.ts +13 -3
- package/src/messages/help/en.json +3 -1
- package/src/messages/help/pl.json +3 -1
- package/src/player/help.ts +163 -37
- package/src/player/player.ts +63 -34
package/src/player/help.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Help for students in the player, in a module of its own:
|
|
3
|
-
* without it (or when its chunk fails) the exercise plays without help.
|
|
2
|
+
* Help for students in the player, in a module of its own: a view that offers help (`hasHelp`) loads it, and so does
|
|
3
|
+
* practice that checks one question at a time; without it (or when its chunk fails) the exercise plays without help.
|
|
4
4
|
*
|
|
5
|
-
* Under each graded interaction that offers help
|
|
6
|
-
*
|
|
7
|
-
* - "Podpowiedź
|
|
8
|
-
* - "Sprawdź" for that interaction alone (
|
|
5
|
+
* Under each graded interaction that offers help, and under every one where practice checks one question at a time
|
|
6
|
+
* (`checkScope: 'interaction'`), after the block holding it for one in a line of text, a row:
|
|
7
|
+
* - "Podpowiedź 1 z 2", one hint at a time from the checker, what the next one costs said before it is used;
|
|
8
|
+
* - "Sprawdź" for that interaction alone, counted like any check ("Sprawdź pole 1" for a field in a line of text whose
|
|
9
|
+
* paragraph holds other fields, their rows under each other after it; the end of the name is hidden otherwise);
|
|
9
10
|
* - the feedback text of the last verdict, in a box of the verdict's colour and edge;
|
|
10
11
|
* - "Dlaczego?", a disclosure with the explanation.
|
|
12
|
+
* At the foot of each page with help of its own, or with `check`, a row like it whose "Sprawdź tę stronę" checks the
|
|
13
|
+
* page's questions at once (practice checking one question at a time); the page's feedback and explanation come only
|
|
14
|
+
* with a check of the page or of everything, never with one question's. Once every question has a result, from its own
|
|
15
|
+
* check or its page's, the player shows the overall result composed from them (`HelpHost.overall`).
|
|
11
16
|
* The texts come with check and submit responses as the policy says (`helpShown` in the engine); the view only says
|
|
12
17
|
* what there is (`HELP_ATTRIBUTES`). A row next to a floated or placed interaction floats with it, below it.
|
|
13
18
|
*
|
|
@@ -24,10 +29,12 @@ import {
|
|
|
24
29
|
FEEDBACK_VARIANTS,
|
|
25
30
|
type Feedback,
|
|
26
31
|
type GradeResult,
|
|
32
|
+
type GroupResult,
|
|
27
33
|
type GroupVerdict,
|
|
28
34
|
helpPolicy,
|
|
29
35
|
inertStyles,
|
|
30
36
|
type MessageCatalog,
|
|
37
|
+
PAGE_CHECK_ATTRIBUTE,
|
|
31
38
|
type PlayerElementApi,
|
|
32
39
|
type SubmitResponse,
|
|
33
40
|
type Translate,
|
|
@@ -65,8 +72,13 @@ export interface HelpHost {
|
|
|
65
72
|
/** The player's shadow root, for the module's stylesheet. */
|
|
66
73
|
readonly root: Node;
|
|
67
74
|
checker(): Checker | null;
|
|
68
|
-
/** Checks one interaction through the player, which shows a failure; resolves either way. */
|
|
75
|
+
/** Checks one interaction or one page through the player, which shows a failure; resolves either way. */
|
|
69
76
|
check(id: string): Promise<unknown>;
|
|
77
|
+
/**
|
|
78
|
+
* The overall result composed from the latest checks once every question has one, null while one has none; returns
|
|
79
|
+
* what to say of it, which the module says with the check that completed it.
|
|
80
|
+
*/
|
|
81
|
+
overall(response: CheckResponse | null): string | null;
|
|
70
82
|
announce(message: string): void;
|
|
71
83
|
}
|
|
72
84
|
|
|
@@ -76,19 +88,28 @@ export interface Help {
|
|
|
76
88
|
}
|
|
77
89
|
|
|
78
90
|
const COST = /^(?:0|1|0?\.\d{1,6}|1\.0{1,6})$/;
|
|
91
|
+
const POINTS = /^\d{1,9}(?:\.\d{1,6})?$/;
|
|
79
92
|
|
|
80
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* What a view element offers, from its `HELP_ATTRIBUTES`; null when nothing. Costs outside 0..1 are left out, and
|
|
95
|
+
* points that do not go one to one with the costs.
|
|
96
|
+
*/
|
|
81
97
|
export function readHelp(el: Element): ElementHelp | null {
|
|
82
98
|
const words = (name: string) => (el.getAttribute(name) ?? '').split(' ').filter(Boolean);
|
|
83
99
|
const hints = words('hints').flatMap((w) => (COST.test(w) ? [Number(w)] : []));
|
|
100
|
+
const points = words('hint-points');
|
|
84
101
|
const written = new Set(words('feedback'));
|
|
85
102
|
const feedback = FEEDBACK_VARIANTS.filter((v) => written.has(v));
|
|
86
103
|
const explanation = el.hasAttribute('explanation');
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
if (hints.length === 0 && feedback.length === 0 && !explanation) return null;
|
|
105
|
+
return points.length === hints.length && points.every((w) => POINTS.test(w))
|
|
106
|
+
? { hints, hintPoints: points.map(Number), explanation, feedback }
|
|
89
107
|
: { hints, explanation, feedback };
|
|
90
108
|
}
|
|
91
109
|
|
|
110
|
+
/** What a graded interaction without help of its own offers, where practice checks one question at a time. */
|
|
111
|
+
const NO_HELP: ElementHelp = { hints: [], explanation: false, feedback: [] };
|
|
112
|
+
|
|
92
113
|
/**
|
|
93
114
|
* Help content from a checker (rich text of format 1) as clean live DOM in a `div`: cleaned in an inert document like
|
|
94
115
|
* a view's content, without components or other custom elements, and without styles (the engine writes none into
|
|
@@ -125,20 +146,34 @@ function overall(verdicts: readonly GroupVerdict[]): GroupVerdict | null {
|
|
|
125
146
|
|
|
126
147
|
const isCount = (v: unknown): v is number => Number.isInteger(v) && (v as number) >= 0;
|
|
127
148
|
|
|
149
|
+
/** The order verdicts are told in, as in the result's counts. */
|
|
150
|
+
const VERDICT_ORDER: readonly GroupVerdict[] = ['correct', 'partial', 'incorrect', 'empty'];
|
|
151
|
+
|
|
128
152
|
interface Row {
|
|
129
153
|
/** View element or page id: what the checker's help is keyed by. */
|
|
130
154
|
readonly id: string;
|
|
131
155
|
readonly offer: ElementHelp;
|
|
132
156
|
readonly box: HTMLElement;
|
|
133
157
|
readonly label: string;
|
|
134
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* The end of the check button's name ("to pytanie", "pole 2"), hidden unless `named`; a page's row says "Sprawdź tę
|
|
160
|
+
* stronę" instead. Null where the row has no Check.
|
|
161
|
+
*/
|
|
135
162
|
readonly check: string | null;
|
|
163
|
+
/**
|
|
164
|
+
* The Check shows the end of its name: a field in a line of text whose block holds other fields, their rows under
|
|
165
|
+
* each other after it ("Sprawdź pole 2"). A field alone in its block shows "Sprawdź", like a block question.
|
|
166
|
+
*/
|
|
167
|
+
readonly named: boolean;
|
|
136
168
|
/**
|
|
137
169
|
* Its element says its verdict in words itself (a block, right above): the feedback box then keeps the icon beside
|
|
138
170
|
* its text and leaves the word to assistive tech. A field in a line of text shows an icon only, a page nothing.
|
|
139
171
|
*/
|
|
140
172
|
readonly ownVerdict: boolean;
|
|
141
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Its groups in a result: the element's own id and those it names (graded in parts), as the scoring the key chose has
|
|
175
|
+
* them (a crossword graded whole has one group, by words several); empty for a page.
|
|
176
|
+
*/
|
|
142
177
|
readonly groups: readonly string[];
|
|
143
178
|
/** The slots whose change makes its feedback stale. */
|
|
144
179
|
readonly slots: ReadonlySet<string>;
|
|
@@ -208,7 +243,7 @@ export function mountHelp(host: HelpHost): Help {
|
|
|
208
243
|
const row = (
|
|
209
244
|
owner: Element,
|
|
210
245
|
offer: ElementHelp,
|
|
211
|
-
extra: Pick<Row, 'label' | 'check' | 'ownVerdict' | 'groups' | 'slots'>,
|
|
246
|
+
extra: Pick<Row, 'label' | 'check' | 'named' | 'ownVerdict' | 'groups' | 'slots'>,
|
|
212
247
|
) => {
|
|
213
248
|
const box = document.createElement('div');
|
|
214
249
|
box.className = 'astl-help';
|
|
@@ -236,36 +271,49 @@ export function mountHelp(host: HelpHost): Help {
|
|
|
236
271
|
return entry;
|
|
237
272
|
};
|
|
238
273
|
|
|
274
|
+
// Practice checking one question at a time: every graded question gets a row with its Check, help or not.
|
|
275
|
+
const each = practice && help.checkScope === 'interaction';
|
|
276
|
+
const isGraded = ({ element, manifest }: HelpHost['mounted'][number]) =>
|
|
277
|
+
manifest.graded && element.slotIds.length > 0;
|
|
278
|
+
// The graded fields in a line of text per block: their rows sit under each other after it.
|
|
279
|
+
const fields = new Map<Element, number>();
|
|
280
|
+
for (const mounted of host.mounted) {
|
|
281
|
+
if (mounted.manifest.display !== 'inline' || !isGraded(mounted)) continue;
|
|
282
|
+
const anchor = anchorOf(mounted.element);
|
|
283
|
+
fields.set(anchor, (fields.get(anchor) ?? 0) + 1);
|
|
284
|
+
}
|
|
239
285
|
let field = 0;
|
|
240
|
-
for (const
|
|
286
|
+
for (const mounted of host.mounted) {
|
|
287
|
+
const { element, manifest } = mounted;
|
|
241
288
|
const inline = manifest.display === 'inline';
|
|
242
289
|
if (inline) field++;
|
|
243
|
-
const
|
|
290
|
+
const graded = isGraded(mounted);
|
|
291
|
+
const offer = manifest.graded ? (readHelp(element) ?? (each && graded ? NO_HELP : null)) : null;
|
|
244
292
|
if (offer === null) continue;
|
|
245
293
|
const n = field;
|
|
294
|
+
const anchor = anchorOf(element);
|
|
246
295
|
const entry = row(element, offer, {
|
|
247
296
|
label: inline ? t('help.labelField', { n }) : t('help.label'),
|
|
248
|
-
check:
|
|
249
|
-
|
|
250
|
-
? inline
|
|
251
|
-
? t('help.checkField', { n })
|
|
252
|
-
: t('help.check')
|
|
253
|
-
: null,
|
|
297
|
+
check: each && graded ? (inline ? t('help.checkField', { n }) : t('help.check')) : null,
|
|
298
|
+
named: inline && (fields.get(anchor) ?? 0) > 1,
|
|
254
299
|
ownVerdict: !inline,
|
|
255
|
-
groups: element.groupIds ?? [
|
|
300
|
+
groups: [element.id, ...(element.groupIds ?? [])],
|
|
256
301
|
slots: new Set(element.slotIds),
|
|
257
302
|
});
|
|
258
|
-
const anchor = anchorOf(element);
|
|
259
303
|
(after.get(anchor) ?? anchor).after(entry.box);
|
|
260
304
|
after.set(anchor, entry.box);
|
|
261
305
|
place(entry.box, anchor);
|
|
262
306
|
}
|
|
263
307
|
host.pages.forEach((page, index) => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
308
|
+
if (page.localName !== 'astl-page') return;
|
|
309
|
+
// A page with help and without `check` (a 0.1 source) gets its Check all the same: its help needs a check.
|
|
310
|
+
const offer = readHelp(page);
|
|
311
|
+
const checked = each && (offer !== null || page.hasAttribute(PAGE_CHECK_ATTRIBUTE));
|
|
312
|
+
if (offer === null && !checked) return;
|
|
313
|
+
const entry = row(page, offer ?? NO_HELP, {
|
|
267
314
|
label: t('help.labelPage'),
|
|
268
|
-
check: null,
|
|
315
|
+
check: checked ? '' : null,
|
|
316
|
+
named: false,
|
|
269
317
|
ownVerdict: false,
|
|
270
318
|
groups: [],
|
|
271
319
|
slots: new Set(controller.pages[index]?.slotIds ?? []),
|
|
@@ -352,6 +400,8 @@ export function mountHelp(host: HelpHost): Help {
|
|
|
352
400
|
const open = !controller.readOnly;
|
|
353
401
|
const next = entry.used < entry.total && help.hints && practice && open ? entry.used : null;
|
|
354
402
|
const cost = next === null ? 0 : (entry.offer.hints[next] ?? 0);
|
|
403
|
+
// In points where the view says them (views compiled before 0.2 only have the share).
|
|
404
|
+
const points = next === null ? undefined : entry.offer.hintPoints?.[next];
|
|
355
405
|
const costId = `astl-help-cost-${rows.indexOf(entry)}`;
|
|
356
406
|
const check = entry.check !== null && open;
|
|
357
407
|
const shows =
|
|
@@ -382,7 +432,11 @@ export function mountHelp(host: HelpHost): Help {
|
|
|
382
432
|
${
|
|
383
433
|
cost > 0
|
|
384
434
|
? html`<span class="help-cost" id=${costId}
|
|
385
|
-
>${
|
|
435
|
+
>${
|
|
436
|
+
points === undefined
|
|
437
|
+
? t('help.hintCost', { percent: Math.round(cost * 100) })
|
|
438
|
+
: t('help.hintPoints', { points })
|
|
439
|
+
}</span
|
|
386
440
|
>`
|
|
387
441
|
: nothing
|
|
388
442
|
}</span
|
|
@@ -398,7 +452,13 @@ export function mountHelp(host: HelpHost): Help {
|
|
|
398
452
|
if (controller.canCheck()) void host.check(entry.id);
|
|
399
453
|
}}
|
|
400
454
|
>
|
|
401
|
-
${
|
|
455
|
+
${
|
|
456
|
+
entry.groups.length === 0
|
|
457
|
+
? t('help.checkPage')
|
|
458
|
+
: entry.named
|
|
459
|
+
? `${t('action.check')} ${entry.check}`
|
|
460
|
+
: html`${t('action.check')}<span class="astl-vh"> ${entry.check}</span>`
|
|
461
|
+
}
|
|
402
462
|
</button>`
|
|
403
463
|
: nothing
|
|
404
464
|
}
|
|
@@ -434,25 +494,91 @@ export function mountHelp(host: HelpHost): Help {
|
|
|
434
494
|
${entry.problem === null ? nothing : html`<p class="help-problem" role="alert">${problemText(entry.problem)}</p>`}`;
|
|
435
495
|
};
|
|
436
496
|
|
|
497
|
+
/**
|
|
498
|
+
* The latest result of each question (its groups), from its own check, its page's or one of everything: once every
|
|
499
|
+
* question has one, the overall result is theirs, with no request of its own. An answer changed since makes its
|
|
500
|
+
* question's stale.
|
|
501
|
+
*/
|
|
502
|
+
const latest = new Map<Row, readonly GroupResult[]>();
|
|
503
|
+
const questions = each ? rows.filter((r) => r.groups.length > 0) : [];
|
|
504
|
+
let composed = false;
|
|
505
|
+
const take = (response: CheckResponse | SubmitResponse): void => {
|
|
506
|
+
for (const entry of questions) {
|
|
507
|
+
const own = response.result?.groups.filter((g) => entry.groups.includes(g.id)) ?? [];
|
|
508
|
+
if (own.length > 0) latest.set(entry, own);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const compose = (): string | null => {
|
|
512
|
+
const done = questions.length > 0 && questions.every((entry) => latest.has(entry));
|
|
513
|
+
if (!done) {
|
|
514
|
+
if (composed) host.overall(null);
|
|
515
|
+
composed = false;
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
const groups = questions.flatMap((entry) => latest.get(entry) ?? []);
|
|
519
|
+
const counts = { correct: 0, partial: 0, incorrect: 0, empty: 0, total: groups.length };
|
|
520
|
+
for (const g of groups) counts[g.verdict]++;
|
|
521
|
+
const sum = (pick: (g: GroupResult) => number) =>
|
|
522
|
+
Math.round(groups.reduce((n, g) => n + pick(g), 0) * 1e6) / 1e6;
|
|
523
|
+
const result: GradeResult = {
|
|
524
|
+
score: sum((g) => g.score),
|
|
525
|
+
max: sum((g) => g.max),
|
|
526
|
+
correct: counts.correct === groups.length,
|
|
527
|
+
slots: {},
|
|
528
|
+
groups,
|
|
529
|
+
pages: {},
|
|
530
|
+
counts,
|
|
531
|
+
};
|
|
532
|
+
composed = true;
|
|
533
|
+
return host.overall({ result, checksLeft: controller.checksLeft });
|
|
534
|
+
};
|
|
535
|
+
const say = (...parts: readonly (string | null | undefined)[]): void => {
|
|
536
|
+
const text = parts.filter(Boolean).join(' ');
|
|
537
|
+
if (text !== '') host.announce(text);
|
|
538
|
+
};
|
|
539
|
+
/** A row's verdict and feedback text, said after its check, as sentences. */
|
|
540
|
+
const told = (entry: Row | undefined): string | null => {
|
|
541
|
+
if (entry?.verdict == null) return null;
|
|
542
|
+
const said = [t(`verdict.${entry.verdict}`), entry.feedback?.textContent?.trim()]
|
|
543
|
+
.filter(Boolean)
|
|
544
|
+
.join('. ');
|
|
545
|
+
return /[.!?…]$/.test(said) ? said : `${said}.`;
|
|
546
|
+
};
|
|
547
|
+
|
|
437
548
|
const unsubscribe = controller.subscribe((change) => {
|
|
438
|
-
if (change.type === 'result')
|
|
439
|
-
|
|
549
|
+
if (change.type === 'result') {
|
|
550
|
+
apply(change.response, null);
|
|
551
|
+
take(change.response);
|
|
552
|
+
// The player says a whole result itself.
|
|
553
|
+
compose();
|
|
554
|
+
} else if (change.type === 'element') {
|
|
440
555
|
apply(change.response, change.id);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
556
|
+
take(change.response);
|
|
557
|
+
say(told(rows.find((r) => r.id === change.id)), compose());
|
|
558
|
+
} else if (change.type === 'page-check') {
|
|
559
|
+
apply(change.response, null);
|
|
560
|
+
take(change.response);
|
|
561
|
+
// What the page's check says: its feedback text, else how its questions came out.
|
|
562
|
+
const counts = change.response.result.counts;
|
|
563
|
+
const page =
|
|
564
|
+
told(rows.find((r) => r.id === change.id)) ??
|
|
565
|
+
VERDICT_ORDER.flatMap((v) =>
|
|
566
|
+
counts[v] > 0 ? [t('result.countAnnounce', { verdict: t(`verdict.${v}`), count: counts[v] })] : [],
|
|
567
|
+
).join(' ');
|
|
568
|
+
say(page, compose());
|
|
447
569
|
} else if (change.type === 'answers') {
|
|
448
570
|
const changed = Object.keys(change.answers);
|
|
449
571
|
for (const entry of rows) {
|
|
450
572
|
if (changed.some((id) => entry.slots.has(id))) {
|
|
451
573
|
entry.verdict = null;
|
|
452
574
|
entry.feedback = null;
|
|
575
|
+
latest.delete(entry);
|
|
453
576
|
}
|
|
454
577
|
}
|
|
578
|
+
compose();
|
|
455
579
|
} else if (change.type === 'reset') {
|
|
580
|
+
latest.clear();
|
|
581
|
+
compose();
|
|
456
582
|
for (const entry of rows) {
|
|
457
583
|
entry.verdict = null;
|
|
458
584
|
entry.feedback = null;
|
package/src/player/player.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
fitsAnswer,
|
|
20
20
|
type GradeResult,
|
|
21
21
|
type GroupVerdict,
|
|
22
|
+
helpPolicy,
|
|
22
23
|
type I18n,
|
|
23
24
|
isSnapshot,
|
|
24
25
|
type JsonValue,
|
|
@@ -183,8 +184,13 @@ export class AstlPlayer extends LitElement {
|
|
|
183
184
|
#mountedLocale: string | null = null;
|
|
184
185
|
#controller: AttemptController | null = null;
|
|
185
186
|
#unsubscribe: (() => void) | null = null;
|
|
186
|
-
/** The rows of hints, feedback and explanations, when the view offers help. */
|
|
187
|
+
/** The rows of hints, feedback and explanations, when the view offers help or practice checks one question. */
|
|
187
188
|
#help: Help | null = null;
|
|
189
|
+
/**
|
|
190
|
+
* Practice checking one question at a time: the overall result the help module composes from the latest checks
|
|
191
|
+
* once every question has one (no request of its own), else null.
|
|
192
|
+
*/
|
|
193
|
+
#overall: CheckResponse | null = null;
|
|
188
194
|
#mounted: Mounted[] = [];
|
|
189
195
|
#pages: HTMLElement[] = [];
|
|
190
196
|
/** The mounted view's `astl-doc`. */
|
|
@@ -256,11 +262,11 @@ export class AstlPlayer extends LitElement {
|
|
|
256
262
|
}
|
|
257
263
|
|
|
258
264
|
/**
|
|
259
|
-
* Practice: grades the answers and shows verdicts; with `
|
|
260
|
-
* `checkScope: 'interaction'
|
|
261
|
-
* never thrown.
|
|
265
|
+
* Practice: grades the answers and shows verdicts; with `id`, a view page (its questions at once) or, under a policy
|
|
266
|
+
* with `checkScope: 'interaction'`, a view element (that interaction only): neither is an `astl-result`. Failures are
|
|
267
|
+
* shown and emitted, never thrown.
|
|
262
268
|
*/
|
|
263
|
-
async check(
|
|
269
|
+
async check(id?: string): Promise<CheckResponse | null> {
|
|
264
270
|
const controller = this.#controller;
|
|
265
271
|
if (controller === null) return null;
|
|
266
272
|
this.#problem = null;
|
|
@@ -269,7 +275,8 @@ export class AstlPlayer extends LitElement {
|
|
|
269
275
|
return null;
|
|
270
276
|
}
|
|
271
277
|
try {
|
|
272
|
-
|
|
278
|
+
if (id === undefined || controller.pages.some((p) => p.id === id)) return await controller.check(id);
|
|
279
|
+
return await controller.checkElement(id);
|
|
273
280
|
} catch (error) {
|
|
274
281
|
this.#showProblem(codeOf(error, 'internal_error'));
|
|
275
282
|
return null;
|
|
@@ -490,7 +497,7 @@ export class AstlPlayer extends LitElement {
|
|
|
490
497
|
}
|
|
491
498
|
|
|
492
499
|
#renderResult(c: AttemptController, t: Translate): TemplateResult | typeof nothing {
|
|
493
|
-
const response = c.response;
|
|
500
|
+
const response = this.#overall ?? c.response;
|
|
494
501
|
if (response === null) return nothing;
|
|
495
502
|
const result = response.result;
|
|
496
503
|
const passed = 'passed' in response ? response.passed : null;
|
|
@@ -619,24 +626,33 @@ export class AstlPlayer extends LitElement {
|
|
|
619
626
|
if (!this.#mounted.some(({ element }) => element.slotIds.length > 0)) {
|
|
620
627
|
return c.result === null ? html`<p class="practice-only">${t('result.practice')}</p>` : nothing;
|
|
621
628
|
}
|
|
629
|
+
// Each question has its own Check (and a page with `check` one of its own): no Check here, and "Start over" once
|
|
630
|
+
// every question has a result.
|
|
631
|
+
const each = helpPolicy(c.policy).checkScope === 'interaction';
|
|
622
632
|
const left = c.checksLeft;
|
|
633
|
+
const done = c.result !== null || this.#overall !== null;
|
|
634
|
+
if (each && left === null && !done) return nothing;
|
|
623
635
|
return html`<div class="actions">
|
|
624
636
|
${left === null ? nothing : html`<span class="hint">${t('checks.left', { count: left })}</span>`}
|
|
625
637
|
${
|
|
626
|
-
|
|
638
|
+
done
|
|
639
|
+
? html`<button type="button" class="button" @click=${() => this.reset()}>${t('action.reset')}</button>`
|
|
640
|
+
: nothing
|
|
641
|
+
}
|
|
642
|
+
${
|
|
643
|
+
each
|
|
627
644
|
? nothing
|
|
628
|
-
: html`<button
|
|
645
|
+
: html`<button
|
|
646
|
+
type="button"
|
|
647
|
+
class="button primary"
|
|
648
|
+
aria-disabled=${c.canCheck() ? nothing : 'true'}
|
|
649
|
+
@click=${() => {
|
|
650
|
+
if (c.canCheck()) void this.check();
|
|
651
|
+
}}
|
|
652
|
+
>
|
|
653
|
+
${t('action.check')}
|
|
654
|
+
</button>`
|
|
629
655
|
}
|
|
630
|
-
<button
|
|
631
|
-
type="button"
|
|
632
|
-
class="button primary"
|
|
633
|
-
aria-disabled=${c.canCheck() ? nothing : 'true'}
|
|
634
|
-
@click=${() => {
|
|
635
|
-
if (c.canCheck()) void this.check();
|
|
636
|
-
}}
|
|
637
|
-
>
|
|
638
|
-
${t('action.check')}
|
|
639
|
-
</button>
|
|
640
656
|
</div>`;
|
|
641
657
|
}
|
|
642
658
|
if (c.policy.mode === 'test') {
|
|
@@ -675,8 +691,7 @@ export class AstlPlayer extends LitElement {
|
|
|
675
691
|
return t('result.score', { score: roundScore(result.score), max: roundScore(result.max) });
|
|
676
692
|
}
|
|
677
693
|
|
|
678
|
-
#resultAnnouncement(t: Translate): string | null {
|
|
679
|
-
const response = this.#controller?.response ?? null;
|
|
694
|
+
#resultAnnouncement(t: Translate, response = this.#controller?.response ?? null): string | null {
|
|
680
695
|
if (response === null) return null;
|
|
681
696
|
const result = response.result;
|
|
682
697
|
if (result === null) return `${t('result.submitted')} ${t('result.later')}`;
|
|
@@ -782,6 +797,7 @@ export class AstlPlayer extends LitElement {
|
|
|
782
797
|
this.#unsubscribe = null;
|
|
783
798
|
this.#help?.destroy();
|
|
784
799
|
this.#help = null;
|
|
800
|
+
this.#overall = null;
|
|
785
801
|
this.#controller = null;
|
|
786
802
|
this.#mounted = [];
|
|
787
803
|
this.#pages = [];
|
|
@@ -820,13 +836,16 @@ export class AstlPlayer extends LitElement {
|
|
|
820
836
|
return null;
|
|
821
837
|
})
|
|
822
838
|
: null;
|
|
823
|
-
// The same for help: without its module the exercise plays without hints and feedback texts.
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
839
|
+
// The same for help: without its module the exercise plays without hints and feedback texts. It also brings the
|
|
840
|
+
// Check of each question where practice checks one at a time.
|
|
841
|
+
const each = this.policy.mode === 'practice' && helpPolicy(this.policy).checkScope === 'interaction';
|
|
842
|
+
const helping =
|
|
843
|
+
each || hasHelp(fragment)
|
|
844
|
+
? import('./help.js').catch((error) => {
|
|
845
|
+
console.error(error);
|
|
846
|
+
return null;
|
|
847
|
+
})
|
|
848
|
+
: null;
|
|
830
849
|
// And for a book: without its module it plays one page at a time, as an exercise.
|
|
831
850
|
const booking = isBook(fragment)
|
|
832
851
|
? import('./book.js').catch((error) => {
|
|
@@ -968,6 +987,12 @@ export class AstlPlayer extends LitElement {
|
|
|
968
987
|
root: this.renderRoot,
|
|
969
988
|
checker: () => this.#effectiveChecker(),
|
|
970
989
|
check: (id) => this.check(id),
|
|
990
|
+
overall: (response) => {
|
|
991
|
+
this.#overall = response;
|
|
992
|
+
this.requestUpdate();
|
|
993
|
+
const t = this.#i18n().translator(this.#uiLocale(), PLAYER_NAMESPACE);
|
|
994
|
+
return response === null ? null : this.#resultAnnouncement(t, response);
|
|
995
|
+
},
|
|
971
996
|
announce: (message) => this.#announce(message),
|
|
972
997
|
}) ?? null;
|
|
973
998
|
const book = pages.length > 1 ? await booking : null;
|
|
@@ -1048,7 +1073,8 @@ export class AstlPlayer extends LitElement {
|
|
|
1048
1073
|
this.#scheduleSnapshot();
|
|
1049
1074
|
break;
|
|
1050
1075
|
case 'element':
|
|
1051
|
-
|
|
1076
|
+
case 'page-check':
|
|
1077
|
+
this.#applyResult(change.response);
|
|
1052
1078
|
this.#scheduleSnapshot();
|
|
1053
1079
|
break;
|
|
1054
1080
|
case 'reset':
|
|
@@ -1067,9 +1093,10 @@ export class AstlPlayer extends LitElement {
|
|
|
1067
1093
|
|
|
1068
1094
|
/**
|
|
1069
1095
|
* Pushes verdicts, the help texts the response brings and solutions after a revealing submit to the elements, then
|
|
1070
|
-
* announces the summary. With `
|
|
1096
|
+
* announces the summary. With `checked`, the response of a check of one element or one page: the verdicts of the
|
|
1097
|
+
* elements it graded, no summary.
|
|
1071
1098
|
*/
|
|
1072
|
-
#applyResult(
|
|
1099
|
+
#applyResult(checked?: CheckResponse): void {
|
|
1073
1100
|
const controller = this.#controller;
|
|
1074
1101
|
if (controller === null) return;
|
|
1075
1102
|
const response = checked ?? controller.response;
|
|
@@ -1077,7 +1104,9 @@ export class AstlPlayer extends LitElement {
|
|
|
1077
1104
|
const solution = controller.solution;
|
|
1078
1105
|
const groups = new Map(result?.groups.map((g) => [g.id, g.verdict]) ?? []);
|
|
1079
1106
|
for (const { element } of this.#mounted) {
|
|
1080
|
-
|
|
1107
|
+
// Its groups: those it names (graded in parts) or its own, as the scoring the key chose has them.
|
|
1108
|
+
if (checked !== undefined && ![element.id, ...(element.groupIds ?? [])].some((id) => groups.has(id)))
|
|
1109
|
+
continue;
|
|
1081
1110
|
if (result === null) {
|
|
1082
1111
|
element.feedback = null;
|
|
1083
1112
|
} else {
|
|
@@ -1101,12 +1130,12 @@ export class AstlPlayer extends LitElement {
|
|
|
1101
1130
|
? { slots, group, ...help }
|
|
1102
1131
|
: { slots, group, groups: Object.fromEntries(named), ...help };
|
|
1103
1132
|
}
|
|
1104
|
-
if (
|
|
1133
|
+
if (checked !== undefined) continue;
|
|
1105
1134
|
element.solution = solution === null ? null : pick(solution, element.slotIds);
|
|
1106
1135
|
element.disabled = controller.readOnly;
|
|
1107
1136
|
}
|
|
1108
1137
|
const text =
|
|
1109
|
-
|
|
1138
|
+
checked === undefined
|
|
1110
1139
|
? this.#resultAnnouncement(this.#i18n().translator(this.#uiLocale(), PLAYER_NAMESPACE))
|
|
1111
1140
|
: null;
|
|
1112
1141
|
if (text !== null) this.#announce(text);
|