forge
Explore
Log in

Don't you dare go Hollow

✨ exam weight badge from settings, allowRejoin toggle, beforeLoad guards complete

Browse files at this commit

8dda6ac4c76f20b1ac108aaf30227032f96070f2Burak BoduroğluParent: 143c07a
  • feat
    • ✨ exam weight badge from settings, allowRejoin toggle, beforeLoad guards complete
Show full message
feat: ✨ exam weight badge from settings, allowRejoin toggle, beforeLoad guards complete
- exam-weight: resolve weight from GET /settings exam_kinds by kind name fallback
- exam-card + exam-detail + course-detail: pass settings exam_kinds to examWeight
- marks-report-view: resolve weight from settings for report entries
- exam-form: allowRejoin checkbox with help text
- routers: beforeLoad guards on exam-room (student), live (teacher+), settings/terms (manager+)
- exam-detail: exam-room CTA uses isStudent() instead of !isTeacherPlus()
- i18n: exams.allowRejoin, exams.allowRejoinHelp
- docs: mark all backlog items as done
docs/frontend-next-steps.mdmodified+6 -6
@@ -68,12 +68,12 @@ validation, and list filtering cleanup.
68 68
69 ### Incomplete Product Features69 ### Incomplete Product Features
70 70
71-| Feature | API | UI | Notes |71+| Feature | Status |
72-|---|---|---|---|72+|---|---|
73-| `allow_rejoin` | Type + body exist | No toggle; form always sends `true` | Deferred |73+| `allow_rejoin` toggle | Done — exam form checkbox + help text |
74-| Exam weight badge | BE exam DTO has no weight | Badge never shows; needs weight derived from settings kind map | Needs BE or FE-side resolution |74+| Exam weight badge | Done — resolved from `GET /settings` exam_kinds by kind name |
75-| Router `beforeLoad` | — | Still missing on live monitor, settings, terms | Consistency |75+| Router `beforeLoad` | Done — live (teacher+), settings/terms (manager+), exam-room (student) |
76-| Exam room CTA | — | Visible to manager/admin on detail page; page itself blocks | Minor |76+| Exam room CTA | Done — student-only on exam detail |
77 77
78 ### Backend-Dependent Follow-Up78 ### Backend-Dependent Follow-Up
79 79
src/components/exams/exam-card.tsxmodified+4 -2
@@ -1,4 +1,5 @@
1-import { Show } from "solid-js";1+import { Show, createResource } from "solid-js";
2+import { getSettings } from "@/api/getSettings";
2 import type { Exam } from "@/api/types";3 import type { Exam } from "@/api/types";
3 import { Badge } from "@/components/ui/badge";4 import { Badge } from "@/components/ui/badge";
4 import { ExamLink } from "@/components/exams/exam-link";5 import { ExamLink } from "@/components/exams/exam-link";
@@ -11,6 +12,7 @@ import { usePreferences, useT } from "@/stores/preferences-context";
11 export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number }) {12 export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number }) {
12 const t = useT();13 const t = useT();
13 const { locale } = usePreferences();14 const { locale } = usePreferences();
15+ const [settings] = createResource(() => getSettings());
14 const modeLabel = () => {16 const modeLabel = () => {
15 if (props.exam.mode === "sync") return t("exams.mode.sync");17 if (props.exam.mode === "sync") return t("exams.mode.sync");
16 if (props.exam.mode === "async") return t("exams.mode.async");18 if (props.exam.mode === "async") return t("exams.mode.async");
@@ -77,7 +79,7 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
77 <div class="mt-4 flex flex-wrap gap-2">79 <div class="mt-4 flex flex-wrap gap-2">
78 <Badge variant="outline" class="rounded-sm capitalize">80 <Badge variant="outline" class="rounded-sm capitalize">
79 {examKindLabel(String(props.exam.kind), t)}81 {examKindLabel(String(props.exam.kind), t)}
80- <Show when={examWeight(props.exam) != null}>82+ <Show when={examWeight(props.exam, settings()?.exam_kinds) != null}>
81 {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}83 {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}
82 </Show>84 </Show>
83 </Badge>85 </Badge>
src/components/exams/exam-form.tsxmodified+15 -2
@@ -78,7 +78,7 @@ export function ExamForm(props: {
78 const [mode, setMode] = createSignal(String(props.initial?.mode ?? ""));78 const [mode, setMode] = createSignal(String(props.initial?.mode ?? ""));
79 const [hasRetakes, setHasRetakes] = createSignal((props.initial?.max_attempts ?? 1) !== 1);79 const [hasRetakes, setHasRetakes] = createSignal((props.initial?.max_attempts ?? 1) !== 1);
80 const [maxAttempts, setMaxAttempts] = createSignal(String(props.initial?.max_attempts ?? 1));80 const [maxAttempts, setMaxAttempts] = createSignal(String(props.initial?.max_attempts ?? 1));
81- const allowRejoin = () => props.initial?.allow_rejoin ?? true;81+ const [allowRejoin, setAllowRejoin] = createSignal(props.initial?.allow_rejoin ?? true);
82 const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at));82 const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at));
83 const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at));83 const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at));
84 const [endsDate, setEndsDate] = createSignal(dateInputFromMs(props.initial?.ends_at));84 const [endsDate, setEndsDate] = createSignal(dateInputFromMs(props.initial?.ends_at));
@@ -132,6 +132,7 @@ export function ExamForm(props: {
132 setMode("");132 setMode("");
133 setHasRetakes(false);133 setHasRetakes(false);
134 setMaxAttempts("1");134 setMaxAttempts("1");
135+ setAllowRejoin(true);
135 setStartsDate("");136 setStartsDate("");
136 setStartsTime("");137 setStartsTime("");
137 setEndsDate("");138 setEndsDate("");
@@ -165,7 +166,7 @@ export function ExamForm(props: {
165 duration_ms,166 duration_ms,
166 max_attempts: hasRetakes() ? Number(maxAttempts()) : 1,167 max_attempts: hasRetakes() ? Number(maxAttempts()) : 1,
167 allow_rejoin: allowRejoin(),168 allow_rejoin: allowRejoin(),
168- };169+ } satisfies ExamFormValues;
169 if (isEdit()) {170 if (isEdit()) {
170 setPendingValues(values);171 setPendingValues(values);
171 setConfirmOpen(true);172 setConfirmOpen(true);
@@ -256,6 +257,18 @@ export function ExamForm(props: {
256 </div>257 </div>
257 </Show>258 </Show>
258 </div>259 </div>
260+ <div class="space-y-1.5">
261+ <label class="flex h-10 items-center gap-2 rounded-sm border bg-background/60 px-3 text-sm">
262+ <input
263+ type="checkbox"
264+ class="h-4 w-4 rounded border-border"
265+ checked={allowRejoin()}
266+ onChange={(e) => setAllowRejoin(e.currentTarget.checked)}
267+ />
268+ <span>{t("exams.allowRejoin")}</span>
269+ </label>
270+ <p class="text-xs text-muted-foreground">{t("exams.allowRejoinHelp")}</p>
271+ </div>
259 <Show when={mode() === "sync" || mode() === "async"}>272 <Show when={mode() === "sync" || mode() === "async"}>
260 <div class="grid gap-3">273 <div class="grid gap-3">
261 <div class="space-y-1.5">274 <div class="space-y-1.5">
src/components/marks/marks-report-view.tsxmodified+4 -2
@@ -1,5 +1,6 @@
1-import { For, Show } from "solid-js";1+import { For, Show, createResource } from "solid-js";
2 import { Link } from "@tanstack/solid-router";2 import { Link } from "@tanstack/solid-router";
3+import { getSettings } from "@/api/getSettings";
3 import type { MarksReport } from "@/api/types";4 import type { MarksReport } from "@/api/types";
4 import { Badge } from "@/components/ui/badge";5 import { Badge } from "@/components/ui/badge";
5 import { DataTableEmpty, DataTableFrame } from "@/components/ui/data-table";6 import { DataTableEmpty, DataTableFrame } from "@/components/ui/data-table";
@@ -18,6 +19,7 @@ function markWithGrade(mark: number | null, grade?: string | null) {
18 19
19 export function MarksReportView(props: { report: MarksReport }) {20 export function MarksReportView(props: { report: MarksReport }) {
20 const t = useT();21 const t = useT();
22+ const [settings] = createResource(() => getSettings());
21 return (23 return (
22 <Show24 <Show
23 when={props.report.courses.length > 0}25 when={props.report.courses.length > 0}
@@ -86,7 +88,7 @@ export function MarksReportView(props: { report: MarksReport }) {
86 {examKindLabel(entry.kind, t)}88 {examKindLabel(entry.kind, t)}
87 </Badge>89 </Badge>
88 </TableCell>90 </TableCell>
89- <TableCell class="mono text-right">{examWeight(entry) ?? "—"}</TableCell>91+ <TableCell class="mono text-right">{examWeight(entry, settings()?.exam_kinds) ?? "—"}</TableCell>
90 <TableCell class="mono text-right font-semibold">{markWithGrade(entry.mark, entry.grade)}</TableCell>92 <TableCell class="mono text-right font-semibold">{markWithGrade(entry.mark, entry.grade)}</TableCell>
91 </TableRow>93 </TableRow>
92 )}94 )}
src/i18n/messages.tsmodified+6 -0
@@ -233,6 +233,8 @@ export type MessageKey =
233 | "exams.maxAttempts"233 | "exams.maxAttempts"
234 | "exams.maxAttemptsRange"234 | "exams.maxAttemptsRange"
235 | "exams.retakes"235 | "exams.retakes"
236+ | "exams.allowRejoin"
237+ | "exams.allowRejoinHelp"
236 | "exams.startTime"238 | "exams.startTime"
237 | "exams.endTime"239 | "exams.endTime"
238 | "exams.scheduleRequired"240 | "exams.scheduleRequired"
@@ -731,6 +733,8 @@ const en: Dict = {
731 "exams.maxAttempts": "Max attempts",733 "exams.maxAttempts": "Max attempts",
732 "exams.maxAttemptsRange": "Max attempts must be 1 or higher",734 "exams.maxAttemptsRange": "Max attempts must be 1 or higher",
733 "exams.retakes": "Retakes",735 "exams.retakes": "Retakes",
736+ "exams.allowRejoin": "Allow rejoin",
737+ "exams.allowRejoinHelp": "If off, a student who leaves the exam room cannot return to answer.",
734 "exams.startTime": "Start time",738 "exams.startTime": "Start time",
735 "exams.endTime": "End time",739 "exams.endTime": "End time",
736 "exams.scheduleRequired": "Scheduled exams need start and end times",740 "exams.scheduleRequired": "Scheduled exams need start and end times",
@@ -1239,6 +1243,8 @@ const tr: Dict = {
1239 "exams.maxAttempts": "Deneme hakkı",1243 "exams.maxAttempts": "Deneme hakkı",
1240 "exams.maxAttemptsRange": "Deneme hakkı 1 veya daha büyük olmalı",1244 "exams.maxAttemptsRange": "Deneme hakkı 1 veya daha büyük olmalı",
1241 "exams.retakes": "Deneme hakkı",1245 "exams.retakes": "Deneme hakkı",
1246+ "exams.allowRejoin": "Yeniden girişe izin ver",
1247+ "exams.allowRejoinHelp": "Kapalıysa sınav odasından çıkan öğrenci cevap vermek için geri giremez.",
1242 "exams.startTime": "Başlangıç saati",1248 "exams.startTime": "Başlangıç saati",
1243 "exams.endTime": "Bitiş saati",1249 "exams.endTime": "Bitiş saati",
1244 "exams.scheduleRequired": "Zamanlı sınav için başlangıç ve bitiş gerekli",1250 "exams.scheduleRequired": "Zamanlı sınav için başlangıç ve bitiş gerekli",
src/lib/exam-weight.tsmodified+17 -3
@@ -1,11 +1,25 @@
1 type ExamWeightSource = {1 type ExamWeightSource = {
2+ kind?: string | null;
2 weight?: number | null;3 weight?: number | null;
3 kind_weight?: number | null;4 kind_weight?: number | null;
4 type_weight?: number | null;5 type_weight?: number | null;
5 exam_type_weight?: number | null;6 exam_type_weight?: number | null;
6 };7 };
7 8
8-export function examWeight(source: ExamWeightSource): number | null {9+type KindWeight = {
9- const value = source.kind_weight ?? source.type_weight ?? source.exam_type_weight ?? source.weight ?? null;10+ name: string;
10- return typeof value === "number" && Number.isFinite(value) ? value : null;11+ weight: number;
12+};
13+
14+export function examWeight(
15+ source: ExamWeightSource,
16+ kinds?: readonly KindWeight[] | null,
17+): number | null {
18+ const direct = source.kind_weight ?? source.type_weight ?? source.exam_type_weight ?? source.weight ?? null;
19+ if (typeof direct === "number" && Number.isFinite(direct)) return direct;
20+ if (source.kind != null && kinds?.length) {
21+ const match = kinds.find((item) => item.name === String(source.kind));
22+ if (match && Number.isFinite(match.weight)) return match.weight;
23+ }
24+ return null;
11 }25 }
src/pages/course-detail-page.tsxmodified+3 -1
@@ -6,6 +6,7 @@ import { getCourseById } from "@/api/getCourseById";
6 import { getCourseEnrollments } from "@/api/getCourseEnrollments";6 import { getCourseEnrollments } from "@/api/getCourseEnrollments";
7 import { getCourseExams } from "@/api/getCourseExams";7 import { getCourseExams } from "@/api/getCourseExams";
8 import { getMyCourses } from "@/api/getMyCourses";8 import { getMyCourses } from "@/api/getMyCourses";
9+import { getSettings } from "@/api/getSettings";
9 import { getTerms } from "@/api/getTerms";10 import { getTerms } from "@/api/getTerms";
10 import { patchCourseById } from "@/api/patchCourseById";11 import { patchCourseById } from "@/api/patchCourseById";
11 import { postCourseEnrollment } from "@/api/postCourseEnrollment";12 import { postCourseEnrollment } from "@/api/postCourseEnrollment";
@@ -66,6 +67,7 @@ function CourseDetailContent() {
66 67
67 const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId));68 const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId));
68 const [terms] = createResource(async () => (await getTerms()).items);69 const [terms] = createResource(async () => (await getTerms()).items);
70+ const [settings] = createResource(() => getSettings());
69 const [exams, { refetch: refetchExams }] = createResource(id, async (courseId) => (await getCourseExams(courseId)).items);71 const [exams, { refetch: refetchExams }] = createResource(id, async (courseId) => (await getCourseExams(courseId)).items);
70 const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");72 const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");
71 const hasCourseManagementRights = () => {73 const hasCourseManagementRights = () => {
@@ -414,7 +416,7 @@ function CourseDetailContent() {
414 <div class="flex flex-wrap items-center gap-2">416 <div class="flex flex-wrap items-center gap-2">
415 <Badge variant="outline" class="rounded-sm capitalize">417 <Badge variant="outline" class="rounded-sm capitalize">
416 {examKindLabel(String(exam.kind), t)}418 {examKindLabel(String(exam.kind), t)}
417- <Show when={examWeight(exam) != null}>419+ <Show when={examWeight(exam, settings()?.exam_kinds) != null}>
418 {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}420 {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}
419 </Show>421 </Show>
420 </Badge>422 </Badge>
src/pages/exam-detail-page.tsxmodified+5 -2
@@ -8,6 +8,7 @@ import { getExamResults } from "@/api/getExamResults";
8 import { getExamStatistics } from "@/api/getExamStatistics";8 import { getExamStatistics } from "@/api/getExamStatistics";
9 import { getCourseEnrollments } from "@/api/getCourseEnrollments";9 import { getCourseEnrollments } from "@/api/getCourseEnrollments";
10 import { getMyCourses } from "@/api/getMyCourses";10 import { getMyCourses } from "@/api/getMyCourses";
11+import { getSettings } from "@/api/getSettings";
11 import { patchExamById } from "@/api/patchExamById";12 import { patchExamById } from "@/api/patchExamById";
12 import { postExamResult } from "@/api/postExamResult";13 import { postExamResult } from "@/api/postExamResult";
13 import { ApiError, formatApiError } from "@/api/client";14 import { ApiError, formatApiError } from "@/api/client";
@@ -68,7 +69,9 @@ function ExamDetailContent() {
68 });69 });
69 70
70 const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId));71 const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId));
72+ const [settings] = createResource(() => getSettings());
71 const isTeacherPlus = createMemo(() => hasMinRole(auth.user()?.role, "teacher"));73 const isTeacherPlus = createMemo(() => hasMinRole(auth.user()?.role, "teacher"));
74+ const isStudent = createMemo(() => auth.user()?.role === "student");
72 75
73 const hasCourseManagementRights = () => {76 const hasCourseManagementRights = () => {
74 const e = exam();77 const e = exam();
@@ -226,7 +229,7 @@ function ExamDetailContent() {
226 {t("common.back")}229 {t("common.back")}
227 </Button>230 </Button>
228 </Link>231 </Link>
229- <Show when={!isTeacherPlus() && !isFinished() && !isUpcoming() && isSittable()}>232+ <Show when={isStudent() && !isFinished() && !isUpcoming() && isSittable()}>
230 <Link to="/exam-room/$id" params={{ id: id() }}>233 <Link to="/exam-room/$id" params={{ id: id() }}>
231 <Button size="sm" class="flex-1 rounded-sm sm:flex-none">234 <Button size="sm" class="flex-1 rounded-sm sm:flex-none">
232 <IconExam class="h-4 w-4" />235 <IconExam class="h-4 w-4" />
@@ -289,7 +292,7 @@ function ExamDetailContent() {
289 </Badge>292 </Badge>
290 <Badge variant="outline" class="rounded-sm capitalize">293 <Badge variant="outline" class="rounded-sm capitalize">
291 {examKindLabel(String(ex().kind), t)}294 {examKindLabel(String(ex().kind), t)}
292- <Show when={examWeight(ex()) != null}>295+ <Show when={examWeight(ex(), settings()?.exam_kinds) != null}>
293 {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}296 {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}
294 </Show>297 </Show>
295 </Badge>298 </Badge>
src/routes/router.tsxmodified+40 -0
@@ -119,6 +119,16 @@ const examDetailRoute = createRoute({
119 const examRoomRoute = createRoute({119 const examRoomRoute = createRoute({
120 getParentRoute: () => rootRoute,120 getParentRoute: () => rootRoute,
121 path: "/exam-room/$id",121 path: "/exam-room/$id",
122+ beforeLoad: async () => {
123+ try {
124+ const user = await getMe();
125+ if (user.role !== "student") throw redirect({ to: "/" });
126+ } catch (err) {
127+ if (err instanceof ApiError && err.status === 401) throw redirect({ to: "/login" });
128+ if (isRedirect(err)) throw err;
129+ throw redirect({ to: "/login" });
130+ }
131+ },
122 component: ExamRoomPage,132 component: ExamRoomPage,
123 });133 });
124 134
@@ -241,18 +251,48 @@ const staffWorkRoute = createRoute({
241 const settingsRoute = createRoute({251 const settingsRoute = createRoute({
242 getParentRoute: () => rootRoute,252 getParentRoute: () => rootRoute,
243 path: "/management/settings",253 path: "/management/settings",
254+ beforeLoad: async () => {
255+ try {
256+ const user = await getMe();
257+ if (!hasMinRole(user.role, "manager")) throw redirect({ to: "/" });
258+ } catch (err) {
259+ if (err instanceof ApiError && err.status === 401) throw redirect({ to: "/login" });
260+ if (isRedirect(err)) throw err;
261+ throw redirect({ to: "/login" });
262+ }
263+ },
244 component: SettingsPage,264 component: SettingsPage,
245 });265 });
246 266
247 const termsRoute = createRoute({267 const termsRoute = createRoute({
248 getParentRoute: () => rootRoute,268 getParentRoute: () => rootRoute,
249 path: "/management/terms",269 path: "/management/terms",
270+ beforeLoad: async () => {
271+ try {
272+ const user = await getMe();
273+ if (!hasMinRole(user.role, "manager")) throw redirect({ to: "/" });
274+ } catch (err) {
275+ if (err instanceof ApiError && err.status === 401) throw redirect({ to: "/login" });
276+ if (isRedirect(err)) throw err;
277+ throw redirect({ to: "/login" });
278+ }
279+ },
250 component: TermsPage,280 component: TermsPage,
251 });281 });
252 282
253 const liveMonitorRoute = createRoute({283 const liveMonitorRoute = createRoute({
254 getParentRoute: () => rootRoute,284 getParentRoute: () => rootRoute,
255 path: "/exams/$id/live",285 path: "/exams/$id/live",
286+ beforeLoad: async () => {
287+ try {
288+ const user = await getMe();
289+ if (!hasMinRole(user.role, "teacher")) throw redirect({ to: "/" });
290+ } catch (err) {
291+ if (err instanceof ApiError && err.status === 401) throw redirect({ to: "/login" });
292+ if (isRedirect(err)) throw err;
293+ throw redirect({ to: "/login" });
294+ }
295+ },
256 component: LiveMonitorPage,296 component: LiveMonitorPage,
257 });297 });
258 298