✨ move student mark lookup into management
Browse files at this commit7a6c14031020a4463500aee38898769a782c164eParent: cb8e4ff- feat
- ✨ move student mark lookup into management
6 changed files +191 -174
- src/components/layout/side-nav.tsx +8 -6
- src/components/marks/marks-report-view.tsx +85 -0
- src/i18n/messages.ts +6 -0
- src/pages/marks-page.tsx +2 -168
- src/pages/student-marks-page.tsx +68 -0
- src/routes/router.tsx +22 -0
src/components/layout/side-nav.tsxmodified+8 -6
| @@ -5,6 +5,7 @@ import { useT } from "@/stores/preferences-context"; | |||
| 5 | import { hasMinRole } from "@/lib/roles"; | 5 | import { hasMinRole } from "@/lib/roles"; |
| 6 | import { cn } from "@/lib/cn"; | 6 | import { cn } from "@/lib/cn"; |
| 7 | import type { MessageKey } from "@/i18n/messages"; | 7 | import type { MessageKey } from "@/i18n/messages"; |
| 8 | +import type { Role } from "@/api/types"; | ||
| 8 | import { | 9 | import { |
| 9 | IconBook, | 10 | IconBook, |
| 10 | IconCalendar, | 11 | IconCalendar, |
| @@ -20,7 +21,7 @@ type NavItem = { | |||
| 20 | to: string; | 21 | to: string; |
| 21 | labelKey: MessageKey; | 22 | labelKey: MessageKey; |
| 22 | Icon: Component<{ class?: string }>; | 23 | Icon: Component<{ class?: string }>; |
| 23 | - adminOnly?: boolean; | 24 | + minRole?: Role; |
| 24 | exact?: boolean; | 25 | exact?: boolean; |
| 25 | }; | 26 | }; |
| 26 | 27 | ||
| @@ -31,7 +32,8 @@ const MAIN_ITEMS: NavItem[] = [ | |||
| 31 | { to: "/marks", labelKey: "nav.marks", Icon: IconChart }, | 32 | { to: "/marks", labelKey: "nav.marks", Icon: IconChart }, |
| 32 | { to: "/notes", labelKey: "nav.notes", Icon: IconNote }, | 33 | { to: "/notes", labelKey: "nav.notes", Icon: IconNote }, |
| 33 | { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, | 34 | { to: "/events", labelKey: "nav.events", Icon: IconCalendar }, |
| 34 | - { to: "/admin/users", labelKey: "nav.users", Icon: IconUsers, adminOnly: true }, | 35 | + { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, |
| 36 | + { to: "/admin/users", labelKey: "nav.users", Icon: IconUsers, minRole: "admin" }, | ||
| 35 | ]; | 37 | ]; |
| 36 | 38 | ||
| 37 | const GUIDE_ITEM: NavItem = { | 39 | const GUIDE_ITEM: NavItem = { |
| @@ -79,7 +81,7 @@ function NavLink(props: { | |||
| 79 | </span> | 81 | </span> |
| 80 | <span | 82 | <span |
| 81 | class={cn( | 83 | class={cn( |
| 82 | - "truncate leading-none", | 84 | + "truncate leading-normal", |
| 83 | props.collapsed ? "hidden" : "block min-w-0 flex-1 text-left", | 85 | props.collapsed ? "hidden" : "block min-w-0 flex-1 text-left", |
| 84 | )} | 86 | )} |
| 85 | > | 87 | > |
| @@ -93,7 +95,7 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) | |||
| 93 | const auth = useAuth(); | 95 | const auth = useAuth(); |
| 94 | 96 | ||
| 95 | const items = createMemo(() => | 97 | const items = createMemo(() => |
| 96 | - MAIN_ITEMS.filter((item) => !item.adminOnly || hasMinRole(auth.user()?.role, "admin")), | 98 | + MAIN_ITEMS.filter((item) => !item.minRole || hasMinRole(auth.user()?.role, item.minRole)), |
| 97 | ); | 99 | ); |
| 98 | 100 | ||
| 99 | const t = useT(); | 101 | const t = useT(); |
| @@ -102,9 +104,9 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) | |||
| 102 | <nav class="flex h-full flex-col" aria-label="Main"> | 104 | <nav class="flex h-full flex-col" aria-label="Main"> |
| 103 | <div class="flex flex-col gap-1 px-2"> | 105 | <div class="flex flex-col gap-1 px-2"> |
| 104 | <For each={items()}> | 106 | <For each={items()}> |
| 105 | - {(item) => ( | 107 | + {(item, index) => ( |
| 106 | <> | 108 | <> |
| 107 | - <Show when={item.adminOnly && !props.collapsed}> | 109 | + <Show when={item.minRole && !items()[index() - 1]?.minRole && !props.collapsed}> |
| 108 | <div class="flex items-center gap-2 px-2 pb-0.5 pt-3"> | 110 | <div class="flex items-center gap-2 px-2 pb-0.5 pt-3"> |
| 109 | <span class="h-px flex-1 bg-border" /> | 111 | <span class="h-px flex-1 bg-border" /> |
| 110 | <span lang="en" class="text-[10px] font-semibold uppercase tracking-[0.15em] text-muted-foreground/60"> | 112 | <span lang="en" class="text-[10px] font-semibold uppercase tracking-[0.15em] text-muted-foreground/60"> |
src/components/marks/marks-report-view.tsxadded+85 -0
| @@ -0,0 +1,85 @@ | |||
| 1 | +import { For, Show } from "solid-js"; | ||
| 2 | +import { Link } from "@tanstack/solid-router"; | ||
| 3 | +import type { MarksReport } from "@/api/types"; | ||
| 4 | +import { Badge } from "@/components/ui/badge"; | ||
| 5 | +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; | ||
| 6 | +import { examKindLabel } from "@/lib/exam-labels"; | ||
| 7 | +import { useT } from "@/stores/preferences-context"; | ||
| 8 | + | ||
| 9 | +const round = (n: number) => (Math.round(n * 100) / 100).toString(); | ||
| 10 | + | ||
| 11 | +export function MarksReportView(props: { report: MarksReport }) { | ||
| 12 | + const t = useT(); | ||
| 13 | + return ( | ||
| 14 | + <Show | ||
| 15 | + when={props.report.courses.length > 0} | ||
| 16 | + fallback={ | ||
| 17 | + <div class="rounded-md border border-dashed px-6 py-12 text-center text-sm text-muted-foreground"> | ||
| 18 | + {t("marks.empty")} | ||
| 19 | + </div> | ||
| 20 | + } | ||
| 21 | + > | ||
| 22 | + <div class="space-y-4"> | ||
| 23 | + <div class="surface-card flex items-center justify-between gap-3 p-5"> | ||
| 24 | + <span class="text-sm text-muted-foreground">{t("marks.overall")}</span> | ||
| 25 | + <p class="font-display text-3xl font-semibold tabular-nums"> | ||
| 26 | + {props.report.overall_average == null ? "—" : round(props.report.overall_average)} | ||
| 27 | + <Show when={props.report.overall_average != null}> | ||
| 28 | + <span class="text-base font-medium text-muted-foreground"> / 100</span> | ||
| 29 | + </Show> | ||
| 30 | + </p> | ||
| 31 | + </div> | ||
| 32 | + | ||
| 33 | + <For each={props.report.courses}> | ||
| 34 | + {(block) => ( | ||
| 35 | + <article class="surface-card space-y-3 p-5"> | ||
| 36 | + <header class="flex flex-wrap items-center justify-between gap-2"> | ||
| 37 | + <h3 class="font-display text-lg font-semibold"> | ||
| 38 | + <Link to="/courses/$id" params={{ id: block.course.id }} class="hover:text-primary hover:underline"> | ||
| 39 | + {block.course.title} | ||
| 40 | + </Link> | ||
| 41 | + </h3> | ||
| 42 | + <Badge variant="secondary" title={t("marks.courseAvg")}> | ||
| 43 | + {block.average == null ? "—" : round(block.average)} | ||
| 44 | + </Badge> | ||
| 45 | + </header> | ||
| 46 | + | ||
| 47 | + <Show when={block.results.length > 0} fallback={<p class="text-sm text-muted-foreground">{t("exams.noResults")}</p>}> | ||
| 48 | + <Table> | ||
| 49 | + <TableHeader> | ||
| 50 | + <TableRow> | ||
| 51 | + <TableHead>{t("marks.exam")}</TableHead> | ||
| 52 | + <TableHead>{t("exams.kind")}</TableHead> | ||
| 53 | + <TableHead>{t("marks.weight")}</TableHead> | ||
| 54 | + <TableHead>{t("marks.mark")}</TableHead> | ||
| 55 | + </TableRow> | ||
| 56 | + </TableHeader> | ||
| 57 | + <TableBody> | ||
| 58 | + <For each={block.results}> | ||
| 59 | + {(entry) => ( | ||
| 60 | + <TableRow> | ||
| 61 | + <TableCell> | ||
| 62 | + <Link to="/exams/$id" params={{ id: entry.exam }} class="font-medium hover:underline"> | ||
| 63 | + {entry.title} | ||
| 64 | + </Link> | ||
| 65 | + </TableCell> | ||
| 66 | + <TableCell> | ||
| 67 | + <Badge variant="outline" class="capitalize"> | ||
| 68 | + {examKindLabel(entry.kind, t)} | ||
| 69 | + </Badge> | ||
| 70 | + </TableCell> | ||
| 71 | + <TableCell>{entry.weight}</TableCell> | ||
| 72 | + <TableCell class="font-semibold tabular-nums">{entry.mark}</TableCell> | ||
| 73 | + </TableRow> | ||
| 74 | + )} | ||
| 75 | + </For> | ||
| 76 | + </TableBody> | ||
| 77 | + </Table> | ||
| 78 | + </Show> | ||
| 79 | + </article> | ||
| 80 | + )} | ||
| 81 | + </For> | ||
| 82 | + </div> | ||
| 83 | + </Show> | ||
| 84 | + ); | ||
| 85 | +} | ||
src/i18n/messages.tsmodified+6 -0
| @@ -10,6 +10,7 @@ export type MessageKey = | |||
| 10 | | "nav.courses" | 10 | | "nav.courses" |
| 11 | | "nav.marks" | 11 | | "nav.marks" |
| 12 | | "nav.users" | 12 | | "nav.users" |
| 13 | + | "nav.studentMarks" | ||
| 13 | | "nav.guide" | 14 | | "nav.guide" |
| 14 | | "nav.logout" | 15 | | "nav.logout" |
| 15 | | "nav.admin" | 16 | | "nav.admin" |
| @@ -295,6 +296,7 @@ export type MessageKey = | |||
| 295 | | "marks.courseAvg" | 296 | | "marks.courseAvg" |
| 296 | | "marks.empty" | 297 | | "marks.empty" |
| 297 | | "marks.lookup" | 298 | | "marks.lookup" |
| 299 | + | "marks.userIdentity" | ||
| 298 | | "marks.show" | 300 | | "marks.show" |
| 299 | | "marks.forUser" | 301 | | "marks.forUser" |
| 300 | | "marks.exam" | 302 | | "marks.exam" |
| @@ -361,6 +363,7 @@ const en: Dict = { | |||
| 361 | "nav.courses": "Courses", | 363 | "nav.courses": "Courses", |
| 362 | "nav.marks": "Report card", | 364 | "nav.marks": "Report card", |
| 363 | "nav.users": "Users", | 365 | "nav.users": "Users", |
| 366 | + "nav.studentMarks": "Student marks", | ||
| 364 | "nav.guide": "Guide", | 367 | "nav.guide": "Guide", |
| 365 | "nav.admin": "Admin", | 368 | "nav.admin": "Admin", |
| 366 | "nav.logout": "Log out", | 369 | "nav.logout": "Log out", |
| @@ -660,6 +663,7 @@ const en: Dict = { | |||
| 660 | "marks.courseAvg": "Course average", | 663 | "marks.courseAvg": "Course average", |
| 661 | "marks.empty": "Not enrolled in any course yet.", | 664 | "marks.empty": "Not enrolled in any course yet.", |
| 662 | "marks.lookup": "Look up a student", | 665 | "marks.lookup": "Look up a student", |
| 666 | + "marks.userIdentity": "User identity", | ||
| 663 | "marks.show": "Show marks", | 667 | "marks.show": "Show marks", |
| 664 | "marks.forUser": "Report for {user}", | 668 | "marks.forUser": "Report for {user}", |
| 665 | "marks.exam": "Exam", | 669 | "marks.exam": "Exam", |
| @@ -725,6 +729,7 @@ const tr: Dict = { | |||
| 725 | "nav.courses": "Dersler", | 729 | "nav.courses": "Dersler", |
| 726 | "nav.marks": "Karnem", | 730 | "nav.marks": "Karnem", |
| 727 | "nav.users": "Kullanıcılar", | 731 | "nav.users": "Kullanıcılar", |
| 732 | + "nav.studentMarks": "Öğrenci notları", | ||
| 728 | "nav.guide": "Rehber", | 733 | "nav.guide": "Rehber", |
| 729 | "nav.admin": "Yönetim", | 734 | "nav.admin": "Yönetim", |
| 730 | "nav.logout": "Çıkış yap", | 735 | "nav.logout": "Çıkış yap", |
| @@ -1024,6 +1029,7 @@ const tr: Dict = { | |||
| 1024 | "marks.courseAvg": "Ders ortalaması", | 1029 | "marks.courseAvg": "Ders ortalaması", |
| 1025 | "marks.empty": "Henüz hiçbir derse kayıtlı değilsin.", | 1030 | "marks.empty": "Henüz hiçbir derse kayıtlı değilsin.", |
| 1026 | "marks.lookup": "Öğrenci ara", | 1031 | "marks.lookup": "Öğrenci ara", |
| 1032 | + "marks.userIdentity": "Kullanıcı Kimliği", | ||
| 1027 | "marks.show": "Karnesini göster", | 1033 | "marks.show": "Karnesini göster", |
| 1028 | "marks.forUser": "{user} karnesi", | 1034 | "marks.forUser": "{user} karnesi", |
| 1029 | "marks.exam": "Sınav", | 1035 | "marks.exam": "Sınav", |
src/pages/marks-page.tsxmodified+2 -168
| @@ -1,31 +1,12 @@ | |||
| 1 | -import { For, Show, Suspense, createResource, createSignal } from "solid-js"; | 1 | +import { Show, Suspense, createResource } from "solid-js"; |
| 2 | -import { Link } from "@tanstack/solid-router"; | ||
| 3 | import { getMyMarks } from "@/api/getMyMarks"; | 2 | import { getMyMarks } from "@/api/getMyMarks"; |
| 4 | -import { getUserMarks } from "@/api/getUserMarks"; | ||
| 5 | import { formatApiError } from "@/api/client"; | 3 | import { formatApiError } from "@/api/client"; |
| 6 | import { Alert } from "@/components/ui/alert"; | 4 | import { Alert } from "@/components/ui/alert"; |
| 7 | -import type { MarksReport } from "@/api/types"; | 5 | +import { MarksReportView } from "@/components/marks/marks-report-view"; |
| 8 | import { RouteGuard } from "@/components/layout/route-guard"; | 6 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 9 | import { PageHeader } from "@/components/layout/page-header"; | 7 | import { PageHeader } from "@/components/layout/page-header"; |
| 10 | -import { Badge } from "@/components/ui/badge"; | ||
| 11 | -import { Button } from "@/components/ui/button"; | ||
| 12 | -import { Input } from "@/components/ui/input"; | ||
| 13 | -import { Label } from "@/components/ui/label"; | ||
| 14 | import { PageSpinner } from "@/components/ui/page-spinner"; | 8 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 15 | -import { | ||
| 16 | - Table, | ||
| 17 | - TableBody, | ||
| 18 | - TableCell, | ||
| 19 | - TableHead, | ||
| 20 | - TableHeader, | ||
| 21 | - TableRow, | ||
| 22 | -} from "@/components/ui/table"; | ||
| 23 | -import { useAuth } from "@/stores/auth-context"; | ||
| 24 | import { useT } from "@/stores/preferences-context"; | 9 | import { useT } from "@/stores/preferences-context"; |
| 25 | -import { examKindLabel } from "@/lib/exam-labels"; | ||
| 26 | -import { hasMinRole } from "@/lib/roles"; | ||
| 27 | - | ||
| 28 | -const round = (n: number) => (Math.round(n * 100) / 100).toString(); | ||
| 29 | 10 | ||
| 30 | export default function MarksPage() { | 11 | export default function MarksPage() { |
| 31 | return ( | 12 | return ( |
| @@ -36,10 +17,8 @@ export default function MarksPage() { | |||
| 36 | } | 17 | } |
| 37 | 18 | ||
| 38 | function MarksContent() { | 19 | function MarksContent() { |
| 39 | - const auth = useAuth(); | ||
| 40 | const t = useT(); | 20 | const t = useT(); |
| 41 | const [mine] = createResource(() => getMyMarks()); | 21 | const [mine] = createResource(() => getMyMarks()); |
| 42 | - const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher"); | ||
| 43 | 22 | ||
| 44 | return ( | 23 | return ( |
| 45 | <div class="space-y-6"> | 24 | <div class="space-y-6"> |
| @@ -59,151 +38,6 @@ function MarksContent() { | |||
| 59 | </Show> | 38 | </Show> |
| 60 | </Suspense> | 39 | </Suspense> |
| 61 | 40 | ||
| 62 | - <Show when={isTeacherPlus()}> | ||
| 63 | - <TeacherLookup /> | ||
| 64 | - </Show> | ||
| 65 | </div> | 41 | </div> |
| 66 | ); | 42 | ); |
| 67 | } | 43 | } |
| 68 | - | ||
| 69 | -function MarksReportView(props: { report: MarksReport }) { | ||
| 70 | - const t = useT(); | ||
| 71 | - return ( | ||
| 72 | - <Show | ||
| 73 | - when={props.report.courses.length > 0} | ||
| 74 | - fallback={ | ||
| 75 | - <div class="rounded-md border border-dashed px-6 py-12 text-center text-sm text-muted-foreground"> | ||
| 76 | - {t("marks.empty")} | ||
| 77 | - </div> | ||
| 78 | - } | ||
| 79 | - > | ||
| 80 | - <div class="space-y-4"> | ||
| 81 | - <div class="surface-card flex items-center justify-between gap-3 p-5"> | ||
| 82 | - <span class="text-sm text-muted-foreground">{t("marks.overall")}</span> | ||
| 83 | - <p class="font-display text-3xl font-semibold tabular-nums"> | ||
| 84 | - {props.report.overall_average == null ? "—" : round(props.report.overall_average)} | ||
| 85 | - <Show when={props.report.overall_average != null}> | ||
| 86 | - <span class="text-base font-medium text-muted-foreground"> / 100</span> | ||
| 87 | - </Show> | ||
| 88 | - </p> | ||
| 89 | - </div> | ||
| 90 | - | ||
| 91 | - <For each={props.report.courses}> | ||
| 92 | - {(block) => ( | ||
| 93 | - <article class="surface-card space-y-3 p-5"> | ||
| 94 | - <header class="flex flex-wrap items-center justify-between gap-2"> | ||
| 95 | - <h3 class="font-display text-lg font-semibold"> | ||
| 96 | - <Link | ||
| 97 | - to="/courses/$id" | ||
| 98 | - params={{ id: block.course.id }} | ||
| 99 | - class="hover:text-primary hover:underline" | ||
| 100 | - > | ||
| 101 | - {block.course.title} | ||
| 102 | - </Link> | ||
| 103 | - </h3> | ||
| 104 | - <Badge variant="secondary" title={t("marks.courseAvg")}> | ||
| 105 | - {block.average == null ? "—" : round(block.average)} | ||
| 106 | - </Badge> | ||
| 107 | - </header> | ||
| 108 | - | ||
| 109 | - <Show | ||
| 110 | - when={block.results.length > 0} | ||
| 111 | - fallback={ | ||
| 112 | - <p class="text-sm text-muted-foreground">{t("exams.noResults")}</p> | ||
| 113 | - } | ||
| 114 | - > | ||
| 115 | - <Table> | ||
| 116 | - <TableHeader> | ||
| 117 | - <TableRow> | ||
| 118 | - <TableHead>{t("marks.exam")}</TableHead> | ||
| 119 | - <TableHead>{t("exams.kind")}</TableHead> | ||
| 120 | - <TableHead>{t("marks.weight")}</TableHead> | ||
| 121 | - <TableHead>{t("marks.mark")}</TableHead> | ||
| 122 | - </TableRow> | ||
| 123 | - </TableHeader> | ||
| 124 | - <TableBody> | ||
| 125 | - <For each={block.results}> | ||
| 126 | - {(entry) => ( | ||
| 127 | - <TableRow> | ||
| 128 | - <TableCell> | ||
| 129 | - <Link | ||
| 130 | - to="/exams/$id" | ||
| 131 | - params={{ id: entry.exam }} | ||
| 132 | - class="font-medium hover:underline" | ||
| 133 | - > | ||
| 134 | - {entry.title} | ||
| 135 | - </Link> | ||
| 136 | - </TableCell> | ||
| 137 | - <TableCell> | ||
| 138 | - <Badge variant="outline" class="capitalize"> | ||
| 139 | - {examKindLabel(entry.kind, t)} | ||
| 140 | - </Badge> | ||
| 141 | - </TableCell> | ||
| 142 | - <TableCell>{entry.weight}</TableCell> | ||
| 143 | - <TableCell class="font-semibold tabular-nums">{entry.mark}</TableCell> | ||
| 144 | - </TableRow> | ||
| 145 | - )} | ||
| 146 | - </For> | ||
| 147 | - </TableBody> | ||
| 148 | - </Table> | ||
| 149 | - </Show> | ||
| 150 | - </article> | ||
| 151 | - )} | ||
| 152 | - </For> | ||
| 153 | - </div> | ||
| 154 | - </Show> | ||
| 155 | - ); | ||
| 156 | -} | ||
| 157 | - | ||
| 158 | -function TeacherLookup() { | ||
| 159 | - const t = useT(); | ||
| 160 | - const [userId, setUserId] = createSignal(""); | ||
| 161 | - const [lookupId, setLookupId] = createSignal<string | null>(null); | ||
| 162 | - const [error, setError] = createSignal(""); | ||
| 163 | - const [report] = createResource(lookupId, async (id) => { | ||
| 164 | - if (!id) return null; | ||
| 165 | - return getUserMarks(id); | ||
| 166 | - }); | ||
| 167 | - | ||
| 168 | - return ( | ||
| 169 | - <section class="surface-card space-y-4 p-5"> | ||
| 170 | - <h2 class="font-display text-lg font-semibold">{t("marks.lookup")}</h2> | ||
| 171 | - <form | ||
| 172 | - class="flex flex-col gap-2 sm:flex-row sm:items-end" | ||
| 173 | - onSubmit={(e) => { | ||
| 174 | - e.preventDefault(); | ||
| 175 | - setError(""); | ||
| 176 | - const id = userId().trim(); | ||
| 177 | - if (!id) return; | ||
| 178 | - setLookupId(id); | ||
| 179 | - }} | ||
| 180 | - > | ||
| 181 | - <div class="min-w-0 flex-1 space-y-1.5"> | ||
| 182 | - <Label for="marks-user">{t("events.userId")}</Label> | ||
| 183 | - <Input | ||
| 184 | - id="marks-user" | ||
| 185 | - value={userId()} | ||
| 186 | - onInput={(e) => setUserId(e.currentTarget.value)} | ||
| 187 | - /> | ||
| 188 | - </div> | ||
| 189 | - <Button type="submit">{t("marks.show")}</Button> | ||
| 190 | - </form> | ||
| 191 | - {error() && <p class="text-sm text-destructive">{error()}</p>} | ||
| 192 | - <Show when={report.error}> | ||
| 193 | - <p class="text-sm text-destructive">{formatApiError(report.error)}</p> | ||
| 194 | - </Show> | ||
| 195 | - <Suspense fallback={<PageSpinner />}> | ||
| 196 | - <Show when={report()}> | ||
| 197 | - {(r) => ( | ||
| 198 | - <div class="space-y-3 border-t pt-4"> | ||
| 199 | - <p class="text-sm text-muted-foreground"> | ||
| 200 | - {t("marks.forUser", { user: lookupId() ?? "" })} | ||
| 201 | - </p> | ||
| 202 | - <MarksReportView report={r()} /> | ||
| 203 | - </div> | ||
| 204 | - )} | ||
| 205 | - </Show> | ||
| 206 | - </Suspense> | ||
| 207 | - </section> | ||
| 208 | - ); | ||
| 209 | -} | ||
src/pages/student-marks-page.tsxadded+68 -0
| @@ -0,0 +1,68 @@ | |||
| 1 | +import { Show, Suspense, createResource, createSignal } from "solid-js"; | ||
| 2 | +import { getUserMarks } from "@/api/getUserMarks"; | ||
| 3 | +import { formatApiError } from "@/api/client"; | ||
| 4 | +import { MarksReportView } from "@/components/marks/marks-report-view"; | ||
| 5 | +import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 6 | +import { PageHeader } from "@/components/layout/page-header"; | ||
| 7 | +import { Button } from "@/components/ui/button"; | ||
| 8 | +import { Input } from "@/components/ui/input"; | ||
| 9 | +import { Label } from "@/components/ui/label"; | ||
| 10 | +import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 11 | +import { useT } from "@/stores/preferences-context"; | ||
| 12 | + | ||
| 13 | +export default function StudentMarksPage() { | ||
| 14 | + return ( | ||
| 15 | + <RouteGuard minRole="teacher"> | ||
| 16 | + <StudentMarksContent /> | ||
| 17 | + </RouteGuard> | ||
| 18 | + ); | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +function StudentMarksContent() { | ||
| 22 | + const t = useT(); | ||
| 23 | + const [userId, setUserId] = createSignal(""); | ||
| 24 | + const [lookupId, setLookupId] = createSignal<string | null>(null); | ||
| 25 | + const [report] = createResource(lookupId, async (id) => { | ||
| 26 | + if (!id) return null; | ||
| 27 | + return getUserMarks(id); | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + return ( | ||
| 31 | + <div class="space-y-6"> | ||
| 32 | + <PageHeader accent="violet" eyebrow={t("nav.admin")} title={t("nav.studentMarks")} description={t("marks.lookup")} /> | ||
| 33 | + | ||
| 34 | + <section class="surface-card space-y-4 p-5"> | ||
| 35 | + <form | ||
| 36 | + class="flex flex-col gap-2 sm:flex-row sm:items-end" | ||
| 37 | + onSubmit={(e) => { | ||
| 38 | + e.preventDefault(); | ||
| 39 | + const id = userId().trim(); | ||
| 40 | + if (!id) return; | ||
| 41 | + setLookupId(id); | ||
| 42 | + }} | ||
| 43 | + > | ||
| 44 | + <div class="min-w-0 flex-1 space-y-1.5"> | ||
| 45 | + <Label for="student-marks-user">{t("marks.userIdentity")}</Label> | ||
| 46 | + <Input id="student-marks-user" class="h-10" value={userId()} onInput={(e) => setUserId(e.currentTarget.value)} /> | ||
| 47 | + </div> | ||
| 48 | + <Button type="submit" class="h-10">{t("marks.show")}</Button> | ||
| 49 | + </form> | ||
| 50 | + | ||
| 51 | + <Show when={report.error}> | ||
| 52 | + <p class="text-sm text-destructive">{formatApiError(report.error)}</p> | ||
| 53 | + </Show> | ||
| 54 | + </section> | ||
| 55 | + | ||
| 56 | + <Suspense fallback={<PageSpinner />}> | ||
| 57 | + <Show when={report()}> | ||
| 58 | + {(r) => ( | ||
| 59 | + <div class="space-y-3"> | ||
| 60 | + <p class="text-sm text-muted-foreground">{t("marks.forUser", { user: lookupId() ?? "" })}</p> | ||
| 61 | + <MarksReportView report={r()} /> | ||
| 62 | + </div> | ||
| 63 | + )} | ||
| 64 | + </Show> | ||
| 65 | + </Suspense> | ||
| 66 | + </div> | ||
| 67 | + ); | ||
| 68 | +} | ||
src/routes/router.tsxmodified+22 -0
| @@ -36,6 +36,7 @@ const ExamRoomPage = lazyRoute(() => import("@/pages/exam-room-page")); | |||
| 36 | const CoursesPage = lazyRoute(() => import("@/pages/courses-page")); | 36 | const CoursesPage = lazyRoute(() => import("@/pages/courses-page")); |
| 37 | const CourseDetailPage = lazyRoute(() => import("@/pages/course-detail-page")); | 37 | const CourseDetailPage = lazyRoute(() => import("@/pages/course-detail-page")); |
| 38 | const MarksPage = lazyRoute(() => import("@/pages/marks-page")); | 38 | const MarksPage = lazyRoute(() => import("@/pages/marks-page")); |
| 39 | +const StudentMarksPage = lazyRoute(() => import("@/pages/student-marks-page")); | ||
| 39 | const ProfilePage = lazyRoute(() => import("@/pages/profile-page")); | 40 | const ProfilePage = lazyRoute(() => import("@/pages/profile-page")); |
| 40 | const LiveMonitorPage = lazyRoute(() => import("@/pages/live-monitor-page")); | 41 | const LiveMonitorPage = lazyRoute(() => import("@/pages/live-monitor-page")); |
| 41 | const AdminUsersPage = lazyRoute(() => import("@/pages/admin-users-page")); | 42 | const AdminUsersPage = lazyRoute(() => import("@/pages/admin-users-page")); |
| @@ -133,6 +134,26 @@ const marksRoute = createRoute({ | |||
| 133 | component: MarksPage, | 134 | component: MarksPage, |
| 134 | }); | 135 | }); |
| 135 | 136 | ||
| 137 | +const studentMarksRoute = createRoute({ | ||
| 138 | + getParentRoute: () => rootRoute, | ||
| 139 | + path: "/management/student-marks", | ||
| 140 | + beforeLoad: async () => { | ||
| 141 | + try { | ||
| 142 | + const user = await getMe(); | ||
| 143 | + if (!hasMinRole(user.role, "teacher")) { | ||
| 144 | + throw redirect({ to: "/" }); | ||
| 145 | + } | ||
| 146 | + } catch (err) { | ||
| 147 | + if (err instanceof ApiError && err.status === 401) { | ||
| 148 | + throw redirect({ to: "/login" }); | ||
| 149 | + } | ||
| 150 | + if (isRedirect(err)) throw err; | ||
| 151 | + throw redirect({ to: "/login" }); | ||
| 152 | + } | ||
| 153 | + }, | ||
| 154 | + component: StudentMarksPage, | ||
| 155 | +}); | ||
| 156 | + | ||
| 136 | const liveMonitorRoute = createRoute({ | 157 | const liveMonitorRoute = createRoute({ |
| 137 | getParentRoute: () => rootRoute, | 158 | getParentRoute: () => rootRoute, |
| 138 | path: "/exams/$id/live", | 159 | path: "/exams/$id/live", |
| @@ -185,6 +206,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 185 | coursesRoute, | 206 | coursesRoute, |
| 186 | courseDetailRoute, | 207 | courseDetailRoute, |
| 187 | marksRoute, | 208 | marksRoute, |
| 209 | + studentMarksRoute, | ||
| 188 | profileRoute, | 210 | profileRoute, |
| 189 | adminUsersRoute, | 211 | adminUsersRoute, |
| 190 | guideRoute, | 212 | guideRoute, |