forge
Explore
Log in

Don't you dare go Hollow

📝 grade submitted/expired attempts during live exam

Browse files at this commit

08a1204db46ee3799c10fc9756e2038ccf0dcc53Burak BoduroğluParent: 02a2588
  • feat
    • 📝 grade submitted/expired attempts during live exam
Show full message
feat: 📝 grade submitted/expired attempts during live exam
- add onViewAnswers prop to GradeForm for answer sheet navigation
- fetch live roster for grading; show students who submitted/expired
- enable grade button during the exam (not just after finish)
- remove "grade after exam" helper text
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 import { formatApiError } from "@/api/client";2 import { formatApiError } from "@/api/client";
3 import { Button } from "@/components/ui/button";3 import { Button } from "@/components/ui/button";
4 import { ConfirmDialog } from "@/components/ui/confirm-dialog";4 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
5-import { IconCheck } from "@/components/ui/icons";5+import { IconCheck, IconEye } from "@/components/ui/icons";
6 import { Input } from "@/components/ui/input";6 import { Input } from "@/components/ui/input";
7 import { Label } from "@/components/ui/label";7 import { Label } from "@/components/ui/label";
8 import { Select } from "@/components/ui/select";8 import { Select } from "@/components/ui/select";
@@ -16,6 +16,7 @@ export type GradeFormValues = {
16 export function GradeForm(props: {16 export function GradeForm(props: {
17 students: { id: string; label: string }[];17 students: { id: string; label: string }[];
18 onSubmit: (values: GradeFormValues) => Promise<void>;18 onSubmit: (values: GradeFormValues) => Promise<void>;
19+ onViewAnswers?: (userId: string) => void;
19 }) {20 }) {
20 const t = useT();21 const t = useT();
21 const [userId, setUserId] = createSignal("");22 const [userId, setUserId] = createSignal("");
@@ -87,10 +88,18 @@ export function GradeForm(props: {
87 />88 />
88 </div>89 </div>
89 </div>90 </div>
90- <Button type="submit" disabled={pending()}>91+ <div class="flex flex-wrap gap-2">
91- <IconCheck />92+ <Show when={props.onViewAnswers}>
92- {t("exams.gradeStudent")}93+ <Button type="button" variant="outline" disabled={!userId()} onClick={() => props.onViewAnswers?.(userId())}>
93- </Button>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 {error() && <p class="text-sm text-destructive">{error()}</p>}103 {error() && <p class="text-sm text-destructive">{error()}</p>}
95 </form>104 </form>
96 105
src/pages/exam-detail-page.tsxmodified+18 -4
@@ -5,6 +5,7 @@ import { deleteExamById } from "@/api/exams";
5 import { deleteExamResultByUserId } from "@/api/exams";5 import { deleteExamResultByUserId } from "@/api/exams";
6 import { getExamById } from "@/api/exams";6 import { getExamById } from "@/api/exams";
7 import { getExamAttempt } from "@/api/exams";7 import { getExamAttempt } from "@/api/exams";
8+import { getExamLive } from "@/api/exams";
8 import { getExamResult } from "@/api/exams";9 import { getExamResult } from "@/api/exams";
9 import { getExamResults } from "@/api/exams";10 import { getExamResults } from "@/api/exams";
10 import { getExamStatistics } from "@/api/exams";11 import { getExamStatistics } from "@/api/exams";
@@ -221,6 +222,10 @@ function ExamDetailContent() {
221 return t("exams.unscheduled");222 return t("exams.unscheduled");
222 };223 };
223 const isDraft = () => exam()?.draft === true;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 const resultTotal = () => results()?.total ?? 0;229 const resultTotal = () => results()?.total ?? 0;
225 const resultTotalPages = () => Math.max(1, Math.ceil(resultTotal() / RESULT_PAGE_SIZE));230 const resultTotalPages = () => Math.max(1, Math.ceil(resultTotal() / RESULT_PAGE_SIZE));
226 const setClampedAnswerMark = (value: string) => {231 const setClampedAnswerMark = (value: string) => {
@@ -259,6 +264,14 @@ function ExamDetailContent() {
259 const gradeStudents = () => {264 const gradeStudents = () => {
260 if (gradeResults.loading) return [];265 if (gradeResults.loading) return [];
261 const graded = new Set((gradeResults()?.items ?? []).map((row) => personId(row.user)));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 return (roster() ?? [])275 return (roster() ?? [])
263 .filter((row) => !graded.has(row.user.id))276 .filter((row) => !graded.has(row.user.id))
264 .map((row) => ({277 .map((row) => ({
@@ -671,6 +684,10 @@ function ExamDetailContent() {
671 >684 >
672 <GradeForm685 <GradeForm
673 students={gradeStudents()}686 students={gradeStudents()}
687+ onViewAnswers={(userId) => {
688+ setGradeOpen(false);
689+ setAnswerSheetUserId(userId);
690+ }}
674 onSubmit={async (values) => {691 onSubmit={async (values) => {
675 await postExamResult(id(), values);692 await postExamResult(id(), values);
676 await refetchResults();693 await refetchResults();
@@ -688,10 +705,7 @@ function ExamDetailContent() {
688 actions={705 actions={
689 <Show when={hasCourseManagementRights()}>706 <Show when={hasCourseManagementRights()}>
690 <div class="flex items-center gap-2">707 <div class="flex items-center gap-2">
691- <Show when={!isFinished()}>708+ <Button type="button" variant="outline" size="sm" class="rounded-lg" disabled={isDraft()} onClick={() => setGradeOpen(true)}>
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)}>
695 <IconEdit class="h-4 w-4" />709 <IconEdit class="h-4 w-4" />
696 {t("exams.gradeStudent")}710 {t("exams.gradeStudent")}
697 </Button>711 </Button>