@commonpub/layer 0.27.0 → 0.28.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commonpub/layer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"files": [
|
|
@@ -53,16 +53,16 @@
|
|
|
53
53
|
"vue": "^3.4.0",
|
|
54
54
|
"vue-router": "^4.3.0",
|
|
55
55
|
"zod": "^4.3.6",
|
|
56
|
-
"@commonpub/config": "0.15.0",
|
|
57
56
|
"@commonpub/auth": "0.6.0",
|
|
57
|
+
"@commonpub/config": "0.15.0",
|
|
58
58
|
"@commonpub/docs": "0.6.3",
|
|
59
|
-
"@commonpub/editor": "0.7.11",
|
|
60
59
|
"@commonpub/explainer": "0.7.15",
|
|
61
60
|
"@commonpub/learning": "0.5.2",
|
|
62
|
-
"@commonpub/
|
|
63
|
-
"@commonpub/
|
|
61
|
+
"@commonpub/schema": "0.21.0",
|
|
62
|
+
"@commonpub/editor": "0.7.11",
|
|
64
63
|
"@commonpub/ui": "0.9.1",
|
|
65
|
-
"@commonpub/
|
|
64
|
+
"@commonpub/protocol": "0.12.0",
|
|
65
|
+
"@commonpub/server": "2.62.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -6,15 +6,24 @@ const slug = route.params.slug as string;
|
|
|
6
6
|
const { user } = useAuth();
|
|
7
7
|
const toast = useToast();
|
|
8
8
|
|
|
9
|
-
import type { Serialized, ContestDetail, ContestEntryItem, ContestJudgeItem } from '@commonpub/server';
|
|
9
|
+
import type { Serialized, ContestDetail, ContestEntryItem, ContestJudgeItem, JudgeScoreEntry } from '@commonpub/server';
|
|
10
10
|
|
|
11
11
|
const { data: contest } = useLazyFetch<Serialized<ContestDetail>>(`/api/contests/${slug}`);
|
|
12
12
|
const { data: judgesData, refresh: refreshJudges } = useLazyFetch<ContestJudgeItem[]>(`/api/contests/${slug}/judges`);
|
|
13
|
-
const { data: entriesData, refresh: refreshEntries } = useLazyFetch<{ items: (Serialized<ContestEntryItem> & { judgeScores?:
|
|
13
|
+
const { data: entriesData, refresh: refreshEntries } = useLazyFetch<{ items: (Serialized<ContestEntryItem> & { judgeScores?: JudgeScoreEntry[] })[]; total: number }>(
|
|
14
14
|
`/api/contests/${slug}/entries`,
|
|
15
15
|
{ query: { includeJudgeScores: true } },
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
+
// Judging rubric: when defined, judges score each criterion (0..max) and the
|
|
19
|
+
// overall is the normalized weighted sum (computed server-side).
|
|
20
|
+
const criteria = computed(() => contest.value?.judgingCriteria ?? []);
|
|
21
|
+
const hasCriteria = computed(() => criteria.value.length > 0);
|
|
22
|
+
function critMax(i: number): number {
|
|
23
|
+
const w = criteria.value[i]?.weight;
|
|
24
|
+
return typeof w === 'number' && w > 0 ? w : 100;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
useSeoMeta({ title: () => `Judge: ${contest.value?.title || 'Contest'} — ${useSiteName()}` });
|
|
19
28
|
|
|
20
29
|
// Judge authorization derives from the contest_judges table.
|
|
@@ -54,6 +63,7 @@ const entryList = computed(() => {
|
|
|
54
63
|
rank: entry.rank ?? null,
|
|
55
64
|
myScore: myScore?.score ?? null,
|
|
56
65
|
myFeedback: myScore?.feedback ?? '',
|
|
66
|
+
myCriteriaScores: myScore?.criteriaScores ?? null,
|
|
57
67
|
};
|
|
58
68
|
});
|
|
59
69
|
});
|
|
@@ -63,6 +73,7 @@ const totalCount = computed(() => entryList.value.length);
|
|
|
63
73
|
const progressPct = computed(() => totalCount.value > 0 ? Math.round((scoredCount.value / totalCount.value) * 100) : 0);
|
|
64
74
|
|
|
65
75
|
const scoring = ref<Record<string, number>>({});
|
|
76
|
+
const critScoring = ref<Record<string, number[]>>({}); // per entry → [criterionScore...]
|
|
66
77
|
const feedback = ref<Record<string, string>>({});
|
|
67
78
|
const submitting = ref<string | null>(null);
|
|
68
79
|
const error = ref('');
|
|
@@ -77,18 +88,50 @@ watch(entryList, (list) => {
|
|
|
77
88
|
if (entry.myFeedback && feedback.value[entry.id] === undefined) {
|
|
78
89
|
feedback.value[entry.id] = entry.myFeedback;
|
|
79
90
|
}
|
|
91
|
+
if (hasCriteria.value && critScoring.value[entry.id] === undefined) {
|
|
92
|
+
// seed from a prior per-criterion submission, aligned by index
|
|
93
|
+
critScoring.value[entry.id] = criteria.value.map((c, i) =>
|
|
94
|
+
entry.myCriteriaScores?.[i]?.score ?? 0,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
80
97
|
}
|
|
81
98
|
}, { immediate: true });
|
|
82
99
|
|
|
100
|
+
// Live preview of the normalized overall when scoring by criteria.
|
|
101
|
+
function critTotal(entryId: string): number {
|
|
102
|
+
const vals = critScoring.value[entryId] ?? [];
|
|
103
|
+
const totalMax = criteria.value.reduce((s, _c, i) => s + critMax(i), 0);
|
|
104
|
+
if (totalMax <= 0) return 0;
|
|
105
|
+
const sum = criteria.value.reduce((s, _c, i) => s + Math.min(Math.max(vals[i] ?? 0, 0), critMax(i)), 0);
|
|
106
|
+
return Math.round((sum / totalMax) * 100);
|
|
107
|
+
}
|
|
108
|
+
|
|
83
109
|
async function submitScore(entryId: string): Promise<void> {
|
|
84
110
|
if (!inJudgingPhase.value) {
|
|
85
111
|
error.value = 'Scoring is only open during the judging phase.';
|
|
86
112
|
return;
|
|
87
113
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
|
|
115
|
+
let body: Record<string, unknown>;
|
|
116
|
+
if (hasCriteria.value) {
|
|
117
|
+
const vals = critScoring.value[entryId] ?? [];
|
|
118
|
+
const criteriaScores = criteria.value.map((c, i) => ({
|
|
119
|
+
label: c.label,
|
|
120
|
+
score: Math.round(vals[i] ?? 0),
|
|
121
|
+
max: critMax(i),
|
|
122
|
+
}));
|
|
123
|
+
if (criteriaScores.some((c) => c.score < 0 || c.score > c.max)) {
|
|
124
|
+
error.value = 'Each criterion score must be between 0 and its maximum.';
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
body = { entryId, criteriaScores, feedback: feedback.value[entryId] || undefined };
|
|
128
|
+
} else {
|
|
129
|
+
const score = scoring.value[entryId];
|
|
130
|
+
if (score === undefined || score < 1 || score > 100) {
|
|
131
|
+
error.value = 'Score must be between 1 and 100.';
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
body = { entryId, score, feedback: feedback.value[entryId] || undefined };
|
|
92
135
|
}
|
|
93
136
|
|
|
94
137
|
error.value = '';
|
|
@@ -96,14 +139,7 @@ async function submitScore(entryId: string): Promise<void> {
|
|
|
96
139
|
submitting.value = entryId;
|
|
97
140
|
|
|
98
141
|
try {
|
|
99
|
-
await $fetch(`/api/contests/${slug}/judge`, {
|
|
100
|
-
method: 'POST',
|
|
101
|
-
body: {
|
|
102
|
-
entryId,
|
|
103
|
-
score,
|
|
104
|
-
feedback: feedback.value[entryId] || undefined,
|
|
105
|
-
},
|
|
106
|
-
});
|
|
142
|
+
await $fetch(`/api/contests/${slug}/judge`, { method: 'POST', body });
|
|
107
143
|
success.value = 'Score submitted for entry.';
|
|
108
144
|
await refreshEntries().catch(() => {
|
|
109
145
|
success.value = 'Score saved — refresh to see the updated totals.';
|
|
@@ -202,14 +238,35 @@ async function submitScore(entryId: string): Promise<void> {
|
|
|
202
238
|
<span class="cpub-judge-score-value">{{ entry.myScore }}</span>
|
|
203
239
|
</div>
|
|
204
240
|
<div class="cpub-judge-score-controls">
|
|
241
|
+
<!-- Per-criterion scoring (when the contest defines a rubric) -->
|
|
242
|
+
<div v-if="hasCriteria && critScoring[entry.id]" class="cpub-judge-criteria-inputs">
|
|
243
|
+
<div v-for="(crit, i) in criteria" :key="i" class="cpub-judge-crit-row">
|
|
244
|
+
<label class="cpub-judge-crit-label">{{ crit.label }}</label>
|
|
245
|
+
<div class="cpub-judge-crit-input-wrap">
|
|
246
|
+
<input
|
|
247
|
+
v-model.number="critScoring[entry.id][i]"
|
|
248
|
+
type="number"
|
|
249
|
+
class="cpub-judge-crit-input"
|
|
250
|
+
min="0"
|
|
251
|
+
:max="critMax(i)"
|
|
252
|
+
:aria-label="`${crit.label} score, max ${critMax(i)}`"
|
|
253
|
+
/>
|
|
254
|
+
<span class="cpub-judge-crit-max">/ {{ critMax(i) }}</span>
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
<div class="cpub-judge-crit-total">Overall <strong>{{ critTotal(entry.id) }}</strong> / 100</div>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
205
260
|
<div class="cpub-judge-score-input-wrap">
|
|
206
261
|
<input
|
|
262
|
+
v-if="!hasCriteria"
|
|
207
263
|
v-model.number="scoring[entry.id]"
|
|
208
264
|
type="number"
|
|
209
265
|
class="cpub-judge-score-input"
|
|
210
266
|
min="1"
|
|
211
267
|
max="100"
|
|
212
268
|
placeholder="1-100"
|
|
269
|
+
aria-label="Overall score, 1 to 100"
|
|
213
270
|
/>
|
|
214
271
|
<button
|
|
215
272
|
class="cpub-judge-score-btn"
|
|
@@ -279,6 +336,15 @@ async function submitScore(entryId: string): Promise<void> {
|
|
|
279
336
|
.cpub-judge-score-label { display: block; font-family: var(--font-mono); font-size: 9px; color: var(--text-faint); text-transform: uppercase; }
|
|
280
337
|
.cpub-judge-score-value { font-size: 20px; font-weight: 700; color: var(--accent); font-family: var(--font-mono); }
|
|
281
338
|
.cpub-judge-score-controls { display: flex; flex-direction: column; gap: 6px; }
|
|
339
|
+
.cpub-judge-criteria-inputs { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: var(--border-width-default) dashed var(--border); background: var(--surface2); margin-bottom: 2px; }
|
|
340
|
+
.cpub-judge-crit-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
341
|
+
.cpub-judge-crit-label { font-size: 11px; color: var(--text-dim); flex: 1; min-width: 0; }
|
|
342
|
+
.cpub-judge-crit-input-wrap { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
|
|
343
|
+
.cpub-judge-crit-input { width: 52px; padding: 4px 6px; border: var(--border-width-default) solid var(--border); background: var(--surface); color: var(--text); font-size: 12px; font-family: var(--font-mono); text-align: center; outline: none; }
|
|
344
|
+
.cpub-judge-crit-input:focus { border-color: var(--accent); }
|
|
345
|
+
.cpub-judge-crit-max { font-size: 10px; color: var(--text-faint); font-family: var(--font-mono); }
|
|
346
|
+
.cpub-judge-crit-total { font-size: 11px; font-family: var(--font-mono); color: var(--text-dim); text-align: right; padding-top: 4px; border-top: var(--border-width-default) solid var(--border); }
|
|
347
|
+
.cpub-judge-crit-total strong { color: var(--accent); font-size: 13px; }
|
|
282
348
|
.cpub-judge-score-input-wrap { display: flex; gap: 0; }
|
|
283
349
|
.cpub-judge-score-input {
|
|
284
350
|
width: 70px; padding: 6px 8px; border: var(--border-width-default) solid var(--border); background: var(--surface);
|
|
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event): Promise<{ success: boolean }> =
|
|
|
7
7
|
const db = useDB();
|
|
8
8
|
const input = await parseBody(event, judgeEntrySchema);
|
|
9
9
|
|
|
10
|
-
const result = await judgeContestEntry(db, input.entryId, input.score, user.id, input.feedback);
|
|
10
|
+
const result = await judgeContestEntry(db, input.entryId, input.score, user.id, input.feedback, input.criteriaScores);
|
|
11
11
|
if (!result.judged) {
|
|
12
12
|
throw createError({ statusCode: 403, statusMessage: result.error ?? 'Judging failed' });
|
|
13
13
|
}
|