diff --git a/README.md b/README.md index d6ea42c..f5b1875 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,13 @@ Dashboard and table summaries must use the same role scope as the related page. | `/exams/:id/live` | Teacher+ | Live monitor / final state roster with pagination & sorting | | `/exam-room/:id` | Student+ | WebSocket-based real-time exam room (auto-save, timer, local expiry close) | | `/courses` | Student+ | Course table with search and term filters; create/edit flows for teacher+ | -| `/courses/:id` | Student+ | Course detail, exams, roster, lesson sessions, and roll call tools | +| `/courses/:id` | Student+ | Course detail, subjects, exams, roster, lesson sessions, and roll call tools | | `/guide` | Authenticated | App usage guide | | `/admin/users` | Admin | User management | ## Features -- **Exam lifecycle**: create (scheduled/async/unscheduled), automatic async duration from start/end, questions (multiple-choice / text), real-time WebSocket exam room, auto-close on expiry, teacher grading +- **Exam lifecycle**: create (scheduled/async/unscheduled), automatic async duration from start/end, subject-tagged questions (multiple-choice / text), real-time WebSocket exam room, auto-close on expiry, teacher grading - **Live monitor**: 2-second polling during active exams, static final state view after exam ends, pagination (10/page), column sorting - **Statistics**: graded count, average/min/max marks on exam detail - **Answer sheet**: teacher review of student answers with correct/wrong highlighting @@ -77,6 +77,7 @@ Dashboard and table summaries must use the same role scope as the related page. - **Dense tables**: toolbar search/filter, subtle column separators, narrow centered three-dot row actions - **Side panels**: quick create/edit workflows without losing list context - **Course sessions**: right-panel session creation and paginated roll call panels +- **Course subjects**: course/study curriculum topics managed on the detail page; every exam question must pick one - **Schedule validation**: event, exam, and lesson-session forms use `GET /time` for server-clock-aware past-date warnings before submit - **Notebook**: paper-style note cards; create in `SidePanel`; read in reader panel with attachments; three-dot card actions for edit/delete - **Note files**: per-note upload/list/download/delete via native `FormData`; school `max_file_bytes` from settings diff --git a/docs/frontend-next-steps.md b/docs/frontend-next-steps.md index 4467dcd..5430181 100644 --- a/docs/frontend-next-steps.md +++ b/docs/frontend-next-steps.md @@ -9,7 +9,7 @@ Active backend-refresh work is tracked in ## Completed State -- Backend alignment is complete for settings, terms, course sessions, attendance reports, work logs, exam attempts, and grade bands. +- Backend alignment is complete for settings, terms, course subjects, course sessions, attendance reports, work logs, exam attempts, and grade bands. - Shared UI primitives cover dense tables, data toolbars, row action menus, side panels, confirm dialogs, date picking, and animated disclosures. - Dashboard is a monochrome, role-aware, read-only status board: workspace portal cards (`Title | count` on desktop) + needs-attention / upcoming lists. No create CTAs, no vanity charts, no duplicate KPI strip. Admin sees global course/exam scope; other roles use own/enrolled/related scope where the backend supports it. - Table and card actions use narrow centered three-dot menus through `TableRowActions`. diff --git a/docs/role-scope-matrix.md b/docs/role-scope-matrix.md index 8f40b19..c32f01e 100644 --- a/docs/role-scope-matrix.md +++ b/docs/role-scope-matrix.md @@ -66,6 +66,7 @@ | Enroll students / unenroll any enrollment | ❌ | ✅ (course creator) | ✅ | ✅ | | Edit / delete courses | ❌ | ✅ (course creator) | ✅ | ✅ | | Create / edit / delete course sessions | ❌ | ✅ (course manager) | ✅ | ✅ | +| Create / edit / delete course subjects | ❌ | ✅ (course manager) | ✅ | ✅ | | Take session roll call | ❌ | ✅ (session teacher or course manager) | ✅ | ✅ | | Mark session teacher's own presence | ❌ | ❌ | ✅ | ✅ | | Create exams | ❌ | ✅ (course manager) | ✅ | ✅ | @@ -87,7 +88,7 @@ ## Architectural Rules - **Hierarchical roles:** `student < teacher < manager < admin`. A higher role satisfies any lower requirement. The only exception is `exactRole` page guards (below), which are presentation filters — backend authorization never breaks the hierarchy. -- **Course management rights:** course creator or `manager+`. Required for enrollment, session CRUD, exam CRUD, grading, roster read. +- **Course management rights:** course creator or `manager+`. Required for enrollment, subject/session CRUD, exam CRUD, grading, roster read. - **Ownership edits:** event/note edit/delete respects creator id. Manager+ overrides creator gate. - **Student-only actions (BE-enforced):** enrolling, sitting exams (including the exam-room WebSocket — the role is re-checked on every answer save, so a mid-exam promotion closes the sheet), being graded, and being marked on lesson roll call all require the target's live role to be `student`. Unenroll, result removal, and roll-call removal stay role-free on the target, so stale rows left behind by a promotion remain removable. - **Student-only pages (FE-only):** `/marks` (personal report card) is hidden from staff by `RouteGuard exactRole="student"` + router `beforeLoad` redirect as presentation, not security — the backend serves `GET /marks/me` and `GET /exams/{id}/result` to any authenticated user; a staff member's report is just permanently empty (staff cannot be enrolled or graded). Do not "fix" the backend to 403 these: a student promoted to staff must keep read access to their own history. diff --git a/src/api/deleteSubjectById.ts b/src/api/deleteSubjectById.ts new file mode 100644 index 0000000..417aa34 --- /dev/null +++ b/src/api/deleteSubjectById.ts @@ -0,0 +1,5 @@ +import { client } from "./client"; + +export function deleteSubjectById(subjectId: string): Promise { + return client(`/subjects/${subjectId}`, { method: "DELETE" }); +} diff --git a/src/api/getCourseSubjects.ts b/src/api/getCourseSubjects.ts new file mode 100644 index 0000000..2d7f336 --- /dev/null +++ b/src/api/getCourseSubjects.ts @@ -0,0 +1,12 @@ +import { client } from "./client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "./page"; +import type { Subject } from "./types"; + +export async function getCourseSubjects( + courseId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client(`/courses/${courseId}/subjects${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/patchExamQuestionById.ts b/src/api/patchExamQuestionById.ts index 263e123..3d770e3 100644 --- a/src/api/patchExamQuestionById.ts +++ b/src/api/patchExamQuestionById.ts @@ -2,6 +2,7 @@ import { client } from "./client"; import type { ExamQuestion, QuestionKind } from "./types"; export type PatchExamQuestionBody = { + subject_id?: string; text?: string | null; kind?: QuestionKind | null; points?: number | null; diff --git a/src/api/patchSubjectById.ts b/src/api/patchSubjectById.ts new file mode 100644 index 0000000..6070d80 --- /dev/null +++ b/src/api/patchSubjectById.ts @@ -0,0 +1,11 @@ +import { client } from "./client"; +import type { Subject } from "./types"; + +export type PatchSubjectBody = { + name?: string; + description?: string; +}; + +export function patchSubjectById(subjectId: string, body: PatchSubjectBody): Promise { + return client(`/subjects/${subjectId}`, { method: "PATCH", body }); +} diff --git a/src/api/postCourseSubject.ts b/src/api/postCourseSubject.ts new file mode 100644 index 0000000..228db34 --- /dev/null +++ b/src/api/postCourseSubject.ts @@ -0,0 +1,11 @@ +import { client } from "./client"; +import type { Subject } from "./types"; + +export type PostCourseSubjectBody = { + name: string; + description?: string | null; +}; + +export function postCourseSubject(courseId: string, body: PostCourseSubjectBody): Promise { + return client(`/courses/${courseId}/subjects`, { method: "POST", body }); +} diff --git a/src/api/postExamQuestion.ts b/src/api/postExamQuestion.ts index 9404eef..ab00ab3 100644 --- a/src/api/postExamQuestion.ts +++ b/src/api/postExamQuestion.ts @@ -2,6 +2,7 @@ import { client } from "./client"; import type { ExamQuestion, QuestionKind } from "./types"; export type ExamQuestionBody = { + subject_id: string; text: string; kind: QuestionKind; points: number; diff --git a/src/api/types.ts b/src/api/types.ts index ffd4cd3..4be2643 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -148,6 +148,7 @@ export type ExamResult = { export type ExamQuestion = { id: string; exam: string; + subject: string; text: string; kind: QuestionKind; points: number; @@ -181,6 +182,7 @@ export type AttemptAnswer = { export type AttemptQuestion = { id: string; exam: string; + subject: string; text: string; kind: QuestionKind; points: number; @@ -188,6 +190,13 @@ export type AttemptQuestion = { answer: AttemptAnswer | null; }; +export type Subject = { + id: string; + course: string; + name: string; + description: string; +}; + export type MarkEntry = { exam: string; title: string; diff --git a/src/components/courses/course-subjects-panel.tsx b/src/components/courses/course-subjects-panel.tsx new file mode 100644 index 0000000..74cf539 --- /dev/null +++ b/src/components/courses/course-subjects-panel.tsx @@ -0,0 +1,179 @@ +import { For, Show, Suspense, createEffect, createResource, createSignal } from "solid-js"; +import { deleteSubjectById } from "@/api/deleteSubjectById"; +import { getCourseSubjects } from "@/api/getCourseSubjects"; +import { patchSubjectById } from "@/api/patchSubjectById"; +import { postCourseSubject } from "@/api/postCourseSubject"; +import { formatApiError } from "@/api/client"; +import type { Subject } from "@/api/types"; +import { Alert } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { EmptyState } from "@/components/ui/empty-state"; +import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { PageSpinner } from "@/components/ui/page-spinner"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { Textarea } from "@/components/ui/textarea"; +import { createFlash } from "@/lib/flash"; +import { useT } from "@/stores/preferences-context"; + +export function CourseSubjectsPanel(props: { courseId: string; canManage: boolean; active: boolean }) { + const t = useT(); + const [subjects, { refetch }] = createResource( + () => (props.active ? props.courseId : null), + async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), + ); + const [panelOpen, setPanelOpen] = createSignal(false); + const [editing, setEditing] = createSignal(null); + const [removeSubject, setRemoveSubject] = createSignal(null); + const [name, setName] = createSignal(""); + const [description, setDescription] = createSignal(""); + const [error, setError] = createSignal(""); + const [pending, setPending] = createSignal(false); + const [flash, setFlash] = createFlash(); + + createEffect(() => { + const subject = editing(); + setName(subject?.name ?? ""); + setDescription(subject?.description ?? ""); + }); + + const openCreate = () => { + setEditing(null); + setName(""); + setDescription(""); + setPanelOpen(true); + }; + + const openEdit = (subject: Subject) => { + setEditing(subject); + setPanelOpen(true); + }; + + const save = async (event: SubmitEvent) => { + event.preventDefault(); + setError(""); + setPending(true); + try { + const body = { name: name().trim(), description: description().trim() }; + const subject = editing(); + if (subject) await patchSubjectById(subject.id, body); + else await postCourseSubject(props.courseId, body); + setPanelOpen(false); + setEditing(null); + await refetch(); + setFlash(subject ? t("common.saved") : t("common.created")); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + return ( +
+ + {flash()} + + + + + + +
void save(event)}> +
+ + setName(event.currentTarget.value)} /> +
+
+ +