📝 grade submitted/expired attempts during live exam
Browse files at this commit08a1204db46ee3799c10fc9756e2038ccf0dcc53Parent: 02a2588- feat
- 📝 grade submitted/expired attempts during live exam
2 changed files +33 -10
src/components/exams/grade-form.tsxmodified+15 -6
| @@ -1,8 +1,8 @@ | ||
| 1 | -import { For, createMemo, createSignal } from "solid-js"; | |
| 1 | +import { For, Show, createMemo, createSignal } from "solid-js"; | |
| 2 | 2 | import { formatApiError } from "@/api/client"; |
| 3 | 3 | import { Button } from "@/components/ui/button"; |
| 4 | 4 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 5 | -import { IconCheck } from "@/components/ui/icons"; | |
| 5 | +import { IconCheck, IconEye } from "@/components/ui/icons"; | |
| 6 | 6 | import { Input } from "@/components/ui/input"; |
| 7 | 7 | import { Label } from "@/components/ui/label"; |
| 8 | 8 | import { Select } from "@/components/ui/select"; |
| @@ -16,6 +16,7 @@ export type GradeFormValues = { | ||
| 16 | 16 | export function GradeForm(props: { |
| 17 | 17 | students: { id: string; label: string }[]; |
| 18 | 18 | onSubmit: (values: GradeFormValues) => Promise<void>; |
| 19 | + onViewAnswers?: (userId: string) => void; | |
| 19 | 20 | }) { |
| 20 | 21 | const t = useT(); |
| 21 | 22 | const [userId, setUserId] = createSignal(""); |
| @@ -87,10 +88,18 @@ export function GradeForm(props: { | ||
| 87 | 88 | /> |
| 88 | 89 | </div> |
| 89 | 90 | </div> |
| 90 | - <Button type="submit" disabled={pending()}> | |
| 91 | - <IconCheck /> | |
| 92 | - {t("exams.gradeStudent")} | |
| 93 | - </Button> | |
| 91 | + <div class="flex flex-wrap gap-2"> | |
| 92 | + <Show when={props.onViewAnswers}> | |
| 93 | + <Button type="button" variant="outline" disabled={!userId()} onClick={() => props.onViewAnswers?.(userId())}> | |
| 94 | + <IconEye /> | |
| 95 | + {t("exams.answerSheet")} | |
| 96 | + </Button> | |
| 97 | + </Show> | |
| 98 | + <Button type="submit" disabled={pending()}> | |
| 99 | + <IconCheck /> | |
| 100 | + {t("exams.gradeStudent")} | |
| 101 | + </Button> | |
| 102 | + </div> | |
| 94 | 103 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 95 | 104 | </form> |
| 96 | 105 |
src/pages/exam-detail-page.tsxmodified+18 -4
| @@ -5,6 +5,7 @@ import { deleteExamById } from "@/api/exams"; | ||
| 5 | 5 | import { deleteExamResultByUserId } from "@/api/exams"; |
| 6 | 6 | import { getExamById } from "@/api/exams"; |
| 7 | 7 | import { getExamAttempt } from "@/api/exams"; |
| 8 | +import { getExamLive } from "@/api/exams"; | |
| 8 | 9 | import { getExamResult } from "@/api/exams"; |
| 9 | 10 | import { getExamResults } from "@/api/exams"; |
| 10 | 11 | import { getExamStatistics } from "@/api/exams"; |
| @@ -221,6 +222,10 @@ function ExamDetailContent() { | ||
| 221 | 222 | return t("exams.unscheduled"); |
| 222 | 223 | }; |
| 223 | 224 | const isDraft = () => exam()?.draft === true; |
| 225 | + const [gradeLive] = createResource( | |
| 226 | + () => (hasCourseManagementRights() && gradeOpen() && !isFinished() ? id() : null), | |
| 227 | + async (examId) => examId ? getExamLive(examId) : null, | |
| 228 | + ); | |
| 224 | 229 | const resultTotal = () => results()?.total ?? 0; |
| 225 | 230 | const resultTotalPages = () => Math.max(1, Math.ceil(resultTotal() / RESULT_PAGE_SIZE)); |
| 226 | 231 | const setClampedAnswerMark = (value: string) => { |
| @@ -259,6 +264,14 @@ function ExamDetailContent() { | ||
| 259 | 264 | const gradeStudents = () => { |
| 260 | 265 | if (gradeResults.loading) return []; |
| 261 | 266 | const graded = new Set((gradeResults()?.items ?? []).map((row) => personId(row.user))); |
| 267 | + if (!isFinished()) { | |
| 268 | + return (gradeLive()?.students ?? []) | |
| 269 | + .filter((row) => (row.status === "submitted" || row.status === "expired") && !graded.has(personId(row.user))) | |
| 270 | + .map((row) => ({ | |
| 271 | + id: personId(row.user), | |
| 272 | + label: personLabelWithId(row.user), | |
| 273 | + })); | |
| 274 | + } | |
| 262 | 275 | return (roster() ?? []) |
| 263 | 276 | .filter((row) => !graded.has(row.user.id)) |
| 264 | 277 | .map((row) => ({ |
| @@ -671,6 +684,10 @@ function ExamDetailContent() { | ||
| 671 | 684 | > |
| 672 | 685 | <GradeForm |
| 673 | 686 | students={gradeStudents()} |
| 687 | + onViewAnswers={(userId) => { | |
| 688 | + setGradeOpen(false); | |
| 689 | + setAnswerSheetUserId(userId); | |
| 690 | + }} | |
| 674 | 691 | onSubmit={async (values) => { |
| 675 | 692 | await postExamResult(id(), values); |
| 676 | 693 | await refetchResults(); |
| @@ -688,10 +705,7 @@ function ExamDetailContent() { | ||
| 688 | 705 | actions={ |
| 689 | 706 | <Show when={hasCourseManagementRights()}> |
| 690 | 707 | <div class="flex items-center gap-2"> |
| 691 | - <Show when={!isFinished()}> | |
| 692 | - <span class="text-xs text-muted-foreground">{t("exams.gradeAfterExam")}</span> | |
| 693 | - </Show> | |
| 694 | - <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={!isFinished() || isDraft()} onClick={() => setGradeOpen(true)}> | |
| 708 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={isDraft()} onClick={() => setGradeOpen(true)}> | |
| 695 | 709 | <IconEdit class="h-4 w-4" /> |
| 696 | 710 | {t("exams.gradeStudent")} |
| 697 | 711 | </Button> |