🏫 follow the backend split between a catalog course and a şube×ders instance
Browse files at this commit211d704fc8357fbb2c5deddbd155cb1e3950a1f5Parent: fbaff64- feat
- 🏫 follow the backend split between a catalog course and a şube×ders instance
117 changed files +3627 -1062
- AGENTS.md +8 -0
- CLAUDE.md +8 -0
- src/api/__tests__/academic-years/academic-years.test.ts +98 -0
- src/api/__tests__/ai/ai.test.ts +7 -1
- src/api/__tests__/classes/classes.test.ts +14 -12
- src/api/__tests__/contract/bank-questions.contract.test.ts +37 -3
- src/api/__tests__/contract/learning.contract.test.ts +58 -8
- src/api/__tests__/course-notes/course-notes.test.ts +11 -0
- src/api/__tests__/courses/courses.test.ts +18 -130
- src/api/__tests__/exams/exams.test.ts +33 -0
- src/api/__tests__/instances/instances.test.ts +171 -0
- src/api/__tests__/rag/rag.test.ts +104 -0
- src/api/__tests__/reports/reports.test.ts +30 -0
- src/api/academic-years/deleteAcademicYearById.ts +6 -0
- src/api/academic-years/getAcademicYearById.ts +6 -0
- src/api/academic-years/getAcademicYears.ts +9 -0
- src/api/academic-years/index.ts +7 -0
- src/api/academic-years/patchAcademicYearById.ts +15 -0
- src/api/academic-years/postAcademicYear.ts +15 -0
- src/api/academic-years/postAcademicYearArchive.ts +10 -0
- src/api/academic-years/postAcademicYearRollover.ts +15 -0
- src/api/ai/getAiCapabilities.ts +10 -0
- src/api/ai/index.ts +1 -0
- src/api/classes/deleteClassCourse.ts +0 -7
- src/api/classes/deleteClassInstance.ts +12 -0
- src/api/classes/getClassCourses.ts +0 -8
- src/api/classes/getClassInstances.ts +16 -0
- src/api/classes/index.ts +3 -3
- src/api/classes/patchClassById.ts +3 -2
- src/api/classes/postClass.ts +3 -1
- src/api/classes/postClassCourse.ts +0 -11
- src/api/classes/postClassInstance.ts +14 -0
- src/api/client/types.ts +216 -14
- src/api/course-notes/index.ts +1 -0
- src/api/course-notes/postCourseNoteRagReindex.ts +9 -0
- src/api/courses/deleteCourseEnrollmentByUserId.ts +0 -10
- src/api/courses/deleteCourseMemberByUserId.ts +6 -0
- src/api/courses/deleteCourseTeacherByUserId.ts +0 -10
- src/api/courses/getCourseMembers.ts +16 -0
- src/api/courses/index.ts +3 -12
- src/api/courses/patchCourseById.ts +1 -3
- src/api/courses/postCourse.ts +4 -2
- src/api/courses/postCourseEnrollment.ts +0 -12
- src/api/courses/postCourseExam.ts +0 -23
- src/api/courses/postCourseHomework.ts +0 -14
- src/api/courses/postCourseMember.ts +13 -0
- src/api/courses/postCourseSession.ts +0 -13
- src/api/courses/postCourseTeacher.ts +0 -12
- src/api/exams/deleteExamAudienceByInstanceId.ts +5 -0
- src/api/exams/getExamAudience.ts +13 -0
- src/api/exams/index.ts +3 -0
- src/api/exams/postExamAudience.ts +14 -0
- src/api/instances/deleteInstanceEnrollmentByUserId.ts +6 -0
- src/api/instances/deleteInstanceTeacherByUserId.ts +6 -0
- src/api/instances/getInstanceById.ts +6 -0
- src/api/courses/getCourseEnrollments.ts → src/api/instances/getInstanceEnrollments.ts +3 -3
- src/api/courses/getCourseExams.ts → src/api/instances/getInstanceExams.ts +4 -3
- src/api/courses/getCourseHomework.ts → src/api/instances/getInstanceHomework.ts +4 -3
- src/api/courses/getCourseSessions.ts → src/api/instances/getInstanceSessions.ts +3 -3
- src/api/instances/getMyInstances.ts +13 -0
- src/api/instances/index.ts +14 -0
- src/api/instances/patchInstanceById.ts +12 -0
- src/api/instances/postInstanceEnrollment.ts +13 -0
- src/api/instances/postInstanceExam.ts +26 -0
- src/api/instances/postInstanceHomework.ts +17 -0
- src/api/instances/postInstanceSession.ts +14 -0
- src/api/instances/postInstanceTeacher.ts +13 -0
- src/api/rag/deleteRagThreadById.ts +5 -0
- src/api/rag/getRagMessageById.ts +8 -0
- src/api/rag/getRagThreadMessages.ts +11 -0
- src/api/rag/getRagThreads.ts +7 -0
- src/api/rag/index.ts +8 -0
- src/api/rag/patchRagThreadById.ts +10 -0
- src/api/rag/postRagMessage.ts +18 -0
- src/api/rag/postRagThread.ts +7 -0
- src/api/rag/ragStreamUrl.ts +7 -0
- src/api/reports/getMyKarne.ts +11 -0
- src/api/reports/getUserKarne.ts +12 -0
- src/api/reports/index.ts +2 -0
- src/api/settings/patchSettings.ts +9 -0
- src/api/terms/postTerm.ts +2 -0
- src/components/attendance/attendance-report-view.tsx +42 -0
- src/components/courses/course-card.tsx +9 -8
- src/components/courses/course-teachers-panel.tsx +9 -7
- src/components/exams/exam-form.tsx +25 -0
- src/components/homework/course-homework-panel.tsx +8 -4
- src/components/homework/homework-submissions-panel.tsx +4 -4
- src/components/layout/nav-items.ts +1 -0
- src/components/marks/karne-view.tsx +93 -0
- src/components/marks/marks-report-view.tsx +11 -12
- src/components/sessions/course-sessions-panel.tsx +7 -7
- src/i18n/messages.ts +181 -1
- src/lib/instance-options.ts +74 -0
- src/lib/meals.test.ts +16 -4
- src/lib/meals.ts +8 -3
- src/pages/academic-years-page.tsx +450 -0
- src/pages/bank-question-detail-page.tsx +0 -1
- src/pages/calendar-page.tsx +14 -7
- src/pages/class-detail-page.tsx +30 -15
- src/pages/classes-page.tsx +10 -10
- src/pages/course-detail-page.tsx +366 -509
- src/pages/courses-page.test.tsx +7 -14
- src/pages/courses-page.tsx +16 -28
- src/pages/dashboard-page.test.tsx +19 -4
- src/pages/dashboard-page.tsx +21 -7
- src/pages/exam-detail-page.tsx +9 -7
- src/pages/exam-room-page.tsx +3 -3
- src/pages/exams-page.tsx +55 -44
- src/pages/homework-detail-page.tsx +8 -4
- src/pages/homework-page.tsx +30 -18
- src/pages/instance-detail-page.tsx +619 -0
- src/pages/marks-page.tsx +42 -5
- src/pages/question-bank-page.tsx +0 -1
- src/pages/settings-page.tsx +61 -0
- src/pages/students-roster-page.tsx +9 -9
- src/pages/terms-page.tsx +30 -2
- src/routes/router.tsx +23 -1
AGENTS.mdmodified+8 -0
| @@ -11,6 +11,14 @@ Bilingual codebase: Turkish UI labels, English code + commits. | |||
| 11 | 11 | ||
| 12 | - **SolidJS, not React.** Components run once. No re-render. Signals = functions. | 12 | - **SolidJS, not React.** Components run once. No re-render. Signals = functions. |
| 13 | Load `solidjs-pitfalls` skill before writing components. | 13 | Load `solidjs-pitfalls` skill before writing components. |
| 14 | +- **A ders is a catalog row; a şube×ders `instance` is where teaching happens.** | ||
| 15 | + `/courses/{id}` is the catalog (title, kind, subjects, notes, club/etüt | ||
| 16 | + members). Attaching it to a class (`postClassInstance`) mints the instance, | ||
| 17 | + and that is what carries enrollments, exams, homework, sessions, roll call, | ||
| 18 | + `ders_saati` and the karne flag — see `src/api/instances/` and | ||
| 19 | + `/instances/$id`. Exam/homework/session rows name `class_course`, never | ||
| 20 | + `course`; a class links an academic year (`/academic-years`), and a dönem | ||
| 21 | + lives inside one. | ||
| 14 | - **Podman, not Docker.** Never suggest docker. `podman build`, `podman compose`. | 22 | - **Podman, not Docker.** Never suggest docker. `podman build`, `podman compose`. |
| 15 | - **Bun only, never npm/npx/yarn/pnpm.** Install/run/exec with `bun add`, | 23 | - **Bun only, never npm/npx/yarn/pnpm.** Install/run/exec with `bun add`, |
| 16 | `bun run`, `bunx` — this repo has no `package-lock.json`/`yarn.lock`/ | 24 | `bun run`, `bunx` — this repo has no `package-lock.json`/`yarn.lock`/ |
CLAUDE.mdmodified+8 -0
| @@ -10,6 +10,14 @@ Bilingual codebase: Turkish UI labels, English code + commits. | |||
| 10 | 10 | ||
| 11 | - **SolidJS, not React.** Components run once. No re-render. Signals = functions. | 11 | - **SolidJS, not React.** Components run once. No re-render. Signals = functions. |
| 12 | Load `solidjs-pitfalls` skill before writing components. | 12 | Load `solidjs-pitfalls` skill before writing components. |
| 13 | +- **A ders is a catalog row; a şube×ders `instance` is where teaching happens.** | ||
| 14 | + `/courses/{id}` is the catalog (title, kind, subjects, notes, club/etüt | ||
| 15 | + members). Attaching it to a class (`postClassInstance`) mints the instance, | ||
| 16 | + and that is what carries enrollments, exams, homework, sessions, roll call, | ||
| 17 | + `ders_saati` and the karne flag — see `src/api/instances/` and | ||
| 18 | + `/instances/$id`. Exam/homework/session rows name `class_course`, never | ||
| 19 | + `course`; a class links an academic year (`/academic-years`), and a dönem | ||
| 20 | + lives inside one. | ||
| 13 | - **Podman, not Docker.** Never suggest docker. `podman build`, `podman compose`. | 21 | - **Podman, not Docker.** Never suggest docker. `podman build`, `podman compose`. |
| 14 | - **Bun only, never npm/npx/yarn/pnpm.** Install/run/exec with `bun add`, | 22 | - **Bun only, never npm/npx/yarn/pnpm.** Install/run/exec with `bun add`, |
| 15 | `bun run`, `bunx` — this repo has no `package-lock.json`/`yarn.lock`/ | 23 | `bun run`, `bunx` — this repo has no `package-lock.json`/`yarn.lock`/ |
src/api/__tests__/academic-years/academic-years.test.tsadded+98 -0
| @@ -0,0 +1,98 @@ | |||
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| 2 | +import { | ||
| 3 | + deleteAcademicYearById, | ||
| 4 | + getAcademicYearById, | ||
| 5 | + getAcademicYears, | ||
| 6 | + patchAcademicYearById, | ||
| 7 | + postAcademicYear, | ||
| 8 | + postAcademicYearArchive, | ||
| 9 | + postAcademicYearRollover, | ||
| 10 | +} from "../../academic-years"; | ||
| 11 | +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | ||
| 12 | + | ||
| 13 | +describe("academic years API", () => { | ||
| 14 | + afterEach(() => { | ||
| 15 | + vi.restoreAllMocks(); | ||
| 16 | + }); | ||
| 17 | + | ||
| 18 | + it("getAcademicYears GETs /academic-years with pagination", async () => { | ||
| 19 | + mockFetchSuccess({ items: [{ id: "y1" }], total: 1 }); | ||
| 20 | + | ||
| 21 | + const result = await getAcademicYears({ limit: 10 }); | ||
| 22 | + expect(result.items).toEqual([{ id: "y1" }]); | ||
| 23 | + | ||
| 24 | + const [url, init] = lastFetchCall(); | ||
| 25 | + expect(url).toBe("/api/academic-years?limit=10"); | ||
| 26 | + expect(init?.method).toBe("GET"); | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + it("getAcademicYearById GETs /academic-years/:id", async () => { | ||
| 30 | + mockFetchSuccess({ id: "y1" }); | ||
| 31 | + | ||
| 32 | + await getAcademicYearById("y1"); | ||
| 33 | + | ||
| 34 | + const [url] = lastFetchCall(); | ||
| 35 | + expect(url).toBe("/api/academic-years/y1"); | ||
| 36 | + }); | ||
| 37 | + | ||
| 38 | + it("postAcademicYear POSTs /academic-years with the body", async () => { | ||
| 39 | + mockFetchSuccess({ id: "y1" }); | ||
| 40 | + const body = { | ||
| 41 | + name: "2026-2027", | ||
| 42 | + starts_at: 1780000000000, | ||
| 43 | + ends_at: 1810000000000, | ||
| 44 | + grade_promotions: [{ from_grade: "5", to_grade: "6" }], | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + await postAcademicYear(body); | ||
| 48 | + | ||
| 49 | + const [url, init] = lastFetchCall(); | ||
| 50 | + expect(url).toBe("/api/academic-years"); | ||
| 51 | + expect(init?.method).toBe("POST"); | ||
| 52 | + expect(init?.body).toBe(JSON.stringify(body)); | ||
| 53 | + }); | ||
| 54 | + | ||
| 55 | + it("patchAcademicYearById PATCHes /academic-years/:id", async () => { | ||
| 56 | + mockFetchSuccess({ id: "y1" }); | ||
| 57 | + const body = { name: "2027-2028" }; | ||
| 58 | + | ||
| 59 | + await patchAcademicYearById("y1", body); | ||
| 60 | + | ||
| 61 | + const [url, init] = lastFetchCall(); | ||
| 62 | + expect(url).toBe("/api/academic-years/y1"); | ||
| 63 | + expect(init?.method).toBe("PATCH"); | ||
| 64 | + expect(init?.body).toBe(JSON.stringify(body)); | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | + it("deleteAcademicYearById DELETEs /academic-years/:id", async () => { | ||
| 68 | + mockFetch204(); | ||
| 69 | + | ||
| 70 | + await deleteAcademicYearById("y1"); | ||
| 71 | + | ||
| 72 | + const [url, init] = lastFetchCall(); | ||
| 73 | + expect(url).toBe("/api/academic-years/y1"); | ||
| 74 | + expect(init?.method).toBe("DELETE"); | ||
| 75 | + }); | ||
| 76 | + | ||
| 77 | + it("postAcademicYearArchive POSTs /academic-years/:id/archive", async () => { | ||
| 78 | + mockFetchSuccess({ id: "y1", archived_at: 1 }); | ||
| 79 | + | ||
| 80 | + await postAcademicYearArchive("y1"); | ||
| 81 | + | ||
| 82 | + const [url, init] = lastFetchCall(); | ||
| 83 | + expect(url).toBe("/api/academic-years/y1/archive"); | ||
| 84 | + expect(init?.method).toBe("POST"); | ||
| 85 | + }); | ||
| 86 | + | ||
| 87 | + it("postAcademicYearRollover POSTs /academic-years/:id/rollover with from_year", async () => { | ||
| 88 | + mockFetchSuccess({ year: "y2", classes: 12, students: 312, graduated: ["12"] }); | ||
| 89 | + | ||
| 90 | + const result = await postAcademicYearRollover("y2", "y1"); | ||
| 91 | + expect(result.classes).toBe(12); | ||
| 92 | + | ||
| 93 | + const [url, init] = lastFetchCall(); | ||
| 94 | + expect(url).toBe("/api/academic-years/y2/rollover"); | ||
| 95 | + expect(init?.method).toBe("POST"); | ||
| 96 | + expect(init?.body).toBe(JSON.stringify({ from_year: "y1" })); | ||
| 97 | + }); | ||
| 98 | +}); | ||
src/api/__tests__/ai/ai.test.tsmodified+7 -1
| @@ -1,5 +1,5 @@ | |||
| 1 | import { afterEach, describe, expect, it, vi } from "vitest"; | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | -import { getBridgeCertificate } from "../../ai"; | 2 | +import { getAiCapabilities, getBridgeCertificate } from "../../ai"; |
| 3 | import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; | 3 | import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 4 | describe("ai API", () => { | 4 | describe("ai API", () => { |
| 5 | afterEach(() => vi.restoreAllMocks()); | 5 | afterEach(() => vi.restoreAllMocks()); |
| @@ -8,4 +8,10 @@ describe("ai API", () => { | |||
| 8 | await getBridgeCertificate(); | 8 | await getBridgeCertificate(); |
| 9 | expect(lastFetchCall()[0]).toBe("/api/ai/certificate"); | 9 | expect(lastFetchCall()[0]).toBe("/api/ai/certificate"); |
| 10 | }); | 10 | }); |
| 11 | + it("gets the bridge capabilities", async () => { | ||
| 12 | + mockFetchSuccess({ enabled: true, protocol: "hab/2", capabilities: [] }); | ||
| 13 | + const result = await getAiCapabilities(); | ||
| 14 | + expect(result.protocol).toBe("hab/2"); | ||
| 15 | + expect(lastFetchCall()[0]).toBe("/api/ai/capabilities"); | ||
| 16 | + }); | ||
| 11 | }); | 17 | }); |
src/api/__tests__/classes/classes.test.tsmodified+14 -12
| @@ -10,9 +10,9 @@ import { | |||
| 10 | postClassMember, | 10 | postClassMember, |
| 11 | getClassMembers, | 11 | getClassMembers, |
| 12 | deleteClassMember, | 12 | deleteClassMember, |
| 13 | - postClassCourse, | 13 | + postClassInstance, |
| 14 | - getClassCourses, | 14 | + getClassInstances, |
| 15 | - deleteClassCourse, | 15 | + deleteClassInstance, |
| 16 | postClassBlueprint, | 16 | postClassBlueprint, |
| 17 | getClassBlueprints, | 17 | getClassBlueprints, |
| 18 | getClassBlueprintByGrade, | 18 | getClassBlueprintByGrade, |
| @@ -111,28 +111,30 @@ describe("classes API", () => { | |||
| 111 | expect(init?.method).toBe("DELETE"); | 111 | expect(init?.method).toBe("DELETE"); |
| 112 | }); | 112 | }); |
| 113 | 113 | ||
| 114 | - it("postClassCourse POSTs /classes/:id/courses with the body", async () => { | 114 | + it("postClassInstance POSTs /classes/:id/instances with the body", async () => { |
| 115 | mockFetchSuccess({ id: "cc1" }); | 115 | mockFetchSuccess({ id: "cc1" }); |
| 116 | const body = { course_id: "co1" }; | 116 | const body = { course_id: "co1" }; |
| 117 | - await postClassCourse("c1", body); | 117 | + await postClassInstance("c1", body); |
| 118 | const [url, init] = lastFetchCall(); | 118 | const [url, init] = lastFetchCall(); |
| 119 | - expect(url).toBe("/api/classes/c1/courses"); | 119 | + expect(url).toBe("/api/classes/c1/instances"); |
| 120 | expect(init?.method).toBe("POST"); | 120 | expect(init?.method).toBe("POST"); |
| 121 | expect(init?.body).toBe(JSON.stringify(body)); | 121 | expect(init?.body).toBe(JSON.stringify(body)); |
| 122 | }); | 122 | }); |
| 123 | 123 | ||
| 124 | - it("getClassCourses GETs /classes/:id/courses with pagination", async () => { | 124 | + it("getClassInstances GETs /classes/:id/instances with pagination", async () => { |
| 125 | mockFetchSuccess({ items: [], total: 0 }); | 125 | mockFetchSuccess({ items: [], total: 0 }); |
| 126 | - await getClassCourses("c1", { limit: 5, offset: 10 }); | 126 | + await getClassInstances("c1", { limit: 5, offset: 10 }); |
| 127 | const [url] = lastFetchCall(); | 127 | const [url] = lastFetchCall(); |
| 128 | - expect(url).toBe("/api/classes/c1/courses?limit=5&offset=10"); | 128 | + expect(url).toBe("/api/classes/c1/instances?limit=5&offset=10"); |
| 129 | }); | 129 | }); |
| 130 | 130 | ||
| 131 | - it("deleteClassCourse DELETEs /classes/:id/courses/:course", async () => { | 131 | + // The second segment is the instance id, not the course id — two şubeler |
| 132 | + // teaching the same course hold two instances. | ||
| 133 | + it("deleteClassInstance DELETEs /classes/:id/instances/:instance", async () => { | ||
| 132 | mockFetch204(); | 134 | mockFetch204(); |
| 133 | - await deleteClassCourse("c1", "co1"); | 135 | + await deleteClassInstance("c1", "i1"); |
| 134 | const [url, init] = lastFetchCall(); | 136 | const [url, init] = lastFetchCall(); |
| 135 | - expect(url).toBe("/api/classes/c1/courses/co1"); | 137 | + expect(url).toBe("/api/classes/c1/instances/i1"); |
| 136 | expect(init?.method).toBe("DELETE"); | 138 | expect(init?.method).toBe("DELETE"); |
| 137 | }); | 139 | }); |
| 138 | 140 | ||
src/api/__tests__/contract/bank-questions.contract.test.tsmodified+37 -3
| @@ -4,15 +4,39 @@ import type { BankQuestion, Course, ExamQuestion, Subject } from "@/api/client"; | |||
| 4 | if (!isLive) console.warn(SKIP_MESSAGE); | 4 | if (!isLive) console.warn(SKIP_MESSAGE); |
| 5 | 5 | ||
| 6 | describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { | 6 | describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { |
| 7 | + let yearId = ""; | ||
| 8 | + let termId = ""; | ||
| 9 | + let classId = ""; | ||
| 7 | let courseId = ""; | 10 | let courseId = ""; |
| 11 | + let instanceId = ""; | ||
| 8 | let subjectId = ""; | 12 | let subjectId = ""; |
| 9 | let questionId = ""; | 13 | let questionId = ""; |
| 10 | 14 | ||
| 15 | + // Bank templates hang off a catalog subject, but the exam that copies one | ||
| 16 | + // has to live in an instance — so the fixture builds the whole şube chain. | ||
| 11 | beforeAll(async () => { | 17 | beforeAll(async () => { |
| 12 | await loginAdmin(); | 18 | await loginAdmin(); |
| 19 | + const tag = `contract-${Date.now()}`; | ||
| 20 | + | ||
| 21 | + const year = await json<{ id: string }>("/academic-years", { | ||
| 22 | + method: "POST", | ||
| 23 | + body: { name: tag, starts_at: Date.now(), ends_at: Date.now() + 300 * 24 * 60 * 60 * 1000 }, | ||
| 24 | + }); | ||
| 25 | + yearId = year.id; | ||
| 26 | + const term = await json<{ id: string }>("/terms", { | ||
| 27 | + method: "POST", | ||
| 28 | + body: { name: tag, year: yearId, starts_at: Date.now(), ends_at: Date.now() + 120 * 24 * 60 * 60 * 1000 }, | ||
| 29 | + }); | ||
| 30 | + termId = term.id; | ||
| 31 | + const klass = await json<{ id: string }>("/classes", { | ||
| 32 | + method: "POST", | ||
| 33 | + body: { name: tag, grade: "9", year: yearId }, | ||
| 34 | + }); | ||
| 35 | + classId = klass.id; | ||
| 36 | + | ||
| 13 | const course = await json<Course>("/courses", { | 37 | const course = await json<Course>("/courses", { |
| 14 | method: "POST", | 38 | method: "POST", |
| 15 | - body: { title: `contract-${Date.now()}` }, | 39 | + body: { title: tag }, |
| 16 | }); | 40 | }); |
| 17 | courseId = course.id; | 41 | courseId = course.id; |
| 18 | const subject = await json<Subject>(`/courses/${courseId}/subjects`, { | 42 | const subject = await json<Subject>(`/courses/${courseId}/subjects`, { |
| @@ -20,6 +44,12 @@ describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { | |||
| 20 | body: { name: "contract subject" }, | 44 | body: { name: "contract subject" }, |
| 21 | }); | 45 | }); |
| 22 | subjectId = subject.id; | 46 | subjectId = subject.id; |
| 47 | + | ||
| 48 | + const instance = await json<{ id: string }>(`/classes/${classId}/instances`, { | ||
| 49 | + method: "POST", | ||
| 50 | + body: { course_id: courseId }, | ||
| 51 | + }); | ||
| 52 | + instanceId = instance.id; | ||
| 23 | }); | 53 | }); |
| 24 | 54 | ||
| 25 | /** Templates created by the paging/search tests, torn down with the course. */ | 55 | /** Templates created by the paging/search tests, torn down with the course. */ |
| @@ -28,7 +58,11 @@ describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { | |||
| 28 | afterAll(async () => { | 58 | afterAll(async () => { |
| 29 | for (const id of scratchIds) await api(`/bank-questions/${id}`, { method: "DELETE" }); | 59 | for (const id of scratchIds) await api(`/bank-questions/${id}`, { method: "DELETE" }); |
| 30 | if (questionId) await api(`/bank-questions/${questionId}`, { method: "DELETE" }); | 60 | if (questionId) await api(`/bank-questions/${questionId}`, { method: "DELETE" }); |
| 61 | + if (instanceId) await api(`/classes/${classId}/instances/${instanceId}`, { method: "DELETE" }); | ||
| 31 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); | 62 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); |
| 63 | + if (classId) await api(`/classes/${classId}`, { method: "DELETE" }); | ||
| 64 | + if (termId) await api(`/terms/${termId}`, { method: "DELETE" }); | ||
| 65 | + if (yearId) await api(`/academic-years/${yearId}`, { method: "DELETE" }); | ||
| 32 | }); | 66 | }); |
| 33 | 67 | ||
| 34 | const createTemplate = async (text: string) => { | 68 | const createTemplate = async (text: string) => { |
| @@ -226,9 +260,9 @@ describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { | |||
| 226 | it("reports used_count on the list and refreshes a copy from its template", async () => { | 260 | it("reports used_count on the list and refreshes a copy from its template", async () => { |
| 227 | const tag = `use${Date.now()}`; | 261 | const tag = `use${Date.now()}`; |
| 228 | const template = await createTemplate(`${tag} original text`); | 262 | const template = await createTemplate(`${tag} original text`); |
| 229 | - const exam = await json<{ id: string }>(`/courses/${courseId}/exams`, { | 263 | + const exam = await json<{ id: string }>(`/instances/${instanceId}/exams`, { |
| 230 | method: "POST", | 264 | method: "POST", |
| 231 | - body: { title: tag, kind: await configuredExamKind() }, | 265 | + body: { title: tag, kind: await configuredExamKind(), term: termId }, |
| 232 | }); | 266 | }); |
| 233 | 267 | ||
| 234 | const copy = await json<ExamQuestion>( | 268 | const copy = await json<ExamQuestion>( |
src/api/__tests__/contract/learning.contract.test.tsmodified+58 -8
| @@ -3,32 +3,78 @@ import { api, configuredExamKind, contractBaseUrl, expectPage, isLive, json, log | |||
| 3 | if (!isLive) console.warn(SKIP_MESSAGE); | 3 | if (!isLive) console.warn(SKIP_MESSAGE); |
| 4 | 4 | ||
| 5 | describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { | 5 | describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { |
| 6 | + let yearId = ""; | ||
| 7 | + let termId = ""; | ||
| 8 | + let classId = ""; | ||
| 6 | let courseId = ""; | 9 | let courseId = ""; |
| 10 | + let instanceId = ""; | ||
| 7 | let examId = ""; | 11 | let examId = ""; |
| 8 | 12 | ||
| 13 | + // A catalog course teaches nobody on its own: the chain an exam needs is | ||
| 14 | + // academic year → dönem → şube → attach the course (which mints the | ||
| 15 | + // instance) → exam inside that instance. | ||
| 9 | beforeAll(async () => { | 16 | beforeAll(async () => { |
| 10 | await loginAdmin(); | 17 | await loginAdmin(); |
| 11 | const tag = `contract-learning-${Date.now()}`; | 18 | const tag = `contract-learning-${Date.now()}`; |
| 19 | + | ||
| 20 | + const year = await json<{ id: string }>("/academic-years", { | ||
| 21 | + method: "POST", | ||
| 22 | + body: { name: tag, starts_at: Date.now(), ends_at: Date.now() + 300 * 24 * 60 * 60 * 1000 }, | ||
| 23 | + }); | ||
| 24 | + yearId = year.id; | ||
| 25 | + | ||
| 26 | + const term = await json<{ id: string; year: string }>("/terms", { | ||
| 27 | + method: "POST", | ||
| 28 | + body: { name: tag, year: yearId, starts_at: Date.now(), ends_at: Date.now() + 120 * 24 * 60 * 60 * 1000 }, | ||
| 29 | + }); | ||
| 30 | + termId = term.id; | ||
| 31 | + expect(term.year).toBe(yearId); | ||
| 32 | + | ||
| 33 | + const klass = await json<{ id: string }>("/classes", { | ||
| 34 | + method: "POST", | ||
| 35 | + body: { name: tag, grade: "9", year: yearId }, | ||
| 36 | + }); | ||
| 37 | + classId = klass.id; | ||
| 38 | + | ||
| 12 | const course = await json<{ id: string; title: string; kind: string }>("/courses", { | 39 | const course = await json<{ id: string; title: string; kind: string }>("/courses", { |
| 13 | method: "POST", | 40 | method: "POST", |
| 14 | body: { title: tag, kind: "course" }, | 41 | body: { title: tag, kind: "course" }, |
| 15 | }); | 42 | }); |
| 16 | courseId = course.id; | 43 | courseId = course.id; |
| 17 | expect(course).toMatchObject({ title: tag, kind: "course" }); | 44 | expect(course).toMatchObject({ title: tag, kind: "course" }); |
| 45 | + | ||
| 46 | + const instance = await json<{ id: string; class: string; course: string }>(`/classes/${classId}/instances`, { | ||
| 47 | + method: "POST", | ||
| 48 | + body: { course_id: courseId }, | ||
| 49 | + }); | ||
| 50 | + instanceId = instance.id; | ||
| 51 | + expect(instance).toMatchObject({ class: classId, course: courseId }); | ||
| 18 | }); | 52 | }); |
| 19 | 53 | ||
| 54 | + // Teardown runs inside-out: an instance holds the exams, a şube holds the | ||
| 55 | + // instance, and a year refuses deletion while a dönem or şube still links it. | ||
| 20 | afterAll(async () => { | 56 | afterAll(async () => { |
| 57 | + if (instanceId) await api(`/classes/${classId}/instances/${instanceId}`, { method: "DELETE" }); | ||
| 21 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); | 58 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); |
| 59 | + if (classId) await api(`/classes/${classId}`, { method: "DELETE" }); | ||
| 60 | + if (termId) await api(`/terms/${termId}`, { method: "DELETE" }); | ||
| 61 | + if (yearId) await api(`/academic-years/${yearId}`, { method: "DELETE" }); | ||
| 22 | }); | 62 | }); |
| 23 | 63 | ||
| 24 | - // `/courses` takes limit/offset only — kind/term/search filtering is the | 64 | + // `/courses` takes limit/offset only — kind/search filtering is the caller's |
| 25 | - // caller's job, so this asserts the envelope, not a server-side filter. | 65 | + // job, so this asserts the envelope, not a server-side filter. |
| 26 | it("returns courses through the standard page envelope", async () => { | 66 | it("returns courses through the standard page envelope", async () => { |
| 27 | const page = await json<{ items: Array<{ id: string }> }>(`/courses?limit=10`); | 67 | const page = await json<{ items: Array<{ id: string }> }>(`/courses?limit=10`); |
| 28 | expectPage(page); | 68 | expectPage(page); |
| 29 | expect(page.items.some((course) => course.id === courseId)).toBe(true); | 69 | expect(page.items.some((course) => course.id === courseId)).toBe(true); |
| 30 | }); | 70 | }); |
| 31 | 71 | ||
| 72 | + it("lists the instances a class carries", async () => { | ||
| 73 | + const page = await json<{ items: Array<{ id: string }> }>(`/classes/${classId}/instances?limit=10`); | ||
| 74 | + expectPage(page); | ||
| 75 | + expect(page.items.some((instance) => instance.id === instanceId)).toBe(true); | ||
| 76 | + }); | ||
| 77 | + | ||
| 32 | it("supports course subjects and exam-question lists", async () => { | 78 | it("supports course subjects and exam-question lists", async () => { |
| 33 | const subject = await json<{ id: string; course: string }>(`/courses/${courseId}/subjects`, { | 79 | const subject = await json<{ id: string; course: string }>(`/courses/${courseId}/subjects`, { |
| 34 | method: "POST", | 80 | method: "POST", |
| @@ -37,12 +83,16 @@ describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { | |||
| 37 | expect(subject.course).toBe(courseId); | 83 | expect(subject.course).toBe(courseId); |
| 38 | 84 | ||
| 39 | const examKind = await configuredExamKind(); | 85 | const examKind = await configuredExamKind(); |
| 40 | - const exam = await json<{ id: string; course: string; draft: boolean }>(`/courses/${courseId}/exams`, { | 86 | + const exam = await json<{ id: string; class_course: string; term: string; draft: boolean }>( |
| 41 | - method: "POST", | 87 | + `/instances/${instanceId}/exams`, |
| 42 | - body: { title: "contract exam", kind: examKind, draft: true }, | 88 | + { |
| 43 | - }); | 89 | + method: "POST", |
| 90 | + body: { title: "contract exam", kind: examKind, term: termId, draft: true }, | ||
| 91 | + }, | ||
| 92 | + ); | ||
| 44 | examId = exam.id; | 93 | examId = exam.id; |
| 45 | - expect(exam.course).toBe(courseId); | 94 | + expect(exam.class_course).toBe(instanceId); |
| 95 | + expect(exam.term).toBe(termId); | ||
| 46 | 96 | ||
| 47 | const question = await json<{ id: string; exam: string }>(`/exams/${examId}/questions`, { | 97 | const question = await json<{ id: string; exam: string }>(`/exams/${examId}/questions`, { |
| 48 | method: "POST", | 98 | method: "POST", |
| @@ -50,6 +100,6 @@ describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { | |||
| 50 | }); | 100 | }); |
| 51 | expect(question.exam).toBe(examId); | 101 | expect(question.exam).toBe(examId); |
| 52 | expectPage(await json(`/exams/${examId}/questions?limit=10`)); | 102 | expectPage(await json(`/exams/${examId}/questions?limit=10`)); |
| 53 | - expectPage(await json(`/courses/${courseId}/exams?limit=10`)); | 103 | + expectPage(await json(`/instances/${instanceId}/exams?limit=10`)); |
| 54 | }); | 104 | }); |
| 55 | }); | 105 | }); |
src/api/__tests__/course-notes/course-notes.test.tsmodified+11 -0
| @@ -1,5 +1,6 @@ | |||
| 1 | import { afterEach, describe, expect, it, vi } from "vitest"; | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | import { getCourseNotes } from "../../course-notes"; | 2 | import { getCourseNotes } from "../../course-notes"; |
| 3 | +import { postCourseNoteRagReindex } from "../../course-notes"; | ||
| 3 | import { getCourseNoteById } from "../../course-notes"; | 4 | import { getCourseNoteById } from "../../course-notes"; |
| 4 | import { postCourseNote } from "../../course-notes"; | 5 | import { postCourseNote } from "../../course-notes"; |
| 5 | import { patchCourseNoteById } from "../../course-notes"; | 6 | import { patchCourseNoteById } from "../../course-notes"; |
| @@ -164,4 +165,14 @@ describe("course notes API", () => { | |||
| 164 | expect(url).toBe("/api/course-notes/cn1/rag/r1"); | 165 | expect(url).toBe("/api/course-notes/cn1/rag/r1"); |
| 165 | expect(init?.method).toBe("DELETE"); | 166 | expect(init?.method).toBe("DELETE"); |
| 166 | }); | 167 | }); |
| 168 | + it("postCourseNoteRagReindex POSTs /course-notes/:id/rag/reindex", async () => { | ||
| 169 | + mockFetch204(); | ||
| 170 | + | ||
| 171 | + await postCourseNoteRagReindex("n1"); | ||
| 172 | + | ||
| 173 | + const [url, init] = lastFetchCall(); | ||
| 174 | + expect(url).toBe("/api/course-notes/n1/rag/reindex"); | ||
| 175 | + expect(init?.method).toBe("POST"); | ||
| 176 | + }); | ||
| 177 | + | ||
| 167 | }); | 178 | }); |
src/api/__tests__/courses/courses.test.tsmodified+18 -130
| @@ -4,19 +4,11 @@ import { getCourseById } from "../../courses"; | |||
| 4 | import { postCourse } from "../../courses"; | 4 | import { postCourse } from "../../courses"; |
| 5 | import { patchCourseById } from "../../courses"; | 5 | import { patchCourseById } from "../../courses"; |
| 6 | import { deleteCourseById } from "../../courses"; | 6 | import { deleteCourseById } from "../../courses"; |
| 7 | -import { getCourseEnrollments } from "../../courses"; | 7 | +import { getCourseMembers } from "../../courses"; |
| 8 | -import { postCourseEnrollment } from "../../courses"; | 8 | +import { postCourseMember } from "../../courses"; |
| 9 | -import { deleteCourseEnrollmentByUserId } from "../../courses"; | 9 | +import { deleteCourseMemberByUserId } from "../../courses"; |
| 10 | -import { getCourseSessions } from "../../courses"; | ||
| 11 | -import { postCourseSession } from "../../courses"; | ||
| 12 | import { getCourseSubjects } from "../../courses"; | 10 | import { getCourseSubjects } from "../../courses"; |
| 13 | import { postCourseSubject } from "../../courses"; | 11 | import { postCourseSubject } from "../../courses"; |
| 14 | -import { getCourseExams } from "../../courses"; | ||
| 15 | -import { postCourseExam } from "../../courses"; | ||
| 16 | -import { postCourseTeacher } from "../../courses"; | ||
| 17 | -import { deleteCourseTeacherByUserId } from "../../courses"; | ||
| 18 | -import { getCourseHomework } from "../../courses"; | ||
| 19 | -import { postCourseHomework } from "../../courses"; | ||
| 20 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | 12 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 21 | 13 | ||
| 22 | describe("courses API", () => { | 14 | describe("courses API", () => { |
| @@ -24,30 +16,6 @@ describe("courses API", () => { | |||
| 24 | vi.restoreAllMocks(); | 16 | vi.restoreAllMocks(); |
| 25 | }); | 17 | }); |
| 26 | 18 | ||
| 27 | - it("postCourseTeacher calls /courses/:id/teachers", async () => { | ||
| 28 | - const mockCourse = { id: "c1", title: "Course", teachers: [{ id: "t1", username: "teacher1", display_name: "Teacher 1" }] }; | ||
| 29 | - mockFetchSuccess(mockCourse); | ||
| 30 | - | ||
| 31 | - const result = await postCourseTeacher("c1", "t1"); | ||
| 32 | - expect(result).toEqual(mockCourse); | ||
| 33 | - | ||
| 34 | - const [url, init] = lastFetchCall(); | ||
| 35 | - expect(url).toBe("/api/courses/c1/teachers"); | ||
| 36 | - expect(init?.method).toBe("POST"); | ||
| 37 | - expect(init?.body).toBe(JSON.stringify({ user_id: "t1" })); | ||
| 38 | - }); | ||
| 39 | - | ||
| 40 | - it("deleteCourseTeacherByUserId calls /courses/:id/teachers/:userId", async () => { | ||
| 41 | - mockFetch204(); | ||
| 42 | - | ||
| 43 | - await deleteCourseTeacherByUserId("c1", "t1"); | ||
| 44 | - | ||
| 45 | - const [url, init] = lastFetchCall(); | ||
| 46 | - expect(url).toBe("/api/courses/c1/teachers/t1"); | ||
| 47 | - expect(init?.method).toBe("DELETE"); | ||
| 48 | - }); | ||
| 49 | - | ||
| 50 | - | ||
| 51 | it("getCourses calls /courses with pagination", async () => { | 19 | it("getCourses calls /courses with pagination", async () => { |
| 52 | const mockPage = { items: [{ id: "c1" }], total: 1 }; | 20 | const mockPage = { items: [{ id: "c1" }], total: 1 }; |
| 53 | mockFetchSuccess(mockPage); | 21 | mockFetchSuccess(mockPage); |
| @@ -116,67 +84,6 @@ describe("courses API", () => { | |||
| 116 | expect(init?.method).toBe("DELETE"); | 84 | expect(init?.method).toBe("DELETE"); |
| 117 | }); | 85 | }); |
| 118 | 86 | ||
| 119 | - it("getCourseEnrollments calls /courses/:id/enrollments", async () => { | ||
| 120 | - const mockPage = { items: [{ id: "en1" }], total: 1 }; | ||
| 121 | - mockFetchSuccess(mockPage); | ||
| 122 | - | ||
| 123 | - const result = await getCourseEnrollments("c1"); | ||
| 124 | - expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); | ||
| 125 | - | ||
| 126 | - const [url, init] = lastFetchCall(); | ||
| 127 | - expect(url).toBe("/api/courses/c1/enrollments"); | ||
| 128 | - expect(init?.method).toBe("GET"); | ||
| 129 | - }); | ||
| 130 | - | ||
| 131 | - it("postCourseEnrollment calls /courses/:id/enrollments", async () => { | ||
| 132 | - const mockEnr = { id: "en1", course: "c1" }; | ||
| 133 | - mockFetchSuccess(mockEnr); | ||
| 134 | - | ||
| 135 | - const result = await postCourseEnrollment("c1", "u1"); | ||
| 136 | - expect(result).toEqual(mockEnr); | ||
| 137 | - | ||
| 138 | - const [url, init] = lastFetchCall(); | ||
| 139 | - expect(url).toBe("/api/courses/c1/enrollments"); | ||
| 140 | - expect(init?.method).toBe("POST"); | ||
| 141 | - expect(init?.body).toBe(JSON.stringify({ user_id: "u1" })); | ||
| 142 | - }); | ||
| 143 | - | ||
| 144 | - it("deleteCourseEnrollmentByUserId calls /courses/:id/enrollments/:userId", async () => { | ||
| 145 | - mockFetch204(); | ||
| 146 | - | ||
| 147 | - await deleteCourseEnrollmentByUserId("c1", "u1"); | ||
| 148 | - | ||
| 149 | - const [url, init] = lastFetchCall(); | ||
| 150 | - expect(url).toBe("/api/courses/c1/enrollments/u1"); | ||
| 151 | - expect(init?.method).toBe("DELETE"); | ||
| 152 | - }); | ||
| 153 | - | ||
| 154 | - it("getCourseSessions calls /courses/:id/sessions", async () => { | ||
| 155 | - const mockPage = { items: [{ id: "s1" }], total: 1 }; | ||
| 156 | - mockFetchSuccess(mockPage); | ||
| 157 | - | ||
| 158 | - const result = await getCourseSessions("c1"); | ||
| 159 | - expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); | ||
| 160 | - | ||
| 161 | - const [url, init] = lastFetchCall(); | ||
| 162 | - expect(url).toBe("/api/courses/c1/sessions"); | ||
| 163 | - expect(init?.method).toBe("GET"); | ||
| 164 | - }); | ||
| 165 | - | ||
| 166 | - it("postCourseSession calls /courses/:id/sessions", async () => { | ||
| 167 | - const mockSession = { id: "s1", course: "c1" }; | ||
| 168 | - mockFetchSuccess(mockSession); | ||
| 169 | - | ||
| 170 | - const data = { topic: "Topic", starts_at: 1000 }; | ||
| 171 | - const result = await postCourseSession("c1", data); | ||
| 172 | - expect(result).toEqual(mockSession); | ||
| 173 | - | ||
| 174 | - const [url, init] = lastFetchCall(); | ||
| 175 | - expect(url).toBe("/api/courses/c1/sessions"); | ||
| 176 | - expect(init?.method).toBe("POST"); | ||
| 177 | - expect(init?.body).toBe(JSON.stringify(data)); | ||
| 178 | - }); | ||
| 179 | - | ||
| 180 | it("getCourseSubjects calls /courses/:id/subjects", async () => { | 87 | it("getCourseSubjects calls /courses/:id/subjects", async () => { |
| 181 | const mockPage = { items: [{ id: "sub1" }], total: 1 }; | 88 | const mockPage = { items: [{ id: "sub1" }], total: 1 }; |
| 182 | mockFetchSuccess(mockPage); | 89 | mockFetchSuccess(mockPage); |
| @@ -203,55 +110,36 @@ describe("courses API", () => { | |||
| 203 | expect(init?.body).toBe(JSON.stringify(data)); | 110 | expect(init?.body).toBe(JSON.stringify(data)); |
| 204 | }); | 111 | }); |
| 205 | 112 | ||
| 206 | - it("getCourseExams calls /courses/:id/exams", async () => { | 113 | + it("getCourseMembers calls /courses/:id/members with pagination", async () => { |
| 207 | - const mockPage = { items: [{ id: "ex1" }], total: 1 }; | 114 | + mockFetchSuccess({ items: [{ id: "m1" }], total: 1 }); |
| 208 | - mockFetchSuccess(mockPage); | ||
| 209 | 115 | ||
| 210 | - const result = await getCourseExams("c1"); | 116 | + const result = await getCourseMembers("c1", { limit: 10 }); |
| 211 | - expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); | 117 | + expect(result.items).toEqual([{ id: "m1" }]); |
| 212 | 118 | ||
| 213 | const [url, init] = lastFetchCall(); | 119 | const [url, init] = lastFetchCall(); |
| 214 | - expect(url).toBe("/api/courses/c1/exams"); | 120 | + expect(url).toBe("/api/courses/c1/members?limit=10"); |
| 215 | expect(init?.method).toBe("GET"); | 121 | expect(init?.method).toBe("GET"); |
| 216 | }); | 122 | }); |
| 217 | 123 | ||
| 218 | - it("postCourseExam calls /courses/:id/exams", async () => { | 124 | + it("postCourseMember calls /courses/:id/members with the user id", async () => { |
| 219 | - const mockExam = { id: "ex1", course: "c1" }; | 125 | + mockFetchSuccess({ id: "m1" }); |
| 220 | - mockFetchSuccess(mockExam); | ||
| 221 | 126 | ||
| 222 | - const data = { title: "Exam", kind: "quiz" }; | 127 | + await postCourseMember("c1", "u1"); |
| 223 | - const result = await postCourseExam("c1", data); | ||
| 224 | - expect(result).toEqual(mockExam); | ||
| 225 | 128 | ||
| 226 | const [url, init] = lastFetchCall(); | 129 | const [url, init] = lastFetchCall(); |
| 227 | - expect(url).toBe("/api/courses/c1/exams"); | 130 | + expect(url).toBe("/api/courses/c1/members"); |
| 228 | expect(init?.method).toBe("POST"); | 131 | expect(init?.method).toBe("POST"); |
| 229 | - expect(init?.body).toBe(JSON.stringify(data)); | 132 | + expect(init?.body).toBe(JSON.stringify({ user_id: "u1" })); |
| 230 | }); | 133 | }); |
| 231 | 134 | ||
| 232 | - it("getCourseHomework calls /courses/:id/homework", async () => { | 135 | + it("deleteCourseMemberByUserId calls /courses/:id/members/:userId", async () => { |
| 233 | - const mockPage = { items: [{ id: "hw1" }], total: 1 }; | 136 | + mockFetch204(); |
| 234 | - mockFetchSuccess(mockPage); | ||
| 235 | 137 | ||
| 236 | - const result = await getCourseHomework("c1", { limit: 5 }); | 138 | + await deleteCourseMemberByUserId("c1", "u1"); |
| 237 | - expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); | ||
| 238 | 139 | ||
| 239 | const [url, init] = lastFetchCall(); | 140 | const [url, init] = lastFetchCall(); |
| 240 | - expect(url).toBe("/api/courses/c1/homework?limit=5"); | 141 | + expect(url).toBe("/api/courses/c1/members/u1"); |
| 241 | - expect(init?.method).toBe("GET"); | 142 | + expect(init?.method).toBe("DELETE"); |
| 242 | }); | 143 | }); |
| 243 | 144 | ||
| 244 | - it("postCourseHomework calls /courses/:id/homework", async () => { | ||
| 245 | - const mockHomework = { id: "hw1", course: "c1" }; | ||
| 246 | - mockFetchSuccess(mockHomework); | ||
| 247 | - | ||
| 248 | - const data = { title: "HW", subject_id: "sub1", due_at: 1900000000000, assigned: ["u1"] }; | ||
| 249 | - const result = await postCourseHomework("c1", data); | ||
| 250 | - expect(result).toEqual(mockHomework); | ||
| 251 | - | ||
| 252 | - const [url, init] = lastFetchCall(); | ||
| 253 | - expect(url).toBe("/api/courses/c1/homework"); | ||
| 254 | - expect(init?.method).toBe("POST"); | ||
| 255 | - expect(init?.body).toBe(JSON.stringify(data)); | ||
| 256 | - }); | ||
| 257 | }); | 145 | }); |
src/api/__tests__/exams/exams.test.tsmodified+33 -0
| @@ -8,6 +8,9 @@ import { getExamChoiceImageBlob } from "../../exams"; | |||
| 8 | import { postExamAttemptAnswerImage } from "../../exams"; | 8 | import { postExamAttemptAnswerImage } from "../../exams"; |
| 9 | import { deleteExamAttemptAnswerImage } from "../../exams"; | 9 | import { deleteExamAttemptAnswerImage } from "../../exams"; |
| 10 | import { getExamAnswerImageBlob } from "../../exams"; | 10 | import { getExamAnswerImageBlob } from "../../exams"; |
| 11 | +import { getExamAudience } from "../../exams"; | ||
| 12 | +import { postExamAudience } from "../../exams"; | ||
| 13 | +import { deleteExamAudienceByInstanceId } from "../../exams"; | ||
| 11 | import { lastFetchCall, mockFetch204, mockFetchBlob, mockFetchSuccess } from "../helpers/mock-fetch"; | 14 | import { lastFetchCall, mockFetch204, mockFetchBlob, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 12 | 15 | ||
| 13 | describe("exams API - core", () => { | 16 | describe("exams API - core", () => { |
| @@ -143,4 +146,34 @@ describe("exams API - core", () => { | |||
| 143 | expect(init?.method ?? "GET").toBe("GET"); | 146 | expect(init?.method ?? "GET").toBe("GET"); |
| 144 | expect(init?.credentials).toBe("same-origin"); | 147 | expect(init?.credentials).toBe("same-origin"); |
| 145 | }); | 148 | }); |
| 149 | + it("getExamAudience calls /exams/:id/audience", async () => { | ||
| 150 | + mockFetchSuccess({ items: [], total: 0 }); | ||
| 151 | + | ||
| 152 | + await getExamAudience("x1", { limit: 10 }); | ||
| 153 | + | ||
| 154 | + const [url] = lastFetchCall(); | ||
| 155 | + expect(url).toBe("/api/exams/x1/audience?limit=10"); | ||
| 156 | + }); | ||
| 157 | + | ||
| 158 | + it("postExamAudience announces the exam to another instance", async () => { | ||
| 159 | + mockFetchSuccess({ instance: "i2", class: "c2", course: "co1" }); | ||
| 160 | + | ||
| 161 | + await postExamAudience("x1", "i2"); | ||
| 162 | + | ||
| 163 | + const [url, init] = lastFetchCall(); | ||
| 164 | + expect(url).toBe("/api/exams/x1/audience"); | ||
| 165 | + expect(init?.method).toBe("POST"); | ||
| 166 | + expect(init?.body).toBe(JSON.stringify({ instance: "i2" })); | ||
| 167 | + }); | ||
| 168 | + | ||
| 169 | + it("deleteExamAudienceByInstanceId calls /exams/:id/audience/:instance", async () => { | ||
| 170 | + mockFetch204(); | ||
| 171 | + | ||
| 172 | + await deleteExamAudienceByInstanceId("x1", "i2"); | ||
| 173 | + | ||
| 174 | + const [url, init] = lastFetchCall(); | ||
| 175 | + expect(url).toBe("/api/exams/x1/audience/i2"); | ||
| 176 | + expect(init?.method).toBe("DELETE"); | ||
| 177 | + }); | ||
| 178 | + | ||
| 146 | }); | 179 | }); |
src/api/__tests__/instances/instances.test.tsadded+171 -0
| @@ -0,0 +1,171 @@ | |||
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| 2 | +import { | ||
| 3 | + deleteInstanceEnrollmentByUserId, | ||
| 4 | + deleteInstanceTeacherByUserId, | ||
| 5 | + getInstanceById, | ||
| 6 | + getInstanceEnrollments, | ||
| 7 | + getInstanceExams, | ||
| 8 | + getInstanceHomework, | ||
| 9 | + getInstanceSessions, | ||
| 10 | + getMyInstances, | ||
| 11 | + patchInstanceById, | ||
| 12 | + postInstanceEnrollment, | ||
| 13 | + postInstanceExam, | ||
| 14 | + postInstanceHomework, | ||
| 15 | + postInstanceSession, | ||
| 16 | + postInstanceTeacher, | ||
| 17 | +} from "../../instances"; | ||
| 18 | +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | ||
| 19 | + | ||
| 20 | +describe("instances API", () => { | ||
| 21 | + afterEach(() => { | ||
| 22 | + vi.restoreAllMocks(); | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + it("getMyInstances GETs /instances/me with pagination", async () => { | ||
| 26 | + mockFetchSuccess({ items: [{ id: "i1" }], total: 1 }); | ||
| 27 | + | ||
| 28 | + const result = await getMyInstances({ limit: 20, offset: 40 }); | ||
| 29 | + expect(result.items).toEqual([{ id: "i1" }]); | ||
| 30 | + | ||
| 31 | + const [url, init] = lastFetchCall(); | ||
| 32 | + expect(url).toBe("/api/instances/me?limit=20&offset=40"); | ||
| 33 | + expect(init?.method).toBe("GET"); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + it("getInstanceById GETs /instances/:id", async () => { | ||
| 37 | + mockFetchSuccess({ id: "i1" }); | ||
| 38 | + | ||
| 39 | + await getInstanceById("i1"); | ||
| 40 | + | ||
| 41 | + const [url, init] = lastFetchCall(); | ||
| 42 | + expect(url).toBe("/api/instances/i1"); | ||
| 43 | + expect(init?.method).toBe("GET"); | ||
| 44 | + }); | ||
| 45 | + | ||
| 46 | + it("patchInstanceById PATCHes /instances/:id with the policy body", async () => { | ||
| 47 | + mockFetchSuccess({ id: "i1" }); | ||
| 48 | + const body = { ders_saati: 4, counts_toward_karne: false }; | ||
| 49 | + | ||
| 50 | + await patchInstanceById("i1", body); | ||
| 51 | + | ||
| 52 | + const [url, init] = lastFetchCall(); | ||
| 53 | + expect(url).toBe("/api/instances/i1"); | ||
| 54 | + expect(init?.method).toBe("PATCH"); | ||
| 55 | + expect(init?.body).toBe(JSON.stringify(body)); | ||
| 56 | + }); | ||
| 57 | + | ||
| 58 | + it("getInstanceEnrollments GETs /instances/:id/enrollments with pagination", async () => { | ||
| 59 | + mockFetchSuccess({ items: [], total: 0 }); | ||
| 60 | + | ||
| 61 | + await getInstanceEnrollments("i1", { limit: 5 }); | ||
| 62 | + | ||
| 63 | + const [url] = lastFetchCall(); | ||
| 64 | + expect(url).toBe("/api/instances/i1/enrollments?limit=5"); | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | + it("postInstanceEnrollment POSTs /instances/:id/enrollments with the user id", async () => { | ||
| 68 | + mockFetchSuccess({ id: "e1" }); | ||
| 69 | + | ||
| 70 | + await postInstanceEnrollment("i1", "u1"); | ||
| 71 | + | ||
| 72 | + const [url, init] = lastFetchCall(); | ||
| 73 | + expect(url).toBe("/api/instances/i1/enrollments"); | ||
| 74 | + expect(init?.method).toBe("POST"); | ||
| 75 | + expect(init?.body).toBe(JSON.stringify({ user_id: "u1" })); | ||
| 76 | + }); | ||
| 77 | + | ||
| 78 | + it("deleteInstanceEnrollmentByUserId DELETEs /instances/:id/enrollments/:user", async () => { | ||
| 79 | + mockFetch204(); | ||
| 80 | + | ||
| 81 | + await deleteInstanceEnrollmentByUserId("i1", "u1"); | ||
| 82 | + | ||
| 83 | + const [url, init] = lastFetchCall(); | ||
| 84 | + expect(url).toBe("/api/instances/i1/enrollments/u1"); | ||
| 85 | + expect(init?.method).toBe("DELETE"); | ||
| 86 | + }); | ||
| 87 | + | ||
| 88 | + it("getInstanceExams GETs /instances/:id/exams", async () => { | ||
| 89 | + mockFetchSuccess({ items: [], total: 0 }); | ||
| 90 | + | ||
| 91 | + await getInstanceExams("i1"); | ||
| 92 | + | ||
| 93 | + const [url] = lastFetchCall(); | ||
| 94 | + expect(url).toBe("/api/instances/i1/exams"); | ||
| 95 | + }); | ||
| 96 | + | ||
| 97 | + it("postInstanceExam POSTs /instances/:id/exams with the term", async () => { | ||
| 98 | + mockFetchSuccess({ id: "x1" }); | ||
| 99 | + const body = { title: "Quiz 1", kind: "quiz", term: "t1" }; | ||
| 100 | + | ||
| 101 | + await postInstanceExam("i1", body); | ||
| 102 | + | ||
| 103 | + const [url, init] = lastFetchCall(); | ||
| 104 | + expect(url).toBe("/api/instances/i1/exams"); | ||
| 105 | + expect(init?.method).toBe("POST"); | ||
| 106 | + expect(init?.body).toBe(JSON.stringify(body)); | ||
| 107 | + }); | ||
| 108 | + | ||
| 109 | + it("getInstanceHomework GETs /instances/:id/homework", async () => { | ||
| 110 | + mockFetchSuccess({ items: [], total: 0 }); | ||
| 111 | + | ||
| 112 | + await getInstanceHomework("i1"); | ||
| 113 | + | ||
| 114 | + const [url] = lastFetchCall(); | ||
| 115 | + expect(url).toBe("/api/instances/i1/homework"); | ||
| 116 | + }); | ||
| 117 | + | ||
| 118 | + it("postInstanceHomework POSTs /instances/:id/homework with the body", async () => { | ||
| 119 | + mockFetchSuccess({ id: "h1" }); | ||
| 120 | + const body = { title: "Read ch. 3", subject_id: "s1", due_at: 1900000000000 }; | ||
| 121 | + | ||
| 122 | + await postInstanceHomework("i1", body); | ||
| 123 | + | ||
| 124 | + const [url, init] = lastFetchCall(); | ||
| 125 | + expect(url).toBe("/api/instances/i1/homework"); | ||
| 126 | + expect(init?.method).toBe("POST"); | ||
| 127 | + expect(init?.body).toBe(JSON.stringify(body)); | ||
| 128 | + }); | ||
| 129 | + | ||
| 130 | + it("getInstanceSessions GETs /instances/:id/sessions", async () => { | ||
| 131 | + mockFetchSuccess({ items: [], total: 0 }); | ||
| 132 | + | ||
| 133 | + await getInstanceSessions("i1"); | ||
| 134 | + | ||
| 135 | + const [url] = lastFetchCall(); | ||
| 136 | + expect(url).toBe("/api/instances/i1/sessions"); | ||
| 137 | + }); | ||
| 138 | + | ||
| 139 | + it("postInstanceSession POSTs /instances/:id/sessions with the body", async () => { | ||
| 140 | + mockFetchSuccess({ id: "se1" }); | ||
| 141 | + const body = { starts_at: 1900000000000, topic: "Limits" }; | ||
| 142 | + | ||
| 143 | + await postInstanceSession("i1", body); | ||
| 144 | + | ||
| 145 | + const [url, init] = lastFetchCall(); | ||
| 146 | + expect(url).toBe("/api/instances/i1/sessions"); | ||
| 147 | + expect(init?.method).toBe("POST"); | ||
| 148 | + expect(init?.body).toBe(JSON.stringify(body)); | ||
| 149 | + }); | ||
| 150 | + | ||
| 151 | + it("postInstanceTeacher POSTs /instances/:id/teachers with the user id", async () => { | ||
| 152 | + mockFetchSuccess({ id: "i1" }); | ||
| 153 | + | ||
| 154 | + await postInstanceTeacher("i1", "t1"); | ||
| 155 | + | ||
| 156 | + const [url, init] = lastFetchCall(); | ||
| 157 | + expect(url).toBe("/api/instances/i1/teachers"); | ||
| 158 | + expect(init?.method).toBe("POST"); | ||
| 159 | + expect(init?.body).toBe(JSON.stringify({ user_id: "t1" })); | ||
| 160 | + }); | ||
| 161 | + | ||
| 162 | + it("deleteInstanceTeacherByUserId DELETEs /instances/:id/teachers/:user", async () => { | ||
| 163 | + mockFetch204(); | ||
| 164 | + | ||
| 165 | + await deleteInstanceTeacherByUserId("i1", "t1"); | ||
| 166 | + | ||
| 167 | + const [url, init] = lastFetchCall(); | ||
| 168 | + expect(url).toBe("/api/instances/i1/teachers/t1"); | ||
| 169 | + expect(init?.method).toBe("DELETE"); | ||
| 170 | + }); | ||
| 171 | +}); | ||
src/api/__tests__/rag/rag.test.tsadded+104 -0
| @@ -0,0 +1,104 @@ | |||
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| 2 | +import { | ||
| 3 | + deleteRagThreadById, | ||
| 4 | + getRagMessageById, | ||
| 5 | + getRagThreadMessages, | ||
| 6 | + getRagThreads, | ||
| 7 | + patchRagThreadById, | ||
| 8 | + postRagMessage, | ||
| 9 | + postRagThread, | ||
| 10 | + ragStreamUrl, | ||
| 11 | +} from "../../rag"; | ||
| 12 | +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | ||
| 13 | + | ||
| 14 | +describe("rag API", () => { | ||
| 15 | + afterEach(() => { | ||
| 16 | + vi.restoreAllMocks(); | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + it("getRagThreads GETs /rag/threads with pagination", async () => { | ||
| 20 | + mockFetchSuccess({ items: [{ id: "r1" }], total: 1 }); | ||
| 21 | + | ||
| 22 | + const result = await getRagThreads({ limit: 10 }); | ||
| 23 | + expect(result.items).toEqual([{ id: "r1" }]); | ||
| 24 | + | ||
| 25 | + const [url, init] = lastFetchCall(); | ||
| 26 | + expect(url).toBe("/api/rag/threads?limit=10"); | ||
| 27 | + expect(init?.method).toBe("GET"); | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + it("postRagThread POSTs /rag/threads with the title", async () => { | ||
| 31 | + mockFetchSuccess({ id: "r1" }); | ||
| 32 | + | ||
| 33 | + await postRagThread("Fizik ödevi"); | ||
| 34 | + | ||
| 35 | + const [url, init] = lastFetchCall(); | ||
| 36 | + expect(url).toBe("/api/rag/threads"); | ||
| 37 | + expect(init?.method).toBe("POST"); | ||
| 38 | + expect(init?.body).toBe(JSON.stringify({ title: "Fizik ödevi" })); | ||
| 39 | + }); | ||
| 40 | + | ||
| 41 | + it("postRagThread sends a null title when none is given", async () => { | ||
| 42 | + mockFetchSuccess({ id: "r1" }); | ||
| 43 | + | ||
| 44 | + await postRagThread(); | ||
| 45 | + | ||
| 46 | + const [, init] = lastFetchCall(); | ||
| 47 | + expect(init?.body).toBe(JSON.stringify({ title: null })); | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + it("patchRagThreadById PATCHes /rag/threads/:id", async () => { | ||
| 51 | + mockFetchSuccess({ id: "r1" }); | ||
| 52 | + | ||
| 53 | + await patchRagThreadById("r1", null); | ||
| 54 | + | ||
| 55 | + const [url, init] = lastFetchCall(); | ||
| 56 | + expect(url).toBe("/api/rag/threads/r1"); | ||
| 57 | + expect(init?.method).toBe("PATCH"); | ||
| 58 | + expect(init?.body).toBe(JSON.stringify({ title: null })); | ||
| 59 | + }); | ||
| 60 | + | ||
| 61 | + it("deleteRagThreadById DELETEs /rag/threads/:id", async () => { | ||
| 62 | + mockFetch204(); | ||
| 63 | + | ||
| 64 | + await deleteRagThreadById("r1"); | ||
| 65 | + | ||
| 66 | + const [url, init] = lastFetchCall(); | ||
| 67 | + expect(url).toBe("/api/rag/threads/r1"); | ||
| 68 | + expect(init?.method).toBe("DELETE"); | ||
| 69 | + }); | ||
| 70 | + | ||
| 71 | + it("getRagThreadMessages GETs /rag/threads/:id/messages", async () => { | ||
| 72 | + mockFetchSuccess({ items: [], total: 0 }); | ||
| 73 | + | ||
| 74 | + await getRagThreadMessages("r1", { limit: 50 }); | ||
| 75 | + | ||
| 76 | + const [url] = lastFetchCall(); | ||
| 77 | + expect(url).toBe("/api/rag/threads/r1/messages?limit=50"); | ||
| 78 | + }); | ||
| 79 | + | ||
| 80 | + it("getRagMessageById GETs one turn", async () => { | ||
| 81 | + mockFetchSuccess({ id: "m1", status: "pending" }); | ||
| 82 | + | ||
| 83 | + await getRagMessageById("r1", "m1"); | ||
| 84 | + | ||
| 85 | + const [url] = lastFetchCall(); | ||
| 86 | + expect(url).toBe("/api/rag/threads/r1/messages/m1"); | ||
| 87 | + }); | ||
| 88 | + | ||
| 89 | + it("postRagMessage POSTs /rag/threads/:id/messages with the content", async () => { | ||
| 90 | + mockFetchSuccess({ message_id: "m1", status: "pending" }, 202); | ||
| 91 | + | ||
| 92 | + const result = await postRagMessage("r1", "Newton'un ikinci yasası?"); | ||
| 93 | + expect(result.message_id).toBe("m1"); | ||
| 94 | + | ||
| 95 | + const [url, init] = lastFetchCall(); | ||
| 96 | + expect(url).toBe("/api/rag/threads/r1/messages"); | ||
| 97 | + expect(init?.method).toBe("POST"); | ||
| 98 | + expect(init?.body).toBe(JSON.stringify({ content: "Newton'un ikinci yasası?" })); | ||
| 99 | + }); | ||
| 100 | + | ||
| 101 | + it("ragStreamUrl builds the SSE path for an EventSource", () => { | ||
| 102 | + expect(ragStreamUrl("r 1", "m1")).toBe("/api/rag/threads/r%201/messages/m1/stream"); | ||
| 103 | + }); | ||
| 104 | +}); | ||
src/api/__tests__/reports/reports.test.tsmodified+30 -0
| @@ -4,6 +4,8 @@ import { getMyAttendance } from "../../reports"; | |||
| 4 | import { getMyMarks } from "../../reports"; | 4 | import { getMyMarks } from "../../reports"; |
| 5 | import { getUserAttendance } from "../../reports"; | 5 | import { getUserAttendance } from "../../reports"; |
| 6 | import { getUserMarks } from "../../reports"; | 6 | import { getUserMarks } from "../../reports"; |
| 7 | +import { getMyKarne } from "../../reports"; | ||
| 8 | +import { getUserKarne } from "../../reports"; | ||
| 7 | import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; | 9 | import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 8 | 10 | ||
| 9 | describe("reports API", () => { | 11 | describe("reports API", () => { |
| @@ -76,4 +78,32 @@ describe("reports API", () => { | |||
| 76 | expect(url).toBe("/api/marks/u1"); | 78 | expect(url).toBe("/api/marks/u1"); |
| 77 | expect(init?.method).toBe("GET"); | 79 | expect(init?.method).toBe("GET"); |
| 78 | }); | 80 | }); |
| 81 | + it("getMyKarne calls /marks/karne without a term", async () => { | ||
| 82 | + mockFetchSuccess({ user: "u1", term: "t1", instances: [] }); | ||
| 83 | + | ||
| 84 | + await getMyKarne(); | ||
| 85 | + | ||
| 86 | + const [url, init] = lastFetchCall(); | ||
| 87 | + expect(url).toBe("/api/marks/karne"); | ||
| 88 | + expect(init?.method).toBe("GET"); | ||
| 89 | + }); | ||
| 90 | + | ||
| 91 | + it("getMyKarne passes the term through as a query", async () => { | ||
| 92 | + mockFetchSuccess({ user: "u1", term: "t 1", instances: [] }); | ||
| 93 | + | ||
| 94 | + await getMyKarne("t 1"); | ||
| 95 | + | ||
| 96 | + const [url] = lastFetchCall(); | ||
| 97 | + expect(url).toBe("/api/marks/karne?term=t%201"); | ||
| 98 | + }); | ||
| 99 | + | ||
| 100 | + it("getUserKarne calls /marks/karne/:user with the term", async () => { | ||
| 101 | + mockFetchSuccess({ user: "u2", term: "t1", instances: [] }); | ||
| 102 | + | ||
| 103 | + await getUserKarne("u2", "t1"); | ||
| 104 | + | ||
| 105 | + const [url] = lastFetchCall(); | ||
| 106 | + expect(url).toBe("/api/marks/karne/u2?term=t1"); | ||
| 107 | + }); | ||
| 108 | + | ||
| 79 | }); | 109 | }); |
src/api/academic-years/deleteAcademicYearById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** 409 while any şube or dönem still links it. An archived year cannot be deleted. */ | ||
| 4 | +export function deleteAcademicYearById(id: string): Promise<void> { | ||
| 5 | + return client<void>(`/academic-years/${id}`, { method: "DELETE" }); | ||
| 6 | +} | ||
src/api/academic-years/getAcademicYearById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { AcademicYear } from "../client"; | ||
| 3 | + | ||
| 4 | +export function getAcademicYearById(id: string, signal?: AbortSignal): Promise<AcademicYear> { | ||
| 5 | + return client<AcademicYear>(`/academic-years/${id}`, { signal }); | ||
| 6 | +} | ||
src/api/academic-years/getAcademicYears.tsadded+9 -0
| @@ -0,0 +1,9 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 3 | +import type { AcademicYear } from "../client"; | ||
| 4 | + | ||
| 5 | +/** Newest first. Requires teacher+. */ | ||
| 6 | +export async function getAcademicYears(params?: PageParams, signal?: AbortSignal): Promise<Page<AcademicYear>> { | ||
| 7 | + const data = await client<unknown>(`/academic-years${pageQuery(params)}`, { signal }); | ||
| 8 | + return normalizePage<AcademicYear>(data); | ||
| 9 | +} | ||
src/api/academic-years/index.tsadded+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | +export * from "./getAcademicYears"; | ||
| 2 | +export * from "./getAcademicYearById"; | ||
| 3 | +export * from "./postAcademicYear"; | ||
| 4 | +export * from "./patchAcademicYearById"; | ||
| 5 | +export * from "./deleteAcademicYearById"; | ||
| 6 | +export * from "./postAcademicYearArchive"; | ||
| 7 | +export * from "./postAcademicYearRollover"; | ||
src/api/academic-years/patchAcademicYearById.tsadded+15 -0
| @@ -0,0 +1,15 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { AcademicYear, GradePromotion } from "../client"; | ||
| 3 | + | ||
| 4 | +export type PatchAcademicYearBody = { | ||
| 5 | + name?: string | null; | ||
| 6 | + starts_at?: number | null; | ||
| 7 | + ends_at?: number | null; | ||
| 8 | + /** The whole new policy, not a delta: a grade left out is no longer promoted. */ | ||
| 9 | + grade_promotions?: GradePromotion[] | null; | ||
| 10 | +}; | ||
| 11 | + | ||
| 12 | +/** An archived year is read-only. */ | ||
| 13 | +export function patchAcademicYearById(id: string, body: PatchAcademicYearBody): Promise<AcademicYear> { | ||
| 14 | + return client<AcademicYear>(`/academic-years/${id}`, { method: "PATCH", body }); | ||
| 15 | +} | ||
src/api/academic-years/postAcademicYear.tsadded+15 -0
| @@ -0,0 +1,15 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { AcademicYear, GradePromotion } from "../client"; | ||
| 3 | + | ||
| 4 | +export type PostAcademicYearBody = { | ||
| 5 | + name: string; | ||
| 6 | + /** May lie in the past — a school adopting the app mid-year backfills legitimately. */ | ||
| 7 | + starts_at: number; | ||
| 8 | + ends_at: number; | ||
| 9 | + /** The sınıf-geçme policy; omit while the rollover is undecided. */ | ||
| 10 | + grade_promotions?: GradePromotion[] | null; | ||
| 11 | +}; | ||
| 12 | + | ||
| 13 | +export function postAcademicYear(body: PostAcademicYearBody): Promise<AcademicYear> { | ||
| 14 | + return client<AcademicYear>("/academic-years", { method: "POST", body }); | ||
| 15 | +} | ||
src/api/academic-years/postAcademicYearArchive.tsadded+10 -0
| @@ -0,0 +1,10 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { AcademicYear } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Freezes the year as past structure: no new şube, dönem or exam inside it, | ||
| 6 | + * and no edit or delete. Idempotent, and there is no unarchive route. | ||
| 7 | + */ | ||
| 8 | +export function postAcademicYearArchive(id: string): Promise<AcademicYear> { | ||
| 9 | + return client<AcademicYear>(`/academic-years/${id}/archive`, { method: "POST" }); | ||
| 10 | +} | ||
src/api/academic-years/postAcademicYearRollover.tsadded+15 -0
| @@ -0,0 +1,15 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { RolloverResult } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Carries `from_year`'s şubeler into this year — same names, promoted grades, | ||
| 6 | + * copies of their instances and live members. The target must be empty, open, | ||
| 7 | + * and a different year; a second rollover is a 409, which is what makes the | ||
| 8 | + * command idempotent. | ||
| 9 | + */ | ||
| 10 | +export function postAcademicYearRollover(id: string, fromYear: string): Promise<RolloverResult> { | ||
| 11 | + return client<RolloverResult>(`/academic-years/${id}/rollover`, { | ||
| 12 | + method: "POST", | ||
| 13 | + body: { from_year: fromYear }, | ||
| 14 | + }); | ||
| 15 | +} | ||
src/api/ai/getAiCapabilities.tsadded+10 -0
| @@ -0,0 +1,10 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { AiCapabilities } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * What the AI bridge can currently do. `enabled: false` is a discovery answer, | ||
| 6 | + * not an error — the deployment simply runs no AI. | ||
| 7 | + */ | ||
| 8 | +export function getAiCapabilities(signal?: AbortSignal): Promise<AiCapabilities> { | ||
| 9 | + return client<AiCapabilities>("/ai/capabilities", { signal }); | ||
| 10 | +} | ||
src/api/ai/index.tsmodified+1 -0
| @@ -1 +1,2 @@ | |||
| 1 | export * from "./getBridgeCertificate"; | 1 | export * from "./getBridgeCertificate"; |
| 2 | +export * from "./getAiCapabilities"; | ||
src/api/classes/deleteClassCourse.tsdeleted+0 -7
| @@ -1,7 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | - | ||
| 3 | -// Detaches the course and sweeps only the rows this class pumped. Needs | ||
| 4 | -// course-manage rights, except when the course row is already gone. | ||
| 5 | -export function deleteClassCourse(classId: string, courseId: string): Promise<void> { | ||
| 6 | - return client<void>(`/classes/${classId}/courses/${courseId}`, { method: "DELETE" }); | ||
| 7 | -} | ||
src/api/classes/deleteClassInstance.tsadded+12 -0
| @@ -0,0 +1,12 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Detaches an instance from a class. The second segment is the **instance id** | ||
| 5 | + * (`getClassInstances`), not a course id — two sections teaching the same | ||
| 6 | + * course hold two instances. Everything the class taught under it goes with | ||
| 7 | + * it: exams, homework, sessions, roll call, and the whole roster, hand-placed | ||
| 8 | + * rows included (an enrollment cannot outlive its instance). | ||
| 9 | + */ | ||
| 10 | +export function deleteClassInstance(classId: string, instanceId: string): Promise<void> { | ||
| 11 | + return client<void>(`/classes/${classId}/instances/${instanceId}`, { method: "DELETE" }); | ||
| 12 | +} | ||
src/api/classes/getClassCourses.tsdeleted+0 -8
| @@ -1,8 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 3 | -import type { ClassCourse } from "../client"; | ||
| 4 | - | ||
| 5 | -export async function getClassCourses(classId: string, params?: PageParams, signal?: AbortSignal): Promise<Page<ClassCourse>> { | ||
| 6 | - const data = await client<unknown>(`/classes/${classId}/courses${pageQuery(params)}`, { signal }); | ||
| 7 | - return normalizePage<ClassCourse>(data); | ||
| 8 | -} | ||
src/api/classes/getClassInstances.tsadded+16 -0
| @@ -0,0 +1,16 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 3 | +import type { ClassCourse } from "../client"; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * The instances a class carries — each a catalog course as this section | ||
| 7 | + * teaches it, with its hours, karne policy and teachers. Requires teacher+. | ||
| 8 | + */ | ||
| 9 | +export async function getClassInstances( | ||
| 10 | + classId: string, | ||
| 11 | + params?: PageParams, | ||
| 12 | + signal?: AbortSignal, | ||
| 13 | +): Promise<Page<ClassCourse>> { | ||
| 14 | + const data = await client<unknown>(`/classes/${classId}/instances${pageQuery(params)}`, { signal }); | ||
| 15 | + return normalizePage<ClassCourse>(data); | ||
| 16 | +} | ||
src/api/classes/index.tsmodified+3 -3
| @@ -8,9 +8,9 @@ export * from "./deleteClassById"; | |||
| 8 | export * from "./postClassMember"; | 8 | export * from "./postClassMember"; |
| 9 | export * from "./getClassMembers"; | 9 | export * from "./getClassMembers"; |
| 10 | export * from "./deleteClassMember"; | 10 | export * from "./deleteClassMember"; |
| 11 | -export * from "./postClassCourse"; | 11 | +export * from "./postClassInstance"; |
| 12 | -export * from "./getClassCourses"; | 12 | +export * from "./getClassInstances"; |
| 13 | -export * from "./deleteClassCourse"; | 13 | +export * from "./deleteClassInstance"; |
| 14 | export * from "./postClassBlueprint"; | 14 | export * from "./postClassBlueprint"; |
| 15 | export * from "./getClassBlueprints"; | 15 | export * from "./getClassBlueprints"; |
| 16 | export * from "./getClassBlueprintByGrade"; | 16 | export * from "./getClassBlueprintByGrade"; |
src/api/classes/patchClassById.tsmodified+3 -2
| @@ -1,11 +1,12 @@ | |||
| 1 | import { client } from "../client"; | 1 | import { client } from "../client"; |
| 2 | import type { ClassGroup } from "../client"; | 2 | import type { ClassGroup } from "../client"; |
| 3 | 3 | ||
| 4 | -// Omit a field to keep it; send null on grade/term_id/teacher_id to clear/unlink it. | 4 | +// Omit a field to keep it; send null on grade/year/teacher_id to clear/unlink it. |
| 5 | export type UpdateClassBody = { | 5 | export type UpdateClassBody = { |
| 6 | name?: string; | 6 | name?: string; |
| 7 | grade?: string | null; | 7 | grade?: string | null; |
| 8 | - term_id?: string | null; | 8 | + /** The academic year (`getAcademicYears`) the şube sits in. */ |
| 9 | + year?: string | null; | ||
| 9 | teacher_id?: string | null; | 10 | teacher_id?: string | null; |
| 10 | }; | 11 | }; |
| 11 | 12 | ||
src/api/classes/postClass.tsmodified+3 -1
| @@ -1,7 +1,9 @@ | |||
| 1 | import { client } from "../client"; | 1 | import { client } from "../client"; |
| 2 | import type { ClassGroup } from "../client"; | 2 | import type { ClassGroup } from "../client"; |
| 3 | 3 | ||
| 4 | -export type CreateClassBody = { name: string; grade?: string; term_id?: string; teacher_id?: string }; | 4 | +// `year` is the academic year (`getAcademicYears`) — what binds the şube to a |
| 5 | +// karne and to the rollover. A şube with no year takes no exam. | ||
| 6 | +export type CreateClassBody = { name: string; grade?: string; year?: string; teacher_id?: string }; | ||
| 5 | 7 | ||
| 6 | export function postClass(body: CreateClassBody): Promise<ClassGroup> { | 8 | export function postClass(body: CreateClassBody): Promise<ClassGroup> { |
| 7 | return client<ClassGroup>("/classes", { method: "POST", body }); | 9 | return client<ClassGroup>("/classes", { method: "POST", body }); |
src/api/classes/postClassCourse.tsdeleted+0 -11
| @@ -1,11 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import type { ClassCourse } from "../client"; | ||
| 3 | - | ||
| 4 | -export type AttachCourseBody = { course_id: string }; | ||
| 5 | - | ||
| 6 | -// Bulk-enrolls the whole roster into the course. Needs course-manage rights | ||
| 7 | -// (403 otherwise); 409 on duplicate, ceiling, or a course too small to seat | ||
| 8 | -// the class. | ||
| 9 | -export function postClassCourse(classId: string, body: AttachCourseBody): Promise<ClassCourse> { | ||
| 10 | - return client<ClassCourse>(`/classes/${classId}/courses`, { method: "POST", body }); | ||
| 11 | -} | ||
src/api/classes/postClassInstance.tsadded+14 -0
| @@ -0,0 +1,14 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { ClassCourse } from "../client"; | ||
| 3 | + | ||
| 4 | +export type AttachCourseBody = { course_id: string }; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * Attaching a catalog course to a şube is what **mints the instance** — the | ||
| 8 | + * class×course row every exam, session and roster keys on. The class's whole | ||
| 9 | + * roster is enrolled in one go; students already enrolled by hand keep their | ||
| 10 | + * own rows. Needs teacher+ and catalog rights on the course; 409 on a repeat. | ||
| 11 | + */ | ||
| 12 | +export function postClassInstance(classId: string, body: AttachCourseBody): Promise<ClassCourse> { | ||
| 13 | + return client<ClassCourse>(`/classes/${classId}/instances`, { method: "POST", body }); | ||
| 14 | +} | ||
src/api/client/types.tsmodified+216 -14
| @@ -281,20 +281,79 @@ export const BANK_QUESTION_LIMITS = { | |||
| 281 | maxChoices: 10, // MAX_QUESTION_CHOICES | 281 | maxChoices: 10, // MAX_QUESTION_CHOICES |
| 282 | } as const; | 282 | } as const; |
| 283 | 283 | ||
| 284 | +// A catalog course: the school's course row, taught by nobody on its own. A | ||
| 285 | +// sube attaches it (POST /classes/{id}/instances), which mints the Instance | ||
| 286 | +// every exam, session, homework and enrollment keys on. | ||
| 284 | export type Course = { | 287 | export type Course = { |
| 285 | id: string; | 288 | id: string; |
| 286 | creator: PersonRef; | 289 | creator: PersonRef; |
| 287 | - teachers?: PersonRef[]; | ||
| 288 | title: string; | 290 | title: string; |
| 289 | description: string; | 291 | description: string; |
| 290 | kind: CourseKind; | 292 | kind: CourseKind; |
| 291 | - term: string | null; | 293 | + // How many instances teach it (how many sections took it). |
| 292 | - capacity: number | null; | 294 | + class_course_count: number; |
| 295 | + // Individual club/etut memberships on the catalog row itself. | ||
| 296 | + course_membership_count: number; | ||
| 297 | +}; | ||
| 298 | + | ||
| 299 | +// One catalog course as one sube teaches it. This is what carries the roster, | ||
| 300 | +// the exams, the sessions and the karne weight. | ||
| 301 | +export type Instance = { | ||
| 302 | + id: string; | ||
| 303 | + class: string; | ||
| 304 | + course: string; | ||
| 305 | + // Weekly lesson hours; the instance's weight in the year's karne average. | ||
| 306 | + ders_saati: number; | ||
| 307 | + counts_toward_karne: boolean; | ||
| 308 | + enrollment_count: number; | ||
| 309 | + teachers: PersonRef[]; | ||
| 310 | +}; | ||
| 311 | + | ||
| 312 | +// A club/etut membership on the catalog course itself — the school-scoped | ||
| 313 | +// tier, distinct from an instance's roster. A regular `course` has none. | ||
| 314 | +export type CourseMembership = { | ||
| 315 | + id: string; | ||
| 316 | + course: string; | ||
| 317 | + user: PersonRef; | ||
| 318 | + added_by: PersonRef; | ||
| 319 | + created_at: number; | ||
| 320 | +}; | ||
| 321 | + | ||
| 322 | +/** One sınıf-geçme pair: the grade label students move to at rollover. */ | ||
| 323 | +export type GradePromotion = { | ||
| 324 | + from_grade: string; | ||
| 325 | + to_grade: string; | ||
| 326 | +}; | ||
| 327 | + | ||
| 328 | +// An academic year: the calendar structure dönemler and şubeler hang off. | ||
| 329 | +// Archiving freezes it — no new şube, dönem or exam inside it, and no edit. | ||
| 330 | +export type AcademicYear = { | ||
| 331 | + id: string; | ||
| 332 | + name: string; | ||
| 333 | + starts_at: number; | ||
| 334 | + ends_at: number; | ||
| 335 | + creator: string; | ||
| 336 | + grade_promotions: GradePromotion[]; | ||
| 337 | + class_count: number; | ||
| 338 | + term_count: number; | ||
| 339 | + /** Archived at, UTC unix-millis; null while the year is open. */ | ||
| 340 | + archived_at: number | null; | ||
| 341 | +}; | ||
| 342 | + | ||
| 343 | +/** What one rollover carried into the target year. */ | ||
| 344 | +export type RolloverResult = { | ||
| 345 | + year: string; | ||
| 346 | + classes: number; | ||
| 347 | + students: number; | ||
| 348 | + /** Grade labels left behind because the year promotes them nowhere. */ | ||
| 349 | + graduated: string[]; | ||
| 293 | }; | 350 | }; |
| 294 | 351 | ||
| 295 | export type Term = { | 352 | export type Term = { |
| 296 | id: string; | 353 | id: string; |
| 297 | name: string; | 354 | name: string; |
| 355 | + /** The academic year the dönem sits in. */ | ||
| 356 | + year: string; | ||
| 298 | starts_at: number; | 357 | starts_at: number; |
| 299 | ends_at: number; | 358 | ends_at: number; |
| 300 | /** Archived at, UTC unix-millis; null while the term is open. */ | 359 | /** Archived at, UTC unix-millis; null while the term is open. */ |
| @@ -303,7 +362,8 @@ export type Term = { | |||
| 303 | 362 | ||
| 304 | export type Enrollment = { | 363 | export type Enrollment = { |
| 305 | id: string; | 364 | id: string; |
| 306 | - course: string; | 365 | + /** The instance (class x course) the student is enrolled in. */ |
| 366 | + class_course: string; | ||
| 307 | user: PersonRef; | 367 | user: PersonRef; |
| 308 | enrolled_by: PersonRef; | 368 | enrolled_by: PersonRef; |
| 309 | // The class (ClassGroup id) that pumped this enrollment, or null for a | 369 | // The class (ClassGroup id) that pumped this enrollment, or null for a |
| @@ -323,7 +383,9 @@ export type ClassGroup = { | |||
| 323 | creator: PersonRef | null; | 383 | creator: PersonRef | null; |
| 324 | name: string; | 384 | name: string; |
| 325 | grade: string | null; | 385 | grade: string | null; |
| 326 | - term: string | null; | 386 | + // The academic year (AcademicYear id) the sube sits in; what binds it to a |
| 387 | + // karne and to the rollover. Null when none is set. | ||
| 388 | + year: string | null; | ||
| 327 | // The class's homeroom teacher (sınıf öğretmeni); null when none is assigned. | 389 | // The class's homeroom teacher (sınıf öğretmeni); null when none is assigned. |
| 328 | teacher: PersonRef | null; | 390 | teacher: PersonRef | null; |
| 329 | }; | 391 | }; |
| @@ -335,10 +397,9 @@ export type ClassMember = { | |||
| 335 | added_by: PersonRef; | 397 | added_by: PersonRef; |
| 336 | }; | 398 | }; |
| 337 | 399 | ||
| 338 | -export type ClassCourse = { | 400 | +// The instance as the class routes return it: an Instance plus who attached |
| 339 | - id: string; | 401 | +// the course to the sube. |
| 340 | - class: string; | 402 | +export type ClassCourse = Instance & { |
| 341 | - course: string; | ||
| 342 | attached_by: PersonRef; | 403 | attached_by: PersonRef; |
| 343 | }; | 404 | }; |
| 344 | 405 | ||
| @@ -384,7 +445,8 @@ export type BlueprintStatus = { | |||
| 384 | 445 | ||
| 385 | export type CourseSession = { | 446 | export type CourseSession = { |
| 386 | id: string; | 447 | id: string; |
| 387 | - course: string; | 448 | + /** The instance this lesson belongs to. */ |
| 449 | + class_course: string; | ||
| 388 | teacher: PersonRef; | 450 | teacher: PersonRef; |
| 389 | topic: string; | 451 | topic: string; |
| 390 | starts_at: number; | 452 | starts_at: number; |
| @@ -394,7 +456,7 @@ export type CourseSession = { | |||
| 394 | export type SessionAttendance = { | 456 | export type SessionAttendance = { |
| 395 | id: string; | 457 | id: string; |
| 396 | session: string; | 458 | session: string; |
| 397 | - course: string; | 459 | + class_course: string; |
| 398 | user: PersonRef; | 460 | user: PersonRef; |
| 399 | status: AttendanceStatus; | 461 | status: AttendanceStatus; |
| 400 | marked_by: PersonRef; | 462 | marked_by: PersonRef; |
| @@ -403,7 +465,10 @@ export type SessionAttendance = { | |||
| 403 | export type Exam = { | 465 | export type Exam = { |
| 404 | id: string; | 466 | id: string; |
| 405 | creator: string; | 467 | creator: string; |
| 406 | - course: string; | 468 | + /** The instance the exam is set in. */ |
| 469 | + class_course: string; | ||
| 470 | + /** The dönem the exam is sat in; its marks count into that term's karne. */ | ||
| 471 | + term: string; | ||
| 407 | title: string; | 472 | title: string; |
| 408 | description: string; | 473 | description: string; |
| 409 | kind: ExamKind | string; | 474 | kind: ExamKind | string; |
| @@ -554,6 +619,8 @@ export type MarkEntry = { | |||
| 554 | }; | 619 | }; |
| 555 | 620 | ||
| 556 | export type CourseMarks = { | 621 | export type CourseMarks = { |
| 622 | + /** The instance these marks belong to; two sections are two blocks. */ | ||
| 623 | + instance: string; | ||
| 557 | course: Course; | 624 | course: Course; |
| 558 | results: MarkEntry[]; | 625 | results: MarkEntry[]; |
| 559 | average: number | null; | 626 | average: number | null; |
| @@ -571,15 +638,36 @@ export type AttendanceCounts = { | |||
| 571 | }; | 638 | }; |
| 572 | 639 | ||
| 573 | export type CourseAttendance = { | 640 | export type CourseAttendance = { |
| 641 | + /** The instance these tallies belong to. */ | ||
| 642 | + instance: string; | ||
| 574 | course: Course; | 643 | course: Course; |
| 575 | counts: AttendanceCounts; | 644 | counts: AttendanceCounts; |
| 576 | }; | 645 | }; |
| 577 | 646 | ||
| 647 | +/** The configured per-dönem absence limits; null per limit when unset. */ | ||
| 648 | +export type AbsenceLimits = { | ||
| 649 | + max_excused_days: number | null; | ||
| 650 | + max_unexcused_days: number | null; | ||
| 651 | +}; | ||
| 652 | + | ||
| 653 | +// One dönem's devamsızlık. A *day* is a calendar day with at least one missed | ||
| 654 | +// lesson — two absences in one day count once, the way the regulation counts. | ||
| 655 | +export type TermAbsence = { | ||
| 656 | + term: string; | ||
| 657 | + name: string; | ||
| 658 | + absent_days: number; | ||
| 659 | + excused_days: number; | ||
| 660 | + unexcused_days: number; | ||
| 661 | + limits: AbsenceLimits; | ||
| 662 | + over_limit: boolean; | ||
| 663 | +}; | ||
| 664 | + | ||
| 578 | export type AttendanceReport = { | 665 | export type AttendanceReport = { |
| 579 | user: string; | 666 | user: string; |
| 580 | events: AttendanceCounts; | 667 | events: AttendanceCounts; |
| 581 | sessions: AttendanceCounts; | 668 | sessions: AttendanceCounts; |
| 582 | courses: CourseAttendance[]; | 669 | courses: CourseAttendance[]; |
| 670 | + devamsizlik: TermAbsence[]; | ||
| 583 | }; | 671 | }; |
| 584 | 672 | ||
| 585 | export type WorkEntry = { | 673 | export type WorkEntry = { |
| @@ -678,6 +766,18 @@ export type SchoolSettings = { | |||
| 678 | meal_slots: MealSlot[]; | 766 | meal_slots: MealSlot[]; |
| 679 | dietary_tags: string[]; | 767 | dietary_tags: string[]; |
| 680 | meal_cancel_cutoff_minutes: number | null; | 768 | meal_cancel_cutoff_minutes: number | null; |
| 769 | + // The branş (teaching subject) vocabulary a profile's `branch` may name. | ||
| 770 | + // Empty = the school keeps no list, and no profile may carry one. | ||
| 771 | + branches: string[]; | ||
| 772 | + /** What an absence may be excused as (raporlu/izinli/…). Empty = none named. */ | ||
| 773 | + excuse_kinds: string[]; | ||
| 774 | + /** Per-dönem excused-absence day limit; null = no limit configured. */ | ||
| 775 | + max_excused_absent_days: number | null; | ||
| 776 | + /** Per-dönem unexcused-absence day limit; null = no limit configured. */ | ||
| 777 | + max_unexcused_absent_days: number | null; | ||
| 778 | + // The school's IANA timezone; null = the deployment default | ||
| 779 | + // (Europe/Istanbul). It is the zone devamsızlık days are bucketed in. | ||
| 780 | + timezone: string | null; | ||
| 681 | }; | 781 | }; |
| 682 | 782 | ||
| 683 | export type Limits = { | 783 | export type Limits = { |
| @@ -835,6 +935,25 @@ export type Limits = { | |||
| 835 | }; | 935 | }; |
| 836 | request: { max_page_limit: number; max_request_id_len: number; schedule_past_grace_ms: number; request_timeout_secs: number }; | 936 | request: { max_page_limit: number; max_request_id_len: number; schedule_past_grace_ms: number; request_timeout_secs: number }; |
| 837 | rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number }; | 937 | rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number }; |
| 938 | + // The RAG nest. Message length, thread titles, history depth and the thread | ||
| 939 | + // cap are the chatbot's own knobs, republished so a RAG client need not read | ||
| 940 | + // the chatbot group to bound its input. | ||
| 941 | + rag: { | ||
| 942 | + max_scope_pairs: number; | ||
| 943 | + max_citations: number; | ||
| 944 | + max_citation_pages: number; | ||
| 945 | + max_message_len: number; | ||
| 946 | + max_thread_title_len: number; | ||
| 947 | + min_max_message_len: number; | ||
| 948 | + max_max_message_len: number; | ||
| 949 | + default_max_message_len: number; | ||
| 950 | + min_history_turns: number; | ||
| 951 | + max_history_turns: number; | ||
| 952 | + default_history_turns: number; | ||
| 953 | + min_max_threads: number; | ||
| 954 | + max_max_threads: number; | ||
| 955 | + default_max_threads: number; | ||
| 956 | + }; | ||
| 838 | }; | 957 | }; |
| 839 | 958 | ||
| 840 | // Fallbacks keep forms usable when the unauthenticated metadata request fails. | 959 | // Fallbacks keep forms usable when the unauthenticated metadata request fails. |
| @@ -861,7 +980,7 @@ export type Message = { | |||
| 861 | 980 | ||
| 862 | export type Homework = { | 981 | export type Homework = { |
| 863 | id: string; | 982 | id: string; |
| 864 | - course: string; | 983 | + class_course: string; |
| 865 | subject: string; | 984 | subject: string; |
| 866 | title: string; | 985 | title: string; |
| 867 | description: string | null; | 986 | description: string | null; |
| @@ -909,7 +1028,7 @@ export type HomeworkRosterEntry = { | |||
| 909 | }; | 1028 | }; |
| 910 | 1029 | ||
| 911 | export type HomeworkReportEntry = { | 1030 | export type HomeworkReportEntry = { |
| 912 | - course: string; | 1031 | + class_course: string; |
| 913 | homework: string; | 1032 | homework: string; |
| 914 | title: string; | 1033 | title: string; |
| 915 | subject: string; | 1034 | subject: string; |
| @@ -983,3 +1102,86 @@ export type MealLedgerEntry = { | |||
| 983 | recorded_by: PersonRef; | 1102 | recorded_by: PersonRef; |
| 984 | created_at: number; | 1103 | created_at: number; |
| 985 | }; | 1104 | }; |
| 1105 | + | ||
| 1106 | +// One instance's line on a karne: the dönem average, its band label, and the | ||
| 1107 | +// ders_saati it weighs into the year average with. | ||
| 1108 | +export type KarneInstance = { | ||
| 1109 | + class_course: string; | ||
| 1110 | + /** The catalog course's title — what a family reads. */ | ||
| 1111 | + course: string; | ||
| 1112 | + ders_saati: number; | ||
| 1113 | + average: number | null; | ||
| 1114 | + band: string | null; | ||
| 1115 | +}; | ||
| 1116 | + | ||
| 1117 | +// A student's karne for one dönem. An archived dönem serves the snapshot the | ||
| 1118 | +// school froze when it closed; an open one computes live. | ||
| 1119 | +export type KarneReport = { | ||
| 1120 | + user: string; | ||
| 1121 | + term: string; | ||
| 1122 | + instances: KarneInstance[]; | ||
| 1123 | + /** The ders_saati-weighted average; null while nothing is graded. */ | ||
| 1124 | + year_average: number | null; | ||
| 1125 | + /** `gecti` / `kaldi`, or null with no average or no passing floor. */ | ||
| 1126 | + verdict: string | null; | ||
| 1127 | +}; | ||
| 1128 | + | ||
| 1129 | +/** One instance an exam is announced to beyond the one that owns it. */ | ||
| 1130 | +export type ExamAudience = { | ||
| 1131 | + instance: string; | ||
| 1132 | + class: string; | ||
| 1133 | + course: string; | ||
| 1134 | +}; | ||
| 1135 | + | ||
| 1136 | +export type RagThread = { | ||
| 1137 | + id: string; | ||
| 1138 | + title: string | null; | ||
| 1139 | + created_at: number; | ||
| 1140 | + updated_at: number; | ||
| 1141 | +}; | ||
| 1142 | + | ||
| 1143 | +export type RagMessageStatus = "pending" | "complete" | "failed"; | ||
| 1144 | + | ||
| 1145 | +// One citation behind a RAG answer. `[N]` in the answer's content resolves to | ||
| 1146 | +// the citation whose `n` is N. `file` is null when no file the asker may view | ||
| 1147 | +// claims the document — citable, just not openable. | ||
| 1148 | +export type RagCitation = { | ||
| 1149 | + n: number; | ||
| 1150 | + pages: number[]; | ||
| 1151 | + span_ids: string[]; | ||
| 1152 | + ders?: string | null; | ||
| 1153 | + file?: string | null; | ||
| 1154 | +}; | ||
| 1155 | + | ||
| 1156 | +export type RagMessage = { | ||
| 1157 | + id: string; | ||
| 1158 | + thread_id: string; | ||
| 1159 | + role: "user" | "assistant" | string; | ||
| 1160 | + status: RagMessageStatus | string; | ||
| 1161 | + /** Empty while `status` is `pending`. */ | ||
| 1162 | + content: string; | ||
| 1163 | + /** True when the service declined to answer — a complete turn, not a failure. */ | ||
| 1164 | + abstained: boolean; | ||
| 1165 | + /** The abstention's short machine code; "" on an ordinary answer. */ | ||
| 1166 | + reason: string; | ||
| 1167 | + citations: RagCitation[]; | ||
| 1168 | + created_at: number; | ||
| 1169 | + completed_at?: number | null; | ||
| 1170 | + /** Set only when `status` is `failed`. Backend English — localize it. */ | ||
| 1171 | + error_code?: string | null; | ||
| 1172 | +}; | ||
| 1173 | + | ||
| 1174 | +/** One capability's live fleet on the AI bridge. */ | ||
| 1175 | +export type AiCapabilityWorkers = { | ||
| 1176 | + capability: string; | ||
| 1177 | + workers: number; | ||
| 1178 | + inflight: number; | ||
| 1179 | +}; | ||
| 1180 | + | ||
| 1181 | +// What the AI bridge can currently do. `enabled: false` is a discovery | ||
| 1182 | +// answer, not an error: the deployment simply runs no AI. | ||
| 1183 | +export type AiCapabilities = { | ||
| 1184 | + enabled: boolean; | ||
| 1185 | + protocol: string; | ||
| 1186 | + capabilities: AiCapabilityWorkers[]; | ||
| 1187 | +}; | ||
src/api/course-notes/index.tsmodified+1 -0
| @@ -10,3 +10,4 @@ export * from "./getCourseNoteFileUrl"; | |||
| 10 | export * from "./getCourseNoteFileBlob"; | 10 | export * from "./getCourseNoteFileBlob"; |
| 11 | export * from "./getCourseNoteRag"; | 11 | export * from "./getCourseNoteRag"; |
| 12 | export * from "./deleteCourseNoteRagOutput"; | 12 | export * from "./deleteCourseNoteRagOutput"; |
| 13 | +export * from "./postCourseNoteRagReindex"; | ||
src/api/course-notes/postCourseNoteRagReindex.tsadded+9 -0
| @@ -0,0 +1,9 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Re-index a course note now instead of waiting for its next write. 202 — | ||
| 5 | + * the work is queued, not done by the time this resolves. | ||
| 6 | + */ | ||
| 7 | +export function postCourseNoteRagReindex(noteId: string): Promise<void> { | ||
| 8 | + return client<void>(`/course-notes/${noteId}/rag/reindex`, { method: "POST" }); | ||
| 9 | +} | ||
src/api/courses/deleteCourseEnrollmentByUserId.tsdeleted+0 -10
| @@ -1,10 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | - | ||
| 3 | -export function deleteCourseEnrollmentByUserId( | ||
| 4 | - courseId: string, | ||
| 5 | - userId: string, | ||
| 6 | -): Promise<void> { | ||
| 7 | - return client<void>(`/courses/${courseId}/enrollments/${userId}`, { | ||
| 8 | - method: "DELETE", | ||
| 9 | - }); | ||
| 10 | -} | ||
src/api/courses/deleteCourseMemberByUserId.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** Exam results and badges are untouched — the membership is a door, not a record. */ | ||
| 4 | +export function deleteCourseMemberByUserId(courseId: string, userId: string): Promise<void> { | ||
| 5 | + return client<void>(`/courses/${courseId}/members/${userId}`, { method: "DELETE" }); | ||
| 6 | +} | ||
src/api/courses/deleteCourseTeacherByUserId.tsdeleted+0 -10
| @@ -1,10 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | - | ||
| 3 | -export function deleteCourseTeacherByUserId( | ||
| 4 | - courseId: string, | ||
| 5 | - userId: string, | ||
| 6 | -): Promise<void> { | ||
| 7 | - return client<void>(`/courses/${courseId}/teachers/${userId}`, { | ||
| 8 | - method: "DELETE", | ||
| 9 | - }); | ||
| 10 | -} | ||
src/api/courses/getCourseMembers.tsadded+16 -0
| @@ -0,0 +1,16 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 3 | +import type { CourseMembership } from "../client"; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * A club/etüt's own members — the school-scoped tier. An instance's roster is | ||
| 7 | + * `getInstanceEnrollments`. Requires teacher+ and catalog rights. | ||
| 8 | + */ | ||
| 9 | +export async function getCourseMembers( | ||
| 10 | + courseId: string, | ||
| 11 | + params?: PageParams, | ||
| 12 | + signal?: AbortSignal, | ||
| 13 | +): Promise<Page<CourseMembership>> { | ||
| 14 | + const data = await client<unknown>(`/courses/${courseId}/members${pageQuery(params)}`, { signal }); | ||
| 15 | + return normalizePage<CourseMembership>(data); | ||
| 16 | +} | ||
src/api/courses/index.tsmodified+3 -12
| @@ -3,17 +3,8 @@ export * from "./getCourseById"; | |||
| 3 | export * from "./postCourse"; | 3 | export * from "./postCourse"; |
| 4 | export * from "./patchCourseById"; | 4 | export * from "./patchCourseById"; |
| 5 | export * from "./deleteCourseById"; | 5 | export * from "./deleteCourseById"; |
| 6 | -export * from "./getCourseEnrollments"; | ||
| 7 | -export * from "./postCourseEnrollment"; | ||
| 8 | -export * from "./deleteCourseEnrollmentByUserId"; | ||
| 9 | -export * from "./getCourseSessions"; | ||
| 10 | -export * from "./postCourseSession"; | ||
| 11 | export * from "./getCourseSubjects"; | 6 | export * from "./getCourseSubjects"; |
| 12 | export * from "./postCourseSubject"; | 7 | export * from "./postCourseSubject"; |
| 13 | -export * from "./getCourseExams"; | 8 | +export * from "./getCourseMembers"; |
| 14 | -export * from "./postCourseExam"; | 9 | +export * from "./postCourseMember"; |
| 15 | -export * from "./postCourseTeacher"; | 10 | +export * from "./deleteCourseMemberByUserId"; |
| 16 | -export * from "./deleteCourseTeacherByUserId"; | ||
| 17 | -export * from "./getCourseHomework"; | ||
| 18 | -export * from "./postCourseHomework"; | ||
| 19 | - | ||
src/api/courses/patchCourseById.tsmodified+1 -3
| @@ -1,13 +1,11 @@ | |||
| 1 | import { client } from "../client"; | 1 | import { client } from "../client"; |
| 2 | import type { Course, CourseKind } from "../client"; | 2 | import type { Course, CourseKind } from "../client"; |
| 3 | 3 | ||
| 4 | -/** Omitted fields keep their value. Only `term_id`/`capacity` clear on explicit null. */ | 4 | +/** Omitted fields keep their value. Requires catalog rights: creator or manager+. */ |
| 5 | export type PatchCourseBody = { | 5 | export type PatchCourseBody = { |
| 6 | title?: string; | 6 | title?: string; |
| 7 | description?: string; | 7 | description?: string; |
| 8 | kind?: CourseKind; | 8 | kind?: CourseKind; |
| 9 | - term_id?: string | null; | ||
| 10 | - capacity?: number | null; | ||
| 11 | }; | 9 | }; |
| 12 | 10 | ||
| 13 | export function patchCourseById(id: string, body: PatchCourseBody): Promise<Course> { | 11 | export function patchCourseById(id: string, body: PatchCourseBody): Promise<Course> { |
src/api/courses/postCourse.tsmodified+4 -2
| @@ -1,12 +1,14 @@ | |||
| 1 | import { client } from "../client"; | 1 | import { client } from "../client"; |
| 2 | import type { Course, CourseKind } from "../client"; | 2 | import type { Course, CourseKind } from "../client"; |
| 3 | 3 | ||
| 4 | +/** | ||
| 5 | + * A catalog row teaches nobody by itself — a şube attaches it | ||
| 6 | + * (`postClassInstance`), which is what mints the instance students sit in. | ||
| 7 | + */ | ||
| 4 | export type PostCourseBody = { | 8 | export type PostCourseBody = { |
| 5 | title: string; | 9 | title: string; |
| 6 | description?: string | null; | 10 | description?: string | null; |
| 7 | kind?: CourseKind | null; | 11 | kind?: CourseKind | null; |
| 8 | - term_id?: string | null; | ||
| 9 | - capacity?: number | null; | ||
| 10 | }; | 12 | }; |
| 11 | 13 | ||
| 12 | export function postCourse(body: PostCourseBody): Promise<Course> { | 14 | export function postCourse(body: PostCourseBody): Promise<Course> { |
src/api/courses/postCourseEnrollment.tsdeleted+0 -12
| @@ -1,12 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import type { Enrollment } from "../client"; | ||
| 3 | - | ||
| 4 | -export function postCourseEnrollment( | ||
| 5 | - courseId: string, | ||
| 6 | - userId: string, | ||
| 7 | -): Promise<Enrollment> { | ||
| 8 | - return client<Enrollment>(`/courses/${courseId}/enrollments`, { | ||
| 9 | - method: "POST", | ||
| 10 | - body: { user_id: userId }, | ||
| 11 | - }); | ||
| 12 | -} | ||
src/api/courses/postCourseExam.tsdeleted+0 -23
| @@ -1,23 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import type { Exam } from "../client"; | ||
| 3 | - | ||
| 4 | -export type PostCourseExamBody = { | ||
| 5 | - title: string; | ||
| 6 | - description?: string | null; | ||
| 7 | - kind: string; | ||
| 8 | - mode?: string | null; | ||
| 9 | - starts_at?: number | null; | ||
| 10 | - ends_at?: number | null; | ||
| 11 | - duration_ms?: number | null; | ||
| 12 | - max_attempts?: number | null; | ||
| 13 | - allow_rejoin?: boolean | null; | ||
| 14 | - allow_review?: boolean | null; | ||
| 15 | - draft?: boolean | null; | ||
| 16 | -}; | ||
| 17 | - | ||
| 18 | -export function postCourseExam( | ||
| 19 | - courseId: string, | ||
| 20 | - body: PostCourseExamBody, | ||
| 21 | -): Promise<Exam> { | ||
| 22 | - return client<Exam>(`/courses/${courseId}/exams`, { method: "POST", body }); | ||
| 23 | -} | ||
src/api/courses/postCourseHomework.tsdeleted+0 -14
| @@ -1,14 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import type { Homework } from "../client"; | ||
| 3 | - | ||
| 4 | -export type PostCourseHomeworkBody = { | ||
| 5 | - title: string; | ||
| 6 | - description?: string | null; | ||
| 7 | - subject_id: string; | ||
| 8 | - due_at: number; | ||
| 9 | - assigned?: string[] | null; | ||
| 10 | -}; | ||
| 11 | - | ||
| 12 | -export function postCourseHomework(courseId: string, body: PostCourseHomeworkBody): Promise<Homework> { | ||
| 13 | - return client<Homework>(`/courses/${courseId}/homework`, { method: "POST", body }); | ||
| 14 | -} | ||
src/api/courses/postCourseMember.tsadded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { CourseMembership } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Only students, and only into a `study` (etüt) or `club` (kulüp): a regular | ||
| 6 | + * ders has no school-wide roster — its students come from the şube. | ||
| 7 | + */ | ||
| 8 | +export function postCourseMember(courseId: string, userId: string): Promise<CourseMembership> { | ||
| 9 | + return client<CourseMembership>(`/courses/${courseId}/members`, { | ||
| 10 | + method: "POST", | ||
| 11 | + body: { user_id: userId }, | ||
| 12 | + }); | ||
| 13 | +} | ||
src/api/courses/postCourseSession.tsdeleted+0 -13
| @@ -1,13 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import type { CourseSession } from "../client"; | ||
| 3 | - | ||
| 4 | -export type PostCourseSessionBody = { | ||
| 5 | - topic?: string | null; | ||
| 6 | - teacher_id?: string | null; | ||
| 7 | - starts_at: number; | ||
| 8 | - ends_at?: number | null; | ||
| 9 | -}; | ||
| 10 | - | ||
| 11 | -export function postCourseSession(courseId: string, body: PostCourseSessionBody): Promise<CourseSession> { | ||
| 12 | - return client<CourseSession>(`/courses/${courseId}/sessions`, { method: "POST", body }); | ||
| 13 | -} | ||
src/api/courses/postCourseTeacher.tsdeleted+0 -12
| @@ -1,12 +0,0 @@ | |||
| 1 | -import { client } from "../client"; | ||
| 2 | -import type { Course } from "../client"; | ||
| 3 | - | ||
| 4 | -export function postCourseTeacher( | ||
| 5 | - courseId: string, | ||
| 6 | - userId: string, | ||
| 7 | -): Promise<Course> { | ||
| 8 | - return client<Course>(`/courses/${courseId}/teachers`, { | ||
| 9 | - method: "POST", | ||
| 10 | - body: { user_id: userId }, | ||
| 11 | - }); | ||
| 12 | -} | ||
src/api/exams/deleteExamAudienceByInstanceId.tsadded+5 -0
| @@ -0,0 +1,5 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +export function deleteExamAudienceByInstanceId(examId: string, instanceId: string): Promise<void> { | ||
| 4 | + return client<void>(`/exams/${examId}/audience/${instanceId}`, { method: "DELETE" }); | ||
| 5 | +} | ||
src/api/exams/getExamAudience.tsadded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 3 | +import type { ExamAudience } from "../client"; | ||
| 4 | + | ||
| 5 | +/** The instances this exam is announced to beyond the one that owns it. */ | ||
| 6 | +export async function getExamAudience( | ||
| 7 | + examId: string, | ||
| 8 | + params?: PageParams, | ||
| 9 | + signal?: AbortSignal, | ||
| 10 | +): Promise<Page<ExamAudience>> { | ||
| 11 | + const data = await client<unknown>(`/exams/${examId}/audience${pageQuery(params)}`, { signal }); | ||
| 12 | + return normalizePage<ExamAudience>(data); | ||
| 13 | +} | ||
src/api/exams/index.tsmodified+3 -0
| @@ -39,3 +39,6 @@ export * from "./getStudentMarksHistory"; | |||
| 39 | export * from "./postExamQuestionFromBank"; | 39 | export * from "./postExamQuestionFromBank"; |
| 40 | export * from "./postExamQuestionRefreshFromBank"; | 40 | export * from "./postExamQuestionRefreshFromBank"; |
| 41 | export * from "./postExamQuestionToBank"; | 41 | export * from "./postExamQuestionToBank"; |
| 42 | +export * from "./getExamAudience"; | ||
| 43 | +export * from "./postExamAudience"; | ||
| 44 | +export * from "./deleteExamAudienceByInstanceId"; | ||
src/api/exams/postExamAudience.tsadded+14 -0
| @@ -0,0 +1,14 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { ExamAudience } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Announce the exam to another instance. It must teach the exam's own catalog | ||
| 6 | + * course, sit under the same academic year, and be a different instance — the | ||
| 7 | + * owner is refused with a 400. | ||
| 8 | + */ | ||
| 9 | +export function postExamAudience(examId: string, instanceId: string): Promise<ExamAudience> { | ||
| 10 | + return client<ExamAudience>(`/exams/${examId}/audience`, { | ||
| 11 | + method: "POST", | ||
| 12 | + body: { instance: instanceId }, | ||
| 13 | + }); | ||
| 14 | +} | ||
src/api/instances/deleteInstanceEnrollmentByUserId.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** Existing exam results are kept — they leave the marks report until re-enrolled. */ | ||
| 4 | +export function deleteInstanceEnrollmentByUserId(instanceId: string, userId: string): Promise<void> { | ||
| 5 | + return client<void>(`/instances/${instanceId}/enrollments/${userId}`, { method: "DELETE" }); | ||
| 6 | +} | ||
src/api/instances/deleteInstanceTeacherByUserId.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** Manager+ only. The instance, its exams, sessions and roster are untouched. */ | ||
| 4 | +export function deleteInstanceTeacherByUserId(instanceId: string, userId: string): Promise<void> { | ||
| 5 | + return client<void>(`/instances/${instanceId}/teachers/${userId}`, { method: "DELETE" }); | ||
| 6 | +} | ||
src/api/instances/getInstanceById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { Instance } from "../client"; | ||
| 3 | + | ||
| 4 | +export function getInstanceById(id: string, signal?: AbortSignal): Promise<Instance> { | ||
| 5 | + return client<Instance>(`/instances/${id}`, { signal }); | ||
| 6 | +} | ||
src/api/courses/getCourseEnrollments.ts → src/api/instances/getInstanceEnrollments.tsrenamed+3 -3
| @@ -2,11 +2,11 @@ import { client } from "../client"; | |||
| 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; |
| 3 | import type { Enrollment } from "../client"; | 3 | import type { Enrollment } from "../client"; |
| 4 | 4 | ||
| 5 | -export async function getCourseEnrollments( | 5 | +export async function getInstanceEnrollments( |
| 6 | - courseId: string, | 6 | + instanceId: string, |
| 7 | params?: PageParams, | 7 | params?: PageParams, |
| 8 | signal?: AbortSignal, | 8 | signal?: AbortSignal, |
| 9 | ): Promise<Page<Enrollment>> { | 9 | ): Promise<Page<Enrollment>> { |
| 10 | - const data = await client<unknown>(`/courses/${courseId}/enrollments${pageQuery(params)}`, { signal }); | 10 | + const data = await client<unknown>(`/instances/${instanceId}/enrollments${pageQuery(params)}`, { signal }); |
| 11 | return normalizePage<Enrollment>(data); | 11 | return normalizePage<Enrollment>(data); |
| 12 | } | 12 | } |
src/api/courses/getCourseExams.ts → src/api/instances/getInstanceExams.tsrenamed+4 -3
| @@ -2,11 +2,12 @@ import { client } from "../client"; | |||
| 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; |
| 3 | import type { Exam } from "../client"; | 3 | import type { Exam } from "../client"; |
| 4 | 4 | ||
| 5 | -export async function getCourseExams( | 5 | +/** Drafts appear only to the instance's managers. */ |
| 6 | - courseId: string, | 6 | +export async function getInstanceExams( |
| 7 | + instanceId: string, | ||
| 7 | params?: PageParams, | 8 | params?: PageParams, |
| 8 | signal?: AbortSignal, | 9 | signal?: AbortSignal, |
| 9 | ): Promise<Page<Exam>> { | 10 | ): Promise<Page<Exam>> { |
| 10 | - const data = await client<unknown>(`/courses/${courseId}/exams${pageQuery(params)}`, { signal }); | 11 | + const data = await client<unknown>(`/instances/${instanceId}/exams${pageQuery(params)}`, { signal }); |
| 11 | return normalizePage<Exam>(data); | 12 | return normalizePage<Exam>(data); |
| 12 | } | 13 | } |
src/api/courses/getCourseHomework.ts → src/api/instances/getInstanceHomework.tsrenamed+4 -3
| @@ -2,11 +2,12 @@ import { client } from "../client"; | |||
| 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; |
| 3 | import type { Homework } from "../client"; | 3 | import type { Homework } from "../client"; |
| 4 | 4 | ||
| 5 | -export async function getCourseHomework( | 5 | +/** A student sees only the homework they are assigned, `assigned` narrowed to themselves. */ |
| 6 | - courseId: string, | 6 | +export async function getInstanceHomework( |
| 7 | + instanceId: string, | ||
| 7 | params?: PageParams, | 8 | params?: PageParams, |
| 8 | signal?: AbortSignal, | 9 | signal?: AbortSignal, |
| 9 | ): Promise<Page<Homework>> { | 10 | ): Promise<Page<Homework>> { |
| 10 | - const data = await client<unknown>(`/courses/${courseId}/homework${pageQuery(params)}`, { signal }); | 11 | + const data = await client<unknown>(`/instances/${instanceId}/homework${pageQuery(params)}`, { signal }); |
| 11 | return normalizePage<Homework>(data); | 12 | return normalizePage<Homework>(data); |
| 12 | } | 13 | } |
src/api/courses/getCourseSessions.ts → src/api/instances/getInstanceSessions.tsrenamed+3 -3
| @@ -2,11 +2,11 @@ import { client } from "../client"; | |||
| 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | 2 | import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; |
| 3 | import type { CourseSession } from "../client"; | 3 | import type { CourseSession } from "../client"; |
| 4 | 4 | ||
| 5 | -export async function getCourseSessions( | 5 | +export async function getInstanceSessions( |
| 6 | - courseId: string, | 6 | + instanceId: string, |
| 7 | params?: PageParams, | 7 | params?: PageParams, |
| 8 | signal?: AbortSignal, | 8 | signal?: AbortSignal, |
| 9 | ): Promise<Page<CourseSession>> { | 9 | ): Promise<Page<CourseSession>> { |
| 10 | - const data = await client<unknown>(`/courses/${courseId}/sessions${pageQuery(params)}`, { signal }); | 10 | + const data = await client<unknown>(`/instances/${instanceId}/sessions${pageQuery(params)}`, { signal }); |
| 11 | return normalizePage<CourseSession>(data); | 11 | return normalizePage<CourseSession>(data); |
| 12 | } | 12 | } |
src/api/instances/getMyInstances.tsadded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 3 | +import type { Instance } from "../client"; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * The instances the caller may act in or see: a student's şube memberships, a | ||
| 7 | + * homeroom teacher's, plus the instances a teacher was assigned to run. One | ||
| 8 | + * rule for what is "theirs", shared with every instance-scoped gate. | ||
| 9 | + */ | ||
| 10 | +export async function getMyInstances(params?: PageParams, signal?: AbortSignal): Promise<Page<Instance>> { | ||
| 11 | + const data = await client<unknown>(`/instances/me${pageQuery(params)}`, { signal }); | ||
| 12 | + return normalizePage<Instance>(data); | ||
| 13 | +} | ||
src/api/instances/index.tsadded+14 -0
| @@ -0,0 +1,14 @@ | |||
| 1 | +export * from "./getMyInstances"; | ||
| 2 | +export * from "./getInstanceById"; | ||
| 3 | +export * from "./patchInstanceById"; | ||
| 4 | +export * from "./getInstanceEnrollments"; | ||
| 5 | +export * from "./postInstanceEnrollment"; | ||
| 6 | +export * from "./deleteInstanceEnrollmentByUserId"; | ||
| 7 | +export * from "./getInstanceExams"; | ||
| 8 | +export * from "./postInstanceExam"; | ||
| 9 | +export * from "./getInstanceHomework"; | ||
| 10 | +export * from "./postInstanceHomework"; | ||
| 11 | +export * from "./getInstanceSessions"; | ||
| 12 | +export * from "./postInstanceSession"; | ||
| 13 | +export * from "./postInstanceTeacher"; | ||
| 14 | +export * from "./deleteInstanceTeacherByUserId"; | ||
src/api/instances/patchInstanceById.tsadded+12 -0
| @@ -0,0 +1,12 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { Instance } from "../client"; | ||
| 3 | + | ||
| 4 | +/** Both fields are non-clearable: omit to keep, never send null. */ | ||
| 5 | +export type PatchInstanceBody = { | ||
| 6 | + ders_saati?: number; | ||
| 7 | + counts_toward_karne?: boolean; | ||
| 8 | +}; | ||
| 9 | + | ||
| 10 | +export function patchInstanceById(id: string, body: PatchInstanceBody): Promise<Instance> { | ||
| 11 | + return client<Instance>(`/instances/${id}`, { method: "PATCH", body }); | ||
| 12 | +} | ||
src/api/instances/postInstanceEnrollment.tsadded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { Enrollment } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Idempotent upsert; students only. The row is hand-placed (`source` null), so | ||
| 6 | + * no şube sweep takes it back. | ||
| 7 | + */ | ||
| 8 | +export function postInstanceEnrollment(instanceId: string, userId: string): Promise<Enrollment> { | ||
| 9 | + return client<Enrollment>(`/instances/${instanceId}/enrollments`, { | ||
| 10 | + method: "POST", | ||
| 11 | + body: { user_id: userId }, | ||
| 12 | + }); | ||
| 13 | +} | ||
src/api/instances/postInstanceExam.tsadded+26 -0
| @@ -0,0 +1,26 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { Exam } from "../client"; | ||
| 3 | + | ||
| 4 | +export type PostInstanceExamBody = { | ||
| 5 | + title: string; | ||
| 6 | + description?: string | null; | ||
| 7 | + kind: string; | ||
| 8 | + /** The dönem the exam is filed in — its marks count into that term's karne. */ | ||
| 9 | + term: string; | ||
| 10 | + /** Omit for an offline-graded exam nobody can sit. */ | ||
| 11 | + mode?: string | null; | ||
| 12 | + starts_at?: number | null; | ||
| 13 | + ends_at?: number | null; | ||
| 14 | + duration_ms?: number | null; | ||
| 15 | + /** Default 1; `0` = unlimited retakes. */ | ||
| 16 | + max_attempts?: number | null; | ||
| 17 | + allow_rejoin?: boolean | null; | ||
| 18 | + allow_review?: boolean | null; | ||
| 19 | + /** Keeps the exam private to the instance's managers until published. */ | ||
| 20 | + draft?: boolean | null; | ||
| 21 | +}; | ||
| 22 | + | ||
| 23 | +/** Only a class-delivered course (`kind` `course`) carries exams. */ | ||
| 24 | +export function postInstanceExam(instanceId: string, body: PostInstanceExamBody): Promise<Exam> { | ||
| 25 | + return client<Exam>(`/instances/${instanceId}/exams`, { method: "POST", body }); | ||
| 26 | +} | ||
src/api/instances/postInstanceHomework.tsadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { Homework } from "../client"; | ||
| 3 | + | ||
| 4 | +export type PostInstanceHomeworkBody = { | ||
| 5 | + title: string; | ||
| 6 | + description?: string | null; | ||
| 7 | + /** One of the catalog course's subjects — required. */ | ||
| 8 | + subject_id: string; | ||
| 9 | + /** Required and must be in the future. */ | ||
| 10 | + due_at: number; | ||
| 11 | + /** Omit, null or [] assigns the whole enrolled roster; a subset caps at 200. */ | ||
| 12 | + assigned?: string[] | null; | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +export function postInstanceHomework(instanceId: string, body: PostInstanceHomeworkBody): Promise<Homework> { | ||
| 16 | + return client<Homework>(`/instances/${instanceId}/homework`, { method: "POST", body }); | ||
| 17 | +} | ||
src/api/instances/postInstanceSession.tsadded+14 -0
| @@ -0,0 +1,14 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { CourseSession } from "../client"; | ||
| 3 | + | ||
| 4 | +export type PostInstanceSessionBody = { | ||
| 5 | + topic?: string | null; | ||
| 6 | + /** Defaults to the caller; must hold `teacher` or higher. */ | ||
| 7 | + teacher_id?: string | null; | ||
| 8 | + starts_at: number; | ||
| 9 | + ends_at?: number | null; | ||
| 10 | +}; | ||
| 11 | + | ||
| 12 | +export function postInstanceSession(instanceId: string, body: PostInstanceSessionBody): Promise<CourseSession> { | ||
| 13 | + return client<CourseSession>(`/instances/${instanceId}/sessions`, { method: "POST", body }); | ||
| 14 | +} | ||
src/api/instances/postInstanceTeacher.tsadded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { Instance } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Manager+ only — staffing is the office's call. The assignee gets full | ||
| 6 | + * management of the instance but no catalog rights over the course itself. | ||
| 7 | + */ | ||
| 8 | +export function postInstanceTeacher(instanceId: string, userId: string): Promise<Instance> { | ||
| 9 | + return client<Instance>(`/instances/${instanceId}/teachers`, { | ||
| 10 | + method: "POST", | ||
| 11 | + body: { user_id: userId }, | ||
| 12 | + }); | ||
| 13 | +} | ||
src/api/rag/deleteRagThreadById.tsadded+5 -0
| @@ -0,0 +1,5 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +export function deleteRagThreadById(threadId: string): Promise<void> { | ||
| 4 | + return client<void>(`/rag/threads/${encodeURIComponent(threadId)}`, { method: "DELETE" }); | ||
| 5 | +} | ||
src/api/rag/getRagMessageById.tsadded+8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { RagMessage } from "../client"; | ||
| 3 | + | ||
| 4 | +/** Poll this while a turn is `pending`, or open its stream instead. */ | ||
| 5 | +export function getRagMessageById(threadId: string, messageId: string, signal?: AbortSignal): Promise<RagMessage> { | ||
| 6 | + const url = `/rag/threads/${encodeURIComponent(threadId)}/messages/${encodeURIComponent(messageId)}`; | ||
| 7 | + return client<RagMessage>(url, { signal }); | ||
| 8 | +} | ||
src/api/rag/getRagThreadMessages.tsadded+11 -0
| @@ -0,0 +1,11 @@ | |||
| 1 | +import { client, normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 2 | +import type { RagMessage } from "../client"; | ||
| 3 | + | ||
| 4 | +export async function getRagThreadMessages( | ||
| 5 | + threadId: string, | ||
| 6 | + params?: PageParams, | ||
| 7 | + signal?: AbortSignal, | ||
| 8 | +): Promise<Page<RagMessage>> { | ||
| 9 | + const url = `/rag/threads/${encodeURIComponent(threadId)}/messages${pageQuery(params)}`; | ||
| 10 | + return normalizePage<RagMessage>(await client<unknown>(url, { signal })); | ||
| 11 | +} | ||
src/api/rag/getRagThreads.tsadded+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | +import { client, normalizePage, pageQuery, type Page, type PageParams } from "../client"; | ||
| 2 | +import type { RagThread } from "../client"; | ||
| 3 | + | ||
| 4 | +/** Sorted by `updated_at`, so the thread just written to is always first. */ | ||
| 5 | +export async function getRagThreads(params?: PageParams, signal?: AbortSignal): Promise<Page<RagThread>> { | ||
| 6 | + return normalizePage<RagThread>(await client<unknown>(`/rag/threads${pageQuery(params)}`, { signal })); | ||
| 7 | +} | ||
src/api/rag/index.tsadded+8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | +export * from "./getRagThreads"; | ||
| 2 | +export * from "./postRagThread"; | ||
| 3 | +export * from "./patchRagThreadById"; | ||
| 4 | +export * from "./deleteRagThreadById"; | ||
| 5 | +export * from "./getRagThreadMessages"; | ||
| 6 | +export * from "./getRagMessageById"; | ||
| 7 | +export * from "./postRagMessage"; | ||
| 8 | +export * from "./ragStreamUrl"; | ||
src/api/rag/patchRagThreadById.tsadded+10 -0
| @@ -0,0 +1,10 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { RagThread } from "../client"; | ||
| 3 | + | ||
| 4 | +/** `null` — or blank — clears the title back to untitled. */ | ||
| 5 | +export function patchRagThreadById(threadId: string, title: string | null): Promise<RagThread> { | ||
| 6 | + return client<RagThread>(`/rag/threads/${encodeURIComponent(threadId)}`, { | ||
| 7 | + method: "PATCH", | ||
| 8 | + body: { title }, | ||
| 9 | + }); | ||
| 10 | +} | ||
src/api/rag/postRagMessage.tsadded+18 -0
| @@ -0,0 +1,18 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | + | ||
| 3 | +/** The receipt for an accepted turn — the answer is not here yet. */ | ||
| 4 | +export type AcceptedRagMessage = { | ||
| 5 | + message_id: string; | ||
| 6 | + status: "pending"; | ||
| 7 | +}; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 202. The live message-length cap is the school's `max_chatbot_message_len` | ||
| 11 | + * (`GET /settings`), the same knob the chatbot nest uses. | ||
| 12 | + */ | ||
| 13 | +export function postRagMessage(threadId: string, content: string): Promise<AcceptedRagMessage> { | ||
| 14 | + return client<AcceptedRagMessage>(`/rag/threads/${encodeURIComponent(threadId)}/messages`, { | ||
| 15 | + method: "POST", | ||
| 16 | + body: { content }, | ||
| 17 | + }); | ||
| 18 | +} | ||
src/api/rag/postRagThread.tsadded+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { RagThread } from "../client"; | ||
| 3 | + | ||
| 4 | +/** Blank counts as absent — an untitled thread is normal, labelled from its first turn. */ | ||
| 5 | +export function postRagThread(title?: string | null): Promise<RagThread> { | ||
| 6 | + return client<RagThread>("/rag/threads", { method: "POST", body: { title: title ?? null } }); | ||
| 7 | +} | ||
src/api/rag/ragStreamUrl.tsadded+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | +/** | ||
| 2 | + * The SSE URL for one pending turn. Not a request — hand it to an | ||
| 3 | + * `EventSource` (`withCredentials: true`), the way the çelebi panel does. | ||
| 4 | + */ | ||
| 5 | +export function ragStreamUrl(threadId: string, messageId: string): string { | ||
| 6 | + return `/api/rag/threads/${encodeURIComponent(threadId)}/messages/${encodeURIComponent(messageId)}/stream`; | ||
| 7 | +} | ||
src/api/reports/getMyKarne.tsadded+11 -0
| @@ -0,0 +1,11 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { KarneReport } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * The caller's karne for one dönem. Omit `term` for the newest one. An | ||
| 6 | + * archived dönem serves the snapshot the school froze when it closed. | ||
| 7 | + */ | ||
| 8 | +export function getMyKarne(term?: string, signal?: AbortSignal): Promise<KarneReport> { | ||
| 9 | + const query = term ? `?term=${encodeURIComponent(term)}` : ""; | ||
| 10 | + return client<KarneReport>(`/marks/karne${query}`, { signal }); | ||
| 11 | +} | ||
src/api/reports/getUserKarne.tsadded+12 -0
| @@ -0,0 +1,12 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { KarneReport } from "../client"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Another user's karne. Requires teacher+, or a parent tied to the student. | ||
| 6 | + * An exactly-teacher caller sees only the lines of the instances they run, | ||
| 7 | + * with the average recomputed over those and no verdict. | ||
| 8 | + */ | ||
| 9 | +export function getUserKarne(userId: string, term?: string, signal?: AbortSignal): Promise<KarneReport> { | ||
| 10 | + const query = term ? `?term=${encodeURIComponent(term)}` : ""; | ||
| 11 | + return client<KarneReport>(`/marks/karne/${userId}${query}`, { signal }); | ||
| 12 | +} | ||
src/api/reports/index.tsmodified+2 -0
| @@ -3,3 +3,5 @@ export * from "./getMyAttendance"; | |||
| 3 | export * from "./getMyMarks"; | 3 | export * from "./getMyMarks"; |
| 4 | export * from "./getUserAttendance"; | 4 | export * from "./getUserAttendance"; |
| 5 | export * from "./getUserMarks"; | 5 | export * from "./getUserMarks"; |
| 6 | +export * from "./getMyKarne"; | ||
| 7 | +export * from "./getUserKarne"; | ||
src/api/settings/patchSettings.tsmodified+9 -0
| @@ -13,6 +13,15 @@ export type PatchSettingsBody = { | |||
| 13 | meal_slots?: MealSlot[]; | 13 | meal_slots?: MealSlot[]; |
| 14 | dietary_tags?: string[]; | 14 | dietary_tags?: string[]; |
| 15 | meal_cancel_cutoff_minutes?: number | null; | 15 | meal_cancel_cutoff_minutes?: number | null; |
| 16 | + /** What an absence may be excused as (raporlu/izinli/…). */ | ||
| 17 | + excuse_kinds?: string[]; | ||
| 18 | + /** The branş vocabulary a profile's `branch` may name. */ | ||
| 19 | + branches?: string[]; | ||
| 20 | + /** Per-dönem day limits; null clears the limit. */ | ||
| 21 | + max_excused_absent_days?: number | null; | ||
| 22 | + max_unexcused_absent_days?: number | null; | ||
| 23 | + /** IANA timezone the devamsızlık days are bucketed in; null = deployment default. */ | ||
| 24 | + timezone?: string | null; | ||
| 16 | }; | 25 | }; |
| 17 | 26 | ||
| 18 | export function patchSettings(body: PatchSettingsBody): Promise<SchoolSettings> { | 27 | export function patchSettings(body: PatchSettingsBody): Promise<SchoolSettings> { |
src/api/terms/postTerm.tsmodified+2 -0
| @@ -3,6 +3,8 @@ import type { Term } from "../client"; | |||
| 3 | 3 | ||
| 4 | export type PostTermBody = { | 4 | export type PostTermBody = { |
| 5 | name: string; | 5 | name: string; |
| 6 | + /** The academic year the dönem sits in; an archived year refuses it (409). */ | ||
| 7 | + year: string; | ||
| 6 | starts_at: number; | 8 | starts_at: number; |
| 7 | ends_at: number; | 9 | ends_at: number; |
| 8 | }; | 10 | }; |
src/components/attendance/attendance-report-view.tsxmodified+42 -0
| @@ -133,6 +133,48 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? | |||
| 133 | </For> | 133 | </For> |
| 134 | </div> | 134 | </div> |
| 135 | 135 | ||
| 136 | + {/* Devamsızlık is counted in *days*, not marks: two absences in one | ||
| 137 | + calendar day count once, which is what the regulation counts. */} | ||
| 138 | + <Show when={(props.report.devamsizlik ?? []).length > 0}> | ||
| 139 | + <section class="rounded-lg border border-border bg-card p-4 shadow-xs"> | ||
| 140 | + <h3 class="text-base font-semibold">{t("attendance.devamsizlik")}</h3> | ||
| 141 | + <div class="mt-3 grid gap-2 sm:grid-cols-2"> | ||
| 142 | + <For each={props.report.devamsizlik ?? []}> | ||
| 143 | + {(term) => ( | ||
| 144 | + <article class="rounded-xl border border-border-line p-3"> | ||
| 145 | + <header class="flex flex-wrap items-center justify-between gap-2"> | ||
| 146 | + <p class="min-w-0 truncate text-sm font-medium">{term.name}</p> | ||
| 147 | + <Show when={term.over_limit}> | ||
| 148 | + <Badge variant="destructive" class="rounded-full text-[11px]">{t("attendance.overLimit")}</Badge> | ||
| 149 | + </Show> | ||
| 150 | + </header> | ||
| 151 | + <dl class="mt-2 grid grid-cols-2 gap-2"> | ||
| 152 | + <div class="rounded-lg border border-border-line p-2"> | ||
| 153 | + <dt class="text-[11px] text-muted-foreground">{t("attendance.unexcusedDays")}</dt> | ||
| 154 | + <dd class="mt-0.5 text-lg font-semibold tabular-nums"> | ||
| 155 | + {term.unexcused_days} | ||
| 156 | + <Show when={term.limits.max_unexcused_days != null}> | ||
| 157 | + <span class="ml-1 text-xs font-normal text-muted-foreground">/ {term.limits.max_unexcused_days}</span> | ||
| 158 | + </Show> | ||
| 159 | + </dd> | ||
| 160 | + </div> | ||
| 161 | + <div class="rounded-lg border border-border-line p-2"> | ||
| 162 | + <dt class="text-[11px] text-muted-foreground">{t("attendance.excusedDays")}</dt> | ||
| 163 | + <dd class="mt-0.5 text-lg font-semibold tabular-nums"> | ||
| 164 | + {term.excused_days} | ||
| 165 | + <Show when={term.limits.max_excused_days != null}> | ||
| 166 | + <span class="ml-1 text-xs font-normal text-muted-foreground">/ {term.limits.max_excused_days}</span> | ||
| 167 | + </Show> | ||
| 168 | + </dd> | ||
| 169 | + </div> | ||
| 170 | + </dl> | ||
| 171 | + </article> | ||
| 172 | + )} | ||
| 173 | + </For> | ||
| 174 | + </div> | ||
| 175 | + </section> | ||
| 176 | + </Show> | ||
| 177 | + | ||
| 136 | <section class="rounded-lg border border-border bg-card p-4 shadow-xs"> | 178 | <section class="rounded-lg border border-border bg-card p-4 shadow-xs"> |
| 137 | <h3 class="text-base font-semibold">{t("attendance.courseBreakdown")}</h3> | 179 | <h3 class="text-base font-semibold">{t("attendance.courseBreakdown")}</h3> |
| 138 | <div class="mt-3"> | 180 | <div class="mt-3"> |
src/components/courses/course-card.tsxmodified+9 -8
| @@ -12,12 +12,12 @@ const courseInitials = (title: string) => | |||
| 12 | 12 | ||
| 13 | export function CourseCard(props: { | 13 | export function CourseCard(props: { |
| 14 | course: Course; | 14 | course: Course; |
| 15 | - term: string; | 15 | + /** The şubeler line under the title: "3 sections", or a dash. */ |
| 16 | + sections: string; | ||
| 16 | enrolled?: boolean; | 17 | enrolled?: boolean; |
| 17 | showTeacherActions?: boolean; | 18 | showTeacherActions?: boolean; |
| 18 | labels: { | 19 | labels: { |
| 19 | - capacity: string; | 20 | + taughtIn: string; |
| 20 | - unlimited: string; | ||
| 21 | enrolled: string; | 21 | enrolled: string; |
| 22 | kind: string; | 22 | kind: string; |
| 23 | weeklyHours: string; | 23 | weeklyHours: string; |
| @@ -28,8 +28,9 @@ export function CourseCard(props: { | |||
| 28 | analysis: string; | 28 | analysis: string; |
| 29 | }; | 29 | }; |
| 30 | }) { | 30 | }) { |
| 31 | - const teachers = () => [props.course.creator, ...(props.course.teachers ?? [])] | 31 | + // Teaching staff is per instance now, so a catalog card can only name the |
| 32 | - .filter((person, index, all) => all.findIndex((row) => row.id === person.id) === index); | 32 | + // course's owner — the şube pages name who actually teaches it. |
| 33 | + const teachers = () => [props.course.creator]; | ||
| 33 | 34 | ||
| 34 | return ( | 35 | return ( |
| 35 | <Link | 36 | <Link |
| @@ -56,7 +57,7 @@ export function CourseCard(props: { | |||
| 56 | <p class="line-clamp-2 min-h-8 text-sm text-text-subtle">{props.course.description || "—"}</p> | 57 | <p class="line-clamp-2 min-h-8 text-sm text-text-subtle">{props.course.description || "—"}</p> |
| 57 | 58 | ||
| 58 | <div class="mt-auto flex items-center justify-between gap-3 border-t border-border-hairline pt-3 text-xs text-text-subtle"> | 59 | <div class="mt-auto flex items-center justify-between gap-3 border-t border-border-hairline pt-3 text-xs text-text-subtle"> |
| 59 | - <span class="min-w-0 flex-1 truncate">{props.term}</span> | 60 | + <span class="min-w-0 flex-1 truncate">{props.sections}</span> |
| 60 | <span class="flex min-w-0 items-center gap-1.5"> | 61 | <span class="flex min-w-0 items-center gap-1.5"> |
| 61 | <IconUsers class="h-3.5 w-3.5 shrink-0" /> | 62 | <IconUsers class="h-3.5 w-3.5 shrink-0" /> |
| 62 | <span class="max-w-32 truncate">{teachers().map(personLabel).join(", ")}</span> | 63 | <span class="max-w-32 truncate">{teachers().map(personLabel).join(", ")}</span> |
| @@ -65,8 +66,8 @@ export function CourseCard(props: { | |||
| 65 | 66 | ||
| 66 | <div class="flex items-center gap-2 rounded-lg bg-surface-tint px-3 py-2 text-xs text-text-subtle"> | 67 | <div class="flex items-center gap-2 rounded-lg bg-surface-tint px-3 py-2 text-xs text-text-subtle"> |
| 67 | <IconBook class="h-3.5 w-3.5 shrink-0" /> | 68 | <IconBook class="h-3.5 w-3.5 shrink-0" /> |
| 68 | - <span class="font-medium text-text-default">{props.labels.capacity}:</span> | 69 | + <span class="font-medium text-text-default">{props.labels.taughtIn}:</span> |
| 69 | - <span class="tabular-nums">{props.course.capacity ?? props.labels.unlimited}</span> | 70 | + <span class="tabular-nums">{props.course.class_course_count}</span> |
| 70 | </div> | 71 | </div> |
| 71 | 72 | ||
| 72 | <div class="flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border-hairline px-3 py-2"> | 73 | <div class="flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border-hairline px-3 py-2"> |
src/components/courses/course-teachers-panel.tsxmodified+9 -7
| @@ -1,6 +1,6 @@ | |||
| 1 | import { Show, createMemo, createSignal } from "solid-js"; | 1 | import { Show, createMemo, createSignal } from "solid-js"; |
| 2 | import type { ColumnDef } from "@tanstack/solid-table"; | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | -import { deleteCourseTeacherByUserId, postCourseTeacher } from "@/api/courses"; | 3 | +import { deleteInstanceTeacherByUserId, postInstanceTeacher } from "@/api/instances"; |
| 4 | import { formatApiError } from "@/api/client"; | 4 | import { formatApiError } from "@/api/client"; |
| 5 | import type { PersonRef } from "@/api/client"; | 5 | import type { PersonRef } from "@/api/client"; |
| 6 | import { Alert } from "@/components/ui/alert"; | 6 | import { Alert } from "@/components/ui/alert"; |
| @@ -14,13 +14,15 @@ import { UserSearchSelect } from "@/components/users/user-search-select"; | |||
| 14 | import { createFlash } from "@/lib/flash"; | 14 | import { createFlash } from "@/lib/flash"; |
| 15 | import { useT } from "@/stores/preferences-context"; | 15 | import { useT } from "@/stores/preferences-context"; |
| 16 | 16 | ||
| 17 | +// Staffing is per instance now: a teacher runs this course *in this şube*, and | ||
| 18 | +// the assignment carries no rights over the catalog course itself. | ||
| 17 | export function CourseTeachersPanel(props: { | 19 | export function CourseTeachersPanel(props: { |
| 18 | - courseId: string; | 20 | + instanceId: string; |
| 19 | teachers: PersonRef[]; | 21 | teachers: PersonRef[]; |
| 20 | canStaff: boolean; | 22 | canStaff: boolean; |
| 21 | assignOpen: boolean; | 23 | assignOpen: boolean; |
| 22 | onAssignOpenChange: (open: boolean) => void; | 24 | onAssignOpenChange: (open: boolean) => void; |
| 23 | - onCourseUpdated: () => void; | 25 | + onInstanceUpdated: () => void; |
| 24 | }) { | 26 | }) { |
| 25 | const t = useT(); | 27 | const t = useT(); |
| 26 | const [selectedTeacherId, setSelectedTeacherId] = createSignal(""); | 28 | const [selectedTeacherId, setSelectedTeacherId] = createSignal(""); |
| @@ -70,11 +72,11 @@ export function CourseTeachersPanel(props: { | |||
| 70 | setError(""); | 72 | setError(""); |
| 71 | 73 | ||
| 72 | try { | 74 | try { |
| 73 | - await postCourseTeacher(props.courseId, teacherId); | 75 | + await postInstanceTeacher(props.instanceId, teacherId); |
| 74 | setFlash(t("courses.teacherAssigned")); | 76 | setFlash(t("courses.teacherAssigned")); |
| 75 | setSelectedTeacherId(""); | 77 | setSelectedTeacherId(""); |
| 76 | props.onAssignOpenChange(false); | 78 | props.onAssignOpenChange(false); |
| 77 | - props.onCourseUpdated(); | 79 | + props.onInstanceUpdated(); |
| 78 | } catch (err) { | 80 | } catch (err) { |
| 79 | setError(formatApiError(err)); | 81 | setError(formatApiError(err)); |
| 80 | } finally { | 82 | } finally { |
| @@ -90,10 +92,10 @@ export function CourseTeachersPanel(props: { | |||
| 90 | setError(""); | 92 | setError(""); |
| 91 | 93 | ||
| 92 | try { | 94 | try { |
| 93 | - await deleteCourseTeacherByUserId(props.courseId, target.id); | 95 | + await deleteInstanceTeacherByUserId(props.instanceId, target.id); |
| 94 | setFlash(t("courses.teacherUnassigned")); | 96 | setFlash(t("courses.teacherUnassigned")); |
| 95 | setRemoveTarget(null); | 97 | setRemoveTarget(null); |
| 96 | - props.onCourseUpdated(); | 98 | + props.onInstanceUpdated(); |
| 97 | } catch (err) { | 99 | } catch (err) { |
| 98 | setError(formatApiError(err)); | 100 | setError(formatApiError(err)); |
| 99 | } finally { | 101 | } finally { |
src/components/exams/exam-form.tsxmodified+25 -0
| @@ -4,6 +4,7 @@ import { formatApiError } from "@/api/client"; | |||
| 4 | import { For } from "solid-js"; | 4 | import { For } from "solid-js"; |
| 5 | import { getSettings } from "@/api/settings"; | 5 | import { getSettings } from "@/api/settings"; |
| 6 | import { getTime } from "@/api/time"; | 6 | import { getTime } from "@/api/time"; |
| 7 | +import { getTerms } from "@/api/terms"; | ||
| 7 | import type { Exam } from "@/api/client"; | 8 | import type { Exam } from "@/api/client"; |
| 8 | import { EXAM_KINDS, EXAM_MODES } from "@/api/client"; | 9 | import { EXAM_KINDS, EXAM_MODES } from "@/api/client"; |
| 9 | import { Button } from "@/components/ui/button"; | 10 | import { Button } from "@/components/ui/button"; |
| @@ -56,6 +57,8 @@ function scheduleInputToMs(date: string, time: string): number | null { | |||
| 56 | 57 | ||
| 57 | export type ExamFormValues = { | 58 | export type ExamFormValues = { |
| 58 | title: string; | 59 | title: string; |
| 60 | + /** The dönem the exam is filed in. Create-only — the backend cannot move it. */ | ||
| 61 | + term: string; | ||
| 59 | description: string; | 62 | description: string; |
| 60 | kind: string; | 63 | kind: string; |
| 61 | mode: string | null; | 64 | mode: string | null; |
| @@ -102,6 +105,16 @@ export function ExamForm(props: { | |||
| 102 | const isEdit = () => !!props.initial?.id; | 105 | const isEdit = () => !!props.initial?.id; |
| 103 | const [settings] = createResource(() => getSettings()); | 106 | const [settings] = createResource(() => getSettings()); |
| 104 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | 107 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); |
| 108 | + // Terms are only asked for while creating: the backend has no way to move a | ||
| 109 | + // filed exam to another dönem, so an edit never shows the field. | ||
| 110 | + const [terms] = createResource(() => (isEdit() ? null : true), async () => (await getTerms({ limit: 100 })).items); | ||
| 111 | + const [term, setTerm] = createSignal(""); | ||
| 112 | + createEffect(() => { | ||
| 113 | + const list = terms(); | ||
| 114 | + if (!list || list.length === 0 || term()) return; | ||
| 115 | + // Newest first from the backend — the open dönem is what a teacher means. | ||
| 116 | + setTerm((list.find((item) => item.archived_at == null) ?? list[0]).id); | ||
| 117 | + }); | ||
| 105 | const examKinds = createMemo(() => { | 118 | const examKinds = createMemo(() => { |
| 106 | const names = settings()?.exam_kinds.map((item) => item.name) ?? EXAM_KINDS; | 119 | const names = settings()?.exam_kinds.map((item) => item.name) ?? EXAM_KINDS; |
| 107 | return names.includes(kind()) ? names : [kind(), ...names]; | 120 | return names.includes(kind()) ? names : [kind(), ...names]; |
| @@ -125,6 +138,7 @@ export function ExamForm(props: { | |||
| 125 | if (ends <= starts) return t("form.timeOrder"); | 138 | if (ends <= starts) return t("form.timeOrder"); |
| 126 | if (!isEdit() && (starts < (serverTime()?.now ?? Date.now()) || ends < (serverTime()?.now ?? Date.now()))) return t("form.timePast"); | 139 | if (!isEdit() && (starts < (serverTime()?.now ?? Date.now()) || ends < (serverTime()?.now ?? Date.now()))) return t("form.timePast"); |
| 127 | } | 140 | } |
| 141 | + if (!isEdit() && !term()) return t("terms.term"); | ||
| 128 | if (hasDuration() || mode() === "async") { | 142 | if (hasDuration() || mode() === "async") { |
| 129 | if (duration == null) return t("exams.durationRequired"); | 143 | if (duration == null) return t("exams.durationRequired"); |
| 130 | if (duration < 60000 || duration > 86400000) return t("exams.durationRange"); | 144 | if (duration < 60000 || duration > 86400000) return t("exams.durationRange"); |
| @@ -182,6 +196,7 @@ export function ExamForm(props: { | |||
| 182 | return; | 196 | return; |
| 183 | } | 197 | } |
| 184 | const values = { | 198 | const values = { |
| 199 | + term: term(), | ||
| 185 | title: title().trim(), | 200 | title: title().trim(), |
| 186 | description: description(), | 201 | description: description(), |
| 187 | kind: kind(), | 202 | kind: kind(), |
| @@ -229,6 +244,16 @@ export function ExamForm(props: { | |||
| 229 | onInput={(e) => setDescription(e.currentTarget.value)} | 244 | onInput={(e) => setDescription(e.currentTarget.value)} |
| 230 | /> | 245 | /> |
| 231 | </div> | 246 | </div> |
| 247 | + <Show when={!isEdit()}> | ||
| 248 | + <div class="space-y-1.5"> | ||
| 249 | + <Label for="exam-term">{t("terms.term")}</Label> | ||
| 250 | + <Select id="exam-term" value={term()} onChange={(e) => setTerm(e.currentTarget.value)}> | ||
| 251 | + <For each={terms() ?? []}> | ||
| 252 | + {(item) => <option value={item.id}>{item.name}</option>} | ||
| 253 | + </For> | ||
| 254 | + </Select> | ||
| 255 | + </div> | ||
| 256 | + </Show> | ||
| 232 | <div class="space-y-1.5"> | 257 | <div class="space-y-1.5"> |
| 233 | <Label for="exam-kind">{t("exams.kind")}</Label> | 258 | <Label for="exam-kind">{t("exams.kind")}</Label> |
| 234 | <Select | 259 | <Select |
src/components/homework/course-homework-panel.tsxmodified+8 -4
| @@ -3,7 +3,8 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import { useNavigate } from "@tanstack/solid-router"; | 3 | import { useNavigate } from "@tanstack/solid-router"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | import { deleteHomeworkById, patchHomeworkById } from "@/api/homework"; | 5 | import { deleteHomeworkById, patchHomeworkById } from "@/api/homework"; |
| 6 | -import { getCourseHomework, getCourseSubjects, postCourseHomework } from "@/api/courses"; | 6 | +import { getCourseSubjects } from "@/api/courses"; |
| 7 | +import { getInstanceHomework, postInstanceHomework } from "@/api/instances"; | ||
| 7 | import { getTime } from "@/api/time"; | 8 | import { getTime } from "@/api/time"; |
| 8 | import { formatApiError } from "@/api/client"; | 9 | import { formatApiError } from "@/api/client"; |
| 9 | import type { Homework, Subject } from "@/api/client"; | 10 | import type { Homework, Subject } from "@/api/client"; |
| @@ -54,6 +55,9 @@ function msToTimeInput(ms: number): string { | |||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | export function CourseHomeworkPanel(props: { | 57 | export function CourseHomeworkPanel(props: { |
| 58 | + /** The instance (class x course) the homework is assigned in. */ | ||
| 59 | + instanceId: string; | ||
| 60 | + /** The catalog course behind it — where the subjects live. */ | ||
| 57 | courseId: string; | 61 | courseId: string; |
| 58 | canManage: boolean; | 62 | canManage: boolean; |
| 59 | active: boolean; | 63 | active: boolean; |
| @@ -65,8 +69,8 @@ export function CourseHomeworkPanel(props: { | |||
| 65 | const { locale } = usePreferences(); | 69 | const { locale } = usePreferences(); |
| 66 | const navigate = useNavigate(); | 70 | const navigate = useNavigate(); |
| 67 | const [homework, { refetch }] = createResource( | 71 | const [homework, { refetch }] = createResource( |
| 68 | - () => (props.active ? props.courseId : null), | 72 | + () => (props.active ? props.instanceId : null), |
| 69 | - async (courseId) => (courseId ? (await getCourseHomework(courseId)).items : []), | 73 | + async (instanceId) => (instanceId ? (await getInstanceHomework(instanceId)).items : []), |
| 70 | ); | 74 | ); |
| 71 | const [subjects] = createResource( | 75 | const [subjects] = createResource( |
| 72 | () => (props.active ? props.courseId : null), | 76 | () => (props.active ? props.courseId : null), |
| @@ -138,7 +142,7 @@ export function CourseHomeworkPanel(props: { | |||
| 138 | }); | 142 | }); |
| 139 | setFlash(t("common.saved")); | 143 | setFlash(t("common.saved")); |
| 140 | } else { | 144 | } else { |
| 141 | - await postCourseHomework(props.courseId, { | 145 | + await postInstanceHomework(props.instanceId, { |
| 142 | title: title().trim(), | 146 | title: title().trim(), |
| 143 | description: description().trim() || null, | 147 | description: description().trim() || null, |
| 144 | subject_id: subjectId(), | 148 | subject_id: subjectId(), |
src/components/homework/homework-submissions-panel.tsxmodified+4 -4
| @@ -1,7 +1,7 @@ | |||
| 1 | import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; | 1 | import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | -import { getCourseEnrollments } from "@/api/courses"; | 4 | +import { getInstanceEnrollments } from "@/api/instances"; |
| 5 | import { deleteHomeworkResultByUserId, getHomeworkRosterSubmissionFileUrl, getHomeworkSubmissions, postHomeworkResult } from "@/api/homework"; | 5 | import { deleteHomeworkResultByUserId, getHomeworkRosterSubmissionFileUrl, getHomeworkSubmissions, postHomeworkResult } from "@/api/homework"; |
| 6 | import { formatApiError } from "@/api/client"; | 6 | import { formatApiError } from "@/api/client"; |
| 7 | import type { HomeworkRosterEntry } from "@/api/client"; | 7 | import type { HomeworkRosterEntry } from "@/api/client"; |
| @@ -23,7 +23,7 @@ import { formatBytes } from "@/lib/upload-limits"; | |||
| 23 | import { usePreferences, useT } from "@/stores/preferences-context"; | 23 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 24 | import { sanitizeRichText } from "@/lib/rich-text"; | 24 | import { sanitizeRichText } from "@/lib/rich-text"; |
| 25 | 25 | ||
| 26 | -export function HomeworkSubmissionsPanel(props: { homeworkId: string; courseId: string }) { | 26 | +export function HomeworkSubmissionsPanel(props: { homeworkId: string; instanceId: string }) { |
| 27 | const t = useT(); | 27 | const t = useT(); |
| 28 | const { locale } = usePreferences(); | 28 | const { locale } = usePreferences(); |
| 29 | const [gradeTarget, setGradeTarget] = createSignal<HomeworkRosterEntry | null>(null); | 29 | const [gradeTarget, setGradeTarget] = createSignal<HomeworkRosterEntry | null>(null); |
| @@ -39,8 +39,8 @@ export function HomeworkSubmissionsPanel(props: { homeworkId: string; courseId: | |||
| 39 | async (id) => getHomeworkSubmissions(id, { limit: 200 }), | 39 | async (id) => getHomeworkSubmissions(id, { limit: 200 }), |
| 40 | ); | 40 | ); |
| 41 | const [enrollments] = createResource( | 41 | const [enrollments] = createResource( |
| 42 | - () => props.courseId, | 42 | + () => props.instanceId, |
| 43 | - async (courseId) => (await getCourseEnrollments(courseId)).items, | 43 | + async (instanceId) => (await getInstanceEnrollments(instanceId)).items, |
| 44 | ); | 44 | ); |
| 45 | const studentLabel = (userId: string) => { | 45 | const studentLabel = (userId: string) => { |
| 46 | const user = (enrollments() ?? []).find((row) => row.user.id === userId)?.user; | 46 | const user = (enrollments() ?? []).find((row) => row.user.id === userId)?.user; |
src/components/layout/nav-items.tsmodified+1 -0
| @@ -109,6 +109,7 @@ const ADMIN_GROUPS: NavGroup[] = [ | |||
| 109 | { id: "students-roster", to: "/management/students", labelKey: "nav.studentsRoster", Icon: IconUsers, minRole: "manager" }, | 109 | { id: "students-roster", to: "/management/students", labelKey: "nav.studentsRoster", Icon: IconUsers, minRole: "manager" }, |
| 110 | { id: "teachers-roster", to: "/management/teachers", labelKey: "nav.teachersRoster", Icon: IconChalkboardTeacher, minRole: "manager" }, | 110 | { id: "teachers-roster", to: "/management/teachers", labelKey: "nav.teachersRoster", Icon: IconChalkboardTeacher, minRole: "manager" }, |
| 111 | { id: "class-groups", to: "/management/classes", labelKey: "nav.classGroups", Icon: IconSchool, minRole: "teacher", module: "classes" }, | 111 | { id: "class-groups", to: "/management/classes", labelKey: "nav.classGroups", Icon: IconSchool, minRole: "teacher", module: "classes" }, |
| 112 | + { id: "academic-years", to: "/management/academic-years", labelKey: "nav.academicYears", Icon: IconCalendar, minRole: "manager" }, | ||
| 112 | { id: "terms", to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendar, minRole: "manager" }, | 113 | { id: "terms", to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendar, minRole: "manager" }, |
| 113 | { id: "schedule", to: "/calendar", labelKey: "nav.schedule", Icon: IconCalendarDays, minRole: "manager" }, | 114 | { id: "schedule", to: "/calendar", labelKey: "nav.schedule", Icon: IconCalendarDays, minRole: "manager" }, |
| 114 | ], | 115 | ], |
src/components/marks/karne-view.tsxadded+93 -0
| @@ -0,0 +1,93 @@ | |||
| 1 | +import { For, Show } from "solid-js"; | ||
| 2 | +import type { KarneReport, Term } from "@/api/client"; | ||
| 3 | +import { Badge } from "@/components/ui/badge"; | ||
| 4 | +import { DataTableEmpty } from "@/components/ui/data-table"; | ||
| 5 | +import { Select } from "@/components/ui/select"; | ||
| 6 | +import { useT } from "@/stores/preferences-context"; | ||
| 7 | + | ||
| 8 | +const formatAverage = (value: number | null) => (value == null ? "—" : value.toFixed(1)); | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * One dönem's karne. An archived dönem serves the snapshot the school froze | ||
| 12 | + * when it closed, so a mark corrected afterwards no longer rewrites what a | ||
| 13 | + * family already read — the view simply renders whatever the backend serves. | ||
| 14 | + */ | ||
| 15 | +export function KarneView(props: { | ||
| 16 | + report: KarneReport; | ||
| 17 | + terms: Term[]; | ||
| 18 | + selectedTerm: string; | ||
| 19 | + onTermChange: (term: string) => void; | ||
| 20 | +}) { | ||
| 21 | + const t = useT(); | ||
| 22 | + const verdictLabel = () => { | ||
| 23 | + const verdict = props.report.verdict; | ||
| 24 | + if (verdict === "gecti") return t("karne.passed"); | ||
| 25 | + if (verdict === "kaldi") return t("karne.failed"); | ||
| 26 | + return verdict ?? "—"; | ||
| 27 | + }; | ||
| 28 | + | ||
| 29 | + return ( | ||
| 30 | + <div class="space-y-4"> | ||
| 31 | + <div class="flex flex-wrap items-end justify-between gap-3"> | ||
| 32 | + <div class="min-w-0 space-y-1.5"> | ||
| 33 | + <label class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground" for="karne-term"> | ||
| 34 | + {t("terms.term")} | ||
| 35 | + </label> | ||
| 36 | + <Select | ||
| 37 | + id="karne-term" | ||
| 38 | + wrapperClass="w-56" | ||
| 39 | + class="h-9 rounded-lg" | ||
| 40 | + value={props.selectedTerm} | ||
| 41 | + onChange={(event) => props.onTermChange(event.currentTarget.value)} | ||
| 42 | + > | ||
| 43 | + <For each={props.terms}>{(term) => <option value={term.id}>{term.name}</option>}</For> | ||
| 44 | + </Select> | ||
| 45 | + </div> | ||
| 46 | + <div class="flex flex-wrap gap-3"> | ||
| 47 | + <div class="rounded-xl border border-border-line bg-surface-base px-4 py-3"> | ||
| 48 | + <p class="text-[11px] text-muted-foreground">{t("karne.average")}</p> | ||
| 49 | + <p class="mt-0.5 text-2xl font-semibold tabular-nums">{formatAverage(props.report.year_average)}</p> | ||
| 50 | + </div> | ||
| 51 | + <div class="rounded-xl border border-border-line bg-surface-base px-4 py-3"> | ||
| 52 | + <p class="text-[11px] text-muted-foreground">{t("karne.verdict")}</p> | ||
| 53 | + <p class="mt-0.5 text-2xl font-semibold">{verdictLabel()}</p> | ||
| 54 | + </div> | ||
| 55 | + </div> | ||
| 56 | + </div> | ||
| 57 | + | ||
| 58 | + <Show | ||
| 59 | + when={props.report.instances.length > 0} | ||
| 60 | + fallback={<DataTableEmpty class="rounded-lg border border-border bg-card py-10">{t("karne.empty")}</DataTableEmpty>} | ||
| 61 | + > | ||
| 62 | + <div class="overflow-x-auto rounded-lg border border-border bg-card"> | ||
| 63 | + <table class="w-full text-sm"> | ||
| 64 | + <thead class="border-b border-border/60 text-left text-xs text-muted-foreground"> | ||
| 65 | + <tr> | ||
| 66 | + <th class="p-3 font-medium">{t("nav.courses")}</th> | ||
| 67 | + <th class="p-3 font-medium">{t("instances.dersSaati")}</th> | ||
| 68 | + <th class="p-3 font-medium">{t("marks.courseAvg")}</th> | ||
| 69 | + <th class="p-3 font-medium">{t("karne.band")}</th> | ||
| 70 | + </tr> | ||
| 71 | + </thead> | ||
| 72 | + <tbody> | ||
| 73 | + <For each={props.report.instances}> | ||
| 74 | + {(line) => ( | ||
| 75 | + <tr class="border-b border-border/60 last:border-0"> | ||
| 76 | + <td class="min-w-0 p-3 font-medium">{line.course}</td> | ||
| 77 | + <td class="mono p-3 tabular-nums text-muted-foreground">{line.ders_saati}</td> | ||
| 78 | + <td class="mono p-3 font-semibold tabular-nums">{formatAverage(line.average)}</td> | ||
| 79 | + <td class="p-3"> | ||
| 80 | + <Show when={line.band} fallback="—"> | ||
| 81 | + {(band) => <Badge variant="outline" class="rounded-full">{band()}</Badge>} | ||
| 82 | + </Show> | ||
| 83 | + </td> | ||
| 84 | + </tr> | ||
| 85 | + )} | ||
| 86 | + </For> | ||
| 87 | + </tbody> | ||
| 88 | + </table> | ||
| 89 | + </div> | ||
| 90 | + </Show> | ||
| 91 | + </div> | ||
| 92 | + ); | ||
| 93 | +} | ||
src/components/marks/marks-report-view.tsxmodified+11 -12
| @@ -11,7 +11,6 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; | |||
| 11 | import { cn } from "@/lib/cn"; | 11 | import { cn } from "@/lib/cn"; |
| 12 | import { examKindLabel } from "@/lib/exam-labels"; | 12 | import { examKindLabel } from "@/lib/exam-labels"; |
| 13 | import { examWeight } from "@/lib/exam-weight"; | 13 | import { examWeight } from "@/lib/exam-weight"; |
| 14 | -import { personLabel } from "@/lib/person"; | ||
| 15 | import { useT } from "@/stores/preferences-context"; | 14 | import { useT } from "@/stores/preferences-context"; |
| 16 | 15 | ||
| 17 | const round = (n: number) => (Math.round(n * 100) / 100).toString(); | 16 | const round = (n: number) => (Math.round(n * 100) / 100).toString(); |
| @@ -32,11 +31,11 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | |||
| 32 | const compact = () => props.compact === true; | 31 | const compact = () => props.compact === true; |
| 33 | const resultCount = createMemo(() => props.report.courses.reduce((total, course) => total + course.results.length, 0)); | 32 | const resultCount = createMemo(() => props.report.courses.reduce((total, course) => total + course.results.length, 0)); |
| 34 | const [tab, setTab] = createSignal<"general" | "byCourse">("general"); | 33 | const [tab, setTab] = createSignal<"general" | "byCourse">("general"); |
| 35 | - const [activeCourseId, setActiveCourseId] = createSignal<string | null>(null); | 34 | + const [activeInstanceId, setActiveInstanceId] = createSignal<string | null>(null); |
| 36 | const activeCourse = createMemo(() => { | 35 | const activeCourse = createMemo(() => { |
| 37 | - const id = activeCourseId(); | 36 | + const id = activeInstanceId(); |
| 38 | const courses = props.report.courses; | 37 | const courses = props.report.courses; |
| 39 | - return (id ? courses.find((c) => c.course.id === id) : undefined) ?? courses[0]; | 38 | + return (id ? courses.find((c) => c.instance === id) : undefined) ?? courses[0]; |
| 40 | }); | 39 | }); |
| 41 | const columns = createMemo<ColumnDef<MarkRow>[]>(() => [ | 40 | const columns = createMemo<ColumnDef<MarkRow>[]>(() => [ |
| 42 | { | 41 | { |
| @@ -136,9 +135,9 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | |||
| 136 | </Link> | 135 | </Link> |
| 137 | </td> | 136 | </td> |
| 138 | <td class="min-w-0 p-3 text-muted-foreground"> | 137 | <td class="min-w-0 p-3 text-muted-foreground"> |
| 139 | - <span class="block truncate"> | 138 | + <Link to="/instances/$id" params={{ id: block.instance }} class="block truncate hover:text-primary hover:underline"> |
| 140 | - {block.course.teachers && block.course.teachers.length > 0 ? block.course.teachers.map((tr) => personLabel(tr)).join(", ") : "—"} | 139 | + {t("instances.open")} |
| 141 | - </span> | 140 | + </Link> |
| 142 | </td> | 141 | </td> |
| 143 | <td class="min-w-0 p-3"> | 142 | <td class="min-w-0 p-3"> |
| 144 | <div class="flex items-center gap-2"> | 143 | <div class="flex items-center gap-2"> |
| @@ -165,11 +164,11 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | |||
| 165 | type="button" | 164 | type="button" |
| 166 | class={cn( | 165 | class={cn( |
| 167 | "rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors", | 166 | "rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors", |
| 168 | - activeCourse()?.course.id === block.course.id | 167 | + activeCourse()?.instance === block.instance |
| 169 | ? "border-border bg-surface-base text-foreground shadow-xs" | 168 | ? "border-border bg-surface-base text-foreground shadow-xs" |
| 170 | : "border-transparent text-muted-foreground hover:bg-muted/60", | 169 | : "border-transparent text-muted-foreground hover:bg-muted/60", |
| 171 | )} | 170 | )} |
| 172 | - onClick={() => setActiveCourseId(block.course.id)} | 171 | + onClick={() => setActiveInstanceId(block.instance)} |
| 173 | > | 172 | > |
| 174 | {block.course.title} | 173 | {block.course.title} |
| 175 | </button> | 174 | </button> |
| @@ -185,9 +184,9 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | |||
| 185 | <Link to="/courses/$id" params={{ id: block.course.id }} class="inline-flex truncate text-sm font-semibold text-primary hover:underline"> | 184 | <Link to="/courses/$id" params={{ id: block.course.id }} class="inline-flex truncate text-sm font-semibold text-primary hover:underline"> |
| 186 | {block.course.title} | 185 | {block.course.title} |
| 187 | </Link> | 186 | </Link> |
| 188 | - <p class="mt-0.5 truncate text-xs text-muted-foreground"> | 187 | + <Link to="/instances/$id" params={{ id: block.instance }} class="mt-0.5 block truncate text-xs text-muted-foreground hover:text-primary hover:underline"> |
| 189 | - {block.course.teachers && block.course.teachers.length > 0 ? block.course.teachers.map((tr) => personLabel(tr)).join(", ") : "—"} | 188 | + {t("instances.open")} |
| 190 | - </p> | 189 | + </Link> |
| 191 | </div> | 190 | </div> |
| 192 | <div class="text-right"> | 191 | <div class="text-right"> |
| 193 | <p class="text-[10px] font-medium uppercase tracking-wider text-muted-foreground">{t("marks.courseAvg")}</p> | 192 | <p class="text-[10px] font-medium uppercase tracking-wider text-muted-foreground">{t("marks.courseAvg")}</p> |
src/components/sessions/course-sessions-panel.tsxmodified+7 -7
| @@ -3,11 +3,10 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | import { deleteSessionById } from "@/api/sessions"; | 4 | import { deleteSessionById } from "@/api/sessions"; |
| 5 | import { deleteSessionAttendanceByUserId } from "@/api/sessions"; | 5 | import { deleteSessionAttendanceByUserId } from "@/api/sessions"; |
| 6 | -import { getCourseSessions } from "@/api/courses"; | ||
| 7 | import { getSessionAttendance } from "@/api/sessions"; | 6 | import { getSessionAttendance } from "@/api/sessions"; |
| 7 | +import { getInstanceSessions, postInstanceSession } from "@/api/instances"; | ||
| 8 | import { getTime } from "@/api/time"; | 8 | import { getTime } from "@/api/time"; |
| 9 | import { patchSessionById } from "@/api/sessions"; | 9 | import { patchSessionById } from "@/api/sessions"; |
| 10 | -import { postCourseSession } from "@/api/courses"; | ||
| 11 | import { postSessionAttendance } from "@/api/sessions"; | 10 | import { postSessionAttendance } from "@/api/sessions"; |
| 12 | import { formatApiError } from "@/api/client"; | 11 | import { formatApiError } from "@/api/client"; |
| 13 | import type { AttendanceStatus, CourseSession, Enrollment, SessionAttendance } from "@/api/client"; | 12 | import type { AttendanceStatus, CourseSession, Enrollment, SessionAttendance } from "@/api/client"; |
| @@ -62,7 +61,8 @@ function msToTimeInput(ms: number): string { | |||
| 62 | const ROLL_CALL_PAGE_SIZE = 8; | 61 | const ROLL_CALL_PAGE_SIZE = 8; |
| 63 | 62 | ||
| 64 | export function CourseSessionsPanel(props: { | 63 | export function CourseSessionsPanel(props: { |
| 65 | - courseId: string; | 64 | + /** The instance (class x course) these lessons belong to. */ |
| 65 | + instanceId: string; | ||
| 66 | roster: Enrollment[]; | 66 | roster: Enrollment[]; |
| 67 | canManage: boolean; | 67 | canManage: boolean; |
| 68 | active: boolean; | 68 | active: boolean; |
| @@ -73,8 +73,8 @@ export function CourseSessionsPanel(props: { | |||
| 73 | const t = useT(); | 73 | const t = useT(); |
| 74 | const { locale } = usePreferences(); | 74 | const { locale } = usePreferences(); |
| 75 | const [sessions, { refetch }] = createResource( | 75 | const [sessions, { refetch }] = createResource( |
| 76 | - () => (props.active ? props.courseId : null), | 76 | + () => (props.active ? props.instanceId : null), |
| 77 | - async (courseId) => (courseId ? (await getCourseSessions(courseId)).items : []), | 77 | + async (instanceId) => (instanceId ? (await getInstanceSessions(instanceId)).items : []), |
| 78 | ); | 78 | ); |
| 79 | const [selectedSession, setSelectedSession] = createSignal<CourseSession | null>(null); | 79 | const [selectedSession, setSelectedSession] = createSignal<CourseSession | null>(null); |
| 80 | const [detailSession, setDetailSession] = createSignal<CourseSession | null>(null); | 80 | const [detailSession, setDetailSession] = createSignal<CourseSession | null>(null); |
| @@ -162,7 +162,7 @@ export function CourseSessionsPanel(props: { | |||
| 162 | }); | 162 | }); |
| 163 | setFlash(t("common.saved")); | 163 | setFlash(t("common.saved")); |
| 164 | } else { | 164 | } else { |
| 165 | - await postCourseSession(props.courseId, { | 165 | + await postInstanceSession(props.instanceId, { |
| 166 | starts_at, | 166 | starts_at, |
| 167 | ...(topic().trim() ? { topic: topic().trim() } : {}), | 167 | ...(topic().trim() ? { topic: topic().trim() } : {}), |
| 168 | ...(ends_at != null ? { ends_at } : {}), | 168 | ...(ends_at != null ? { ends_at } : {}), |
| @@ -245,7 +245,7 @@ export function CourseSessionsPanel(props: { | |||
| 245 | columns={columns()} | 245 | columns={columns()} |
| 246 | data={sessions() ?? []} | 246 | data={sessions() ?? []} |
| 247 | filterColumn="topic" | 247 | filterColumn="topic" |
| 248 | - storageKey={`course-sessions-${props.courseId}`} | 248 | + storageKey={`instance-sessions-${props.instanceId}`} |
| 249 | enablePagination | 249 | enablePagination |
| 250 | pageSize={10} | 250 | pageSize={10} |
| 251 | empty={t("sessions.empty")} | 251 | empty={t("sessions.empty")} |
src/i18n/messages.tsmodified+181 -1
| @@ -1928,7 +1928,67 @@ export type MessageKey = | |||
| 1928 | | "appointments.rejectReasonPlaceholder" | 1928 | | "appointments.rejectReasonPlaceholder" |
| 1929 | | "appointments.rejectReason" | 1929 | | "appointments.rejectReason" |
| 1930 | | "appointments.rejectedBy" | 1930 | | "appointments.rejectedBy" |
| 1931 | - | "appointments.reasonRequired"; | 1931 | + | "appointments.reasonRequired" |
| 1932 | + | "nav.academicYears" | ||
| 1933 | + | "instances.title" | ||
| 1934 | + | "instances.item" | ||
| 1935 | + | "instances.taughtIn" | ||
| 1936 | + | "instances.empty" | ||
| 1937 | + | "instances.emptyHelp" | ||
| 1938 | + | "instances.dersSaati" | ||
| 1939 | + | "instances.countsTowardKarne" | ||
| 1940 | + | "instances.policy" | ||
| 1941 | + | "instances.notFound" | ||
| 1942 | + | "instances.open" | ||
| 1943 | + | "instances.mine" | ||
| 1944 | + | "instances.selectSection" | ||
| 1945 | + | "instances.selectSectionHelp" | ||
| 1946 | + | "academicYears.title" | ||
| 1947 | + | "academicYears.subtitle" | ||
| 1948 | + | "academicYears.new" | ||
| 1949 | + | "academicYears.year" | ||
| 1950 | + | "academicYears.empty" | ||
| 1951 | + | "academicYears.unassigned" | ||
| 1952 | + | "academicYears.classCount" | ||
| 1953 | + | "academicYears.termCount" | ||
| 1954 | + | "academicYears.archive" | ||
| 1955 | + | "academicYears.archiveConfirm" | ||
| 1956 | + | "academicYears.archived" | ||
| 1957 | + | "academicYears.deleteConfirm" | ||
| 1958 | + | "academicYears.promotions" | ||
| 1959 | + | "academicYears.promotionsHelp" | ||
| 1960 | + | "academicYears.fromGrade" | ||
| 1961 | + | "academicYears.toGrade" | ||
| 1962 | + | "academicYears.addPromotion" | ||
| 1963 | + | "academicYears.rollover" | ||
| 1964 | + | "academicYears.rolloverFrom" | ||
| 1965 | + | "academicYears.rolloverHelp" | ||
| 1966 | + | "academicYears.rolloverDone" | ||
| 1967 | + | "academicYears.graduated" | ||
| 1968 | + | "karne.title" | ||
| 1969 | + | "karne.average" | ||
| 1970 | + | "karne.verdict" | ||
| 1971 | + | "karne.passed" | ||
| 1972 | + | "karne.failed" | ||
| 1973 | + | "karne.empty" | ||
| 1974 | + | "karne.band" | ||
| 1975 | + | "courses.members" | ||
| 1976 | + | "courses.memberItem" | ||
| 1977 | + | "courses.addMember" | ||
| 1978 | + | "courses.removeMember" | ||
| 1979 | + | "courses.removeMemberConfirm" | ||
| 1980 | + | "courses.membersClubOnly" | ||
| 1981 | + | "settings.branches" | ||
| 1982 | + | "settings.excuseKinds" | ||
| 1983 | + | "settings.maxExcusedDays" | ||
| 1984 | + | "settings.maxUnexcusedDays" | ||
| 1985 | + | "settings.timezone" | ||
| 1986 | + | "attendance.devamsizlik" | ||
| 1987 | + | "attendance.excusedDays" | ||
| 1988 | + | "attendance.unexcusedDays" | ||
| 1989 | + | "attendance.overLimit" | ||
| 1990 | + | "common.yes" | ||
| 1991 | + | "common.no"; | ||
| 1932 | 1992 | ||
| 1933 | type Dict = Record<MessageKey, string>; | 1993 | type Dict = Record<MessageKey, string>; |
| 1934 | 1994 | ||
| @@ -3873,6 +3933,66 @@ const en: Dict = { | |||
| 3873 | "messages.deleteForeverOnlyTrash": "Permanent delete only applies to messages in the trash.", | 3933 | "messages.deleteForeverOnlyTrash": "Permanent delete only applies to messages in the trash.", |
| 3874 | "messages.readOnlyReceived": "Only received messages can be marked read or unread.", | 3934 | "messages.readOnlyReceived": "Only received messages can be marked read or unread.", |
| 3875 | "messages.trashEmptiedToast": "Trash emptied.", | 3935 | "messages.trashEmptiedToast": "Trash emptied.", |
| 3936 | + "nav.academicYears": "Academic years", | ||
| 3937 | + "instances.title": "Sections", | ||
| 3938 | + "instances.item": "section", | ||
| 3939 | + "instances.taughtIn": "Taught in", | ||
| 3940 | + "instances.empty": "No section teaches this course yet.", | ||
| 3941 | + "instances.emptyHelp": "A course starts teaching when a class attaches it.", | ||
| 3942 | + "instances.dersSaati": "Weekly hours", | ||
| 3943 | + "instances.countsTowardKarne": "Counts toward karne", | ||
| 3944 | + "instances.policy": "Section policy", | ||
| 3945 | + "instances.notFound": "Section not found.", | ||
| 3946 | + "instances.open": "Open section", | ||
| 3947 | + "instances.mine": "My sections", | ||
| 3948 | + "instances.selectSection": "Select a section", | ||
| 3949 | + "instances.selectSectionHelp": "Exams, homework and lessons belong to a section, not to the catalog course.", | ||
| 3950 | + "academicYears.title": "Academic years", | ||
| 3951 | + "academicYears.subtitle": "The calendar structure terms and classes hang off.", | ||
| 3952 | + "academicYears.new": "New academic year", | ||
| 3953 | + "academicYears.year": "Academic year", | ||
| 3954 | + "academicYears.empty": "No academic year yet.", | ||
| 3955 | + "academicYears.unassigned": "Unassigned", | ||
| 3956 | + "academicYears.classCount": "Classes", | ||
| 3957 | + "academicYears.termCount": "Terms", | ||
| 3958 | + "academicYears.archive": "Archive year", | ||
| 3959 | + "academicYears.archiveConfirm": "An archived year takes no new class, term or exam, and cannot be edited. There is no undo.", | ||
| 3960 | + "academicYears.archived": "Archived", | ||
| 3961 | + "academicYears.deleteConfirm": "Delete this academic year?", | ||
| 3962 | + "academicYears.promotions": "Grade promotions", | ||
| 3963 | + "academicYears.promotionsHelp": "Each pair maps a grade to the one its students move to at rollover. A grade left out graduates.", | ||
| 3964 | + "academicYears.fromGrade": "From grade", | ||
| 3965 | + "academicYears.toGrade": "To grade", | ||
| 3966 | + "academicYears.addPromotion": "Add pair", | ||
| 3967 | + "academicYears.rollover": "Carry classes over", | ||
| 3968 | + "academicYears.rolloverFrom": "Carry from", | ||
| 3969 | + "academicYears.rolloverHelp": "Plants the source year's classes here with promoted grades, their sections and their students. The target must still be empty.", | ||
| 3970 | + "academicYears.rolloverDone": "{classes} classes and {students} students carried over.", | ||
| 3971 | + "academicYears.graduated": "Graduated grades", | ||
| 3972 | + "karne.title": "Karne", | ||
| 3973 | + "karne.average": "Year average", | ||
| 3974 | + "karne.verdict": "Verdict", | ||
| 3975 | + "karne.passed": "Passed", | ||
| 3976 | + "karne.failed": "Failed", | ||
| 3977 | + "karne.empty": "No karne line for this term yet.", | ||
| 3978 | + "karne.band": "Band", | ||
| 3979 | + "courses.members": "Members", | ||
| 3980 | + "courses.memberItem": "member", | ||
| 3981 | + "courses.addMember": "Add member", | ||
| 3982 | + "courses.removeMember": "Remove member", | ||
| 3983 | + "courses.removeMemberConfirm": "Remove this member?", | ||
| 3984 | + "courses.membersClubOnly": "Only a club or study group keeps its own member list.", | ||
| 3985 | + "settings.branches": "Teaching subjects (branş)", | ||
| 3986 | + "settings.excuseKinds": "Excuse kinds", | ||
| 3987 | + "settings.maxExcusedDays": "Excused absence day limit", | ||
| 3988 | + "settings.maxUnexcusedDays": "Unexcused absence day limit", | ||
| 3989 | + "settings.timezone": "Timezone", | ||
| 3990 | + "attendance.devamsizlik": "Absence by term", | ||
| 3991 | + "attendance.excusedDays": "Excused days", | ||
| 3992 | + "attendance.unexcusedDays": "Unexcused days", | ||
| 3993 | + "attendance.overLimit": "Over the limit", | ||
| 3994 | + "common.yes": "Yes", | ||
| 3995 | + "common.no": "No", | ||
| 3876 | }; | 3996 | }; |
| 3877 | 3997 | ||
| 3878 | const tr: Dict = { | 3998 | const tr: Dict = { |
| @@ -5816,6 +5936,66 @@ const tr: Dict = { | |||
| 5816 | "messages.deleteForeverOnlyTrash": "Kalıcı silme yalnızca çöp kutusundaki mesajlar için geçerli.", | 5936 | "messages.deleteForeverOnlyTrash": "Kalıcı silme yalnızca çöp kutusundaki mesajlar için geçerli.", |
| 5817 | "messages.readOnlyReceived": "Yalnızca gelen mesajların okundu durumu değiştirilebilir.", | 5937 | "messages.readOnlyReceived": "Yalnızca gelen mesajların okundu durumu değiştirilebilir.", |
| 5818 | "messages.trashEmptiedToast": "Çöp kutusu boşaltıldı.", | 5938 | "messages.trashEmptiedToast": "Çöp kutusu boşaltıldı.", |
| 5939 | + "nav.academicYears": "Eğitim yılları", | ||
| 5940 | + "instances.title": "Şubeler", | ||
| 5941 | + "instances.item": "şube", | ||
| 5942 | + "instances.taughtIn": "İşlendiği şubeler", | ||
| 5943 | + "instances.empty": "Bu dersi işleyen şube yok.", | ||
| 5944 | + "instances.emptyHelp": "Ders, bir şube onu eklediğinde işlenmeye başlar.", | ||
| 5945 | + "instances.dersSaati": "Ders saati", | ||
| 5946 | + "instances.countsTowardKarne": "Karneye işler", | ||
| 5947 | + "instances.policy": "Şube ayarı", | ||
| 5948 | + "instances.notFound": "Şube bulunamadı.", | ||
| 5949 | + "instances.open": "Şubeyi aç", | ||
| 5950 | + "instances.mine": "Şubelerim", | ||
| 5951 | + "instances.selectSection": "Şube seç", | ||
| 5952 | + "instances.selectSectionHelp": "Sınav, ödev ve dersler katalog dersine değil şubeye bağlıdır.", | ||
| 5953 | + "academicYears.title": "Eğitim yılları", | ||
| 5954 | + "academicYears.subtitle": "Dönemlerin ve şubelerin bağlı olduğu takvim yapısı.", | ||
| 5955 | + "academicYears.new": "Yeni eğitim yılı", | ||
| 5956 | + "academicYears.year": "Eğitim yılı", | ||
| 5957 | + "academicYears.empty": "Henüz eğitim yılı yok.", | ||
| 5958 | + "academicYears.unassigned": "Atanmamış", | ||
| 5959 | + "academicYears.classCount": "Şube", | ||
| 5960 | + "academicYears.termCount": "Dönem", | ||
| 5961 | + "academicYears.archive": "Yılı arşivle", | ||
| 5962 | + "academicYears.archiveConfirm": "Arşivlenen yıl yeni şube, dönem veya sınav almaz ve düzenlenemez. Geri alınamaz.", | ||
| 5963 | + "academicYears.archived": "Arşivlendi", | ||
| 5964 | + "academicYears.deleteConfirm": "Bu eğitim yılı silinsin mi?", | ||
| 5965 | + "academicYears.promotions": "Sınıf geçme", | ||
| 5966 | + "academicYears.promotionsHelp": "Her satır bir sınıfın, devir sırasında geçeceği sınıfı belirler. Listede olmayan sınıf mezun olur.", | ||
| 5967 | + "academicYears.fromGrade": "Sınıftan", | ||
| 5968 | + "academicYears.toGrade": "Sınıfa", | ||
| 5969 | + "academicYears.addPromotion": "Satır ekle", | ||
| 5970 | + "academicYears.rollover": "Şubeleri devret", | ||
| 5971 | + "academicYears.rolloverFrom": "Kaynak yıl", | ||
| 5972 | + "academicYears.rolloverHelp": "Kaynak yılın şubelerini, sınıfları yükseltilmiş hâlde, şubeleri ve öğrencileriyle buraya taşır. Hedef yıl boş olmalı.", | ||
| 5973 | + "academicYears.rolloverDone": "{classes} şube ve {students} öğrenci devredildi.", | ||
| 5974 | + "academicYears.graduated": "Mezun olan sınıflar", | ||
| 5975 | + "karne.title": "Karne", | ||
| 5976 | + "karne.average": "Yıl ortalaması", | ||
| 5977 | + "karne.verdict": "Sonuç", | ||
| 5978 | + "karne.passed": "Geçti", | ||
| 5979 | + "karne.failed": "Kaldı", | ||
| 5980 | + "karne.empty": "Bu döneme ait karne satırı yok.", | ||
| 5981 | + "karne.band": "Not aralığı", | ||
| 5982 | + "courses.members": "Üyeler", | ||
| 5983 | + "courses.memberItem": "üye", | ||
| 5984 | + "courses.addMember": "Üye ekle", | ||
| 5985 | + "courses.removeMember": "Üyeyi çıkar", | ||
| 5986 | + "courses.removeMemberConfirm": "Bu üye çıkarılsın mı?", | ||
| 5987 | + "courses.membersClubOnly": "Yalnızca kulüp ve etütlerin kendi üye listesi olur.", | ||
| 5988 | + "settings.branches": "Branşlar", | ||
| 5989 | + "settings.excuseKinds": "Mazeret türleri", | ||
| 5990 | + "settings.maxExcusedDays": "Mazeretli devamsızlık gün sınırı", | ||
| 5991 | + "settings.maxUnexcusedDays": "Mazeretsiz devamsızlık gün sınırı", | ||
| 5992 | + "settings.timezone": "Saat dilimi", | ||
| 5993 | + "attendance.devamsizlik": "Dönemlik devamsızlık", | ||
| 5994 | + "attendance.excusedDays": "Mazeretli gün", | ||
| 5995 | + "attendance.unexcusedDays": "Mazeretsiz gün", | ||
| 5996 | + "attendance.overLimit": "Sınır aşıldı", | ||
| 5997 | + "common.yes": "Evet", | ||
| 5998 | + "common.no": "Hayır", | ||
| 5819 | }; | 5999 | }; |
| 5820 | 6000 | ||
| 5821 | export const messages: Record<Locale, Dict> = { en, tr }; | 6001 | export const messages: Record<Locale, Dict> = { en, tr }; |
src/lib/instance-options.tsadded+74 -0
| @@ -0,0 +1,74 @@ | |||
| 1 | +import { getClasses, getClassInstances, getMyClasses } from "@/api/classes"; | ||
| 2 | +import { getCourseById } from "@/api/courses"; | ||
| 3 | +import { getMyInstances } from "@/api/instances"; | ||
| 4 | +import type { ClassGroup, Role } from "@/api/client"; | ||
| 5 | +import { hasMinRole } from "@/lib/roles"; | ||
| 6 | + | ||
| 7 | +/** One pickable section: "<ders> — <şube>", plus the ids behind the label. */ | ||
| 8 | +export type InstanceOption = { | ||
| 9 | + id: string; | ||
| 10 | + /** The catalog course it teaches — what subjects and question banks key on. */ | ||
| 11 | + course: string; | ||
| 12 | + class: string; | ||
| 13 | + label: string; | ||
| 14 | +}; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * The sections a user may act in, labelled for a picker. | ||
| 18 | + * | ||
| 19 | + * There is no course-scoped instance route, so the office walks the class list | ||
| 20 | + * (one read per class) while everyone else reads the single `/instances/me` | ||
| 21 | + * that already answers "which sections are mine". | ||
| 22 | + */ | ||
| 23 | +export async function loadInstanceOptions(role: Role | undefined): Promise<InstanceOption[]> { | ||
| 24 | + if (!role) return []; | ||
| 25 | + const office = hasMinRole(role, "manager"); | ||
| 26 | + | ||
| 27 | + const rows: { id: string; course: string; class: string }[] = []; | ||
| 28 | + const classNames = new Map<string, string>(); | ||
| 29 | + | ||
| 30 | + if (office) { | ||
| 31 | + const classes = (await getClasses({ limit: 200 })).items; | ||
| 32 | + const perClass = await Promise.all( | ||
| 33 | + classes.map(async (klass) => { | ||
| 34 | + classNames.set(klass.id, klass.name); | ||
| 35 | + try { | ||
| 36 | + return (await getClassInstances(klass.id, { limit: 200 })).items; | ||
| 37 | + } catch { | ||
| 38 | + // One unreadable şube must not empty the whole picker. | ||
| 39 | + return []; | ||
| 40 | + } | ||
| 41 | + }), | ||
| 42 | + ); | ||
| 43 | + for (const instance of perClass.flat()) { | ||
| 44 | + rows.push({ id: instance.id, course: instance.course, class: instance.class }); | ||
| 45 | + } | ||
| 46 | + } else { | ||
| 47 | + const [mine, classes] = await Promise.all([ | ||
| 48 | + getMyInstances({ limit: 200 }), | ||
| 49 | + (hasMinRole(role, "teacher") ? getClasses({ limit: 200 }) : getMyClasses({ limit: 200 })).catch( | ||
| 50 | + () => ({ items: [] as ClassGroup[] }), | ||
| 51 | + ), | ||
| 52 | + ]); | ||
| 53 | + for (const klass of classes.items) classNames.set(klass.id, klass.name); | ||
| 54 | + for (const instance of mine.items) { | ||
| 55 | + rows.push({ id: instance.id, course: instance.course, class: instance.class }); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + const titles = new Map<string, string>(); | ||
| 60 | + await Promise.all( | ||
| 61 | + [...new Set(rows.map((row) => row.course))].map(async (courseId) => { | ||
| 62 | + try { | ||
| 63 | + titles.set(courseId, (await getCourseById(courseId)).title); | ||
| 64 | + } catch { | ||
| 65 | + // Falls back to the id in the label below. | ||
| 66 | + } | ||
| 67 | + }), | ||
| 68 | + ); | ||
| 69 | + | ||
| 70 | + return rows.map((row) => ({ | ||
| 71 | + ...row, | ||
| 72 | + label: `${titles.get(row.course) ?? row.course} — ${classNames.get(row.class) ?? "—"}`, | ||
| 73 | + })); | ||
| 74 | +} | ||
src/lib/meals.test.tsmodified+16 -4
| @@ -18,19 +18,31 @@ describe("meal helpers", () => { | |||
| 18 | .toBe(Date.parse("2026-07-28T10:00:00Z")); | 18 | .toBe(Date.parse("2026-07-28T10:00:00Z")); |
| 19 | }); | 19 | }); |
| 20 | 20 | ||
| 21 | - it("selects nearest course work", () => { | 21 | + it("selects nearest course work for one instance", () => { |
| 22 | expect(nextCourseWork( | 22 | expect(nextCourseWork( |
| 23 | - "c1", | 23 | + "i1", |
| 24 | - [{ course: "c1", title: "Exam", starts_at: 30 } as never], | 24 | + [{ class_course: "i1", title: "Exam", starts_at: 30 } as never], |
| 25 | - [{ course: "c1", title: "Homework", due_at: 20 } as never], | 25 | + [{ class_course: "i1", title: "Homework", due_at: 20 } as never], |
| 26 | )?.title).toBe("Homework"); | 26 | )?.title).toBe("Homework"); |
| 27 | }); | 27 | }); |
| 28 | 28 | ||
| 29 | + // Two şubeler teaching the same course are two instances; work filed against | ||
| 30 | + // the other one must not surface here. | ||
| 31 | + it("ignores work filed against another instance", () => { | ||
| 32 | + expect(nextCourseWork( | ||
| 33 | + "i1", | ||
| 34 | + [{ class_course: "i2", title: "Exam", starts_at: 30 } as never], | ||
| 35 | + [{ class_course: "i2", title: "Homework", due_at: 20 } as never], | ||
| 36 | + )).toBeNull(); | ||
| 37 | + }); | ||
| 38 | + | ||
| 29 | it("builds a field-only settings patch", () => { | 39 | it("builds a field-only settings patch", () => { |
| 30 | const before = { | 40 | const before = { |
| 31 | exam_kinds: [], attendance_statuses: [], grade_bands: [], max_file_bytes: 1, | 41 | exam_kinds: [], attendance_statuses: [], grade_bands: [], max_file_bytes: 1, |
| 32 | chatbot_history_turns: 1, max_chatbot_threads: 1, max_chatbot_message_len: 100, | 42 | chatbot_history_turns: 1, max_chatbot_threads: 1, max_chatbot_message_len: 100, |
| 33 | meal_slots: [], dietary_tags: [], meal_cancel_cutoff_minutes: null, | 43 | meal_slots: [], dietary_tags: [], meal_cancel_cutoff_minutes: null, |
| 44 | + branches: [], excuse_kinds: [], max_excused_absent_days: null, | ||
| 45 | + max_unexcused_absent_days: null, timezone: null, | ||
| 34 | } satisfies SchoolSettings; | 46 | } satisfies SchoolSettings; |
| 35 | expect(dirtySettingsPatch(before, { ...before, max_chatbot_threads: 2 })).toEqual({ max_chatbot_threads: 2 }); | 47 | expect(dirtySettingsPatch(before, { ...before, max_chatbot_threads: 2 })).toEqual({ max_chatbot_threads: 2 }); |
| 36 | }); | 48 | }); |
src/lib/meals.tsmodified+8 -3
| @@ -21,10 +21,10 @@ export function mealCutoffAt(date: string, slot: MealSlot | undefined, minutes: | |||
| 21 | return Date.parse(`${date}T00:00:00Z`) + servingMinute * 60_000 - minutes * 60_000; | 21 | return Date.parse(`${date}T00:00:00Z`) + servingMinute * 60_000 - minutes * 60_000; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | -export function nextCourseWork(courseId: string, exams: Exam[], homework: Homework[]) { | 24 | +export function nextCourseWork(instanceId: string, exams: Exam[], homework: Homework[]) { |
| 25 | return [ | 25 | return [ |
| 26 | - ...exams.filter((item) => item.course === courseId).map((item) => ({ kind: "exam" as const, title: item.title, at: item.starts_at ?? item.ends_at })), | 26 | + ...exams.filter((item) => item.class_course === instanceId).map((item) => ({ kind: "exam" as const, title: item.title, at: item.starts_at ?? item.ends_at })), |
| 27 | - ...homework.filter((item) => item.course === courseId).map((item) => ({ kind: "homework" as const, title: item.title, at: item.due_at })), | 27 | + ...homework.filter((item) => item.class_course === instanceId).map((item) => ({ kind: "homework" as const, title: item.title, at: item.due_at })), |
| 28 | ] | 28 | ] |
| 29 | .filter((item): item is { kind: "exam" | "homework"; title: string; at: number } => item.at != null) | 29 | .filter((item): item is { kind: "exam" | "homework"; title: string; at: number } => item.at != null) |
| 30 | .sort((a, b) => a.at - b.at)[0] ?? null; | 30 | .sort((a, b) => a.at - b.at)[0] ?? null; |
| @@ -43,6 +43,11 @@ export function dirtySettingsPatch(before: SchoolSettings, after: SchoolSettings | |||
| 43 | "meal_slots", | 43 | "meal_slots", |
| 44 | "dietary_tags", | 44 | "dietary_tags", |
| 45 | "meal_cancel_cutoff_minutes", | 45 | "meal_cancel_cutoff_minutes", |
| 46 | + "excuse_kinds", | ||
| 47 | + "branches", | ||
| 48 | + "max_excused_absent_days", | ||
| 49 | + "max_unexcused_absent_days", | ||
| 50 | + "timezone", | ||
| 46 | ] as const) { | 51 | ] as const) { |
| 47 | if (JSON.stringify(before[key]) !== JSON.stringify(after[key])) patch[key] = after[key] as never; | 52 | if (JSON.stringify(before[key]) !== JSON.stringify(after[key])) patch[key] = after[key] as never; |
| 48 | } | 53 | } |
src/pages/academic-years-page.tsxadded+450 -0
| @@ -0,0 +1,450 @@ | |||
| 1 | +import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import { createResource } from "@/lib/create-resource"; | ||
| 3 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 4 | +import { | ||
| 5 | + deleteAcademicYearById, | ||
| 6 | + getAcademicYears, | ||
| 7 | + patchAcademicYearById, | ||
| 8 | + postAcademicYear, | ||
| 9 | + postAcademicYearArchive, | ||
| 10 | + postAcademicYearRollover, | ||
| 11 | +} from "@/api/academic-years"; | ||
| 12 | +import { formatApiError } from "@/api/client"; | ||
| 13 | +import type { AcademicYear, GradePromotion } from "@/api/client"; | ||
| 14 | +import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 15 | +import { Alert } from "@/components/ui/alert"; | ||
| 16 | +import { Badge } from "@/components/ui/badge"; | ||
| 17 | +import { Button } from "@/components/ui/button"; | ||
| 18 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 19 | +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | ||
| 20 | +import { DatePicker } from "@/components/ui/date-picker"; | ||
| 21 | +import { ErrorAlert } from "@/components/ui/error-alert"; | ||
| 22 | +import { IconArchive, IconEdit, IconPlus, IconRotateCcw, IconTrash } from "@/components/ui/icons"; | ||
| 23 | +import { Input } from "@/components/ui/input"; | ||
| 24 | +import { Label } from "@/components/ui/label"; | ||
| 25 | +import { PageHeader } from "@/components/layout/page-header"; | ||
| 26 | +import { Select } from "@/components/ui/select"; | ||
| 27 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 28 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 29 | +import { createFlash } from "@/lib/flash"; | ||
| 30 | +import { formatDateTime } from "@/lib/format"; | ||
| 31 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 32 | + | ||
| 33 | +const YEAR_PAGE_SIZE = 10; | ||
| 34 | + | ||
| 35 | +function dateInputFromMs(ms: number): string { | ||
| 36 | + const date = new Date(ms); | ||
| 37 | + const pad = (n: number) => String(n).padStart(2, "0"); | ||
| 38 | + return `${pad(date.getDate())}/${pad(date.getMonth() + 1)}/${date.getFullYear()}`; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +function dateInputToMs(value: string): number | null { | ||
| 42 | + const match = value.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); | ||
| 43 | + if (!match) return null; | ||
| 44 | + const [, dayRaw, monthRaw, yearRaw] = match; | ||
| 45 | + const day = Number(dayRaw); | ||
| 46 | + const month = Number(monthRaw); | ||
| 47 | + const year = Number(yearRaw); | ||
| 48 | + const date = new Date(year, month - 1, day, 0, 0, 0, 0); | ||
| 49 | + if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null; | ||
| 50 | + return date.getTime(); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +export default function AcademicYearsPage() { | ||
| 54 | + return ( | ||
| 55 | + <RouteGuard minRole="manager"> | ||
| 56 | + <AcademicYearsContent /> | ||
| 57 | + </RouteGuard> | ||
| 58 | + ); | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +function AcademicYearsContent() { | ||
| 62 | + const t = useT(); | ||
| 63 | + const { locale } = usePreferences(); | ||
| 64 | + const [list, { refetch }] = createResource(async () => (await getAcademicYears({ limit: 100 })).items); | ||
| 65 | + const years = () => list() ?? []; | ||
| 66 | + const openYears = createMemo(() => years().filter((year) => year.archived_at == null)); | ||
| 67 | + | ||
| 68 | + const [panelOpen, setPanelOpen] = createSignal(false); | ||
| 69 | + const [name, setName] = createSignal(""); | ||
| 70 | + const [starts, setStarts] = createSignal(""); | ||
| 71 | + const [ends, setEnds] = createSignal(""); | ||
| 72 | + const [promotions, setPromotions] = createSignal<GradePromotion[]>([]); | ||
| 73 | + const [editing, setEditing] = createSignal<AcademicYear | null>(null); | ||
| 74 | + const [deleteTarget, setDeleteTarget] = createSignal<AcademicYear | null>(null); | ||
| 75 | + const [archiveTarget, setArchiveTarget] = createSignal<AcademicYear | null>(null); | ||
| 76 | + const [rolloverTarget, setRolloverTarget] = createSignal<AcademicYear | null>(null); | ||
| 77 | + const [rolloverFrom, setRolloverFrom] = createSignal(""); | ||
| 78 | + const [error, setError] = createSignal(""); | ||
| 79 | + const [flash, setFlash] = createFlash(); | ||
| 80 | + const [pending, setPending] = createSignal(false); | ||
| 81 | + | ||
| 82 | + const resetForm = () => { | ||
| 83 | + setName(""); | ||
| 84 | + setStarts(""); | ||
| 85 | + setEnds(""); | ||
| 86 | + setPromotions([]); | ||
| 87 | + setEditing(null); | ||
| 88 | + setError(""); | ||
| 89 | + }; | ||
| 90 | + | ||
| 91 | + const openCreate = () => { | ||
| 92 | + resetForm(); | ||
| 93 | + setPanelOpen(true); | ||
| 94 | + }; | ||
| 95 | + | ||
| 96 | + const startEdit = (year: AcademicYear) => { | ||
| 97 | + setEditing(year); | ||
| 98 | + setName(year.name); | ||
| 99 | + setStarts(dateInputFromMs(year.starts_at)); | ||
| 100 | + setEnds(dateInputFromMs(year.ends_at)); | ||
| 101 | + setPromotions(year.grade_promotions.map((pair) => ({ ...pair }))); | ||
| 102 | + setError(""); | ||
| 103 | + setPanelOpen(true); | ||
| 104 | + }; | ||
| 105 | + | ||
| 106 | + const save = async (event: SubmitEvent) => { | ||
| 107 | + event.preventDefault(); | ||
| 108 | + setError(""); | ||
| 109 | + const starts_at = dateInputToMs(starts()); | ||
| 110 | + const ends_at = dateInputToMs(ends()); | ||
| 111 | + if (starts_at == null || ends_at == null) { | ||
| 112 | + setError(t("form.datePlaceholder")); | ||
| 113 | + return; | ||
| 114 | + } | ||
| 115 | + if (ends_at < starts_at) { | ||
| 116 | + setError(t("form.timeOrder")); | ||
| 117 | + return; | ||
| 118 | + } | ||
| 119 | + // A blank half is a half-written rule, not a policy — drop it rather than | ||
| 120 | + // sending a promotion the rollover cannot act on. | ||
| 121 | + const grade_promotions = promotions() | ||
| 122 | + .map((pair) => ({ from_grade: pair.from_grade.trim(), to_grade: pair.to_grade.trim() })) | ||
| 123 | + .filter((pair) => pair.from_grade && pair.to_grade); | ||
| 124 | + | ||
| 125 | + setPending(true); | ||
| 126 | + try { | ||
| 127 | + const current = editing(); | ||
| 128 | + if (current) { | ||
| 129 | + await patchAcademicYearById(current.id, { name: name().trim(), starts_at, ends_at, grade_promotions }); | ||
| 130 | + setFlash(t("common.saved")); | ||
| 131 | + } else { | ||
| 132 | + await postAcademicYear({ name: name().trim(), starts_at, ends_at, grade_promotions }); | ||
| 133 | + setFlash(t("common.created")); | ||
| 134 | + } | ||
| 135 | + resetForm(); | ||
| 136 | + setPanelOpen(false); | ||
| 137 | + await refetch(); | ||
| 138 | + } catch (err) { | ||
| 139 | + setError(formatApiError(err)); | ||
| 140 | + } finally { | ||
| 141 | + setPending(false); | ||
| 142 | + } | ||
| 143 | + }; | ||
| 144 | + | ||
| 145 | + const columns = createMemo<ColumnDef<AcademicYear>[]>(() => [ | ||
| 146 | + { | ||
| 147 | + accessorKey: "name", | ||
| 148 | + header: t("settings.name"), | ||
| 149 | + cell: (cell) => ( | ||
| 150 | + <span class="flex items-center gap-2 font-medium"> | ||
| 151 | + {cell.row.original.name} | ||
| 152 | + <Show when={cell.row.original.archived_at != null}> | ||
| 153 | + <Badge variant="secondary" class="rounded-full">{t("academicYears.archived")}</Badge> | ||
| 154 | + </Show> | ||
| 155 | + </span> | ||
| 156 | + ), | ||
| 157 | + }, | ||
| 158 | + { | ||
| 159 | + accessorKey: "starts_at", | ||
| 160 | + header: t("events.starts"), | ||
| 161 | + cell: (cell) => <span class="mono text-sm">{formatDateTime(cell.row.original.starts_at, locale())}</span>, | ||
| 162 | + }, | ||
| 163 | + { | ||
| 164 | + accessorKey: "ends_at", | ||
| 165 | + header: t("events.ends"), | ||
| 166 | + cell: (cell) => <span class="mono text-sm">{formatDateTime(cell.row.original.ends_at, locale())}</span>, | ||
| 167 | + }, | ||
| 168 | + { | ||
| 169 | + id: "classes", | ||
| 170 | + accessorFn: (row) => row.class_count, | ||
| 171 | + header: t("academicYears.classCount"), | ||
| 172 | + meta: { cellClass: "mono" }, | ||
| 173 | + }, | ||
| 174 | + { | ||
| 175 | + id: "terms", | ||
| 176 | + accessorFn: (row) => row.term_count, | ||
| 177 | + header: t("academicYears.termCount"), | ||
| 178 | + meta: { cellClass: "mono" }, | ||
| 179 | + }, | ||
| 180 | + { | ||
| 181 | + id: "actions", | ||
| 182 | + header: t("common.actions"), | ||
| 183 | + meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" }, | ||
| 184 | + cell: (cell) => { | ||
| 185 | + const year = cell.row.original; | ||
| 186 | + const archived = year.archived_at != null; | ||
| 187 | + return ( | ||
| 188 | + <TableRowActions | ||
| 189 | + label={t("common.actions")} | ||
| 190 | + actions={[ | ||
| 191 | + ...(archived | ||
| 192 | + ? [] | ||
| 193 | + : [ | ||
| 194 | + { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => startEdit(year) }, | ||
| 195 | + { | ||
| 196 | + label: t("academicYears.rollover"), | ||
| 197 | + icon: <IconRotateCcw class="h-4 w-4" />, | ||
| 198 | + onSelect: () => { | ||
| 199 | + setRolloverFrom(""); | ||
| 200 | + setRolloverTarget(year); | ||
| 201 | + }, | ||
| 202 | + }, | ||
| 203 | + { | ||
| 204 | + label: t("academicYears.archive"), | ||
| 205 | + icon: <IconArchive class="h-4 w-4" />, | ||
| 206 | + onSelect: () => setArchiveTarget(year), | ||
| 207 | + }, | ||
| 208 | + ]), | ||
| 209 | + { | ||
| 210 | + label: t("common.delete"), | ||
| 211 | + icon: <IconTrash class="h-4 w-4" />, | ||
| 212 | + destructive: true, | ||
| 213 | + onSelect: () => setDeleteTarget(year), | ||
| 214 | + }, | ||
| 215 | + ]} | ||
| 216 | + /> | ||
| 217 | + ); | ||
| 218 | + }, | ||
| 219 | + }, | ||
| 220 | + ]); | ||
| 221 | + | ||
| 222 | + return ( | ||
| 223 | + <div class="space-y-6"> | ||
| 224 | + <PageHeader title={t("academicYears.title")} description={t("academicYears.subtitle")} /> | ||
| 225 | + | ||
| 226 | + <Show when={flash()}> | ||
| 227 | + <Alert variant="success">{flash()}</Alert> | ||
| 228 | + </Show> | ||
| 229 | + <Show when={error() && !panelOpen()}> | ||
| 230 | + <Alert variant="destructive">{error()}</Alert> | ||
| 231 | + </Show> | ||
| 232 | + | ||
| 233 | + <section class="data-shell space-y-4 p-4"> | ||
| 234 | + <Suspense fallback={<DataTableSkeleton columns={6} rows={6} />}> | ||
| 235 | + <Show when={list.error}> | ||
| 236 | + <ErrorAlert message={formatApiError(list.error)} onRetry={() => void refetch()} /> | ||
| 237 | + </Show> | ||
| 238 | + <DataTable | ||
| 239 | + title={t("academicYears.title")} | ||
| 240 | + description={t("academicYears.subtitle")} | ||
| 241 | + actions={ | ||
| 242 | + <Button type="button" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={openCreate}> | ||
| 243 | + <IconPlus class="h-4 w-4" /> | ||
| 244 | + {t("academicYears.new")} | ||
| 245 | + </Button> | ||
| 246 | + } | ||
| 247 | + columns={columns()} | ||
| 248 | + data={years()} | ||
| 249 | + tableClass="min-w-160" | ||
| 250 | + filterColumn="name" | ||
| 251 | + enablePagination | ||
| 252 | + pageSize={YEAR_PAGE_SIZE} | ||
| 253 | + empty={t("academicYears.empty")} | ||
| 254 | + /> | ||
| 255 | + </Suspense> | ||
| 256 | + </section> | ||
| 257 | + | ||
| 258 | + <SidePanel | ||
| 259 | + open={panelOpen()} | ||
| 260 | + onOpenChange={(open) => { | ||
| 261 | + setPanelOpen(open); | ||
| 262 | + if (!open) resetForm(); | ||
| 263 | + }} | ||
| 264 | + title={editing() ? t("common.edit") : t("academicYears.new")} | ||
| 265 | + description={t("academicYears.subtitle")} | ||
| 266 | + > | ||
| 267 | + <form class="space-y-4" onSubmit={save}> | ||
| 268 | + <Show when={error()}> | ||
| 269 | + <Alert variant="destructive">{error()}</Alert> | ||
| 270 | + </Show> | ||
| 271 | + <div class="space-y-1.5"> | ||
| 272 | + <Label for="year-name">{t("settings.name")}</Label> | ||
| 273 | + <Input id="year-name" class="rounded-lg" required maxlength={100} value={name()} onInput={(e) => setName(e.currentTarget.value)} /> | ||
| 274 | + </div> | ||
| 275 | + <div class="space-y-1.5"> | ||
| 276 | + <Label for="year-starts">{t("events.starts")}</Label> | ||
| 277 | + <DatePicker id="year-starts" placeholder={t("form.datePlaceholder")} required value={starts()} onChange={setStarts} /> | ||
| 278 | + </div> | ||
| 279 | + <div class="space-y-1.5"> | ||
| 280 | + <Label for="year-ends">{t("events.ends")}</Label> | ||
| 281 | + <DatePicker id="year-ends" placeholder={t("form.datePlaceholder")} required value={ends()} onChange={setEnds} /> | ||
| 282 | + </div> | ||
| 283 | + | ||
| 284 | + <div class="space-y-2 rounded-xl border border-border-line bg-surface-tint p-3"> | ||
| 285 | + <div class="flex flex-wrap items-center justify-between gap-2"> | ||
| 286 | + <div class="min-w-0"> | ||
| 287 | + <p class="text-sm font-semibold">{t("academicYears.promotions")}</p> | ||
| 288 | + <p class="mt-0.5 text-xs text-muted-foreground">{t("academicYears.promotionsHelp")}</p> | ||
| 289 | + </div> | ||
| 290 | + <Button | ||
| 291 | + type="button" | ||
| 292 | + size="sm" | ||
| 293 | + variant="outline" | ||
| 294 | + class="rounded-lg" | ||
| 295 | + onClick={() => setPromotions((rows) => [...rows, { from_grade: "", to_grade: "" }])} | ||
| 296 | + > | ||
| 297 | + <IconPlus class="h-4 w-4" /> | ||
| 298 | + {t("academicYears.addPromotion")} | ||
| 299 | + </Button> | ||
| 300 | + </div> | ||
| 301 | + <For each={promotions()}> | ||
| 302 | + {(pair, index) => ( | ||
| 303 | + <div class="grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] items-center gap-2"> | ||
| 304 | + <Input | ||
| 305 | + aria-label={t("academicYears.fromGrade")} | ||
| 306 | + class="h-9 rounded-md" | ||
| 307 | + maxlength={20} | ||
| 308 | + value={pair.from_grade} | ||
| 309 | + placeholder={t("academicYears.fromGrade")} | ||
| 310 | + onInput={(e) => | ||
| 311 | + setPromotions((rows) => rows.map((row, i) => (i === index() ? { ...row, from_grade: e.currentTarget.value } : row))) | ||
| 312 | + } | ||
| 313 | + /> | ||
| 314 | + <Input | ||
| 315 | + aria-label={t("academicYears.toGrade")} | ||
| 316 | + class="h-9 rounded-md" | ||
| 317 | + maxlength={20} | ||
| 318 | + value={pair.to_grade} | ||
| 319 | + placeholder={t("academicYears.toGrade")} | ||
| 320 | + onInput={(e) => | ||
| 321 | + setPromotions((rows) => rows.map((row, i) => (i === index() ? { ...row, to_grade: e.currentTarget.value } : row))) | ||
| 322 | + } | ||
| 323 | + /> | ||
| 324 | + <Button | ||
| 325 | + type="button" | ||
| 326 | + variant="ghost" | ||
| 327 | + size="icon" | ||
| 328 | + class="h-9 w-9 rounded-md text-muted-foreground hover:text-destructive" | ||
| 329 | + aria-label={t("common.delete")} | ||
| 330 | + onClick={() => setPromotions((rows) => rows.filter((_, i) => i !== index()))} | ||
| 331 | + > | ||
| 332 | + <IconTrash class="h-4 w-4" /> | ||
| 333 | + </Button> | ||
| 334 | + </div> | ||
| 335 | + )} | ||
| 336 | + </For> | ||
| 337 | + </div> | ||
| 338 | + | ||
| 339 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 340 | + <Button type="button" variant="outline" class="h-10 rounded-lg" onClick={() => setPanelOpen(false)}> | ||
| 341 | + {t("common.cancel")} | ||
| 342 | + </Button> | ||
| 343 | + <Button type="submit" class="h-10 rounded-lg" disabled={pending()}> | ||
| 344 | + {editing() ? t("common.update") : t("common.create")} | ||
| 345 | + </Button> | ||
| 346 | + </div> | ||
| 347 | + </form> | ||
| 348 | + </SidePanel> | ||
| 349 | + | ||
| 350 | + <SidePanel | ||
| 351 | + open={rolloverTarget() !== null} | ||
| 352 | + onOpenChange={(open) => !open && setRolloverTarget(null)} | ||
| 353 | + title={t("academicYears.rollover")} | ||
| 354 | + description={rolloverTarget()?.name ?? ""} | ||
| 355 | + > | ||
| 356 | + <form | ||
| 357 | + class="space-y-4" | ||
| 358 | + onSubmit={(event) => { | ||
| 359 | + event.preventDefault(); | ||
| 360 | + const target = rolloverTarget(); | ||
| 361 | + const from = rolloverFrom(); | ||
| 362 | + if (!target || !from) return; | ||
| 363 | + void (async () => { | ||
| 364 | + setPending(true); | ||
| 365 | + setError(""); | ||
| 366 | + try { | ||
| 367 | + const result = await postAcademicYearRollover(target.id, from); | ||
| 368 | + setFlash(t("academicYears.rolloverDone", { classes: result.classes, students: result.students })); | ||
| 369 | + setRolloverTarget(null); | ||
| 370 | + await refetch(); | ||
| 371 | + } catch (err) { | ||
| 372 | + setError(formatApiError(err)); | ||
| 373 | + } finally { | ||
| 374 | + setPending(false); | ||
| 375 | + } | ||
| 376 | + })(); | ||
| 377 | + }} | ||
| 378 | + > | ||
| 379 | + <Show when={error()}> | ||
| 380 | + <Alert variant="destructive">{error()}</Alert> | ||
| 381 | + </Show> | ||
| 382 | + <p class="text-sm text-muted-foreground">{t("academicYears.rolloverHelp")}</p> | ||
| 383 | + <div class="space-y-1.5"> | ||
| 384 | + <Label for="rollover-from">{t("academicYears.rolloverFrom")}</Label> | ||
| 385 | + <Select id="rollover-from" class="rounded-lg" value={rolloverFrom()} onChange={(e) => setRolloverFrom(e.currentTarget.value)}> | ||
| 386 | + <option value="">{t("academicYears.unassigned")}</option> | ||
| 387 | + <For each={years().filter((year) => year.id !== rolloverTarget()?.id)}> | ||
| 388 | + {(year) => <option value={year.id}>{year.name}</option>} | ||
| 389 | + </For> | ||
| 390 | + </Select> | ||
| 391 | + </div> | ||
| 392 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 393 | + <Button type="button" variant="outline" class="h-10 rounded-lg" onClick={() => setRolloverTarget(null)}> | ||
| 394 | + {t("common.cancel")} | ||
| 395 | + </Button> | ||
| 396 | + <Button type="submit" class="h-10 rounded-lg" disabled={pending() || !rolloverFrom()}> | ||
| 397 | + {t("academicYears.rollover")} | ||
| 398 | + </Button> | ||
| 399 | + </div> | ||
| 400 | + </form> | ||
| 401 | + </SidePanel> | ||
| 402 | + | ||
| 403 | + <ConfirmDialog | ||
| 404 | + open={archiveTarget() != null} | ||
| 405 | + onOpenChange={(open) => !open && setArchiveTarget(null)} | ||
| 406 | + title={t("academicYears.archive")} | ||
| 407 | + variant="destructive" | ||
| 408 | + summary={`${archiveTarget()?.name ?? ""} — ${t("academicYears.archiveConfirm")}`} | ||
| 409 | + onConfirm={async () => { | ||
| 410 | + const year = archiveTarget(); | ||
| 411 | + if (!year) return; | ||
| 412 | + try { | ||
| 413 | + await postAcademicYearArchive(year.id); | ||
| 414 | + setFlash(t("academicYears.archived")); | ||
| 415 | + await refetch(); | ||
| 416 | + } catch (err) { | ||
| 417 | + setError(formatApiError(err)); | ||
| 418 | + } finally { | ||
| 419 | + setArchiveTarget(null); | ||
| 420 | + } | ||
| 421 | + }} | ||
| 422 | + /> | ||
| 423 | + | ||
| 424 | + <ConfirmDialog | ||
| 425 | + open={deleteTarget() != null} | ||
| 426 | + onOpenChange={(open) => !open && setDeleteTarget(null)} | ||
| 427 | + title={t("confirm.deleteTitle")} | ||
| 428 | + variant="destructive" | ||
| 429 | + summary={`${deleteTarget()?.name ?? ""} — ${t("academicYears.deleteConfirm")}`} | ||
| 430 | + onConfirm={async () => { | ||
| 431 | + const year = deleteTarget(); | ||
| 432 | + if (!year) return; | ||
| 433 | + try { | ||
| 434 | + await deleteAcademicYearById(year.id); | ||
| 435 | + setFlash(t("common.deleted")); | ||
| 436 | + await refetch(); | ||
| 437 | + } catch (err) { | ||
| 438 | + setError(formatApiError(err)); | ||
| 439 | + } finally { | ||
| 440 | + setDeleteTarget(null); | ||
| 441 | + } | ||
| 442 | + }} | ||
| 443 | + /> | ||
| 444 | + | ||
| 445 | + <Show when={openYears().length === 0 && years().length > 0}> | ||
| 446 | + <Alert>{t("academicYears.empty")}</Alert> | ||
| 447 | + </Show> | ||
| 448 | + </div> | ||
| 449 | + ); | ||
| 450 | +} | ||
src/pages/bank-question-detail-page.tsxmodified+0 -1
| @@ -52,7 +52,6 @@ function BankQuestionDetailContent() { | |||
| 52 | const current = auth.user(); | 52 | const current = auth.user(); |
| 53 | return !!current && ( | 53 | return !!current && ( |
| 54 | course.creator.id === current.id || | 54 | course.creator.id === current.id || |
| 55 | - (course.teachers ?? []).some((teacher) => teacher.id === current.id) || | ||
| 56 | hasMinRole(current.role, "manager") | 55 | hasMinRole(current.role, "manager") |
| 57 | ); | 56 | ); |
| 58 | }), | 57 | }), |
src/pages/calendar-page.tsxmodified+14 -7
| @@ -4,7 +4,8 @@ import { getEvents } from "@/api/events"; | |||
| 4 | import { getExams } from "@/api/exams"; | 4 | import { getExams } from "@/api/exams"; |
| 5 | import { getHomework } from "@/api/homework"; | 5 | import { getHomework } from "@/api/homework"; |
| 6 | import { getAppointments } from "@/api/appointments"; | 6 | import { getAppointments } from "@/api/appointments"; |
| 7 | -import { getCourseSessions, getCourses } from "@/api/courses"; | 7 | +import { getCourses } from "@/api/courses"; |
| 8 | +import { getInstanceSessions, getMyInstances } from "@/api/instances"; | ||
| 8 | import { getMyCourses } from "@/api/reports"; | 9 | import { getMyCourses } from "@/api/reports"; |
| 9 | import type { Appointment, AppointmentStatus, Course } from "@/api/client"; | 10 | import type { Appointment, AppointmentStatus, Course } from "@/api/client"; |
| 10 | import { appointmentStatusClass, appointmentStatusDotClass, appointmentStatusLabelKey } from "@/lib/appointment-status"; | 11 | import { appointmentStatusClass, appointmentStatusDotClass, appointmentStatusLabelKey } from "@/lib/appointment-status"; |
| @@ -158,16 +159,22 @@ function CalendarContent() { | |||
| 158 | const [sessions] = createResource( | 159 | const [sessions] = createResource( |
| 159 | () => auth.user()?.role ?? null, | 160 | () => auth.user()?.role ?? null, |
| 160 | async (role) => { | 161 | async (role) => { |
| 161 | - const courses: Course[] = role === "student" | 162 | + // Sessions hang off the instance (şube × ders) now; the catalog course is |
| 162 | - ? (await getMyCourses()).items | 163 | + // still what says whether a meeting is a ders, an etüt or a kulüp. |
| 163 | - : (await getCourses()).items; | 164 | + const [instances, courses] = await Promise.all([ |
| 165 | + getMyInstances({ limit: 200 }), | ||
| 166 | + role === "student" ? getMyCourses() : getCourses(), | ||
| 167 | + ]); | ||
| 168 | + const byId = new Map<string, Course>(courses.items.map((course) => [course.id, course])); | ||
| 164 | const pages = await Promise.all( | 169 | const pages = await Promise.all( |
| 165 | - courses.slice(0, SESSION_COURSE_CAP).map(async (course) => { | 170 | + instances.items.slice(0, SESSION_COURSE_CAP).map(async (instance) => { |
| 171 | + const course = byId.get(instance.course); | ||
| 172 | + if (!course) return []; | ||
| 166 | try { | 173 | try { |
| 167 | - const page = await getCourseSessions(course.id, { limit: 100 }); | 174 | + const page = await getInstanceSessions(instance.id, { limit: 100 }); |
| 168 | return page.items.map((session) => ({ session, course })); | 175 | return page.items.map((session) => ({ session, course })); |
| 169 | } catch { | 176 | } catch { |
| 170 | - // One unreadable course must not empty the whole calendar. | 177 | + // One unreadable section must not empty the whole calendar. |
| 171 | return []; | 178 | return []; |
| 172 | } | 179 | } |
| 173 | }), | 180 | }), |
src/pages/class-detail-page.tsxmodified+30 -15
| @@ -9,13 +9,13 @@ import { | |||
| 9 | getClassMembers, | 9 | getClassMembers, |
| 10 | postClassMember, | 10 | postClassMember, |
| 11 | deleteClassMember, | 11 | deleteClassMember, |
| 12 | - getClassCourses, | 12 | + getClassInstances, |
| 13 | - postClassCourse, | 13 | + postClassInstance, |
| 14 | - deleteClassCourse, | 14 | + deleteClassInstance, |
| 15 | postClassBlueprintApply, | 15 | postClassBlueprintApply, |
| 16 | } from "@/api/classes"; | 16 | } from "@/api/classes"; |
| 17 | import { getCourses } from "@/api/courses"; | 17 | import { getCourses } from "@/api/courses"; |
| 18 | -import { getTerms } from "@/api/terms"; | 18 | +import { getAcademicYears } from "@/api/academic-years"; |
| 19 | import { getLimits } from "@/api/limits"; | 19 | import { getLimits } from "@/api/limits"; |
| 20 | import { ApiError, formatApiError, type BlueprintSkip, type ClassCourse, type ClassGroup, type ClassMember } from "@/api/client"; | 20 | import { ApiError, formatApiError, type BlueprintSkip, type ClassCourse, type ClassGroup, type ClassMember } from "@/api/client"; |
| 21 | import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report"; | 21 | import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report"; |
| @@ -61,7 +61,7 @@ function ClassDetailContent() { | |||
| 61 | const [editing, setEditing] = createSignal(false); | 61 | const [editing, setEditing] = createSignal(false); |
| 62 | const [name, setName] = createSignal(""); | 62 | const [name, setName] = createSignal(""); |
| 63 | const [grade, setGrade] = createSignal(""); | 63 | const [grade, setGrade] = createSignal(""); |
| 64 | - const [termId, setTermId] = createSignal(""); | 64 | + const [yearId, setYearId] = createSignal(""); |
| 65 | const [teacherId, setTeacherId] = createSignal(""); | 65 | const [teacherId, setTeacherId] = createSignal(""); |
| 66 | const [deleteOpen, setDeleteOpen] = createSignal(false); | 66 | const [deleteOpen, setDeleteOpen] = createSignal(false); |
| 67 | const [showAddMember, setShowAddMember] = createSignal(false); | 67 | const [showAddMember, setShowAddMember] = createSignal(false); |
| @@ -74,11 +74,11 @@ function ClassDetailContent() { | |||
| 74 | const [reportOpen, setReportOpen] = createSignal(false); | 74 | const [reportOpen, setReportOpen] = createSignal(false); |
| 75 | 75 | ||
| 76 | const [cls, { refetch: refetchClass }] = createResource(id, (classId) => getClassById(classId)); | 76 | const [cls, { refetch: refetchClass }] = createResource(id, (classId) => getClassById(classId)); |
| 77 | - const [terms] = createResource(async () => (await getTerms({ limit: 100 })).items); | 77 | + const [years] = createResource(async () => (await getAcademicYears({ limit: 100 })).items); |
| 78 | const [limits] = createResource(() => canManage() ? getLimits() : null); | 78 | const [limits] = createResource(() => canManage() ? getLimits() : null); |
| 79 | const [courses] = createResource(() => canManage() ? getCourses().then((page) => page.items) : null); | 79 | const [courses] = createResource(() => canManage() ? getCourses().then((page) => page.items) : null); |
| 80 | const [members, { refetch: refetchMembers }] = createResource(id, async (classId) => (await getClassMembers(classId, { limit: 200 })).items); | 80 | const [members, { refetch: refetchMembers }] = createResource(id, async (classId) => (await getClassMembers(classId, { limit: 200 })).items); |
| 81 | - const [classCourses, { refetch: refetchCourses }] = createResource(id, async (classId) => (await getClassCourses(classId, { limit: 50 })).items); | 81 | + const [classCourses, { refetch: refetchCourses }] = createResource(id, async (classId) => (await getClassInstances(classId, { limit: 50 })).items); |
| 82 | 82 | ||
| 83 | // The last class the page actually loaded. A refetch that fails leaves the | 83 | // The last class the page actually loaded. A refetch that fails leaves the |
| 84 | // resource in an error state, and reading it there throws; holding the last | 84 | // resource in an error state, and reading it there throws; holding the last |
| @@ -89,7 +89,7 @@ function ClassDetailContent() { | |||
| 89 | if (cls.state === "ready") setLoadedClass(cls()); | 89 | if (cls.state === "ready") setLoadedClass(cls()); |
| 90 | }); | 90 | }); |
| 91 | 91 | ||
| 92 | - const termName = (tid: string | null) => terms.latest?.find((term) => term.id === tid)?.name ?? (tid || t("terms.unassigned")); | 92 | + const yearName = (yid: string | null) => years.latest?.find((year) => year.id === yid)?.name ?? (yid || t("academicYears.unassigned")); |
| 93 | const courseTitle = (courseId: string) => courses.latest?.find((course) => course.id === courseId)?.title ?? courseId; | 93 | const courseTitle = (courseId: string) => courses.latest?.find((course) => course.id === courseId)?.title ?? courseId; |
| 94 | const memberUserIds = () => (members.latest ?? []).map((row) => row.user.id); | 94 | const memberUserIds = () => (members.latest ?? []).map((row) => row.user.id); |
| 95 | const attachedCourseIds = () => (classCourses.latest ?? []).map((row) => row.course); | 95 | const attachedCourseIds = () => (classCourses.latest ?? []).map((row) => row.course); |
| @@ -184,6 +184,18 @@ function ClassDetailContent() { | |||
| 184 | header: t("classGroups.courseColumn"), | 184 | header: t("classGroups.courseColumn"), |
| 185 | meta: { cellClass: "font-medium" }, | 185 | meta: { cellClass: "font-medium" }, |
| 186 | }, | 186 | }, |
| 187 | + { | ||
| 188 | + id: "dersSaati", | ||
| 189 | + accessorFn: (row) => row.ders_saati, | ||
| 190 | + header: t("instances.dersSaati"), | ||
| 191 | + meta: { cellClass: "mono" }, | ||
| 192 | + }, | ||
| 193 | + { | ||
| 194 | + id: "roster", | ||
| 195 | + accessorFn: (row) => row.enrollment_count, | ||
| 196 | + header: t("courses.roster"), | ||
| 197 | + meta: { cellClass: "mono" }, | ||
| 198 | + }, | ||
| 187 | { | 199 | { |
| 188 | id: "attachedBy", | 200 | id: "attachedBy", |
| 189 | accessorFn: (row) => personLabel(row.attached_by), | 201 | accessorFn: (row) => personLabel(row.attached_by), |
| @@ -198,7 +210,10 @@ function ClassDetailContent() { | |||
| 198 | <Show when={canManage()}> | 210 | <Show when={canManage()}> |
| 199 | <TableRowActions | 211 | <TableRowActions |
| 200 | label={t("common.actions")} | 212 | label={t("common.actions")} |
| 201 | - actions={[{ label: t("classGroups.detachCourse"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDetachCourse(cell.row.original) }]} | 213 | + actions={[ |
| 214 | + { label: t("instances.open"), icon: <IconExternalLink class="h-4 w-4" />, onSelect: () => void navigate({ to: "/instances/$id", params: { id: cell.row.original.id } }) }, | ||
| 215 | + { label: t("classGroups.detachCourse"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDetachCourse(cell.row.original) }, | ||
| 216 | + ]} | ||
| 202 | /> | 217 | /> |
| 203 | </Show> | 218 | </Show> |
| 204 | ), | 219 | ), |
| @@ -228,7 +243,7 @@ function ClassDetailContent() { | |||
| 228 | <h1 class="text-2xl font-semibold tracking-tight">{c().name}</h1> | 243 | <h1 class="text-2xl font-semibold tracking-tight">{c().name}</h1> |
| 229 | <div class="flex flex-wrap items-center gap-2 text-sm text-muted-foreground"> | 244 | <div class="flex flex-wrap items-center gap-2 text-sm text-muted-foreground"> |
| 230 | <Show when={c().grade}><Badge variant="secondary" class="rounded-full">{c().grade}</Badge></Show> | 245 | <Show when={c().grade}><Badge variant="secondary" class="rounded-full">{c().grade}</Badge></Show> |
| 231 | - <span>{termName(c().term)}</span> | 246 | + <span>{yearName(c().year)}</span> |
| 232 | <span>·</span> | 247 | <span>·</span> |
| 233 | <span>{t("classGroups.homeroomTeacher")}: {c().teacher ? personLabel(c().teacher!) : t("classGroups.noTeacher")}</span> | 248 | <span>{t("classGroups.homeroomTeacher")}: {c().teacher ? personLabel(c().teacher!) : t("classGroups.noTeacher")}</span> |
| 234 | </div> | 249 | </div> |
| @@ -245,7 +260,7 @@ function ClassDetailContent() { | |||
| 245 | > | 260 | > |
| 246 | {t("classBlueprints.apply")} | 261 | {t("classBlueprints.apply")} |
| 247 | </Button> | 262 | </Button> |
| 248 | - <Button size="sm" variant="outline" class="rounded-lg" onClick={() => { setName(c().name); setGrade(c().grade ?? ""); setTermId(c().term ?? ""); setTeacherId(c().teacher?.id ?? ""); setEditing(true); }}>{t("common.edit")}</Button> | 263 | + <Button size="sm" variant="outline" class="rounded-lg" onClick={() => { setName(c().name); setGrade(c().grade ?? ""); setYearId(c().year ?? ""); setTeacherId(c().teacher?.id ?? ""); setEditing(true); }}>{t("common.edit")}</Button> |
| 249 | <Button size="sm" variant="outline" class="rounded-lg text-destructive" onClick={() => setDeleteOpen(true)}>{t("classGroups.deleteClass")}</Button> | 264 | <Button size="sm" variant="outline" class="rounded-lg text-destructive" onClick={() => setDeleteOpen(true)}>{t("classGroups.deleteClass")}</Button> |
| 250 | </div> | 265 | </div> |
| 251 | </Show> | 266 | </Show> |
| @@ -299,11 +314,11 @@ function ClassDetailContent() { | |||
| 299 | 314 | ||
| 300 | {/* Edit class */} | 315 | {/* Edit class */} |
| 301 | <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().name}> | 316 | <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().name}> |
| 302 | - <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { await patchClassById(id(), { name: name().trim(), grade: grade().trim() || null, term_id: termId() || null, teacher_id: teacherId() || null }); setEditing(false); await refresh(refetchClass); }, "common.saved"); }}> | 317 | + <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { await patchClassById(id(), { name: name().trim(), grade: grade().trim() || null, year: yearId() || null, teacher_id: teacherId() || null }); setEditing(false); await refresh(refetchClass); }, "common.saved"); }}> |
| 303 | <div class="space-y-3"> | 318 | <div class="space-y-3"> |
| 304 | <div class="space-y-1.5"><Label for="edit-class-name">{t("classGroups.className")}</Label><Input id="edit-class-name" maxlength={limits.latest?.course.max_class_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div> | 319 | <div class="space-y-1.5"><Label for="edit-class-name">{t("classGroups.className")}</Label><Input id="edit-class-name" maxlength={limits.latest?.course.max_class_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div> |
| 305 | <div class="space-y-1.5"><Label for="edit-class-grade">{t("classGroups.grade")}</Label><Input id="edit-class-grade" maxlength={limits.latest?.course.max_class_grade_len} value={grade()} onInput={(e) => setGrade(e.currentTarget.value)} /></div> | 320 | <div class="space-y-1.5"><Label for="edit-class-grade">{t("classGroups.grade")}</Label><Input id="edit-class-grade" maxlength={limits.latest?.course.max_class_grade_len} value={grade()} onInput={(e) => setGrade(e.currentTarget.value)} /></div> |
| 306 | - <div class="space-y-1.5"><Label for="edit-class-term">{t("terms.term")}</Label><Select id="edit-class-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}><option value="">{t("terms.unassigned")}</option><For each={terms.latest ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For></Select></div> | 321 | + <div class="space-y-1.5"><Label for="edit-class-year">{t("academicYears.year")}</Label><Select id="edit-class-year" value={yearId()} onChange={(e) => setYearId(e.currentTarget.value)}><option value="">{t("academicYears.unassigned")}</option><For each={years.latest ?? []}>{(year) => <option value={year.id}>{year.name}</option>}</For></Select></div> |
| 307 | <UserSearchSelect id="edit-class-teacher" label={t("classGroups.homeroomTeacher")} value={teacherId()} onChange={setTeacherId} placeholder={t("classGroups.selectTeacher")} role="teacher" /> | 322 | <UserSearchSelect id="edit-class-teacher" label={t("classGroups.homeroomTeacher")} value={teacherId()} onChange={setTeacherId} placeholder={t("classGroups.selectTeacher")} role="teacher" /> |
| 308 | </div> | 323 | </div> |
| 309 | <div class="flex gap-2 border-t pt-4"><Button type="submit" disabled={pending()}>{t("common.save")}</Button><Button type="button" variant="outline" onClick={() => setEditing(false)}>{t("common.cancel")}</Button></div> | 324 | <div class="flex gap-2 border-t pt-4"><Button type="submit" disabled={pending()}>{t("common.save")}</Button><Button type="button" variant="outline" onClick={() => setEditing(false)}>{t("common.cancel")}</Button></div> |
| @@ -320,7 +335,7 @@ function ClassDetailContent() { | |||
| 320 | 335 | ||
| 321 | {/* Attach course */} | 336 | {/* Attach course */} |
| 322 | <SidePanel open={showAttachCourse()} onOpenChange={setShowAttachCourse} title={t("classGroups.attachCourse")} description={t("classGroups.attachCourseHelp")}> | 337 | <SidePanel open={showAttachCourse()} onOpenChange={setShowAttachCourse} title={t("classGroups.attachCourse")} description={t("classGroups.attachCourseHelp")}> |
| 323 | - <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); const cid = attachCourseId(); if (!cid) return; void wrap(async () => { await postClassCourse(id(), { course_id: cid }); setAttachCourseId(""); setShowAttachCourse(false); await refresh(refetchCourses); }, "common.saved"); }}> | 338 | + <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); const cid = attachCourseId(); if (!cid) return; void wrap(async () => { await postClassInstance(id(), { course_id: cid }); setAttachCourseId(""); setShowAttachCourse(false); await refresh(refetchCourses); }, "common.saved"); }}> |
| 324 | <div class="space-y-1.5"> | 339 | <div class="space-y-1.5"> |
| 325 | <Label for="class-attach-course">{t("classGroups.selectCourse")}</Label> | 340 | <Label for="class-attach-course">{t("classGroups.selectCourse")}</Label> |
| 326 | <Select id="class-attach-course" value={attachCourseId()} onChange={(e) => setAttachCourseId(e.currentTarget.value)}> | 341 | <Select id="class-attach-course" value={attachCourseId()} onChange={(e) => setAttachCourseId(e.currentTarget.value)}> |
| @@ -359,7 +374,7 @@ function ClassDetailContent() { | |||
| 359 | title={t("classGroups.detachCourse")} | 374 | title={t("classGroups.detachCourse")} |
| 360 | variant="destructive" | 375 | variant="destructive" |
| 361 | summary={t("classGroups.detachCourseConfirm", { course: detachCourse() ? courseTitle(detachCourse()!.course) : "" })} | 376 | summary={t("classGroups.detachCourseConfirm", { course: detachCourse() ? courseTitle(detachCourse()!.course) : "" })} |
| 362 | - onConfirm={async () => { const target = detachCourse(); if (!target) return; await wrap(async () => { await deleteClassCourse(id(), target.course); await refresh(refetchCourses); setDetachCourse(null); }, "common.deleted"); }} | 377 | + onConfirm={async () => { const target = detachCourse(); if (!target) return; await wrap(async () => { await deleteClassInstance(id(), target.id); await refresh(refetchCourses); setDetachCourse(null); }, "common.deleted"); }} |
| 363 | /> | 378 | /> |
| 364 | </div> | 379 | </div> |
| 365 | )} | 380 | )} |
src/pages/classes-page.tsxmodified+10 -10
| @@ -2,7 +2,7 @@ import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; | |||
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { useNavigate } from "@tanstack/solid-router"; | 3 | import { useNavigate } from "@tanstack/solid-router"; |
| 4 | import { getClasses, getClassMembers, postClass } from "@/api/classes"; | 4 | import { getClasses, getClassMembers, postClass } from "@/api/classes"; |
| 5 | -import { getTerms } from "@/api/terms"; | 5 | +import { getAcademicYears } from "@/api/academic-years"; |
| 6 | import { getLimits } from "@/api/limits"; | 6 | import { getLimits } from "@/api/limits"; |
| 7 | import { formatApiError, type ClassGroup } from "@/api/client"; | 7 | import { formatApiError, type ClassGroup } from "@/api/client"; |
| 8 | import { RouteGuard } from "@/components/layout/route-guard"; | 8 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -51,17 +51,17 @@ function ClassesContent() { | |||
| 51 | const [showForm, setShowForm] = createSignal(false); | 51 | const [showForm, setShowForm] = createSignal(false); |
| 52 | const [name, setName] = createSignal(""); | 52 | const [name, setName] = createSignal(""); |
| 53 | const [grade, setGrade] = createSignal(""); | 53 | const [grade, setGrade] = createSignal(""); |
| 54 | - const [termId, setTermId] = createSignal(""); | 54 | + const [yearId, setYearId] = createSignal(""); |
| 55 | const [teacherId, setTeacherId] = createSignal(""); | 55 | const [teacherId, setTeacherId] = createSignal(""); |
| 56 | const [error, setError] = createSignal(""); | 56 | const [error, setError] = createSignal(""); |
| 57 | const [pending, setPending] = createSignal(false); | 57 | const [pending, setPending] = createSignal(false); |
| 58 | const [flash, setFlash] = createFlash(); | 58 | const [flash, setFlash] = createFlash(); |
| 59 | 59 | ||
| 60 | - const [terms] = createResource(async () => (await getTerms({ limit: 100 })).items); | 60 | + const [years] = createResource(async () => (await getAcademicYears({ limit: 100 })).items); |
| 61 | const [limits] = createResource(() => canManage() ? getLimits() : null); | 61 | const [limits] = createResource(() => canManage() ? getLimits() : null); |
| 62 | const [list, { refetch }] = createResource(async () => (await getClasses()).items); | 62 | const [list, { refetch }] = createResource(async () => (await getClasses()).items); |
| 63 | const listData = () => list.latest ?? list() ?? []; | 63 | const listData = () => list.latest ?? list() ?? []; |
| 64 | - const termName = (id: string | null) => terms.latest?.find((term) => term.id === id)?.name ?? (id || t("terms.unassigned")); | 64 | + const yearName = (id: string | null) => years.latest?.find((year) => year.id === id)?.name ?? (id || t("academicYears.unassigned")); |
| 65 | 65 | ||
| 66 | // Grade tabs mirror Figma's Tümü/Lise/Ortaokul row structurally, but the | 66 | // Grade tabs mirror Figma's Tümü/Lise/Ortaokul row structurally, but the |
| 67 | // labels are read from whatever `grade` values this school actually uses | 67 | // labels are read from whatever `grade` values this school actually uses |
| @@ -111,10 +111,10 @@ function ClassesContent() { | |||
| 111 | const created = await postClass({ | 111 | const created = await postClass({ |
| 112 | name: name().trim(), | 112 | name: name().trim(), |
| 113 | grade: grade().trim() || undefined, | 113 | grade: grade().trim() || undefined, |
| 114 | - term_id: termId() || undefined, | 114 | + year: yearId() || undefined, |
| 115 | teacher_id: teacherId() || undefined, | 115 | teacher_id: teacherId() || undefined, |
| 116 | }); | 116 | }); |
| 117 | - setName(""); setGrade(""); setTermId(""); setTeacherId(""); setShowForm(false); | 117 | + setName(""); setGrade(""); setYearId(""); setTeacherId(""); setShowForm(false); |
| 118 | // Reloading the list is housekeeping for a page we are leaving anyway: a | 118 | // Reloading the list is housekeeping for a page we are leaving anyway: a |
| 119 | // failure here used to be reported as if the class had not been created, | 119 | // failure here used to be reported as if the class had not been created, |
| 120 | // and it swallowed the navigation to the class that plainly existed. | 120 | // and it swallowed the navigation to the class that plainly existed. |
| @@ -139,7 +139,7 @@ function ClassesContent() { | |||
| 139 | <div class="space-y-3"> | 139 | <div class="space-y-3"> |
| 140 | <div class="space-y-1.5"><Label for="class-name">{t("classGroups.className")}<span class="ml-0.5 text-destructive">*</span></Label><Input id="class-name" required maxlength={limits.latest?.course.max_class_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div> | 140 | <div class="space-y-1.5"><Label for="class-name">{t("classGroups.className")}<span class="ml-0.5 text-destructive">*</span></Label><Input id="class-name" required maxlength={limits.latest?.course.max_class_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div> |
| 141 | <div class="space-y-1.5"><Label for="class-grade">{t("classGroups.grade")}</Label><Input id="class-grade" maxlength={limits.latest?.course.max_class_grade_len} value={grade()} onInput={(e) => setGrade(e.currentTarget.value)} /></div> | 141 | <div class="space-y-1.5"><Label for="class-grade">{t("classGroups.grade")}</Label><Input id="class-grade" maxlength={limits.latest?.course.max_class_grade_len} value={grade()} onInput={(e) => setGrade(e.currentTarget.value)} /></div> |
| 142 | - <div class="space-y-1.5"><Label for="class-term">{t("terms.term")}</Label><Select id="class-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}><option value="">{t("terms.unassigned")}</option><For each={terms.latest ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For></Select></div> | 142 | + <div class="space-y-1.5"><Label for="class-year">{t("academicYears.year")}</Label><Select id="class-year" value={yearId()} onChange={(e) => setYearId(e.currentTarget.value)}><option value="">{t("academicYears.unassigned")}</option><For each={years.latest ?? []}>{(year) => <option value={year.id}>{year.name}</option>}</For></Select></div> |
| 143 | <UserSearchSelect id="class-teacher" label={t("classGroups.homeroomTeacher")} value={teacherId()} onChange={setTeacherId} placeholder={t("classGroups.selectTeacher")} role="teacher" /> | 143 | <UserSearchSelect id="class-teacher" label={t("classGroups.homeroomTeacher")} value={teacherId()} onChange={setTeacherId} placeholder={t("classGroups.selectTeacher")} role="teacher" /> |
| 144 | </div> | 144 | </div> |
| 145 | <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | 145 | <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> |
| @@ -195,7 +195,7 @@ function ClassesContent() { | |||
| 195 | {(cls) => ( | 195 | {(cls) => ( |
| 196 | <ClassCard | 196 | <ClassCard |
| 197 | cls={cls} | 197 | cls={cls} |
| 198 | - termName={termName(cls.term)} | 198 | + yearName={yearName(cls.year)} |
| 199 | memberCount={memberCounts()?.get(cls.id) ?? null} | 199 | memberCount={memberCounts()?.get(cls.id) ?? null} |
| 200 | onClick={() => void navigate({ to: "/management/classes/$id", params: { id: cls.id } })} | 200 | onClick={() => void navigate({ to: "/management/classes/$id", params: { id: cls.id } })} |
| 201 | /> | 201 | /> |
| @@ -215,7 +215,7 @@ function ClassesContent() { | |||
| 215 | ); | 215 | ); |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | -function ClassCard(props: { cls: ClassGroup; termName: string; memberCount: number | null; onClick: () => void }) { | 218 | +function ClassCard(props: { cls: ClassGroup; yearName: string; memberCount: number | null; onClick: () => void }) { |
| 219 | const t = useT(); | 219 | const t = useT(); |
| 220 | return ( | 220 | return ( |
| 221 | <button | 221 | <button |
| @@ -247,7 +247,7 @@ function ClassCard(props: { cls: ClassGroup; termName: string; memberCount: numb | |||
| 247 | </div> | 247 | </div> |
| 248 | </div> | 248 | </div> |
| 249 | <div class="flex items-center justify-between gap-2 border-t border-border-hairline pt-3 text-sm"> | 249 | <div class="flex items-center justify-between gap-2 border-t border-border-hairline pt-3 text-sm"> |
| 250 | - <Badge variant="outline" class="min-w-0 max-w-[60%] rounded-full"><span class="truncate">{props.termName}</span></Badge> | 250 | + <Badge variant="outline" class="min-w-0 max-w-[60%] rounded-full"><span class="truncate">{props.yearName}</span></Badge> |
| 251 | <Show when={props.memberCount != null} fallback={<span class="shrink-0 text-xs text-text-subtle">—</span>}> | 251 | <Show when={props.memberCount != null} fallback={<span class="shrink-0 text-xs text-text-subtle">—</span>}> |
| 252 | <span class="shrink-0 font-medium text-text-default">{t("classGroups.studentsCount", { count: String(props.memberCount) })}</span> | 252 | <span class="shrink-0 font-medium text-text-default">{t("classGroups.studentsCount", { count: String(props.memberCount) })}</span> |
| 253 | </Show> | 253 | </Show> |
src/pages/course-detail-page.tsxmodified+366 -509
| @@ -3,28 +3,18 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; | 3 | import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | import { deleteCourseById } from "@/api/courses"; | 5 | import { deleteCourseById } from "@/api/courses"; |
| 6 | -import { deleteCourseEnrollmentByUserId } from "@/api/courses"; | 6 | +import { deleteCourseMemberByUserId } from "@/api/courses"; |
| 7 | import { getCourseById } from "@/api/courses"; | 7 | import { getCourseById } from "@/api/courses"; |
| 8 | -import { getCourseEnrollments } from "@/api/courses"; | 8 | +import { getCourseMembers } from "@/api/courses"; |
| 9 | -import { getCourseExams } from "@/api/courses"; | 9 | +import { postCourseMember } from "@/api/courses"; |
| 10 | -import { getClasses } from "@/api/classes"; | 10 | +import { getClasses, getClassInstances, getMyClasses } from "@/api/classes"; |
| 11 | +import { getMyInstances } from "@/api/instances"; | ||
| 11 | import { getMyCourses } from "@/api/reports"; | 12 | import { getMyCourses } from "@/api/reports"; |
| 12 | -import { getSettings } from "@/api/settings"; | ||
| 13 | -import { getTerms } from "@/api/terms"; | ||
| 14 | import { patchCourseById } from "@/api/courses"; | 13 | import { patchCourseById } from "@/api/courses"; |
| 15 | -import { postCourseEnrollment } from "@/api/courses"; | ||
| 16 | -import { postCourseExam } from "@/api/courses"; | ||
| 17 | import { formatApiError } from "@/api/client"; | 14 | import { formatApiError } from "@/api/client"; |
| 18 | -import type { CourseKind, Enrollment, Exam } from "@/api/client"; | 15 | +import type { ClassCourse, ClassGroup, CourseKind, CourseMembership, Instance } from "@/api/client"; |
| 19 | -import { patchExamById } from "@/api/exams"; | ||
| 20 | -import { ExamLink } from "@/components/exams/exam-link"; | ||
| 21 | -import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; | ||
| 22 | -import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; | ||
| 23 | import { CourseNotesPanel } from "@/components/courses/course-notes-panel"; | 16 | import { CourseNotesPanel } from "@/components/courses/course-notes-panel"; |
| 24 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; | 17 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; |
| 25 | -import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel"; | ||
| 26 | -import { CourseHomeworkPanel } from "@/components/homework/course-homework-panel"; | ||
| 27 | -import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; | ||
| 28 | import { RouteGuard } from "@/components/layout/route-guard"; | 18 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 29 | import { PageHeader } from "@/components/layout/page-header"; | 19 | import { PageHeader } from "@/components/layout/page-header"; |
| 30 | import { Alert } from "@/components/ui/alert"; | 20 | import { Alert } from "@/components/ui/alert"; |
| @@ -33,9 +23,8 @@ import { Button } from "@/components/ui/button"; | |||
| 33 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 23 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 34 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | 24 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; |
| 35 | import { EmptyState } from "@/components/ui/empty-state"; | 25 | import { EmptyState } from "@/components/ui/empty-state"; |
| 36 | -import { IconBook, IconCalendarDays, IconEdit, IconExam, IconHomework, IconNote, IconPlus, IconSchool, IconTrash, IconUsers } from "@/components/ui/icons"; | 26 | +import { IconBook, IconEdit, IconNote, IconPlus, IconSchool, IconTrash, IconUsers } from "@/components/ui/icons"; |
| 37 | import { createFlash } from "@/lib/flash"; | 27 | import { createFlash } from "@/lib/flash"; |
| 38 | -import { cn } from "@/lib/cn"; | ||
| 39 | import { Input } from "@/components/ui/input"; | 28 | import { Input } from "@/components/ui/input"; |
| 40 | import { Label } from "@/components/ui/label"; | 29 | import { Label } from "@/components/ui/label"; |
| 41 | import { PageSpinner } from "@/components/ui/page-spinner"; | 30 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| @@ -47,12 +36,13 @@ import { Textarea } from "@/components/ui/textarea"; | |||
| 47 | import { UserSearchSelect } from "@/components/users/user-search-select"; | 36 | import { UserSearchSelect } from "@/components/users/user-search-select"; |
| 48 | import { useAuth } from "@/stores/auth-context"; | 37 | import { useAuth } from "@/stores/auth-context"; |
| 49 | import { useT } from "@/stores/preferences-context"; | 38 | import { useT } from "@/stores/preferences-context"; |
| 50 | -import { examKindLabel } from "@/lib/exam-labels"; | ||
| 51 | -import { examWeight } from "@/lib/exam-weight"; | ||
| 52 | import { hasMinRole } from "@/lib/roles"; | 39 | import { hasMinRole } from "@/lib/roles"; |
| 53 | 40 | ||
| 54 | const COURSE_KINDS: CourseKind[] = ["course", "study", "club"]; | 41 | const COURSE_KINDS: CourseKind[] = ["course", "study", "club"]; |
| 55 | 42 | ||
| 43 | +/** One row of the "taught in" list: an instance plus the şube's name. */ | ||
| 44 | +type SectionRow = { instance: Instance | ClassCourse; className: string }; | ||
| 45 | + | ||
| 56 | export default function CourseDetailPage() { | 46 | export default function CourseDetailPage() { |
| 57 | return ( | 47 | return ( |
| 58 | <RouteGuard> | 48 | <RouteGuard> |
| @@ -74,68 +64,76 @@ function CourseDetailContent() { | |||
| 74 | 64 | ||
| 75 | const [courseTab, setCourseTab] = createSignal("subjects"); | 65 | const [courseTab, setCourseTab] = createSignal("subjects"); |
| 76 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); | 66 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); |
| 77 | - const [terms] = createResource(async () => (await getTerms({ limit: 100 })).items); | 67 | + const [mine] = createResource( |
| 78 | - const [settings] = createResource(() => getSettings()); | 68 | + () => (auth.user()?.role === "student" ? true : null), |
| 79 | - const [exams, { refetch: refetchExams }] = createResource( | 69 | + async (enabled) => (enabled ? (await getMyCourses()).items : []), |
| 80 | - () => id(), | ||
| 81 | - async (courseId) => (courseId ? (await getCourseExams(courseId)).items : []), | ||
| 82 | ); | 70 | ); |
| 83 | - const hasCourseManagementRights = () => { | 71 | + |
| 84 | - const c = course(); | 72 | + // Catalog rights: the creator or a manager+. Teaching rights now live on the |
| 85 | - const u = auth.user(); | 73 | + // instance, so this page only governs the catalog row itself. |
| 86 | - if (!c || !u) return false; | 74 | + const canManageCatalog = () => { |
| 87 | - const isAssigned = (c.teachers ?? []).some((t) => t.id === u.id); | ||
| 88 | - return c.creator.id === u.id || isAssigned || hasMinRole(u.role, "manager"); | ||
| 89 | - }; | ||
| 90 | - const canDeleteCourse = () => { | ||
| 91 | const c = course(); | 75 | const c = course(); |
| 92 | const u = auth.user(); | 76 | const u = auth.user(); |
| 93 | if (!c || !u) return false; | 77 | if (!c || !u) return false; |
| 94 | return c.creator.id === u.id || hasMinRole(u.role, "manager"); | 78 | return c.creator.id === u.id || hasMinRole(u.role, "manager"); |
| 95 | }; | 79 | }; |
| 96 | - const canStaffCourse = () => { | 80 | + const isOffice = () => hasMinRole(auth.user()?.role ?? "student", "manager"); |
| 97 | - const u = auth.user(); | 81 | + // A club/etüt keeps its own school-wide member list; a regular ders does not |
| 98 | - if (!u) return false; | 82 | + // — its students come from the şube that attached it. |
| 99 | - return hasMinRole(u.role, "manager"); | 83 | + const hasMembers = () => course()?.kind === "club" || course()?.kind === "study"; |
| 100 | - }; | 84 | + |
| 101 | - const [roster, { refetch: refetchRoster }] = createResource( | 85 | + // The şubeler teaching this course. A student or teacher reads their own set |
| 102 | - () => (hasCourseManagementRights() ? id() : null), | 86 | + // in one call; the office has no course-scoped instance route, so it walks |
| 103 | - async (courseId) => (courseId ? (await getCourseEnrollments(courseId)).items : []), | 87 | + // the class list instead (one call per class, capped by the page limit). |
| 88 | + const [sections] = createResource( | ||
| 89 | + () => (course() ? { courseId: id(), office: isOffice() } : null), | ||
| 90 | + async (args): Promise<SectionRow[]> => { | ||
| 91 | + if (!args) return []; | ||
| 92 | + if (!args.office) { | ||
| 93 | + // `/instances/me` is the one instance list a student or teacher can | ||
| 94 | + // read; `/classes/me` names the şubeler behind it (one call each). | ||
| 95 | + const [instances, classes] = await Promise.all([ | ||
| 96 | + getMyInstances({ limit: 200 }), | ||
| 97 | + getMyClasses({ limit: 200 }).catch(() => ({ items: [] as ClassGroup[] })), | ||
| 98 | + ]); | ||
| 99 | + const names = new Map(classes.items.map((klass) => [klass.id, klass.name])); | ||
| 100 | + return instances.items | ||
| 101 | + .filter((instance) => instance.course === args.courseId) | ||
| 102 | + .map((instance) => ({ instance, className: names.get(instance.class) ?? "—" })); | ||
| 103 | + } | ||
| 104 | + const classes = (await getClasses({ limit: 200 })).items; | ||
| 105 | + const perClass = await Promise.all( | ||
| 106 | + classes.map(async (klass) => { | ||
| 107 | + const instances = (await getClassInstances(klass.id, { limit: 200 })).items; | ||
| 108 | + return instances | ||
| 109 | + .filter((instance) => instance.course === args.courseId) | ||
| 110 | + .map((instance) => ({ instance, className: klass.name })); | ||
| 111 | + }), | ||
| 112 | + ); | ||
| 113 | + return perClass.flat(); | ||
| 114 | + }, | ||
| 104 | ); | 115 | ); |
| 105 | - const [mine] = createResource( | 116 | + |
| 106 | - () => (auth.user()?.role === "student" ? true : null), | 117 | + const [members, { refetch: refetchMembers }] = createResource( |
| 107 | - async (enabled) => (enabled ? (await getMyCourses()).items : []), | 118 | + () => (hasMembers() && canManageCatalog() ? id() : null), |
| 119 | + async (courseId) => (courseId ? (await getCourseMembers(courseId)).items : []), | ||
| 108 | ); | 120 | ); |
| 109 | 121 | ||
| 110 | const [editing, setEditing] = createSignal(false); | 122 | const [editing, setEditing] = createSignal(false); |
| 111 | const [title, setTitle] = createSignal(""); | 123 | const [title, setTitle] = createSignal(""); |
| 112 | const [description, setDescription] = createSignal(""); | 124 | const [description, setDescription] = createSignal(""); |
| 113 | const [kind, setKind] = createSignal<CourseKind>("course"); | 125 | const [kind, setKind] = createSignal<CourseKind>("course"); |
| 114 | - const [termId, setTermId] = createSignal(""); | ||
| 115 | - const [capacity, setCapacity] = createSignal(""); | ||
| 116 | - const [showExamForm, setShowExamForm] = createSignal(false); | ||
| 117 | - const [examCreateStep, setExamCreateStep] = createSignal<"details" | "questions">("details"); | ||
| 118 | - const [createdCourseExam, setCreatedCourseExam] = createSignal<Exam | null>(null); | ||
| 119 | const [showSubjectForm, setShowSubjectForm] = createSignal(false); | 126 | const [showSubjectForm, setShowSubjectForm] = createSignal(false); |
| 120 | - const [showSessionForm, setShowSessionForm] = createSignal(false); | ||
| 121 | - const [showHomeworkForm, setShowHomeworkForm] = createSignal(false); | ||
| 122 | - const [showTeacherForm, setShowTeacherForm] = createSignal(false); | ||
| 123 | const [showNoteForm, setShowNoteForm] = createSignal(false); | 127 | const [showNoteForm, setShowNoteForm] = createSignal(false); |
| 124 | - const [showEnrollPanel, setShowEnrollPanel] = createSignal(false); | 128 | + const [showMemberForm, setShowMemberForm] = createSignal(false); |
| 125 | const [subjectCount, setSubjectCount] = createSignal(0); | 129 | const [subjectCount, setSubjectCount] = createSignal(0); |
| 126 | - const [sessionCount, setSessionCount] = createSignal(0); | ||
| 127 | - const [homeworkCount, setHomeworkCount] = createSignal(0); | ||
| 128 | const [noteCount, setNoteCount] = createSignal(0); | 130 | const [noteCount, setNoteCount] = createSignal(0); |
| 129 | - const [enrollUserId, setEnrollUserId] = createSignal(""); | 131 | + const [memberUserId, setMemberUserId] = createSignal(""); |
| 130 | const [error, setError] = createSignal(""); | 132 | const [error, setError] = createSignal(""); |
| 131 | const [pending, setPending] = createSignal(false); | 133 | const [pending, setPending] = createSignal(false); |
| 132 | const [deleteOpen, setDeleteOpen] = createSignal(false); | 134 | const [deleteOpen, setDeleteOpen] = createSignal(false); |
| 133 | const [removeTarget, setRemoveTarget] = createSignal<{ userId: string; userName: string } | null>(null); | 135 | const [removeTarget, setRemoveTarget] = createSignal<{ userId: string; userName: string } | null>(null); |
| 134 | 136 | ||
| 135 | - const canManage = () => { | ||
| 136 | - return hasCourseManagementRights(); | ||
| 137 | - }; | ||
| 138 | - | ||
| 139 | const canViewCourse = () => { | 137 | const canViewCourse = () => { |
| 140 | const u = auth.user(); | 138 | const u = auth.user(); |
| 141 | if (!u) return false; | 139 | if (!u) return false; |
| @@ -144,61 +142,70 @@ function CourseDetailContent() { | |||
| 144 | }; | 142 | }; |
| 145 | const accessReady = () => auth.user()?.role !== "student" || mine() !== undefined; | 143 | const accessReady = () => auth.user()?.role !== "student" || mine() !== undefined; |
| 146 | 144 | ||
| 147 | - const examModeLabel = (mode: string | null) => { | ||
| 148 | - if (mode === "sync") return t("exams.mode.sync"); | ||
| 149 | - if (mode === "async") return t("exams.mode.async"); | ||
| 150 | - if (mode === "open") return t("exams.mode.open"); | ||
| 151 | - return t("exams.unscheduled"); | ||
| 152 | - }; | ||
| 153 | const courseKindLabel = (value: CourseKind | undefined) => | 145 | const courseKindLabel = (value: CourseKind | undefined) => |
| 154 | value === "study" ? t("courses.kind.study") : value === "club" ? t("courses.kind.club") : t("courses.kind.course"); | 146 | value === "study" ? t("courses.kind.study") : value === "club" ? t("courses.kind.club") : t("courses.kind.course"); |
| 155 | - const courseListSearch = (value: CourseKind | undefined) => value ? { kind: value } as never : {} as never; | 147 | + const courseListSearch = (value: CourseKind | undefined) => (value ? ({ kind: value } as never) : ({} as never)); |
| 156 | - | ||
| 157 | - const examCount = createMemo(() => exams()?.length ?? 0); | ||
| 158 | - const nextExam = createMemo(() => | ||
| 159 | - (exams() ?? []) | ||
| 160 | - .filter((exam) => (exam.ends_at ?? exam.starts_at ?? 0) > Date.now()) | ||
| 161 | - .sort((a, b) => (a.starts_at ?? a.ends_at ?? 0) - (b.starts_at ?? b.ends_at ?? 0))[0], | ||
| 162 | - ); | ||
| 163 | - const rosterCount = createMemo(() => roster()?.length ?? 0); | ||
| 164 | - // `teachers` is the backend's assigned-teacher list. The course creator is | ||
| 165 | - // rendered separately below, so adding one here made an admin-created course | ||
| 166 | - // look as though it had a teacher who was never assigned to it. | ||
| 167 | - const assignedTeacherCount = createMemo(() => course()?.teachers?.length ?? 0); | ||
| 168 | const countDescription = (count: number, item: string) => t("common.countItem", { count, item }); | 148 | const countDescription = (count: number, item: string) => t("common.countItem", { count, item }); |
| 169 | 149 | ||
| 170 | - const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id); | 150 | + const sectionCount = createMemo(() => sections()?.length ?? 0); |
| 171 | - // Resolve a pumped enrollment's `source` (class id) to a class name so a | 151 | + const memberCount = createMemo(() => members()?.length ?? 0); |
| 172 | - // manager can see which rows a class change will sweep. One list call, | 152 | + const memberUserIds = () => (members() ?? []).map((row) => row.user.id); |
| 173 | - // teacher+ only (matches roster visibility); null-source rows show nothing. | 153 | + |
| 174 | - const [classList] = createResource(() => hasCourseManagementRights() ? getClasses().then((page) => page.items) : null); | 154 | + const sectionColumns = createMemo<ColumnDef<SectionRow>[]>(() => [ |
| 175 | - const className = (source: string | null) => source ? (classList.latest?.find((c) => c.id === source)?.name ?? null) : null; | 155 | + { |
| 176 | - const rosterColumns = createMemo<ColumnDef<Enrollment>[]>(() => [ | 156 | + id: "class", |
| 157 | + accessorFn: (row) => row.className, | ||
| 158 | + header: t("classGroups.className"), | ||
| 159 | + meta: { cellClass: "font-medium" }, | ||
| 160 | + cell: (cell) => ( | ||
| 161 | + <Link to="/instances/$id" params={{ id: cell.row.original.instance.id }} class="hover:text-primary hover:underline"> | ||
| 162 | + {cell.row.original.className} | ||
| 163 | + </Link> | ||
| 164 | + ), | ||
| 165 | + }, | ||
| 166 | + { | ||
| 167 | + id: "dersSaati", | ||
| 168 | + accessorFn: (row) => row.instance.ders_saati, | ||
| 169 | + header: t("instances.dersSaati"), | ||
| 170 | + meta: { cellClass: "mono" }, | ||
| 171 | + }, | ||
| 172 | + { | ||
| 173 | + id: "roster", | ||
| 174 | + accessorFn: (row) => row.instance.enrollment_count, | ||
| 175 | + header: t("courses.roster"), | ||
| 176 | + meta: { cellClass: "mono" }, | ||
| 177 | + }, | ||
| 178 | + { | ||
| 179 | + id: "karne", | ||
| 180 | + accessorFn: (row) => (row.instance.counts_toward_karne ? t("common.yes") : t("common.no")), | ||
| 181 | + header: t("instances.countsTowardKarne"), | ||
| 182 | + cell: (cell) => ( | ||
| 183 | + <Badge variant={cell.row.original.instance.counts_toward_karne ? "secondary" : "outline"} class="rounded-full"> | ||
| 184 | + {cell.row.original.instance.counts_toward_karne ? t("common.yes") : t("common.no")} | ||
| 185 | + </Badge> | ||
| 186 | + ), | ||
| 187 | + }, | ||
| 188 | + ]); | ||
| 189 | + | ||
| 190 | + const memberColumns = createMemo<ColumnDef<CourseMembership>[]>(() => [ | ||
| 177 | { | 191 | { |
| 178 | id: "username", | 192 | id: "username", |
| 179 | accessorFn: (row) => row.user.display_name || row.user.username, | 193 | accessorFn: (row) => row.user.display_name || row.user.username, |
| 180 | header: t("admin.username"), | 194 | header: t("admin.username"), |
| 181 | meta: { cellClass: "font-medium" }, | 195 | meta: { cellClass: "font-medium" }, |
| 182 | - cell: (cell) => ( | 196 | + cell: (cell) => cell.row.original.user.display_name || cell.row.original.user.username, |
| 183 | - <span class="flex items-center gap-2"> | ||
| 184 | - {cell.row.original.user.display_name || cell.row.original.user.username} | ||
| 185 | - <Show when={className(cell.row.original.source)}> | ||
| 186 | - {(name) => <Badge variant="secondary" class="rounded-full text-xs font-normal">{t("course.fromClass", { name: name() })}</Badge>} | ||
| 187 | - </Show> | ||
| 188 | - </span> | ||
| 189 | - ), | ||
| 190 | }, | 197 | }, |
| 191 | { | 198 | { |
| 192 | id: "actions", | 199 | id: "actions", |
| 193 | header: t("common.actions"), | 200 | header: t("common.actions"), |
| 194 | meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" }, | 201 | meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" }, |
| 195 | cell: (cell) => ( | 202 | cell: (cell) => ( |
| 196 | - <Show when={canManage()}> | 203 | + <Show when={canManageCatalog()}> |
| 197 | <TableRowActions | 204 | <TableRowActions |
| 198 | label={t("common.actions")} | 205 | label={t("common.actions")} |
| 199 | actions={[ | 206 | actions={[ |
| 200 | { | 207 | { |
| 201 | - label: t("common.remove"), | 208 | + label: t("courses.removeMember"), |
| 202 | icon: <IconTrash class="h-4 w-4" />, | 209 | icon: <IconTrash class="h-4 w-4" />, |
| 203 | destructive: true, | 210 | destructive: true, |
| 204 | onSelect: () => | 211 | onSelect: () => |
| @@ -213,47 +220,7 @@ function CourseDetailContent() { | |||
| 213 | ), | 220 | ), |
| 214 | }, | 221 | }, |
| 215 | ]); | 222 | ]); |
| 216 | - const examColumns = createMemo<ColumnDef<Exam>[]>(() => [ | 223 | + |
| 217 | - { | ||
| 218 | - accessorKey: "title", | ||
| 219 | - header: t("form.title"), | ||
| 220 | - meta: { cellClass: "font-medium" }, | ||
| 221 | - cell: (cell) => ( | ||
| 222 | - <ExamLink examId={cell.row.original.id} class="hover:text-primary hover:underline"> | ||
| 223 | - {cell.row.original.title} | ||
| 224 | - </ExamLink> | ||
| 225 | - ), | ||
| 226 | - }, | ||
| 227 | - { | ||
| 228 | - id: "kind", | ||
| 229 | - accessorFn: (row) => examKindLabel(String(row.kind), t), | ||
| 230 | - header: t("exams.kind"), | ||
| 231 | - cell: (cell) => ( | ||
| 232 | - <Badge variant="outline" class="rounded-full capitalize"> | ||
| 233 | - {examKindLabel(String(cell.row.original.kind), t)} | ||
| 234 | - <Show when={examWeight(cell.row.original, settings()?.exam_kinds)}> | ||
| 235 | - {(weight) => <span class="ml-1 text-text-subtle">({t("courses.weight")}: {weight()})</span>} | ||
| 236 | - </Show> | ||
| 237 | - </Badge> | ||
| 238 | - ), | ||
| 239 | - }, | ||
| 240 | - { | ||
| 241 | - id: "mode", | ||
| 242 | - accessorFn: (row) => examModeLabel(row.mode), | ||
| 243 | - header: t("exams.mode"), | ||
| 244 | - cell: (cell) => <Badge variant="secondary" class="rounded-full">{examModeLabel(cell.row.original.mode)}</Badge>, | ||
| 245 | - }, | ||
| 246 | - { | ||
| 247 | - id: "status", | ||
| 248 | - accessorFn: (row) => (row.draft ? t("exams.draft") : ""), | ||
| 249 | - header: t("events.status"), | ||
| 250 | - cell: (cell) => ( | ||
| 251 | - <Show when={cell.row.original.draft} fallback="—"> | ||
| 252 | - <Badge variant="secondary" class="rounded-full">{t("exams.draft")}</Badge> | ||
| 253 | - </Show> | ||
| 254 | - ), | ||
| 255 | - }, | ||
| 256 | - ]); | ||
| 257 | const [flash, setFlash] = createFlash(); | 224 | const [flash, setFlash] = createFlash(); |
| 258 | 225 | ||
| 259 | const wrap = async (fn: () => Promise<void>, ok?: string) => { | 226 | const wrap = async (fn: () => Promise<void>, ok?: string) => { |
| @@ -275,8 +242,6 @@ function CourseDetailContent() { | |||
| 275 | setTitle(c.title); | 242 | setTitle(c.title); |
| 276 | setDescription(c.description); | 243 | setDescription(c.description); |
| 277 | setKind(c.kind ?? "course"); | 244 | setKind(c.kind ?? "course"); |
| 278 | - setTermId(c.term ?? ""); | ||
| 279 | - setCapacity(c.capacity == null ? "" : String(c.capacity)); | ||
| 280 | setEditing(true); | 245 | setEditing(true); |
| 281 | }; | 246 | }; |
| 282 | 247 | ||
| @@ -293,397 +258,289 @@ function CourseDetailContent() { | |||
| 293 | {(c) => ( | 258 | {(c) => ( |
| 294 | <Show when={accessReady()} fallback={<PageSpinner />}> | 259 | <Show when={accessReady()} fallback={<PageSpinner />}> |
| 295 | <Show when={canViewCourse()} fallback={<Alert variant="destructive">{t("common.accessDenied")}</Alert>}> | 260 | <Show when={canViewCourse()} fallback={<Alert variant="destructive">{t("common.accessDenied")}</Alert>}> |
| 296 | - <div class="mx-auto w-full max-w-[1440px] space-y-4"> | 261 | + <div class="mx-auto w-full max-w-[1440px] space-y-4"> |
| 297 | - <div class="space-y-1.5"> | 262 | + <div class="space-y-1.5"> |
| 298 | - <nav class="detail-breadcrumb"> | 263 | + <nav class="detail-breadcrumb"> |
| 299 | - <Link to="/courses" search={courseListSearch(c().kind)}>{courseKindLabel(c().kind)}</Link> | 264 | + <Link to="/courses" search={courseListSearch(c().kind)}>{courseKindLabel(c().kind)}</Link> |
| 300 | - <span aria-hidden>›</span> | 265 | + <span aria-hidden>›</span> |
| 301 | - <span class="text-foreground">{c().title}</span> | 266 | + <span class="text-foreground">{c().title}</span> |
| 302 | - </nav> | 267 | + </nav> |
| 303 | - <PageHeader | 268 | + <PageHeader |
| 304 | - title={c().title} | 269 | + title={c().title} |
| 305 | - description={c().description || "—"} | 270 | + description={c().description || "—"} |
| 306 | - class="border-border-line" | 271 | + class="border-border-line" |
| 307 | - actions={ | 272 | + actions={ |
| 308 | - <Show when={canManage()}> | 273 | + <Show when={canManageCatalog()}> |
| 309 | - <TableRowActions | 274 | + <TableRowActions |
| 310 | - label={t("common.actions")} | 275 | + label={t("common.actions")} |
| 311 | - actions={[ | 276 | + actions={[ |
| 312 | - { | 277 | + { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: startEdit }, |
| 313 | - label: t("common.edit"), | 278 | + { |
| 314 | - icon: <IconEdit class="h-4 w-4" />, | ||
| 315 | - onSelect: startEdit, | ||
| 316 | - }, | ||
| 317 | - ...(canDeleteCourse() | ||
| 318 | - ? [{ | ||
| 319 | label: t("courses.delete"), | 279 | label: t("courses.delete"), |
| 320 | icon: <IconTrash class="h-4 w-4" />, | 280 | icon: <IconTrash class="h-4 w-4" />, |
| 321 | destructive: true, | 281 | destructive: true, |
| 322 | onSelect: () => setDeleteOpen(true), | 282 | onSelect: () => setDeleteOpen(true), |
| 323 | - }] | 283 | + }, |
| 324 | - : []), | 284 | + ]} |
| 325 | - ]} | 285 | + /> |
| 326 | - /> | 286 | + </Show> |
| 327 | - </Show> | 287 | + } |
| 328 | - } | 288 | + /> |
| 329 | - /> | 289 | + <div class="grid gap-2 sm:grid-cols-2 xl:grid-cols-3"> |
| 330 | - <div class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"> | 290 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> |
| 331 | - <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | 291 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> |
| 332 | - <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | 292 | + <IconBook class="h-4 w-4" /> |
| 333 | - <IconBook class="h-4 w-4" /> | 293 | + </span> |
| 334 | - </span> | 294 | + <div class="min-w-0"> |
| 335 | - <div class="min-w-0"> | 295 | + <p class="text-xs font-medium text-text-subtle">{t("courses.kind")}</p> |
| 336 | - <p class="text-xs font-medium text-text-subtle">{t("courses.kind")}</p> | 296 | + <p class="truncate text-sm font-semibold text-text-default">{courseKindLabel(c().kind)}</p> |
| 337 | - <p class="truncate text-sm font-semibold text-text-default">{courseKindLabel(c().kind)}</p> | 297 | + </div> |
| 338 | - </div> | 298 | + </div> |
| 339 | - </div> | 299 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> |
| 340 | - <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | 300 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> |
| 341 | - <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | 301 | + <IconSchool class="h-4 w-4" /> |
| 342 | - <IconCalendarDays class="h-4 w-4" /> | 302 | + </span> |
| 343 | - </span> | 303 | + <div class="min-w-0"> |
| 344 | - <div class="min-w-0"> | 304 | + <p class="text-xs font-medium text-text-subtle">{t("instances.taughtIn")}</p> |
| 345 | - <p class="text-xs font-medium text-text-subtle">{t("terms.term")}</p> | 305 | + <p class="mono truncate text-sm font-semibold text-text-default">{c().class_course_count}</p> |
| 346 | - <p class="truncate text-sm font-semibold text-text-default">{terms()?.find((term) => term.id === c().term)?.name ?? t("terms.unassigned")}</p> | 306 | + </div> |
| 347 | - </div> | 307 | + </div> |
| 348 | - </div> | 308 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> |
| 349 | - <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | 309 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> |
| 350 | - <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | 310 | + <IconUsers class="h-4 w-4" /> |
| 351 | - <IconUsers class="h-4 w-4" /> | 311 | + </span> |
| 352 | - </span> | 312 | + <div class="min-w-0"> |
| 353 | - <div class="min-w-0"> | 313 | + <p class="text-xs font-medium text-text-subtle">{t("courses.members")}</p> |
| 354 | - <p class="text-xs font-medium text-text-subtle">{t("courses.capacity")}</p> | 314 | + <p class="mono truncate text-sm font-semibold text-text-default">{c().course_membership_count}</p> |
| 355 | - <p class="mono truncate text-sm font-semibold text-text-default">{c().capacity == null ? "—" : hasCourseManagementRights() ? `${rosterCount()} / ${c().capacity}` : c().capacity}</p> | 315 | + </div> |
| 356 | - </div> | 316 | + </div> |
| 357 | - </div> | ||
| 358 | - <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | ||
| 359 | - <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | ||
| 360 | - <IconExam class="h-4 w-4" /> | ||
| 361 | - </span> | ||
| 362 | - <div class="min-w-0"> | ||
| 363 | - <p class="text-xs font-medium text-text-subtle">{t("courses.nextExam")}</p> | ||
| 364 | - <Show when={nextExam()} fallback={<p class="truncate text-sm font-semibold text-text-default">{t("courses.noUpcoming")}</p>}> | ||
| 365 | - {(exam) => <ExamLink examId={exam().id} class="block truncate text-sm font-semibold text-text-default hover:text-primary hover:underline">{exam().title}</ExamLink>} | ||
| 366 | - </Show> | ||
| 367 | </div> | 317 | </div> |
| 368 | </div> | 318 | </div> |
| 369 | - </div> | ||
| 370 | - </div> | ||
| 371 | - | ||
| 372 | - <ConfirmDialog | ||
| 373 | - open={deleteOpen()} | ||
| 374 | - onOpenChange={setDeleteOpen} | ||
| 375 | - title={t("confirm.deleteTitle")} | ||
| 376 | - variant="destructive" | ||
| 377 | - summary={t("courses.delete") + `: “${c().title}”`} | ||
| 378 | - onConfirm={async () => { | ||
| 379 | - await wrap(async () => { | ||
| 380 | - await deleteCourseById(id()); | ||
| 381 | - void navigate({ to: "/courses", search: courseListSearch(c().kind) }); | ||
| 382 | - }); | ||
| 383 | - }} | ||
| 384 | - /> | ||
| 385 | - | ||
| 386 | - <ConfirmDialog | ||
| 387 | - open={removeTarget() !== null} | ||
| 388 | - onOpenChange={() => setRemoveTarget(null)} | ||
| 389 | - title={t("course.removeStudent")} | ||
| 390 | - variant="destructive" | ||
| 391 | - summary={`${t("course.removeStudentConfirm")} "${removeTarget()?.userName}"?`} | ||
| 392 | - onConfirm={async () => { | ||
| 393 | - const target = removeTarget(); | ||
| 394 | - if (!target) return; | ||
| 395 | - try { | ||
| 396 | - await deleteCourseEnrollmentByUserId(id(), target.userId); | ||
| 397 | - await refetchRoster(); | ||
| 398 | - setFlash(t("common.deleted")); | ||
| 399 | - } catch (err) { | ||
| 400 | - setError(formatApiError(err)); | ||
| 401 | - } finally { | ||
| 402 | - setRemoveTarget(null); | ||
| 403 | - } | ||
| 404 | - }} | ||
| 405 | - /> | ||
| 406 | 319 | ||
| 407 | - <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().title}> | 320 | + <ConfirmDialog |
| 408 | - <form | 321 | + open={deleteOpen()} |
| 409 | - class="space-y-4" | 322 | + onOpenChange={setDeleteOpen} |
| 410 | - onSubmit={(e) => { | 323 | + title={t("confirm.deleteTitle")} |
| 411 | - e.preventDefault(); | 324 | + variant="destructive" |
| 412 | - void wrap(async () => { | 325 | + summary={t("courses.delete") + `: “${c().title}”`} |
| 413 | - const cap = capacity().trim(); | 326 | + onConfirm={async () => { |
| 414 | - await patchCourseById(id(), { | 327 | + await wrap(async () => { |
| 415 | - title: title().trim(), | 328 | + await deleteCourseById(id()); |
| 416 | - description: description(), | 329 | + void navigate({ to: "/courses", search: courseListSearch(c().kind) }); |
| 417 | - kind: kind(), | ||
| 418 | - term_id: termId() || null, | ||
| 419 | - capacity: cap ? Number(cap) : null, | ||
| 420 | }); | 330 | }); |
| 421 | - setEditing(false); | 331 | + }} |
| 422 | - await refetchCourse(); | 332 | + /> |
| 423 | - }, t("common.saved")); | ||
| 424 | - }} | ||
| 425 | - > | ||
| 426 | - <div class="space-y-3 rounded-xl border border-border-line bg-surface-tint p-4"> | ||
| 427 | - <div class="space-y-1.5"> | ||
| 428 | - <Label for="edit-course-title">{t("form.title")}</Label> | ||
| 429 | - <Input | ||
| 430 | - id="edit-course-title" | ||
| 431 | - value={title()} | ||
| 432 | - required | ||
| 433 | - maxlength={200} | ||
| 434 | - onInput={(e) => setTitle(e.currentTarget.value)} | ||
| 435 | - /> | ||
| 436 | - </div> | ||
| 437 | - <div class="space-y-1.5"> | ||
| 438 | - <Label for="edit-course-desc">{t("form.description")}</Label> | ||
| 439 | - <Textarea | ||
| 440 | - id="edit-course-desc" | ||
| 441 | - value={description()} | ||
| 442 | - rows={3} | ||
| 443 | - maxlength={2000} | ||
| 444 | - onInput={(e) => setDescription(e.currentTarget.value)} | ||
| 445 | - /> | ||
| 446 | - </div> | ||
| 447 | - </div> | ||
| 448 | - <div class="space-y-3 rounded-xl border border-border-line bg-surface-tint p-4"> | ||
| 449 | - <div class="space-y-1.5"> | ||
| 450 | - <Label for="edit-course-kind">{t("courses.kind")}</Label> | ||
| 451 | - <Select id="edit-course-kind" value={kind()} onChange={(e) => setKind(e.currentTarget.value as CourseKind)}> | ||
| 452 | - <For each={COURSE_KINDS}>{(item) => <option value={item}>{courseKindLabel(item)}</option>}</For> | ||
| 453 | - </Select> | ||
| 454 | - </div> | ||
| 455 | - <div class="space-y-1.5"> | ||
| 456 | - <Label for="edit-course-term">{t("terms.term")}</Label> | ||
| 457 | - <Select id="edit-course-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}> | ||
| 458 | - <option value="">{t("terms.unassigned")}</option> | ||
| 459 | - <For each={terms() ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For> | ||
| 460 | - </Select> | ||
| 461 | - </div> | ||
| 462 | - <div class="space-y-1.5"> | ||
| 463 | - <Label for="edit-course-capacity">{t("courses.capacity")}</Label> | ||
| 464 | - <Input id="edit-course-capacity" type="number" min={1} value={capacity()} placeholder={t("courses.capacityOptional")} onInput={(e) => setCapacity(e.currentTarget.value)} /> | ||
| 465 | - </div> | ||
| 466 | - </div> | ||
| 467 | - <div class="sticky bottom-0 -mx-5 flex flex-wrap gap-2 border-t border-border-line bg-surface-base px-5 pb-6 pt-4 sm:-mx-6 sm:px-6 sm:pb-6"> | ||
| 468 | - <Button type="submit" class="flex-1 rounded-xl sm:flex-none" disabled={pending()}> | ||
| 469 | - {t("common.update")} | ||
| 470 | - </Button> | ||
| 471 | - <Button type="button" variant="outline" class="flex-1 rounded-xl sm:flex-none" onClick={() => setEditing(false)}> | ||
| 472 | - {t("common.cancel")} | ||
| 473 | - </Button> | ||
| 474 | - </div> | ||
| 475 | - </form> | ||
| 476 | - </SidePanel> | ||
| 477 | - | ||
| 478 | - <SidePanel | ||
| 479 | - open={showExamForm()} | ||
| 480 | - onOpenChange={(open) => { | ||
| 481 | - setShowExamForm(open); | ||
| 482 | - if (!open) { | ||
| 483 | - setCreatedCourseExam(null); | ||
| 484 | - setExamCreateStep("details"); | ||
| 485 | - } | ||
| 486 | - }} | ||
| 487 | - title={createdCourseExam() ? createdCourseExam()!.title : t("courses.addExam")} | ||
| 488 | - description={createdCourseExam() ? t("exams.step2Questions") : c().title} | ||
| 489 | - size={examCreateStep() === "questions" ? "wide" : "default"} | ||
| 490 | - > | ||
| 491 | - <div class="mb-4 flex rounded-xl border border-border-line bg-surface-tint p-1"> | ||
| 492 | - <button | ||
| 493 | - type="button" | ||
| 494 | - class={cn( | ||
| 495 | - "rounded-lg px-3 py-2 text-xs font-semibold transition-colors", | ||
| 496 | - examCreateStep() === "details" | ||
| 497 | - ? "bg-primary text-primary-foreground shadow-2xs" | ||
| 498 | - : "text-text-subtle hover:bg-surface-fill", | ||
| 499 | - )} | ||
| 500 | - onClick={() => setExamCreateStep("details")} | ||
| 501 | - > | ||
| 502 | - {t("exams.step1Details")} | ||
| 503 | - </button> | ||
| 504 | - <button | ||
| 505 | - type="button" | ||
| 506 | - disabled={!createdCourseExam()} | ||
| 507 | - class={cn( | ||
| 508 | - "rounded-lg px-3 py-2 text-xs font-semibold transition-colors", | ||
| 509 | - examCreateStep() === "questions" | ||
| 510 | - ? "bg-primary text-primary-foreground shadow-2xs" | ||
| 511 | - : createdCourseExam() | ||
| 512 | - ? "text-text-subtle hover:bg-surface-fill" | ||
| 513 | - : "opacity-40 cursor-not-allowed text-text-subtle", | ||
| 514 | - )} | ||
| 515 | - onClick={() => createdCourseExam() && setExamCreateStep("questions")} | ||
| 516 | - > | ||
| 517 | - {t("exams.step2Questions")} | ||
| 518 | - </button> | ||
| 519 | - </div> | ||
| 520 | 333 | ||
| 521 | - <Show when={examCreateStep() === "details"}> | 334 | + <ConfirmDialog |
| 522 | - <ExamForm | 335 | + open={removeTarget() !== null} |
| 523 | - initial={createdCourseExam() ?? undefined} | 336 | + onOpenChange={() => setRemoveTarget(null)} |
| 524 | - submitLabel={createdCourseExam() ? t("common.update") : t("exams.nextQuestions")} | 337 | + title={t("courses.removeMember")} |
| 525 | - onCancel={() => setShowExamForm(false)} | 338 | + variant="destructive" |
| 526 | - onSubmit={async (values: ExamFormValues) => { | 339 | + summary={`${t("courses.removeMemberConfirm")} "${removeTarget()?.userName}"`} |
| 527 | - const existing = createdCourseExam(); | 340 | + onConfirm={async () => { |
| 528 | - if (existing) { | 341 | + const target = removeTarget(); |
| 529 | - const updated = await patchExamById(existing.id, values); | 342 | + if (!target) return; |
| 530 | - setCreatedCourseExam(updated); | 343 | + try { |
| 531 | - await refetchExams(); | 344 | + await deleteCourseMemberByUserId(id(), target.userId); |
| 532 | - setExamCreateStep("questions"); | 345 | + await refetchMembers(); |
| 533 | - setFlash(t("common.saved")); | 346 | + await refetchCourse(); |
| 534 | - } else { | 347 | + setFlash(t("common.deleted")); |
| 535 | - const newExam = await postCourseExam(id(), { | 348 | + } catch (err) { |
| 536 | - ...values, | 349 | + setError(formatApiError(err)); |
| 537 | - description: values.description.trim() || undefined, | 350 | + } finally { |
| 538 | - }); | 351 | + setRemoveTarget(null); |
| 539 | - setCreatedCourseExam(newExam); | ||
| 540 | - await refetchExams(); | ||
| 541 | - setExamCreateStep("questions"); | ||
| 542 | - setFlash(t("common.created")); | ||
| 543 | } | 352 | } |
| 544 | }} | 353 | }} |
| 545 | /> | 354 | /> |
| 546 | - </Show> | ||
| 547 | - | ||
| 548 | - <Show when={examCreateStep() === "questions" && createdCourseExam()}> | ||
| 549 | - <div class="space-y-4"> | ||
| 550 | - <ExamQuestionsPanel | ||
| 551 | - examId={createdCourseExam()!.id} | ||
| 552 | - courseId={c().id} | ||
| 553 | - embedded | ||
| 554 | - /> | ||
| 555 | - <div class="flex justify-end border-t pt-3"> | ||
| 556 | - <Button type="button" variant="default" onClick={() => setShowExamForm(false)}> | ||
| 557 | - {t("exams.finishAndClose")} | ||
| 558 | - </Button> | ||
| 559 | - </div> | ||
| 560 | - </div> | ||
| 561 | - </Show> | ||
| 562 | - </SidePanel> | ||
| 563 | 355 | ||
| 564 | - <SidePanel open={showEnrollPanel()} onOpenChange={setShowEnrollPanel} title={t("courses.enroll")} description={c().title}> | 356 | + <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().title}> |
| 565 | - <form | 357 | + <form |
| 566 | - class="space-y-3" | 358 | + class="space-y-4" |
| 567 | - onSubmit={(e) => { | 359 | + onSubmit={(e) => { |
| 568 | - e.preventDefault(); | 360 | + e.preventDefault(); |
| 569 | - void wrap(async () => { | 361 | + void wrap(async () => { |
| 570 | - const uid = enrollUserId().trim(); | 362 | + await patchCourseById(id(), { |
| 571 | - if (!uid) throw new Error(t("events.userId")); | 363 | + title: title().trim(), |
| 572 | - await postCourseEnrollment(id(), uid); | 364 | + description: description(), |
| 573 | - setEnrollUserId(""); | 365 | + kind: kind(), |
| 574 | - setShowEnrollPanel(false); | 366 | + }); |
| 575 | - await refetchRoster(); | 367 | + setEditing(false); |
| 576 | - }, t("common.saved")); | 368 | + await refetchCourse(); |
| 577 | - }} | 369 | + }, t("common.saved")); |
| 578 | - > | 370 | + }} |
| 579 | - <UserSearchSelect | 371 | + > |
| 580 | - id="course-enroll-user" | 372 | + <div class="space-y-3 rounded-xl border border-border-line bg-surface-tint p-4"> |
| 581 | - value={enrollUserId()} | 373 | + <div class="space-y-1.5"> |
| 582 | - excludeIds={enrolledUserIds()} | 374 | + <Label for="edit-course-title">{t("form.title")}</Label> |
| 583 | - placeholder={t("form.selectStudent")} | 375 | + <Input |
| 584 | - onChange={setEnrollUserId} | 376 | + id="edit-course-title" |
| 585 | - role="student" | 377 | + value={title()} |
| 586 | - /> | 378 | + required |
| 587 | - <div class="flex flex-wrap gap-2"> | 379 | + maxlength={200} |
| 588 | - <Button type="submit" class="rounded-xl" disabled={pending()}> | 380 | + onInput={(e) => setTitle(e.currentTarget.value)} |
| 589 | - {t("courses.enroll")} | 381 | + /> |
| 590 | - </Button> | 382 | + </div> |
| 591 | - <Button type="button" variant="outline" class="rounded-xl" onClick={() => setShowEnrollPanel(false)}> | 383 | + <div class="space-y-1.5"> |
| 592 | - {t("common.cancel")} | 384 | + <Label for="edit-course-desc">{t("form.description")}</Label> |
| 593 | - </Button> | 385 | + <Textarea |
| 594 | - </div> | 386 | + id="edit-course-desc" |
| 595 | - </form> | 387 | + value={description()} |
| 596 | - </SidePanel> | 388 | + rows={3} |
| 389 | + maxlength={2000} | ||
| 390 | + onInput={(e) => setDescription(e.currentTarget.value)} | ||
| 391 | + /> | ||
| 392 | + </div> | ||
| 393 | + <div class="space-y-1.5"> | ||
| 394 | + <Label for="edit-course-kind">{t("courses.kind")}</Label> | ||
| 395 | + <Select id="edit-course-kind" value={kind()} onChange={(e) => setKind(e.currentTarget.value as CourseKind)}> | ||
| 396 | + <For each={COURSE_KINDS}>{(item) => <option value={item}>{courseKindLabel(item)}</option>}</For> | ||
| 397 | + </Select> | ||
| 398 | + </div> | ||
| 399 | + </div> | ||
| 400 | + <div class="sticky bottom-0 -mx-5 flex flex-wrap gap-2 border-t border-border-line bg-surface-base px-5 pb-6 pt-4 sm:-mx-6 sm:px-6 sm:pb-6"> | ||
| 401 | + <Button type="submit" class="flex-1 rounded-xl sm:flex-none" disabled={pending()}> | ||
| 402 | + {t("common.update")} | ||
| 403 | + </Button> | ||
| 404 | + <Button type="button" variant="outline" class="flex-1 rounded-xl sm:flex-none" onClick={() => setEditing(false)}> | ||
| 405 | + {t("common.cancel")} | ||
| 406 | + </Button> | ||
| 407 | + </div> | ||
| 408 | + </form> | ||
| 409 | + </SidePanel> | ||
| 597 | 410 | ||
| 598 | - <Show when={flash()}> | 411 | + <SidePanel open={showMemberForm()} onOpenChange={setShowMemberForm} title={t("courses.addMember")} description={c().title}> |
| 599 | - <Alert variant="success">{flash()}</Alert> | 412 | + <form |
| 600 | - </Show> | 413 | + class="space-y-3" |
| 601 | - {error() && ( | 414 | + onSubmit={(e) => { |
| 602 | - <p class="rounded-xl bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> | 415 | + e.preventDefault(); |
| 603 | - )} | 416 | + void wrap(async () => { |
| 417 | + const uid = memberUserId().trim(); | ||
| 418 | + if (!uid) throw new Error(t("events.userId")); | ||
| 419 | + await postCourseMember(id(), uid); | ||
| 420 | + setMemberUserId(""); | ||
| 421 | + setShowMemberForm(false); | ||
| 422 | + await refetchMembers(); | ||
| 423 | + await refetchCourse(); | ||
| 424 | + }, t("common.saved")); | ||
| 425 | + }} | ||
| 426 | + > | ||
| 427 | + <UserSearchSelect | ||
| 428 | + id="course-member-user" | ||
| 429 | + value={memberUserId()} | ||
| 430 | + excludeIds={memberUserIds()} | ||
| 431 | + placeholder={t("form.selectStudent")} | ||
| 432 | + onChange={setMemberUserId} | ||
| 433 | + role="student" | ||
| 434 | + /> | ||
| 435 | + <div class="flex flex-wrap gap-2"> | ||
| 436 | + <Button type="submit" class="rounded-xl" disabled={pending()}> | ||
| 437 | + {t("courses.addMember")} | ||
| 438 | + </Button> | ||
| 439 | + <Button type="button" variant="outline" class="rounded-xl" onClick={() => setShowMemberForm(false)}> | ||
| 440 | + {t("common.cancel")} | ||
| 441 | + </Button> | ||
| 442 | + </div> | ||
| 443 | + </form> | ||
| 444 | + </SidePanel> | ||
| 604 | 445 | ||
| 605 | - <Tabs value={courseTab()} onChange={setCourseTab} class="space-y-4"> | 446 | + <Show when={flash()}> |
| 606 | - <TabsList class="flex w-full justify-start overflow-x-auto sm:grid sm:grid-cols-3 xl:grid-cols-7" aria-label={c().title}> | 447 | + <Alert variant="success">{flash()}</Alert> |
| 607 | - <TabsTrigger value="subjects" class="min-w-0"><IconBook class="h-4 w-4" />{t("subjects.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{subjectCount()}</Badge></TabsTrigger> | 448 | + </Show> |
| 608 | - <TabsTrigger value="exams" class="min-w-0"><IconExam class="h-4 w-4" />{t("courses.exams")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{examCount()}</Badge></TabsTrigger> | 449 | + <Show when={error()}> |
| 609 | - <TabsTrigger value="homework" class="min-w-0"><IconHomework class="h-4 w-4" />{t("homework.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{homeworkCount()}</Badge></TabsTrigger> | 450 | + <p class="rounded-xl bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> |
| 610 | - <TabsTrigger value="sessions" class="min-w-0"><IconCalendarDays class="h-4 w-4" />{t("sessions.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{sessionCount()}</Badge></TabsTrigger> | ||
| 611 | - <TabsTrigger value="notes" class="min-w-0"><IconNote class="h-4 w-4" />{t("courseNotes.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{noteCount()}</Badge></TabsTrigger> | ||
| 612 | - <TabsTrigger value="teachers" class="min-w-0"><IconSchool class="h-4 w-4" />{t("courses.teachers")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{assignedTeacherCount()}</Badge></TabsTrigger> | ||
| 613 | - <Show when={hasCourseManagementRights()}> | ||
| 614 | - <TabsTrigger value="students" class="min-w-0"><IconUsers class="h-4 w-4" />{t("courses.roster")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{rosterCount()}</Badge></TabsTrigger> | ||
| 615 | </Show> | 451 | </Show> |
| 616 | - </TabsList> | ||
| 617 | - | ||
| 618 | - <TabsContent value="subjects" class="space-y-3"> | ||
| 619 | - <div class="flex flex-wrap items-center gap-2"> | ||
| 620 | - <Badge variant="secondary" class="rounded-full">{countDescription(subjectCount(), t("subjects.item"))}</Badge> | ||
| 621 | - <Show when={canManage()}><Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowSubjectForm(true)}><IconPlus class="h-4 w-4" />{t("subjects.add")}</Button></Show> | ||
| 622 | - </div> | ||
| 623 | - <CourseSubjectsPanel courseId={id()} canManage={canManage()} active={courseTab() === "subjects"} createOpen={showSubjectForm()} onCreateOpenChange={setShowSubjectForm} onCountChange={setSubjectCount} /> | ||
| 624 | - </TabsContent> | ||
| 625 | - | ||
| 626 | - <TabsContent value="exams" class="space-y-3"> | ||
| 627 | - <div class="flex flex-wrap items-center gap-2"> | ||
| 628 | - <Badge variant="secondary" class="rounded-full">{countDescription(examCount(), t("courses.examItem"))}</Badge> | ||
| 629 | - <Show when={canManage()}><Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowExamForm(true)}><IconPlus class="h-4 w-4" />{t("courses.addExam")}</Button></Show> | ||
| 630 | - </div> | ||
| 631 | - <Suspense fallback={<DataTableSkeleton />}><DataTable columns={examColumns()} data={exams() ?? []} filterColumn="title" enablePagination pageSize={10} empty={t("exams.empty")} onRowClick={(exam) => void navigate({ to: "/exams/$id", params: { id: exam.id } })} /></Suspense> | ||
| 632 | - </TabsContent> | ||
| 633 | 452 | ||
| 634 | - <TabsContent value="homework" class="space-y-3"> | 453 | + <Tabs value={courseTab()} onChange={setCourseTab} class="space-y-4"> |
| 635 | - <div class="flex flex-wrap items-center gap-2"> | 454 | + <TabsList class="flex w-full justify-start overflow-x-auto sm:grid sm:grid-cols-4" aria-label={c().title}> |
| 636 | - <Badge variant="secondary" class="rounded-full">{countDescription(homeworkCount(), t("homework.item"))}</Badge> | 455 | + <TabsTrigger value="subjects" class="min-w-0"><IconBook class="h-4 w-4" />{t("subjects.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{subjectCount()}</Badge></TabsTrigger> |
| 637 | - <Show when={canManage()}><Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowHomeworkForm(true)}><IconPlus class="h-4 w-4" />{t("homework.add")}</Button></Show> | 456 | + <TabsTrigger value="sections" class="min-w-0"><IconSchool class="h-4 w-4" />{t("instances.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{sectionCount()}</Badge></TabsTrigger> |
| 638 | - </div> | 457 | + <TabsTrigger value="notes" class="min-w-0"><IconNote class="h-4 w-4" />{t("courseNotes.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{noteCount()}</Badge></TabsTrigger> |
| 639 | - <CourseHomeworkPanel courseId={id()} canManage={canManage()} active={courseTab() === "homework"} createOpen={showHomeworkForm()} onCreateOpenChange={setShowHomeworkForm} onCountChange={setHomeworkCount} /> | 458 | + <Show when={hasMembers()}> |
| 640 | - </TabsContent> | 459 | + <TabsTrigger value="members" class="min-w-0"><IconUsers class="h-4 w-4" />{t("courses.members")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{c().course_membership_count}</Badge></TabsTrigger> |
| 460 | + </Show> | ||
| 461 | + </TabsList> | ||
| 641 | 462 | ||
| 642 | - <TabsContent value="sessions" class="space-y-3"> | 463 | + <TabsContent value="subjects" class="space-y-3"> |
| 643 | - <div class="flex flex-wrap items-center gap-2"> | 464 | + <div class="flex flex-wrap items-center gap-2"> |
| 644 | - <Badge variant="secondary" class="rounded-full">{countDescription(sessionCount(), t("sessions.item"))}</Badge> | 465 | + <Badge variant="secondary" class="rounded-full">{countDescription(subjectCount(), t("subjects.item"))}</Badge> |
| 645 | - <Show when={canManage()}> | 466 | + <Show when={canManageCatalog()}> |
| 646 | - <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowSessionForm(true)}> | 467 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowSubjectForm(true)}> |
| 647 | - <IconPlus class="h-4 w-4" /> | 468 | + <IconPlus class="h-4 w-4" />{t("subjects.add")} |
| 648 | - {t("sessions.add")} | 469 | + </Button> |
| 649 | - </Button> | 470 | + </Show> |
| 650 | - </Show> | 471 | + </div> |
| 651 | - </div> | 472 | + <CourseSubjectsPanel |
| 652 | - <CourseSessionsPanel courseId={id()} roster={roster() ?? []} canManage={canManage()} active={courseTab() === "sessions"} createOpen={showSessionForm()} onCreateOpenChange={setShowSessionForm} onCountChange={setSessionCount} /> | 473 | + courseId={id()} |
| 653 | - </TabsContent> | 474 | + canManage={canManageCatalog()} |
| 475 | + active={courseTab() === "subjects"} | ||
| 476 | + createOpen={showSubjectForm()} | ||
| 477 | + onCreateOpenChange={setShowSubjectForm} | ||
| 478 | + onCountChange={setSubjectCount} | ||
| 479 | + /> | ||
| 480 | + </TabsContent> | ||
| 654 | 481 | ||
| 655 | - <TabsContent value="notes" class="space-y-3"> | 482 | + <TabsContent value="sections" class="space-y-3"> |
| 656 | - <div class="flex flex-wrap items-center gap-2"> | 483 | + <div class="flex flex-wrap items-center gap-2"> |
| 657 | - <Badge variant="secondary" class="rounded-full">{countDescription(noteCount(), t("courseNotes.item"))}</Badge> | 484 | + <Badge variant="secondary" class="rounded-full">{countDescription(sectionCount(), t("instances.item"))}</Badge> |
| 658 | - <Show when={canManage()}><Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowNoteForm(true)}><IconPlus class="h-4 w-4" />{t("courseNotes.add")}</Button></Show> | 485 | + <span class="text-xs text-text-subtle">{t("instances.selectSectionHelp")}</span> |
| 659 | - </div> | 486 | + </div> |
| 660 | - <CourseNotesPanel courseId={id()} canManage={canManage()} active={courseTab() === "notes"} createOpen={showNoteForm()} onCreateOpenChange={setShowNoteForm} onCountChange={setNoteCount} /> | 487 | + <Suspense fallback={<DataTableSkeleton />}> |
| 661 | - </TabsContent> | 488 | + <Show |
| 489 | + when={sectionCount() > 0} | ||
| 490 | + fallback={<EmptyState kind="people" title={t("instances.empty")} description={t("instances.emptyHelp")} />} | ||
| 491 | + > | ||
| 492 | + <DataTable | ||
| 493 | + columns={sectionColumns()} | ||
| 494 | + data={sections() ?? []} | ||
| 495 | + filterColumn="class" | ||
| 496 | + enablePagination | ||
| 497 | + pageSize={10} | ||
| 498 | + onRowClick={(row) => void navigate({ to: "/instances/$id", params: { id: row.instance.id } })} | ||
| 499 | + /> | ||
| 500 | + </Show> | ||
| 501 | + </Suspense> | ||
| 502 | + </TabsContent> | ||
| 662 | 503 | ||
| 663 | - <TabsContent value="teachers" class="space-y-3"> | 504 | + <TabsContent value="notes" class="space-y-3"> |
| 664 | - <div class="flex flex-wrap items-center gap-2 text-sm"> | 505 | + <div class="flex flex-wrap items-center gap-2"> |
| 665 | - <Badge variant="secondary" class="rounded-full">{countDescription(assignedTeacherCount(), t("courses.teachers"))}</Badge> | 506 | + <Badge variant="secondary" class="rounded-full">{countDescription(noteCount(), t("courseNotes.item"))}</Badge> |
| 666 | - <span class="inline-flex min-w-0 items-center gap-1.5 text-text-subtle"> | 507 | + <Show when={canManageCatalog()}> |
| 667 | - <IconSchool class="h-4 w-4 shrink-0" /> | 508 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowNoteForm(true)}> |
| 668 | - <span>{t("common.creator")}:</span> | 509 | + <IconPlus class="h-4 w-4" />{t("courseNotes.add")} |
| 669 | - <span class="truncate font-medium text-foreground">{c().creator.display_name || c().creator.username}</span> | 510 | + </Button> |
| 670 | - </span> | 511 | + </Show> |
| 671 | - <Show when={canStaffCourse()}><Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowTeacherForm(true)}><IconPlus class="h-4 w-4" />{t("courses.assignTeacher")}</Button></Show> | 512 | + </div> |
| 672 | - </div> | 513 | + <CourseNotesPanel |
| 673 | - <CourseTeachersPanel courseId={id()} teachers={c().teachers ?? []} canStaff={canStaffCourse()} assignOpen={showTeacherForm()} onAssignOpenChange={setShowTeacherForm} onCourseUpdated={refetchCourse} /> | 514 | + courseId={id()} |
| 674 | - </TabsContent> | 515 | + canManage={canManageCatalog()} |
| 516 | + active={courseTab() === "notes"} | ||
| 517 | + createOpen={showNoteForm()} | ||
| 518 | + onCreateOpenChange={setShowNoteForm} | ||
| 519 | + onCountChange={setNoteCount} | ||
| 520 | + /> | ||
| 521 | + </TabsContent> | ||
| 675 | 522 | ||
| 676 | - <Show when={hasCourseManagementRights()}> | 523 | + <Show when={hasMembers()}> |
| 677 | - <TabsContent value="students" class="space-y-3"> | 524 | + <TabsContent value="members" class="space-y-3"> |
| 678 | - <div class="flex flex-wrap items-center gap-2"> | 525 | + <div class="flex flex-wrap items-center gap-2"> |
| 679 | - <Badge variant="secondary" class="rounded-full">{countDescription(rosterCount(), t("courses.rosterItem"))}</Badge> | 526 | + <Badge variant="secondary" class="rounded-full">{countDescription(memberCount(), t("courses.memberItem"))}</Badge> |
| 680 | - <Show when={canManage()}><Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowEnrollPanel(true)}><IconPlus class="h-4 w-4" />{t("courses.enroll")}</Button></Show> | 527 | + <Show when={canManageCatalog()}> |
| 681 | - </div> | 528 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowMemberForm(true)}> |
| 682 | - <Suspense fallback={<DataTableSkeleton />}><Show when={(roster() ?? []).length > 0} fallback={<EmptyState kind="people" title={t("exams.emptyRoster")} />}><DataTable columns={rosterColumns()} data={roster() ?? []} filterColumn="username" enablePagination pageSize={10} /></Show></Suspense> | 529 | + <IconPlus class="h-4 w-4" />{t("courses.addMember")} |
| 683 | - </TabsContent> | 530 | + </Button> |
| 684 | - </Show> | 531 | + </Show> |
| 685 | - </Tabs> | 532 | + </div> |
| 686 | - </div> | 533 | + <Show when={canManageCatalog()} fallback={<EmptyState kind="people" title={t("common.accessDenied")} />}> |
| 534 | + <Suspense fallback={<DataTableSkeleton />}> | ||
| 535 | + <Show when={memberCount() > 0} fallback={<EmptyState kind="people" title={t("exams.emptyRoster")} />}> | ||
| 536 | + <DataTable columns={memberColumns()} data={members() ?? []} filterColumn="username" enablePagination pageSize={10} /> | ||
| 537 | + </Show> | ||
| 538 | + </Suspense> | ||
| 539 | + </Show> | ||
| 540 | + </TabsContent> | ||
| 541 | + </Show> | ||
| 542 | + </Tabs> | ||
| 543 | + </div> | ||
| 687 | </Show> | 544 | </Show> |
| 688 | </Show> | 545 | </Show> |
| 689 | )} | 546 | )} |
src/pages/courses-page.test.tsxmodified+7 -14
| @@ -25,12 +25,8 @@ vi.mock("@/stores/auth-context", () => ({ | |||
| 25 | vi.mock("@/api/courses", () => ({ | 25 | vi.mock("@/api/courses", () => ({ |
| 26 | getCourses, | 26 | getCourses, |
| 27 | postCourse: vi.fn(), | 27 | postCourse: vi.fn(), |
| 28 | - postCourseTeacher: vi.fn(), | ||
| 29 | })); | 28 | })); |
| 30 | vi.mock("@/api/reports", () => ({ getMyCourses })); | 29 | vi.mock("@/api/reports", () => ({ getMyCourses })); |
| 31 | -vi.mock("@/api/terms", () => ({ | ||
| 32 | - getTerms: async () => ({ items: [{ id: "term-1", name: "Fall" }], total: 1, limit: 100, offset: 0 }), | ||
| 33 | -})); | ||
| 34 | vi.mock("@/api/limits", () => ({ getLimits: vi.fn() })); | 30 | vi.mock("@/api/limits", () => ({ getLimits: vi.fn() })); |
| 35 | 31 | ||
| 36 | afterEach(() => { | 32 | afterEach(() => { |
| @@ -46,30 +42,27 @@ test("student class directory uses only enrolled-course data", async () => { | |||
| 46 | title: "Algebra", | 42 | title: "Algebra", |
| 47 | description: "Core mathematics", | 43 | description: "Core mathematics", |
| 48 | kind: "course", | 44 | kind: "course", |
| 49 | - term: "term-1", | 45 | + class_course_count: 2, |
| 50 | - capacity: 24, | 46 | + course_membership_count: 0, |
| 51 | creator: { id: "teacher-1", username: "teacher", display_name: "Ada Teacher" }, | 47 | creator: { id: "teacher-1", username: "teacher", display_name: "Ada Teacher" }, |
| 52 | - teachers: [], | ||
| 53 | }, | 48 | }, |
| 54 | { | 49 | { |
| 55 | id: "study-1", | 50 | id: "study-1", |
| 56 | title: "Study Lab", | 51 | title: "Study Lab", |
| 57 | description: "Weekly review", | 52 | description: "Weekly review", |
| 58 | kind: "study", | 53 | kind: "study", |
| 59 | - term: null, | 54 | + class_course_count: 0, |
| 60 | - capacity: 12, | 55 | + course_membership_count: 5, |
| 61 | creator: { id: "teacher-1", username: "teacher", display_name: "Ada Teacher" }, | 56 | creator: { id: "teacher-1", username: "teacher", display_name: "Ada Teacher" }, |
| 62 | - teachers: [], | ||
| 63 | }, | 57 | }, |
| 64 | { | 58 | { |
| 65 | id: "club-1", | 59 | id: "club-1", |
| 66 | title: "Robotics", | 60 | title: "Robotics", |
| 67 | description: "Build robots", | 61 | description: "Build robots", |
| 68 | kind: "club", | 62 | kind: "club", |
| 69 | - term: "term-1", | 63 | + class_course_count: 1, |
| 70 | - capacity: 18, | 64 | + course_membership_count: 9, |
| 71 | creator: { id: "teacher-2", username: "mentor", display_name: "Club Mentor" }, | 65 | creator: { id: "teacher-2", username: "mentor", display_name: "Club Mentor" }, |
| 72 | - teachers: [], | ||
| 73 | }, | 66 | }, |
| 74 | ], | 67 | ], |
| 75 | total: 3, | 68 | total: 3, |
| @@ -108,7 +101,7 @@ test("student class directory uses only enrolled-course data", async () => { | |||
| 108 | expect(screen.queryByRole("link", { name: /Algebra/ })).toBeNull(); | 101 | expect(screen.queryByRole("link", { name: /Algebra/ })).toBeNull(); |
| 109 | 102 | ||
| 110 | fireEvent.input(screen.getByPlaceholderText("Search…"), { target: { value: "" } }); | 103 | fireEvent.input(screen.getByPlaceholderText("Search…"), { target: { value: "" } }); |
| 111 | - fireEvent.change(screen.getByLabelText("Term", { selector: "select" }), { target: { value: "unassigned" } }); | 104 | + fireEvent.change(screen.getByLabelText("Taught in", { selector: "select" }), { target: { value: "untaught" } }); |
| 112 | expect(await screen.findByRole("link", { name: /Study Lab/ })).toBeTruthy(); | 105 | expect(await screen.findByRole("link", { name: /Study Lab/ })).toBeTruthy(); |
| 113 | expect(screen.queryByRole("link", { name: /Robotics/ })).toBeNull(); | 106 | expect(screen.queryByRole("link", { name: /Robotics/ })).toBeNull(); |
| 114 | }); | 107 | }); |
src/pages/courses-page.tsxmodified+16 -28
| @@ -1,9 +1,8 @@ | |||
| 1 | import { For, Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; | 1 | import { For, Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { useNavigate, useSearch } from "@tanstack/solid-router"; | 3 | import { useNavigate, useSearch } from "@tanstack/solid-router"; |
| 4 | -import { getCourses, postCourse, postCourseTeacher } from "@/api/courses"; | 4 | +import { getCourses, postCourse } from "@/api/courses"; |
| 5 | import { getMyCourses } from "@/api/reports"; | 5 | import { getMyCourses } from "@/api/reports"; |
| 6 | -import { getTerms } from "@/api/terms"; | ||
| 7 | import { getLimits } from "@/api/limits"; | 6 | import { getLimits } from "@/api/limits"; |
| 8 | import { formatApiError, type CourseKind } from "@/api/client"; | 7 | import { formatApiError, type CourseKind } from "@/api/client"; |
| 9 | import { CourseCard } from "@/components/courses/course-card"; | 8 | import { CourseCard } from "@/components/courses/course-card"; |
| @@ -24,7 +23,6 @@ import { courseKindLabel } from "@/lib/course-kind"; | |||
| 24 | import { SidePanel } from "@/components/ui/side-panel"; | 23 | import { SidePanel } from "@/components/ui/side-panel"; |
| 25 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | 24 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 26 | import { Textarea } from "@/components/ui/textarea"; | 25 | import { Textarea } from "@/components/ui/textarea"; |
| 27 | -import { UserSearchSelect } from "@/components/users/user-search-select"; | ||
| 28 | import { createFlash } from "@/lib/flash"; | 26 | import { createFlash } from "@/lib/flash"; |
| 29 | import { personLabel } from "@/lib/person"; | 27 | import { personLabel } from "@/lib/person"; |
| 30 | import { hasMinRole } from "@/lib/roles"; | 28 | import { hasMinRole } from "@/lib/roles"; |
| @@ -54,10 +52,10 @@ function CoursesContent() { | |||
| 54 | const [showForm, setShowForm] = createSignal(routeSearch().action === "new"); | 52 | const [showForm, setShowForm] = createSignal(routeSearch().action === "new"); |
| 55 | const [title, setTitle] = createSignal(""); | 53 | const [title, setTitle] = createSignal(""); |
| 56 | const [description, setDescription] = createSignal(""); | 54 | const [description, setDescription] = createSignal(""); |
| 57 | - const [termId, setTermId] = createSignal(""); | 55 | + // Catalog rows carry no term, capacity or staff any more — a şube decides |
| 58 | - const [capacity, setCapacity] = createSignal(""); | 56 | + // all three when it attaches the course. `taughtFilter` narrows by whether |
| 59 | - const [teacherId, setTeacherId] = createSignal(""); | 57 | + // any şube has. |
| 60 | - const [termFilter, setTermFilter] = createSignal("all"); | 58 | + const [taughtFilter, setTaughtFilter] = createSignal("all"); |
| 61 | const [page, setPage] = createSignal(0); | 59 | const [page, setPage] = createSignal(0); |
| 62 | const [search, setSearch] = createSignal(""); | 60 | const [search, setSearch] = createSignal(""); |
| 63 | const [error, setError] = createSignal(""); | 61 | const [error, setError] = createSignal(""); |
| @@ -71,30 +69,26 @@ function CoursesContent() { | |||
| 71 | setPageKind(routeSearch().kind); | 69 | setPageKind(routeSearch().kind); |
| 72 | }); | 70 | }); |
| 73 | createEffect(() => { | 71 | createEffect(() => { |
| 74 | - pageKind(); termFilter(); search(); setPage(0); | 72 | + pageKind(); taughtFilter(); search(); setPage(0); |
| 75 | }); | 73 | }); |
| 76 | 74 | ||
| 77 | - const [terms] = createResource(async () => (await getTerms({ limit: 100 })).items); | ||
| 78 | const [limits, { refetch: refetchLimits }] = createResource(() => canCreate() ? getLimits() : null); | 75 | const [limits, { refetch: refetchLimits }] = createResource(() => canCreate() ? getLimits() : null); |
| 79 | const [list, { refetch }] = createResource( | 76 | const [list, { refetch }] = createResource( |
| 80 | () => auth.user()?.role ?? null, | 77 | () => auth.user()?.role ?? null, |
| 81 | async (role) => role === "student" ? getMyCourses() : getCourses(), | 78 | async (role) => role === "student" ? getMyCourses() : getCourses(), |
| 82 | ); | 79 | ); |
| 83 | const listData = () => list.latest ?? list(); | 80 | const listData = () => list.latest ?? list(); |
| 84 | - const termName = (id: string | null) => terms.latest?.find((term) => term.id === id)?.name ?? (id || t("terms.unassigned")); | ||
| 85 | const filteredCourses = createMemo(() => { | 81 | const filteredCourses = createMemo(() => { |
| 86 | const query = search().trim().toLocaleLowerCase(); | 82 | const query = search().trim().toLocaleLowerCase(); |
| 87 | return (listData()?.items ?? []).filter((course) => { | 83 | return (listData()?.items ?? []).filter((course) => { |
| 88 | if (pageKind() && course.kind !== pageKind()) return false; | 84 | if (pageKind() && course.kind !== pageKind()) return false; |
| 89 | - if (termFilter() === "unassigned" && course.term) return false; | 85 | + if (taughtFilter() === "untaught" && course.class_course_count > 0) return false; |
| 90 | - if (termFilter() !== "all" && termFilter() !== "unassigned" && course.term !== termFilter()) return false; | 86 | + if (taughtFilter() === "taught" && course.class_course_count === 0) return false; |
| 91 | if (!query) return true; | 87 | if (!query) return true; |
| 92 | return [ | 88 | return [ |
| 93 | course.title, | 89 | course.title, |
| 94 | course.description, | 90 | course.description, |
| 95 | personLabel(course.creator), | 91 | personLabel(course.creator), |
| 96 | - ...(course.teachers ?? []).map(personLabel), | ||
| 97 | - termName(course.term), | ||
| 98 | ].join(" ").toLocaleLowerCase().includes(query); | 92 | ].join(" ").toLocaleLowerCase().includes(query); |
| 99 | }); | 93 | }); |
| 100 | }); | 94 | }); |
| @@ -106,15 +100,12 @@ function CoursesContent() { | |||
| 106 | setError(""); | 100 | setError(""); |
| 107 | setPending(true); | 101 | setPending(true); |
| 108 | try { | 102 | try { |
| 109 | - const course = await postCourse({ | 103 | + await postCourse({ |
| 110 | title: title().trim(), | 104 | title: title().trim(), |
| 111 | description: description().trim() || undefined, | 105 | description: description().trim() || undefined, |
| 112 | kind: createKind(), | 106 | kind: createKind(), |
| 113 | - term_id: termId() || null, | ||
| 114 | - capacity: capacity().trim() ? Number(capacity()) : null, | ||
| 115 | }); | 107 | }); |
| 116 | - if (teacherId() && hasMinRole(auth.user()?.role, "manager")) await postCourseTeacher(course.id, teacherId()); | 108 | + setTitle(""); setDescription(""); setShowForm(false); |
| 117 | - setTitle(""); setDescription(""); setTermId(""); setCapacity(""); setTeacherId(""); setShowForm(false); | ||
| 118 | await refetch(); | 109 | await refetch(); |
| 119 | setFlash(t("common.created")); | 110 | setFlash(t("common.created")); |
| 120 | } catch (err) { | 111 | } catch (err) { |
| @@ -136,9 +127,7 @@ function CoursesContent() { | |||
| 136 | <div class="space-y-3"> | 127 | <div class="space-y-3"> |
| 137 | <div class="space-y-1.5"><Label for="course-title">{t("form.title")}<span class="ml-0.5 text-destructive">*</span></Label><Input id="course-title" required maxlength={limits.latest?.course.max_title_len} value={title()} onInput={(e) => setTitle(e.currentTarget.value)} /></div> | 128 | <div class="space-y-1.5"><Label for="course-title">{t("form.title")}<span class="ml-0.5 text-destructive">*</span></Label><Input id="course-title" required maxlength={limits.latest?.course.max_title_len} value={title()} onInput={(e) => setTitle(e.currentTarget.value)} /></div> |
| 138 | <div class="space-y-1.5"><Label for="course-description">{t("form.description")}</Label><Textarea id="course-description" maxlength={limits.latest?.course.max_description_len} rows={3} value={description()} onInput={(e) => setDescription(e.currentTarget.value)} /></div> | 129 | <div class="space-y-1.5"><Label for="course-description">{t("form.description")}</Label><Textarea id="course-description" maxlength={limits.latest?.course.max_description_len} rows={3} value={description()} onInput={(e) => setDescription(e.currentTarget.value)} /></div> |
| 139 | - <div class="space-y-1.5"><Label for="course-term">{t("terms.term")}</Label><Select id="course-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}><option value="">{t("terms.unassigned")}</option><For each={terms.latest ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For></Select></div> | 130 | + <p class="rounded-xl border border-border-line bg-surface-tint px-3 py-2 text-xs text-text-subtle">{t("instances.emptyHelp")}</p> |
| 140 | - <div class="space-y-1.5"><Label for="course-capacity">{t("courses.capacity")}</Label><Input id="course-capacity" type="number" min={1} value={capacity()} onInput={(e) => setCapacity(e.currentTarget.value)} /></div> | ||
| 141 | - <Show when={hasMinRole(auth.user()?.role, "manager")}><UserSearchSelect id="course-teacher" role="teacher" value={teacherId()} onChange={setTeacherId} placeholder={t("courses.assignTeacher")} label={t("courses.teachers")} /></Show> | ||
| 142 | </div> | 131 | </div> |
| 143 | <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | 132 | <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> |
| 144 | <div class="flex gap-2 border-t pt-4"><Button type="submit" disabled={pending()}>{t("common.create")}</Button><Button type="button" variant="outline" onClick={() => setShowForm(false)}>{t("common.cancel")}</Button></div> | 133 | <div class="flex gap-2 border-t pt-4"><Button type="submit" disabled={pending()}>{t("common.create")}</Button><Button type="button" variant="outline" onClick={() => setShowForm(false)}>{t("common.cancel")}</Button></div> |
| @@ -187,10 +176,10 @@ function CoursesContent() { | |||
| 187 | searchHint={t("search.hint.courses")} | 176 | searchHint={t("search.hint.courses")} |
| 188 | onSearchInput={setSearch} | 177 | onSearchInput={setSearch} |
| 189 | filters={ | 178 | filters={ |
| 190 | - <Select wrapperClass="w-40 shrink-0 sm:w-52" class="h-8 rounded-lg" aria-label={t("terms.term")} value={termFilter()} onChange={(e) => setTermFilter(e.currentTarget.value)}> | 179 | + <Select wrapperClass="w-40 shrink-0 sm:w-52" class="h-8 rounded-lg" aria-label={t("instances.taughtIn")} value={taughtFilter()} onChange={(e) => setTaughtFilter(e.currentTarget.value)}> |
| 191 | <option value="all">{t("common.all")}</option> | 180 | <option value="all">{t("common.all")}</option> |
| 192 | - <option value="unassigned">{t("terms.unassigned")}</option> | 181 | + <option value="taught">{t("instances.taughtIn")}</option> |
| 193 | - <For each={terms.latest ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For> | 182 | + <option value="untaught">{t("instances.empty")}</option> |
| 194 | </Select> | 183 | </Select> |
| 195 | } | 184 | } |
| 196 | /> | 185 | /> |
| @@ -210,12 +199,11 @@ function CoursesContent() { | |||
| 210 | {(course) => ( | 199 | {(course) => ( |
| 211 | <CourseCard | 200 | <CourseCard |
| 212 | course={course} | 201 | course={course} |
| 213 | - term={termName(course.term)} | 202 | + sections={t("common.countItem", { count: course.class_course_count, item: t("instances.item") })} |
| 214 | enrolled={auth.user()?.role === "student"} | 203 | enrolled={auth.user()?.role === "student"} |
| 215 | showTeacherActions={hasMinRole(auth.user()?.role, "teacher")} | 204 | showTeacherActions={hasMinRole(auth.user()?.role, "teacher")} |
| 216 | labels={{ | 205 | labels={{ |
| 217 | - capacity: t("courses.capacity"), | 206 | + taughtIn: t("instances.taughtIn"), |
| 218 | - unlimited: t("courses.unlimited"), | ||
| 219 | enrolled: t("courses.enrolled"), | 207 | enrolled: t("courses.enrolled"), |
| 220 | kind: courseKindLabel(course.kind, t), | 208 | kind: courseKindLabel(course.kind, t), |
| 221 | weeklyHours: t("courses.weeklyHours"), | 209 | weeklyHours: t("courses.weeklyHours"), |
src/pages/dashboard-page.test.tsxmodified+19 -4
| @@ -37,7 +37,18 @@ vi.mock("@/stores/auth-context", () => ({ | |||
| 37 | const now = Date.UTC(2026, 6, 28, 9); | 37 | const now = Date.UTC(2026, 6, 28, 9); |
| 38 | const DAY = 24 * 60 * 60 * 1000; | 38 | const DAY = 24 * 60 * 60 * 1000; |
| 39 | const page = <T,>(items: T[]) => ({ items, total: items.length, limit: 50, offset: 0 }); | 39 | const page = <T,>(items: T[]) => ({ items, total: items.length, limit: 50, offset: 0 }); |
| 40 | -const course = { id: "course-1", title: "Algebra", capacity: 24 }; | 40 | +const course = { id: "course-1", title: "Algebra", class_course_count: 1, course_membership_count: 0 }; |
| 41 | +// Exams, homework and rosters hang off the instance (şube × ders); the catalog | ||
| 42 | +// course is one hop away, which is what the dashboard resolves for its labels. | ||
| 43 | +const instance = { | ||
| 44 | + id: "instance-1", | ||
| 45 | + class: "class-1", | ||
| 46 | + course: "course-1", | ||
| 47 | + ders_saati: 4, | ||
| 48 | + counts_toward_karne: true, | ||
| 49 | + enrollment_count: 0, | ||
| 50 | + teachers: [], | ||
| 51 | +}; | ||
| 41 | 52 | ||
| 42 | vi.mock("@/stores/modules-context", () => ({ | 53 | vi.mock("@/stores/modules-context", () => ({ |
| 43 | useModules: () => ({ | 54 | useModules: () => ({ |
| @@ -51,13 +62,17 @@ vi.mock("@/api/modules", () => ({ getModulesCatalog: async () => ({ modules: [], | |||
| 51 | vi.mock("@/api/time/getTime", () => ({ getTime: async () => ({ now }) })); | 62 | vi.mock("@/api/time/getTime", () => ({ getTime: async () => ({ now }) })); |
| 52 | vi.mock("@/api/courses", () => ({ | 63 | vi.mock("@/api/courses", () => ({ |
| 53 | getCourses: async () => page([course]), | 64 | getCourses: async () => page([course]), |
| 54 | - getCourseEnrollments: async () => page([]), | 65 | +})); |
| 66 | +vi.mock("@/api/instances", () => ({ | ||
| 67 | + getMyInstances: async () => page([instance]), | ||
| 68 | + getInstanceEnrollments: async () => page([]), | ||
| 55 | })); | 69 | })); |
| 56 | vi.mock("@/api/reports", () => ({ | 70 | vi.mock("@/api/reports", () => ({ |
| 57 | getMyCourses: async () => page([course]), | 71 | getMyCourses: async () => page([course]), |
| 58 | getMyMarks: async () => (calls.push("marks"), { | 72 | getMyMarks: async () => (calls.push("marks"), { |
| 59 | overall_average: 82.5, | 73 | overall_average: 82.5, |
| 60 | courses: [{ | 74 | courses: [{ |
| 75 | + instance: instance.id, | ||
| 61 | course, | 76 | course, |
| 62 | average: 82.5, | 77 | average: 82.5, |
| 63 | results: [{ exam: "exam-past", title: "Midterm", kind: "exam", weight: 1, mark: 78, graded_by: "t-1" }], | 78 | results: [{ exam: "exam-past", title: "Midterm", kind: "exam", weight: 1, mark: 78, graded_by: "t-1" }], |
| @@ -89,7 +104,7 @@ vi.mock("@/api/exams", async () => { | |||
| 89 | { | 104 | { |
| 90 | id: "exam-1", | 105 | id: "exam-1", |
| 91 | title: "Exam deadline", | 106 | title: "Exam deadline", |
| 92 | - course: "course-1", | 107 | + class_course: "instance-1", |
| 93 | draft: false, | 108 | draft: false, |
| 94 | starts_at: now + 1_000, | 109 | starts_at: now + 1_000, |
| 95 | ends_at: now + 3_000, | 110 | ends_at: now + 3_000, |
| @@ -97,7 +112,7 @@ vi.mock("@/api/exams", async () => { | |||
| 97 | { | 112 | { |
| 98 | id: "exam-past", | 113 | id: "exam-past", |
| 99 | title: "Midterm", | 114 | title: "Midterm", |
| 100 | - course: "course-1", | 115 | + class_course: "instance-1", |
| 101 | draft: false, | 116 | draft: false, |
| 102 | starts_at: now - 10 * DAY, | 117 | starts_at: now - 10 * DAY, |
| 103 | ends_at: now - 10 * DAY + 3_000, | 118 | ends_at: now - 10 * DAY + 3_000, |
src/pages/dashboard-page.tsxmodified+21 -7
| @@ -6,7 +6,8 @@ import type { Role } from "@/api/client"; | |||
| 6 | import { formatApiError, isModuleDisabledError } from "@/api/client"; | 6 | import { formatApiError, isModuleDisabledError } from "@/api/client"; |
| 7 | import { getAppointments } from "@/api/appointments"; | 7 | import { getAppointments } from "@/api/appointments"; |
| 8 | import { getClasses, getClassesByUserId, getMyClasses } from "@/api/classes"; | 8 | import { getClasses, getClassesByUserId, getMyClasses } from "@/api/classes"; |
| 9 | -import { getCourseEnrollments, getCourses } from "@/api/courses"; | 9 | +import { getCourses } from "@/api/courses"; |
| 10 | +import { getInstanceEnrollments, getMyInstances } from "@/api/instances"; | ||
| 10 | import { getEvents } from "@/api/events"; | 11 | import { getEvents } from "@/api/events"; |
| 11 | import { getExams, getExamStatistics } from "@/api/exams"; | 12 | import { getExams, getExamStatistics } from "@/api/exams"; |
| 12 | import { getHomework } from "@/api/homework"; | 13 | import { getHomework } from "@/api/homework"; |
| @@ -227,10 +228,13 @@ function DashboardContent() { | |||
| 227 | // user ids. Bounded to a handful of courses, the same cost shape as the | 228 | // user ids. Bounded to a handful of courses, the same cost shape as the |
| 228 | // admin quick-link class-member lookups. | 229 | // admin quick-link class-member lookups. |
| 229 | const [teacherStudentCount] = createResource( | 230 | const [teacherStudentCount] = createResource( |
| 230 | - () => (role() === "teacher" ? courses.latest?.items ?? null : null), | 231 | + () => (role() === "teacher" ? true : null), |
| 231 | - async (items) => { | 232 | + async () => { |
| 233 | + // Rosters hang off the instance now, so the count walks the teacher's | ||
| 234 | + // own sections instead of the catalog rows they own. | ||
| 235 | + const items = (await getMyInstances({ limit: 200 })).items; | ||
| 232 | const settled = await Promise.all( | 236 | const settled = await Promise.all( |
| 233 | - items.slice(0, 20).map((course) => getCourseEnrollments(course.id, { limit: 200 }).catch(() => null)), | 237 | + items.slice(0, 20).map((instance) => getInstanceEnrollments(instance.id, { limit: 200 }).catch(() => null)), |
| 234 | ); | 238 | ); |
| 235 | const ids = new Set<string>(); | 239 | const ids = new Set<string>(); |
| 236 | for (const page of settled) for (const enrollment of page?.items ?? []) ids.add(enrollment.user.id); | 240 | for (const page of settled) for (const enrollment of page?.items ?? []) ids.add(enrollment.user.id); |
| @@ -455,12 +459,21 @@ function DashboardContent() { | |||
| 455 | })); | 459 | })); |
| 456 | }); | 460 | }); |
| 457 | 461 | ||
| 462 | + // Exams name an instance; the catalog course behind it is what a chart label | ||
| 463 | + // should read, and `/instances/me` already covers the teacher's own sections. | ||
| 464 | + const [myInstances] = createResource( | ||
| 465 | + () => (role() && role() !== "parent" ? true : null), | ||
| 466 | + async () => (await getMyInstances({ limit: 200 })).items, | ||
| 467 | + ); | ||
| 468 | + const instanceCourse = (instanceId: string) => | ||
| 469 | + (myInstances.latest ?? []).find((instance) => instance.id === instanceId)?.course ?? null; | ||
| 470 | + | ||
| 458 | // Teacher+ trend — the backend's own per-exam average, oldest exam first. | 471 | // Teacher+ trend — the backend's own per-exam average, oldest exam first. |
| 459 | const examAverageTrend = createMemo(() => { | 472 | const examAverageTrend = createMemo(() => { |
| 460 | const titles = new Map((courses()?.items ?? []).map((course) => [course.id, course.title])); | 473 | const titles = new Map((courses()?.items ?? []).map((course) => [course.id, course.title])); |
| 461 | return (examStats() ?? []).map((row) => ({ | 474 | return (examStats() ?? []).map((row) => ({ |
| 462 | id: row.exam.id, | 475 | id: row.exam.id, |
| 463 | - label: `${titles.get(row.exam.course) ?? row.exam.course}: ${row.exam.title}`, | 476 | + label: `${titles.get(instanceCourse(row.exam.class_course) ?? "") ?? row.exam.class_course}: ${row.exam.title}`, |
| 464 | value: row.stats!.average!, | 477 | value: row.stats!.average!, |
| 465 | formattedValue: row.stats!.average!.toFixed(1), | 478 | formattedValue: row.stats!.average!.toFixed(1), |
| 466 | caption: formatTrendDate(row.exam.starts_at!), | 479 | caption: formatTrendDate(row.exam.starts_at!), |
| @@ -473,9 +486,10 @@ function DashboardContent() { | |||
| 473 | const titles = new Map((courses()?.items ?? []).map((course) => [course.id, course.title])); | 486 | const titles = new Map((courses()?.items ?? []).map((course) => [course.id, course.title])); |
| 474 | const buckets = new Map<string, number[]>(); | 487 | const buckets = new Map<string, number[]>(); |
| 475 | for (const row of examStats() ?? []) { | 488 | for (const row of examStats() ?? []) { |
| 476 | - const list = buckets.get(row.exam.course) ?? []; | 489 | + const courseId = instanceCourse(row.exam.class_course) ?? row.exam.class_course; |
| 490 | + const list = buckets.get(courseId) ?? []; | ||
| 477 | list.push(row.stats!.average!); | 491 | list.push(row.stats!.average!); |
| 478 | - buckets.set(row.exam.course, list); | 492 | + buckets.set(courseId, list); |
| 479 | } | 493 | } |
| 480 | return [...buckets.entries()] | 494 | return [...buckets.entries()] |
| 481 | .map(([courseId, averages]) => { | 495 | .map(([courseId, averages]) => { |
src/pages/exam-detail-page.tsxmodified+9 -7
| @@ -11,8 +11,7 @@ import { getExamResult } from "@/api/exams"; | |||
| 11 | import { getExamResults } from "@/api/exams"; | 11 | import { getExamResults } from "@/api/exams"; |
| 12 | import { getStudentMarksHistory } from "@/api/exams"; | 12 | import { getStudentMarksHistory } from "@/api/exams"; |
| 13 | import { getExamStatistics } from "@/api/exams"; | 13 | import { getExamStatistics } from "@/api/exams"; |
| 14 | -import { getCourseEnrollments } from "@/api/courses"; | 14 | +import { getInstanceById, getInstanceEnrollments, getMyInstances } from "@/api/instances"; |
| 15 | -import { getMyCourses } from "@/api/reports"; | ||
| 16 | import { patchExamById } from "@/api/exams"; | 15 | import { patchExamById } from "@/api/exams"; |
| 17 | import { postExamResult } from "@/api/exams"; | 16 | import { postExamResult } from "@/api/exams"; |
| 18 | import { ApiError, formatApiError } from "@/api/client"; | 17 | import { ApiError, formatApiError } from "@/api/client"; |
| @@ -186,12 +185,15 @@ function ExamDetailContent() { | |||
| 186 | }, | 185 | }, |
| 187 | ); | 186 | ); |
| 188 | const [roster] = createResource( | 187 | const [roster] = createResource( |
| 189 | - () => (hasCourseManagementRights() && gradeOpen() ? exam()?.course ?? null : null), | 188 | + () => (hasCourseManagementRights() && gradeOpen() ? exam()?.class_course ?? null : null), |
| 190 | - async (courseId) => (courseId ? (await getCourseEnrollments(courseId)).items : []), | 189 | + async (instanceId) => (instanceId ? (await getInstanceEnrollments(instanceId)).items : []), |
| 191 | ); | 190 | ); |
| 191 | + // The exam sits in an instance; its catalog course — which the question bank | ||
| 192 | + // keys on — is one hop away. | ||
| 193 | + const [instance] = createResource(() => exam()?.class_course ?? null, (instanceId) => getInstanceById(instanceId)); | ||
| 192 | const [mine] = createResource( | 194 | const [mine] = createResource( |
| 193 | () => (auth.user()?.role === "student" ? true : null), | 195 | () => (auth.user()?.role === "student" ? true : null), |
| 194 | - async (enabled) => (enabled ? (await getMyCourses()).items : []), | 196 | + async (enabled) => (enabled ? (await getMyInstances({ limit: 200 })).items : []), |
| 195 | ); | 197 | ); |
| 196 | 198 | ||
| 197 | const examStatus = () => { | 199 | const examStatus = () => { |
| @@ -238,7 +240,7 @@ function ExamDetailContent() { | |||
| 238 | const u = auth.user(); | 240 | const u = auth.user(); |
| 239 | if (!e || !u) return false; | 241 | if (!e || !u) return false; |
| 240 | if (u.role !== "student") return true; | 242 | if (u.role !== "student") return true; |
| 241 | - return (mine() ?? []).some((course) => course.id === e.course); | 243 | + return (mine() ?? []).some((row) => row.id === e.class_course); |
| 242 | }; | 244 | }; |
| 243 | const accessReady = () => auth.user()?.role !== "student" || mine() !== undefined; | 245 | const accessReady = () => auth.user()?.role !== "student" || mine() !== undefined; |
| 244 | 246 | ||
| @@ -694,7 +696,7 @@ function ExamDetailContent() { | |||
| 694 | </TabsContent> | 696 | </TabsContent> |
| 695 | 697 | ||
| 696 | <TabsContent value="questions" forceMount class="data-shell p-4"> | 698 | <TabsContent value="questions" forceMount class="data-shell p-4"> |
| 697 | - <ExamQuestionsPanel examId={id()} courseId={ex().course} readOnly={isFinished()} embedded /> | 699 | + <ExamQuestionsPanel examId={id()} courseId={instance()?.course ?? ""} readOnly={isFinished()} embedded /> |
| 698 | </TabsContent> | 700 | </TabsContent> |
| 699 | 701 | ||
| 700 | <TabsContent value="results" forceMount class="data-shell space-y-4 p-4"> | 702 | <TabsContent value="results" forceMount class="data-shell space-y-4 p-4"> |
src/pages/exam-room-page.tsxmodified+3 -3
| @@ -2,7 +2,7 @@ import { Link, useLocation } from "@tanstack/solid-router"; | |||
| 2 | import { Show, Suspense, createMemo } from "solid-js"; | 2 | import { Show, Suspense, createMemo } from "solid-js"; |
| 3 | import { createResource } from "@/lib/create-resource"; | 3 | import { createResource } from "@/lib/create-resource"; |
| 4 | import { getExamById } from "@/api/exams"; | 4 | import { getExamById } from "@/api/exams"; |
| 5 | -import { getMyCourses } from "@/api/reports"; | 5 | +import { getMyInstances } from "@/api/instances"; |
| 6 | import { formatApiError } from "@/api/client"; | 6 | import { formatApiError } from "@/api/client"; |
| 7 | import { ExamRoomWS } from "@/components/exams/exam-room-ws"; | 7 | import { ExamRoomWS } from "@/components/exams/exam-room-ws"; |
| 8 | import { RouteGuard } from "@/components/layout/route-guard"; | 8 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -35,14 +35,14 @@ function ExamRoomContent() { | |||
| 35 | const [exam] = createResource(id, (examId) => getExamById(examId)); | 35 | const [exam] = createResource(id, (examId) => getExamById(examId)); |
| 36 | const [mine] = createResource( | 36 | const [mine] = createResource( |
| 37 | () => (auth.user()?.role === "student" ? true : null), | 37 | () => (auth.user()?.role === "student" ? true : null), |
| 38 | - async (enabled) => (enabled ? (await getMyCourses()).items : []), | 38 | + async (enabled) => (enabled ? (await getMyInstances({ limit: 200 })).items : []), |
| 39 | ); | 39 | ); |
| 40 | const canViewExam = () => { | 40 | const canViewExam = () => { |
| 41 | const e = exam(); | 41 | const e = exam(); |
| 42 | const u = auth.user(); | 42 | const u = auth.user(); |
| 43 | if (!e || !u) return false; | 43 | if (!e || !u) return false; |
| 44 | if (u.role !== "student") return false; | 44 | if (u.role !== "student") return false; |
| 45 | - return (mine() ?? []).some((course) => course.id === e.course); | 45 | + return (mine() ?? []).some((row) => row.id === e.class_course); |
| 46 | }; | 46 | }; |
| 47 | const accessReady = () => auth.user()?.role !== "student" || mine() !== undefined; | 47 | const accessReady = () => auth.user()?.role !== "student" || mine() !== undefined; |
| 48 | 48 | ||
src/pages/exams-page.tsxmodified+55 -44
| @@ -3,13 +3,12 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | import { useLocation, useNavigate } from "@tanstack/solid-router"; | 4 | import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 5 | import { getCourseById } from "@/api/courses"; | 5 | import { getCourseById } from "@/api/courses"; |
| 6 | -import { getCourses } from "@/api/courses"; | ||
| 7 | import { getExams } from "@/api/exams"; | 6 | import { getExams } from "@/api/exams"; |
| 8 | -import { getMyCourses } from "@/api/reports"; | ||
| 9 | import { patchExamById } from "@/api/exams"; | 7 | import { patchExamById } from "@/api/exams"; |
| 10 | -import { postCourseExam } from "@/api/courses"; | 8 | +import { getInstanceById, postInstanceExam } from "@/api/instances"; |
| 9 | +import { loadInstanceOptions } from "@/lib/instance-options"; | ||
| 11 | import { formatApiError } from "@/api/client"; | 10 | import { formatApiError } from "@/api/client"; |
| 12 | -import type { Course, Exam } from "@/api/client"; | 11 | +import type { Exam } from "@/api/client"; |
| 13 | import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; | 12 | import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; |
| 14 | import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; | 13 | import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; |
| 15 | import { RouteGuard } from "@/components/layout/route-guard"; | 14 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -79,62 +78,71 @@ function ExamsContent() { | |||
| 79 | const [createdExam, setCreatedExam] = createSignal<Exam | null>(null); | 78 | const [createdExam, setCreatedExam] = createSignal<Exam | null>(null); |
| 80 | const [editTab, setEditTab] = createSignal<"details" | "questions">("details"); | 79 | const [editTab, setEditTab] = createSignal<"details" | "questions">("details"); |
| 81 | 80 | ||
| 82 | - const [courses] = createResource( | 81 | + // An exam is set inside an instance (şube × ders), so everything on this page |
| 83 | - () => (auth.user()?.role && auth.user()?.role !== "student" ? true : null), | 82 | + // — the filter, the picker, the section column — keys on the instance and |
| 84 | - async (enabled) => (enabled ? (await getCourses({ limit: 100 })).items : []), | 83 | + // resolves the catalog title through it. |
| 85 | - ); | 84 | + const [sections] = createResource( |
| 86 | - const [mine] = createResource( | 85 | + () => auth.user()?.role ?? null, |
| 87 | - () => (auth.user()?.role === "student" ? true : null), | 86 | + (role) => loadInstanceOptions(role ?? undefined), |
| 88 | - async (enabled) => (enabled ? (await getMyCourses({ limit: 100 })).items : []), | ||
| 89 | ); | 87 | ); |
| 90 | 88 | ||
| 91 | const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher"); | 89 | const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher"); |
| 92 | const isStudent = () => auth.user()?.role === "student"; | 90 | const isStudent = () => auth.user()?.role === "student"; |
| 93 | const canEditExam = (exam: Exam) => exam.creator === auth.user()?.id || hasMinRole(auth.user()?.role, "manager"); | 91 | const canEditExam = (exam: Exam) => exam.creator === auth.user()?.id || hasMinRole(auth.user()?.role, "manager"); |
| 94 | - const visibleCourses = createMemo(() => (isStudent() ? mine() : courses()) ?? []); | 92 | + const visibleCourses = createMemo(() => sections() ?? []); |
| 95 | - const manageableCourses = createMemo(() => | 93 | + // Teacher+ may set an exam in any section the picker offers them; the backend |
| 96 | - visibleCourses().filter((course) => course.creator.id === auth.user()?.id || hasMinRole(auth.user()?.role, "manager")), | 94 | + // is the real gate and answers 403 for anything else. |
| 97 | - ); | 95 | + const manageableCourses = createMemo(() => (hasMinRole(auth.user()?.role, "teacher") ? visibleCourses() : [])); |
| 98 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher") && manageableCourses().length > 0; | 96 | const canCreate = () => hasMinRole(auth.user()?.role, "teacher") && manageableCourses().length > 0; |
| 97 | + /** Instance id → label, filled for rows the picker did not already name. */ | ||
| 99 | const [courseMap, setCourseMap] = createSignal<Record<string, string>>({}); | 98 | const [courseMap, setCourseMap] = createSignal<Record<string, string>>({}); |
| 100 | - const courseTitle = (courseId: string) => { | 99 | + const courseTitle = (instanceId: string) => { |
| 101 | - const cached = visibleCourses().find((c) => c.id === courseId); | 100 | + const cached = visibleCourses().find((row) => row.id === instanceId); |
| 102 | - if (cached) return cached.title; | 101 | + if (cached) return cached.label; |
| 103 | - return courseMap()[courseId] ?? courseId; | 102 | + return courseMap()[instanceId] ?? instanceId; |
| 104 | }; | 103 | }; |
| 105 | 104 | ||
| 106 | const examStatus = (exam: Exam) => examDisplayStatus(exam, now()); | 105 | const examStatus = (exam: Exam) => examDisplayStatus(exam, now()); |
| 106 | + // The question bank keys on the catalog course, which an exam only names | ||
| 107 | + // through its instance. | ||
| 108 | + const examCourseId = (exam: Exam) => visibleCourses().find((row) => row.id === exam.class_course)?.course ?? null; | ||
| 107 | 109 | ||
| 108 | const filterExams = (items: Exam[]) => { | 110 | const filterExams = (items: Exam[]) => { |
| 109 | - const allowed = isStudent() ? new Set(visibleCourses().map((course) => course.id)) : null; | 111 | + const allowed = isStudent() ? new Set(visibleCourses().map((row) => row.id)) : null; |
| 110 | return items.filter((exam) => { | 112 | return items.filter((exam) => { |
| 111 | - if (allowed && !allowed.has(exam.course)) return false; | 113 | + if (allowed && !allowed.has(exam.class_course)) return false; |
| 112 | if (tab() !== "all" && examTabGroup(examStatus(exam)) !== tab()) return false; | 114 | if (tab() !== "all" && examTabGroup(examStatus(exam)) !== tab()) return false; |
| 113 | - if (courseFilter() !== "all" && exam.course !== courseFilter()) return false; | 115 | + if (courseFilter() !== "all" && exam.class_course !== courseFilter()) return false; |
| 114 | if (kindFilter() !== "all" && String(exam.kind) !== kindFilter()) return false; | 116 | if (kindFilter() !== "all" && String(exam.kind) !== kindFilter()) return false; |
| 115 | return true; | 117 | return true; |
| 116 | }); | 118 | }); |
| 117 | }; | 119 | }; |
| 118 | const searchExam = (exam: ExamRow, query: string) => | 120 | const searchExam = (exam: ExamRow, query: string) => |
| 119 | - [exam.title, exam.description, courseTitle(exam.course), examKindLabel(String(exam.kind), t), statusLabel(exam.displayStatus)] | 121 | + [exam.title, exam.description, courseTitle(exam.class_course), examKindLabel(String(exam.kind), t), statusLabel(exam.displayStatus)] |
| 120 | .join(" ") | 122 | .join(" ") |
| 121 | .toLocaleLowerCase(locale()) | 123 | .toLocaleLowerCase(locale()) |
| 122 | .includes(query.toLocaleLowerCase(locale())); | 124 | .includes(query.toLocaleLowerCase(locale())); |
| 123 | 125 | ||
| 124 | const [list, { refetch: refetchExams }] = createResource( | 126 | const [list, { refetch: refetchExams }] = createResource( |
| 125 | () => { | 127 | () => { |
| 126 | - if (isStudent() && mine() === undefined) return null; | 128 | + if (sections() === undefined) return null; |
| 127 | - if (!isStudent() && courses() === undefined) return null; | 129 | + return visibleCourses().map((row) => row.id).join(","); |
| 128 | - return [isStudent() ? "s" : "t", (mine() ?? []).map((c) => c.id).join(",")].join("|"); | ||
| 129 | }, | 130 | }, |
| 130 | async () => { | 131 | async () => { |
| 131 | const items = (await getExams({ limit: 100 })).items; | 132 | const items = (await getExams({ limit: 100 })).items; |
| 132 | - const known = new Map(visibleCourses().map((c) => [c.id, c.title])); | 133 | + const known = new Map(visibleCourses().map((row) => [row.id, row.label])); |
| 133 | - const missing = [...new Set(items.map((e) => e.course))].filter((id) => !known.has(id)); | 134 | + const missing = [...new Set(items.map((exam) => exam.class_course))].filter((instanceId) => !known.has(instanceId)); |
| 134 | if (missing.length > 0) { | 135 | if (missing.length > 0) { |
| 135 | - await Promise.all(missing.map((id) => | 136 | + await Promise.all( |
| 136 | - getCourseById(id).then((c) => known.set(id, c.title)).catch(() => {}), | 137 | + missing.map(async (instanceId) => { |
| 137 | - )); | 138 | + try { |
| 139 | + const instance = await getInstanceById(instanceId); | ||
| 140 | + known.set(instanceId, (await getCourseById(instance.course)).title); | ||
| 141 | + } catch { | ||
| 142 | + // The id stays as the label. | ||
| 143 | + } | ||
| 144 | + }), | ||
| 145 | + ); | ||
| 138 | } | 146 | } |
| 139 | setCourseMap(Object.fromEntries(known)); | 147 | setCourseMap(Object.fromEntries(known)); |
| 140 | return items; | 148 | return items; |
| @@ -169,10 +177,10 @@ function ExamsContent() { | |||
| 169 | }, | 177 | }, |
| 170 | { | 178 | { |
| 171 | id: "course", | 179 | id: "course", |
| 172 | - accessorFn: (exam) => courseTitle(exam.course), | 180 | + accessorFn: (exam) => courseTitle(exam.class_course), |
| 173 | - header: t("nav.courses"), | 181 | + header: t("instances.title"), |
| 174 | meta: { cellClass: "truncate text-muted-foreground" }, | 182 | meta: { cellClass: "truncate text-muted-foreground" }, |
| 175 | - cell: (cell) => courseTitle(cell.row.original.course), | 183 | + cell: (cell) => courseTitle(cell.row.original.class_course), |
| 176 | }, | 184 | }, |
| 177 | { | 185 | { |
| 178 | accessorKey: "starts_at", | 186 | accessorKey: "starts_at", |
| @@ -228,15 +236,17 @@ function ExamsContent() { | |||
| 228 | const saveOrCreateExam = async (values: ExamFormValues) => { | 236 | const saveOrCreateExam = async (values: ExamFormValues) => { |
| 229 | const existing = createdExam(); | 237 | const existing = createdExam(); |
| 230 | if (existing) { | 238 | if (existing) { |
| 231 | - const updated = await patchExamById(existing.id, values); | 239 | + // `term` is create-only — the backend cannot move a filed exam. |
| 240 | + const { term: _term, ...patch } = values; | ||
| 241 | + const updated = await patchExamById(existing.id, patch); | ||
| 232 | setCreatedExam(updated); | 242 | setCreatedExam(updated); |
| 233 | await refetchExams(); | 243 | await refetchExams(); |
| 234 | setCreateStep("questions"); | 244 | setCreateStep("questions"); |
| 235 | setFlash(t("common.saved")); | 245 | setFlash(t("common.saved")); |
| 236 | } else { | 246 | } else { |
| 237 | - const courseId = selectedCourseId(); | 247 | + const instanceId = selectedCourseId(); |
| 238 | - if (!courseId) throw new Error(t("exams.selectCourse")); | 248 | + if (!instanceId) throw new Error(t("instances.selectSection")); |
| 239 | - const newExam = await postCourseExam(courseId, { | 249 | + const newExam = await postInstanceExam(instanceId, { |
| 240 | ...values, | 250 | ...values, |
| 241 | description: values.description.trim() || undefined, | 251 | description: values.description.trim() || undefined, |
| 242 | }); | 252 | }); |
| @@ -250,7 +260,8 @@ function ExamsContent() { | |||
| 250 | const updateExam = async (values: ExamFormValues) => { | 260 | const updateExam = async (values: ExamFormValues) => { |
| 251 | const exam = editingExam(); | 261 | const exam = editingExam(); |
| 252 | if (!exam) return; | 262 | if (!exam) return; |
| 253 | - const updated = await patchExamById(exam.id, values); | 263 | + const { term: _term, ...patch } = values; |
| 264 | + const updated = await patchExamById(exam.id, patch); | ||
| 254 | setEditingExam(updated); | 265 | setEditingExam(updated); |
| 255 | await refetchExams(); | 266 | await refetchExams(); |
| 256 | setFlash(t("common.saved")); | 267 | setFlash(t("common.saved")); |
| @@ -323,7 +334,7 @@ function ExamsContent() { | |||
| 323 | onChange={(val) => setCourseFilter(val)} | 334 | onChange={(val) => setCourseFilter(val)} |
| 324 | options={[ | 335 | options={[ |
| 325 | { value: "all", label: t("common.all") }, | 336 | { value: "all", label: t("common.all") }, |
| 326 | - ...visibleCourses().map((course) => ({ value: course.id, label: course.title })), | 337 | + ...visibleCourses().map((row) => ({ value: row.id, label: row.label })), |
| 327 | ]} | 338 | ]} |
| 328 | /> | 339 | /> |
| 329 | 340 | ||
| @@ -407,9 +418,9 @@ function ExamsContent() { | |||
| 407 | <Show when={!createdExam()}> | 418 | <Show when={!createdExam()}> |
| 408 | <div class="mb-4 space-y-1.5 rounded-xl border border-border-line bg-surface-overlay p-4"> | 419 | <div class="mb-4 space-y-1.5 rounded-xl border border-border-line bg-surface-overlay p-4"> |
| 409 | <label class="text-sm font-medium" for="exam-course"> | 420 | <label class="text-sm font-medium" for="exam-course"> |
| 410 | - {t("exams.selectCourse")} | 421 | + {t("instances.selectSection")} |
| 411 | </label> | 422 | </label> |
| 412 | - <SearchableSelect id="exam-course" value={selectedCourseId()} required onChange={setSelectedCourseId} placeholder={t("exams.selectCourse")} options={manageableCourses().map((course: Course) => ({ value: course.id, label: course.title }))} /> | 423 | + <SearchableSelect id="exam-course" value={selectedCourseId()} required onChange={setSelectedCourseId} placeholder={t("instances.selectSection")} options={manageableCourses().map((row) => ({ value: row.id, label: row.label }))} /> |
| 413 | </div> | 424 | </div> |
| 414 | </Show> | 425 | </Show> |
| 415 | <ExamForm | 426 | <ExamForm |
| @@ -424,7 +435,7 @@ function ExamsContent() { | |||
| 424 | <div class="space-y-4"> | 435 | <div class="space-y-4"> |
| 425 | <ExamQuestionsPanel | 436 | <ExamQuestionsPanel |
| 426 | examId={createdExam()!.id} | 437 | examId={createdExam()!.id} |
| 427 | - courseId={createdExam()!.course} | 438 | + courseId={examCourseId(createdExam()!) ?? ""} |
| 428 | embedded | 439 | embedded |
| 429 | /> | 440 | /> |
| 430 | <div class="flex justify-end border-t pt-3"> | 441 | <div class="flex justify-end border-t pt-3"> |
| @@ -490,7 +501,7 @@ function ExamsContent() { | |||
| 490 | <Show when={editTab() === "questions"}> | 501 | <Show when={editTab() === "questions"}> |
| 491 | <ExamQuestionsPanel | 502 | <ExamQuestionsPanel |
| 492 | examId={exam().id} | 503 | examId={exam().id} |
| 493 | - courseId={exam().course} | 504 | + courseId={examCourseId(exam()) ?? ""} |
| 494 | embedded | 505 | embedded |
| 495 | /> | 506 | /> |
| 496 | </Show> | 507 | </Show> |
src/pages/homework-detail-page.tsxmodified+8 -4
| @@ -2,6 +2,7 @@ import { Link, useLocation } from "@tanstack/solid-router"; | |||
| 2 | import { Show, Suspense, createMemo } from "solid-js"; | 2 | import { Show, Suspense, createMemo } from "solid-js"; |
| 3 | import { createResource } from "@/lib/create-resource"; | 3 | import { createResource } from "@/lib/create-resource"; |
| 4 | import { getCourseById } from "@/api/courses"; | 4 | import { getCourseById } from "@/api/courses"; |
| 5 | +import { getInstanceById } from "@/api/instances"; | ||
| 5 | import { formatApiError } from "@/api/client"; | 6 | import { formatApiError } from "@/api/client"; |
| 6 | import { getHomeworkById } from "@/api/homework"; | 7 | import { getHomeworkById } from "@/api/homework"; |
| 7 | import { getSubjectById } from "@/api/subjects"; | 8 | import { getSubjectById } from "@/api/subjects"; |
| @@ -29,14 +30,17 @@ export default function HomeworkDetailPage() { | |||
| 29 | return match ? decodeURIComponent(match[1]) : prev; | 30 | return match ? decodeURIComponent(match[1]) : prev; |
| 30 | }, ""); | 31 | }, ""); |
| 31 | const [homework] = createResource(id, (homeworkId) => getHomeworkById(homeworkId)); | 32 | const [homework] = createResource(id, (homeworkId) => getHomeworkById(homeworkId)); |
| 32 | - const [course] = createResource(() => homework()?.course ?? null, async (courseId) => courseId ? getCourseById(courseId) : null); | 33 | + // Homework hangs off the instance; the catalog course behind it is one hop |
| 34 | + // further, and it is what names the work on screen. | ||
| 35 | + const [instance] = createResource(() => homework()?.class_course ?? null, (instanceId) => getInstanceById(instanceId)); | ||
| 36 | + const [course] = createResource(() => instance()?.course ?? null, (courseId) => getCourseById(courseId)); | ||
| 33 | const [subject] = createResource(() => homework()?.subject ?? null, async (subjectId) => subjectId ? getSubjectById(subjectId) : null); | 37 | const [subject] = createResource(() => homework()?.subject ?? null, async (subjectId) => subjectId ? getSubjectById(subjectId) : null); |
| 34 | const canManage = () => { | 38 | const canManage = () => { |
| 35 | const user = auth.user(); | 39 | const user = auth.user(); |
| 36 | const item = homework(); | 40 | const item = homework(); |
| 37 | const currentCourse = course(); | 41 | const currentCourse = course(); |
| 38 | if (!user || !item) return false; | 42 | if (!user || !item) return false; |
| 39 | - return item.created_by === user.id || currentCourse?.creator.id === user.id || (currentCourse?.teachers ?? []).some((teacher) => teacher.id === user.id) || hasMinRole(user.role, "manager"); | 43 | + return item.created_by === user.id || currentCourse?.creator.id === user.id || (instance()?.teachers ?? []).some((teacher) => teacher.id === user.id) || hasMinRole(user.role, "manager"); |
| 40 | }; | 44 | }; |
| 41 | 45 | ||
| 42 | return ( | 46 | return ( |
| @@ -64,7 +68,7 @@ export default function HomeworkDetailPage() { | |||
| 64 | <div class="grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-4"> | 68 | <div class="grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-4"> |
| 65 | <div class="rounded-xl border border-border-line bg-surface-base px-4 py-4"> | 69 | <div class="rounded-xl border border-border-line bg-surface-base px-4 py-4"> |
| 66 | <p class="text-xs font-medium uppercase tracking-[0.08em] text-text-subtle">{t("nav.courses")}</p> | 70 | <p class="text-xs font-medium uppercase tracking-[0.08em] text-text-subtle">{t("nav.courses")}</p> |
| 67 | - <p class="mt-1 font-medium text-text-default">{course()?.title ?? item().course}</p> | 71 | + <p class="mt-1 font-medium text-text-default">{course()?.title ?? item().class_course}</p> |
| 68 | </div> | 72 | </div> |
| 69 | <div class="rounded-xl border border-border-line bg-surface-base px-4 py-4"> | 73 | <div class="rounded-xl border border-border-line bg-surface-base px-4 py-4"> |
| 70 | <p class="text-xs font-medium uppercase tracking-[0.08em] text-text-subtle">{t("subjects.subject")}</p> | 74 | <p class="text-xs font-medium uppercase tracking-[0.08em] text-text-subtle">{t("subjects.subject")}</p> |
| @@ -85,7 +89,7 @@ export default function HomeworkDetailPage() { | |||
| 85 | <HomeworkSubmissionPanel homeworkId={id()} /> | 89 | <HomeworkSubmissionPanel homeworkId={id()} /> |
| 86 | </Show> | 90 | </Show> |
| 87 | <Show when={canManage()}> | 91 | <Show when={canManage()}> |
| 88 | - <HomeworkSubmissionsPanel homeworkId={id()} courseId={item().course} /> | 92 | + <HomeworkSubmissionsPanel homeworkId={id()} instanceId={item().class_course} /> |
| 89 | </Show> | 93 | </Show> |
| 90 | </div> | 94 | </div> |
| 91 | )} | 95 | )} |
src/pages/homework-page.tsxmodified+30 -18
| @@ -2,11 +2,13 @@ import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js | |||
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { useLocation, useNavigate } from "@tanstack/solid-router"; | 3 | import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | -import { getCourseById, getCourseSubjects, getCourses, postCourseHomework } from "@/api/courses"; | 5 | +import { getCourseById, getCourseSubjects } from "@/api/courses"; |
| 6 | +import { getInstanceById, postInstanceHomework } from "@/api/instances"; | ||
| 7 | +import { loadInstanceOptions } from "@/lib/instance-options"; | ||
| 6 | import { getHomework } from "@/api/homework"; | 8 | import { getHomework } from "@/api/homework"; |
| 7 | import { getTime } from "@/api/time"; | 9 | import { getTime } from "@/api/time"; |
| 8 | import { formatApiError } from "@/api/client"; | 10 | import { formatApiError } from "@/api/client"; |
| 9 | -import type { Course, Homework } from "@/api/client"; | 11 | +import type { Homework } from "@/api/client"; |
| 10 | import { RouteGuard } from "@/components/layout/route-guard"; | 12 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 11 | import { Alert } from "@/components/ui/alert"; | 13 | import { Alert } from "@/components/ui/alert"; |
| 12 | import { Button } from "@/components/ui/button"; | 14 | import { Button } from "@/components/ui/button"; |
| @@ -69,24 +71,34 @@ function HomeworkContent() { | |||
| 69 | const [dueTime, setDueTime] = createSignal(""); | 71 | const [dueTime, setDueTime] = createSignal(""); |
| 70 | const [error, setError] = createSignal(""); | 72 | const [error, setError] = createSignal(""); |
| 71 | const [pending, setPending] = createSignal(false); | 73 | const [pending, setPending] = createSignal(false); |
| 74 | + // Homework is filed against an instance (şube × ders), so a row's label is | ||
| 75 | + // the catalog course's title, resolved one hop through the instance. | ||
| 72 | const [courseNames, setCourseNames] = createSignal<Record<string, string>>({}); | 76 | const [courseNames, setCourseNames] = createSignal<Record<string, string>>({}); |
| 73 | const [list, { refetch }] = createResource(async () => { | 77 | const [list, { refetch }] = createResource(async () => { |
| 74 | const items = (await getHomework({ limit: 100 })).items; | 78 | const items = (await getHomework({ limit: 100 })).items; |
| 75 | - const courses = [...new Set(items.map((item) => item.course))]; | 79 | + const instanceIds = [...new Set(items.map((item) => item.class_course))]; |
| 76 | - await Promise.all(courses.map((id) => getCourseById(id).then((course) => setCourseNames((current) => ({ ...current, [id]: course.title }))).catch(() => {}))); | 80 | + await Promise.all( |
| 81 | + instanceIds.map(async (instanceId) => { | ||
| 82 | + try { | ||
| 83 | + const instance = await getInstanceById(instanceId); | ||
| 84 | + const course = await getCourseById(instance.course); | ||
| 85 | + setCourseNames((current) => ({ ...current, [instanceId]: course.title })); | ||
| 86 | + } catch { | ||
| 87 | + // An unreadable section just keeps its id as the label. | ||
| 88 | + } | ||
| 89 | + }), | ||
| 90 | + ); | ||
| 77 | return items; | 91 | return items; |
| 78 | }); | 92 | }); |
| 79 | - const [courses] = createResource( | 93 | + // The sections a teacher may assign work in, labelled "<ders> — <şube>". |
| 80 | - () => (hasMinRole(auth.user()?.role, "teacher") ? true : null), | 94 | + const [instances] = createResource( |
| 81 | - async (enabled) => (enabled ? (await getCourses({ limit: 100 })).items : []), | 95 | + () => (hasMinRole(auth.user()?.role, "teacher") ? auth.user()?.role : null), |
| 96 | + (role) => loadInstanceOptions(role ?? undefined), | ||
| 82 | ); | 97 | ); |
| 83 | - const manageableCourses = createMemo(() => (courses() ?? []).filter((course: Course) => { | 98 | + const manageableCourses = createMemo(() => instances() ?? []); |
| 84 | - const user = auth.user(); | 99 | + const selectedCourse = createMemo(() => manageableCourses().find((row) => row.id === selectedCourseId())?.course ?? null); |
| 85 | - if (!user) return false; | ||
| 86 | - return course.creator.id === user.id || (course.teachers ?? []).some((teacher) => teacher.id === user.id) || hasMinRole(user.role, "manager"); | ||
| 87 | - })); | ||
| 88 | const [subjects] = createResource( | 100 | const [subjects] = createResource( |
| 89 | - () => selectedCourseId() || null, | 101 | + () => selectedCourse(), |
| 90 | async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), | 102 | async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), |
| 91 | ); | 103 | ); |
| 92 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | 104 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); |
| @@ -132,7 +144,7 @@ function HomeworkContent() { | |||
| 132 | if (due_at < (serverTime()?.now ?? Date.now())) return setError(t("form.timePast")); | 144 | if (due_at < (serverTime()?.now ?? Date.now())) return setError(t("form.timePast")); |
| 133 | setPending(true); | 145 | setPending(true); |
| 134 | try { | 146 | try { |
| 135 | - await postCourseHomework(selectedCourseId(), { | 147 | + await postInstanceHomework(selectedCourseId(), { |
| 136 | title: title().trim(), | 148 | title: title().trim(), |
| 137 | description: description().trim() || null, | 149 | description: description().trim() || null, |
| 138 | subject_id: subjectId(), | 150 | subject_id: subjectId(), |
| @@ -161,10 +173,10 @@ function HomeworkContent() { | |||
| 161 | }, | 173 | }, |
| 162 | { | 174 | { |
| 163 | id: "course", | 175 | id: "course", |
| 164 | - accessorFn: (row) => courseName(row.course), | 176 | + accessorFn: (row) => courseName(row.class_course), |
| 165 | header: t("nav.courses"), | 177 | header: t("nav.courses"), |
| 166 | meta: { cellClass: "max-w-0 truncate text-text-subtle" }, | 178 | meta: { cellClass: "max-w-0 truncate text-text-subtle" }, |
| 167 | - cell: (cell) => <span class="block truncate">{courseName(cell.row.original.course)}</span>, | 179 | + cell: (cell) => <span class="block truncate">{courseName(cell.row.original.class_course)}</span>, |
| 168 | }, | 180 | }, |
| 169 | { | 181 | { |
| 170 | id: "due_at", | 182 | id: "due_at", |
| @@ -204,8 +216,8 @@ function HomeworkContent() { | |||
| 204 | <Alert variant="destructive">{error()}</Alert> | 216 | <Alert variant="destructive">{error()}</Alert> |
| 205 | </Show> | 217 | </Show> |
| 206 | <div class="space-y-1.5"> | 218 | <div class="space-y-1.5"> |
| 207 | - <Label for="homework-course">{t("nav.courses")}</Label> | 219 | + <Label for="homework-course">{t("instances.selectSection")}</Label> |
| 208 | - <SearchableSelect id="homework-course" required value={selectedCourseId()} onChange={setSelectedCourseId} placeholder={t("exams.selectCourse")} options={manageableCourses().map((course) => ({ value: course.id, label: course.title }))} /> | 220 | + <SearchableSelect id="homework-course" required value={selectedCourseId()} onChange={setSelectedCourseId} placeholder={t("exams.selectCourse")} options={manageableCourses().map((row) => ({ value: row.id, label: row.label }))} /> |
| 209 | </div> | 221 | </div> |
| 210 | <div class="space-y-1.5"> | 222 | <div class="space-y-1.5"> |
| 211 | <Label for="homework-subject-global">{t("subjects.subject")}</Label> | 223 | <Label for="homework-subject-global">{t("subjects.subject")}</Label> |
src/pages/instance-detail-page.tsxadded+619 -0
| @@ -0,0 +1,619 @@ | |||
| 1 | +import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import { createResource } from "@/lib/create-resource"; | ||
| 3 | +import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; | ||
| 4 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 5 | +import { getClassById } from "@/api/classes"; | ||
| 6 | +import { getCourseById } from "@/api/courses"; | ||
| 7 | +import { | ||
| 8 | + deleteInstanceEnrollmentByUserId, | ||
| 9 | + getInstanceById, | ||
| 10 | + getInstanceEnrollments, | ||
| 11 | + getInstanceExams, | ||
| 12 | + patchInstanceById, | ||
| 13 | + postInstanceEnrollment, | ||
| 14 | + postInstanceExam, | ||
| 15 | +} from "@/api/instances"; | ||
| 16 | +import { getSettings } from "@/api/settings"; | ||
| 17 | +import { formatApiError } from "@/api/client"; | ||
| 18 | +import type { Enrollment, Exam } from "@/api/client"; | ||
| 19 | +import { patchExamById } from "@/api/exams"; | ||
| 20 | +import { ExamLink } from "@/components/exams/exam-link"; | ||
| 21 | +import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; | ||
| 22 | +import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; | ||
| 23 | +import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel"; | ||
| 24 | +import { CourseHomeworkPanel } from "@/components/homework/course-homework-panel"; | ||
| 25 | +import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; | ||
| 26 | +import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 27 | +import { PageHeader } from "@/components/layout/page-header"; | ||
| 28 | +import { Alert } from "@/components/ui/alert"; | ||
| 29 | +import { Badge } from "@/components/ui/badge"; | ||
| 30 | +import { Button } from "@/components/ui/button"; | ||
| 31 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 32 | +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | ||
| 33 | +import { EmptyState } from "@/components/ui/empty-state"; | ||
| 34 | +import { IconCalendarDays, IconExam, IconHomework, IconPlus, IconSchool, IconTrash, IconUsers } from "@/components/ui/icons"; | ||
| 35 | +import { Input } from "@/components/ui/input"; | ||
| 36 | +import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 37 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 38 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
| 39 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 40 | +import { UserSearchSelect } from "@/components/users/user-search-select"; | ||
| 41 | +import { cn } from "@/lib/cn"; | ||
| 42 | +import { createFlash } from "@/lib/flash"; | ||
| 43 | +import { examKindLabel } from "@/lib/exam-labels"; | ||
| 44 | +import { examWeight } from "@/lib/exam-weight"; | ||
| 45 | +import { hasMinRole } from "@/lib/roles"; | ||
| 46 | +import { useAuth } from "@/stores/auth-context"; | ||
| 47 | +import { useT } from "@/stores/preferences-context"; | ||
| 48 | + | ||
| 49 | +export default function InstanceDetailPage() { | ||
| 50 | + return ( | ||
| 51 | + <RouteGuard> | ||
| 52 | + <InstanceDetailContent /> | ||
| 53 | + </RouteGuard> | ||
| 54 | + ); | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +function InstanceDetailContent() { | ||
| 58 | + const location = useLocation(); | ||
| 59 | + const params = useParams({ from: "/instances/$id" }); | ||
| 60 | + const auth = useAuth(); | ||
| 61 | + const navigate = useNavigate(); | ||
| 62 | + const t = useT(); | ||
| 63 | + const id = createMemo(() => { | ||
| 64 | + location(); | ||
| 65 | + return params().id; | ||
| 66 | + }); | ||
| 67 | + | ||
| 68 | + const [tab, setTab] = createSignal("exams"); | ||
| 69 | + const [instance, { refetch: refetchInstance }] = createResource(id, (instanceId) => getInstanceById(instanceId)); | ||
| 70 | + const [course] = createResource(() => instance()?.course ?? null, (courseId) => getCourseById(courseId)); | ||
| 71 | + const [klass] = createResource(() => instance()?.class ?? null, (classId) => getClassById(classId).catch(() => null)); | ||
| 72 | + const [settings] = createResource(() => getSettings()); | ||
| 73 | + | ||
| 74 | + // Manager+, an assigned teacher, or the şube's homeroom teacher may run it. | ||
| 75 | + const canManage = () => { | ||
| 76 | + const i = instance(); | ||
| 77 | + const u = auth.user(); | ||
| 78 | + if (!i || !u) return false; | ||
| 79 | + if (hasMinRole(u.role, "manager")) return true; | ||
| 80 | + if (i.teachers.some((teacher) => teacher.id === u.id)) return true; | ||
| 81 | + return klass.latest?.teacher?.id === u.id; | ||
| 82 | + }; | ||
| 83 | + const canStaff = () => hasMinRole(auth.user()?.role ?? "student", "manager"); | ||
| 84 | + | ||
| 85 | + const [exams, { refetch: refetchExams }] = createResource( | ||
| 86 | + () => id(), | ||
| 87 | + async (instanceId) => (instanceId ? (await getInstanceExams(instanceId)).items : []), | ||
| 88 | + ); | ||
| 89 | + const [roster, { refetch: refetchRoster }] = createResource( | ||
| 90 | + () => (canManage() ? id() : null), | ||
| 91 | + async (instanceId) => (instanceId ? (await getInstanceEnrollments(instanceId)).items : []), | ||
| 92 | + ); | ||
| 93 | + | ||
| 94 | + const [showExamForm, setShowExamForm] = createSignal(false); | ||
| 95 | + const [examCreateStep, setExamCreateStep] = createSignal<"details" | "questions">("details"); | ||
| 96 | + const [createdExam, setCreatedExam] = createSignal<Exam | null>(null); | ||
| 97 | + const [showSessionForm, setShowSessionForm] = createSignal(false); | ||
| 98 | + const [showHomeworkForm, setShowHomeworkForm] = createSignal(false); | ||
| 99 | + const [showTeacherForm, setShowTeacherForm] = createSignal(false); | ||
| 100 | + const [showEnrollPanel, setShowEnrollPanel] = createSignal(false); | ||
| 101 | + const [sessionCount, setSessionCount] = createSignal(0); | ||
| 102 | + const [homeworkCount, setHomeworkCount] = createSignal(0); | ||
| 103 | + const [enrollUserId, setEnrollUserId] = createSignal(""); | ||
| 104 | + const [removeTarget, setRemoveTarget] = createSignal<{ userId: string; userName: string } | null>(null); | ||
| 105 | + const [error, setError] = createSignal(""); | ||
| 106 | + const [pending, setPending] = createSignal(false); | ||
| 107 | + const [flash, setFlash] = createFlash(); | ||
| 108 | + | ||
| 109 | + // Policy edits are two inline writes on a shared resource, so they keep local | ||
| 110 | + // signals and PATCH optimistically instead of refetching the instance. | ||
| 111 | + const [countsTowardKarne, setCountsTowardKarne] = createSignal(true); | ||
| 112 | + const [dersSaati, setDersSaati] = createSignal(""); | ||
| 113 | + const [savingPolicy, setSavingPolicy] = createSignal(false); | ||
| 114 | + createEffect(() => { | ||
| 115 | + const i = instance(); | ||
| 116 | + if (!i) return; | ||
| 117 | + setCountsTowardKarne(i.counts_toward_karne); | ||
| 118 | + setDersSaati(String(i.ders_saati)); | ||
| 119 | + }); | ||
| 120 | + | ||
| 121 | + const toggleKarne = async (next: boolean) => { | ||
| 122 | + if (savingPolicy()) return; | ||
| 123 | + setCountsTowardKarne(next); | ||
| 124 | + setSavingPolicy(true); | ||
| 125 | + try { | ||
| 126 | + await patchInstanceById(id(), { counts_toward_karne: next }); | ||
| 127 | + } catch (err) { | ||
| 128 | + setCountsTowardKarne(!next); | ||
| 129 | + setError(formatApiError(err)); | ||
| 130 | + } finally { | ||
| 131 | + setSavingPolicy(false); | ||
| 132 | + } | ||
| 133 | + }; | ||
| 134 | + | ||
| 135 | + const saveDersSaati = async () => { | ||
| 136 | + const value = Number(dersSaati().trim()); | ||
| 137 | + const current = instance()?.ders_saati; | ||
| 138 | + if (!Number.isInteger(value) || value < 0 || value === current) { | ||
| 139 | + setDersSaati(String(current ?? "")); | ||
| 140 | + return; | ||
| 141 | + } | ||
| 142 | + setSavingPolicy(true); | ||
| 143 | + try { | ||
| 144 | + await patchInstanceById(id(), { ders_saati: value }); | ||
| 145 | + await refetchInstance(); | ||
| 146 | + } catch (err) { | ||
| 147 | + setDersSaati(String(current ?? "")); | ||
| 148 | + setError(formatApiError(err)); | ||
| 149 | + } finally { | ||
| 150 | + setSavingPolicy(false); | ||
| 151 | + } | ||
| 152 | + }; | ||
| 153 | + | ||
| 154 | + const examModeLabel = (mode: string | null) => { | ||
| 155 | + if (mode === "sync") return t("exams.mode.sync"); | ||
| 156 | + if (mode === "async") return t("exams.mode.async"); | ||
| 157 | + if (mode === "open") return t("exams.mode.open"); | ||
| 158 | + return t("exams.unscheduled"); | ||
| 159 | + }; | ||
| 160 | + const countDescription = (count: number, item: string) => t("common.countItem", { count, item }); | ||
| 161 | + const examCount = createMemo(() => exams()?.length ?? 0); | ||
| 162 | + const rosterCount = createMemo(() => roster()?.length ?? 0); | ||
| 163 | + const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id); | ||
| 164 | + | ||
| 165 | + const rosterColumns = createMemo<ColumnDef<Enrollment>[]>(() => [ | ||
| 166 | + { | ||
| 167 | + id: "username", | ||
| 168 | + accessorFn: (row) => row.user.display_name || row.user.username, | ||
| 169 | + header: t("admin.username"), | ||
| 170 | + meta: { cellClass: "font-medium" }, | ||
| 171 | + cell: (cell) => ( | ||
| 172 | + <span class="flex items-center gap-2"> | ||
| 173 | + {cell.row.original.user.display_name || cell.row.original.user.username} | ||
| 174 | + <Show when={cell.row.original.source}> | ||
| 175 | + <Badge variant="secondary" class="rounded-full text-xs font-normal"> | ||
| 176 | + {t("course.fromClass", { name: klass.latest?.name ?? "—" })} | ||
| 177 | + </Badge> | ||
| 178 | + </Show> | ||
| 179 | + </span> | ||
| 180 | + ), | ||
| 181 | + }, | ||
| 182 | + { | ||
| 183 | + id: "actions", | ||
| 184 | + header: t("common.actions"), | ||
| 185 | + meta: { headerClass: "w-14 text-center", cellClass: "px-1 text-center" }, | ||
| 186 | + cell: (cell) => ( | ||
| 187 | + <Show when={canManage()}> | ||
| 188 | + <TableRowActions | ||
| 189 | + label={t("common.actions")} | ||
| 190 | + actions={[ | ||
| 191 | + { | ||
| 192 | + label: t("common.remove"), | ||
| 193 | + icon: <IconTrash class="h-4 w-4" />, | ||
| 194 | + destructive: true, | ||
| 195 | + onSelect: () => | ||
| 196 | + setRemoveTarget({ | ||
| 197 | + userId: cell.row.original.user.id, | ||
| 198 | + userName: cell.row.original.user.display_name || cell.row.original.user.username, | ||
| 199 | + }), | ||
| 200 | + }, | ||
| 201 | + ]} | ||
| 202 | + /> | ||
| 203 | + </Show> | ||
| 204 | + ), | ||
| 205 | + }, | ||
| 206 | + ]); | ||
| 207 | + | ||
| 208 | + const examColumns = createMemo<ColumnDef<Exam>[]>(() => [ | ||
| 209 | + { | ||
| 210 | + accessorKey: "title", | ||
| 211 | + header: t("form.title"), | ||
| 212 | + meta: { cellClass: "font-medium" }, | ||
| 213 | + cell: (cell) => ( | ||
| 214 | + <ExamLink examId={cell.row.original.id} class="hover:text-primary hover:underline"> | ||
| 215 | + {cell.row.original.title} | ||
| 216 | + </ExamLink> | ||
| 217 | + ), | ||
| 218 | + }, | ||
| 219 | + { | ||
| 220 | + id: "kind", | ||
| 221 | + accessorFn: (row) => examKindLabel(String(row.kind), t), | ||
| 222 | + header: t("exams.kind"), | ||
| 223 | + cell: (cell) => ( | ||
| 224 | + <Badge variant="outline" class="rounded-full capitalize"> | ||
| 225 | + {examKindLabel(String(cell.row.original.kind), t)} | ||
| 226 | + <Show when={examWeight(cell.row.original, settings()?.exam_kinds)}> | ||
| 227 | + {(weight) => <span class="ml-1 text-text-subtle">({t("courses.weight")}: {weight()})</span>} | ||
| 228 | + </Show> | ||
| 229 | + </Badge> | ||
| 230 | + ), | ||
| 231 | + }, | ||
| 232 | + { | ||
| 233 | + id: "mode", | ||
| 234 | + accessorFn: (row) => examModeLabel(row.mode), | ||
| 235 | + header: t("exams.mode"), | ||
| 236 | + cell: (cell) => <Badge variant="secondary" class="rounded-full">{examModeLabel(cell.row.original.mode)}</Badge>, | ||
| 237 | + }, | ||
| 238 | + { | ||
| 239 | + id: "status", | ||
| 240 | + accessorFn: (row) => (row.draft ? t("exams.draft") : ""), | ||
| 241 | + header: t("events.status"), | ||
| 242 | + cell: (cell) => ( | ||
| 243 | + <Show when={cell.row.original.draft} fallback="—"> | ||
| 244 | + <Badge variant="secondary" class="rounded-full">{t("exams.draft")}</Badge> | ||
| 245 | + </Show> | ||
| 246 | + ), | ||
| 247 | + }, | ||
| 248 | + ]); | ||
| 249 | + | ||
| 250 | + return ( | ||
| 251 | + <Suspense fallback={<PageSpinner />}> | ||
| 252 | + <Show | ||
| 253 | + when={instance()?.id === id() ? instance() : undefined} | ||
| 254 | + fallback={ | ||
| 255 | + <Show when={instance.error} fallback={<PageSpinner />}> | ||
| 256 | + <Alert variant="destructive">{formatApiError(instance.error)}</Alert> | ||
| 257 | + </Show> | ||
| 258 | + } | ||
| 259 | + > | ||
| 260 | + {(inst) => ( | ||
| 261 | + <div class="mx-auto w-full max-w-[1440px] space-y-4"> | ||
| 262 | + <div class="space-y-1.5"> | ||
| 263 | + <nav class="detail-breadcrumb"> | ||
| 264 | + <Link to="/courses" search={{} as never}>{t("courses.title")}</Link> | ||
| 265 | + <span aria-hidden>›</span> | ||
| 266 | + <Link to="/courses/$id" params={{ id: inst().course }}>{course.latest?.title ?? "…"}</Link> | ||
| 267 | + <span aria-hidden>›</span> | ||
| 268 | + <span class="text-foreground">{klass.latest?.name ?? t("instances.title")}</span> | ||
| 269 | + </nav> | ||
| 270 | + <PageHeader | ||
| 271 | + title={`${course.latest?.title ?? ""} — ${klass.latest?.name ?? ""}`.replace(/^ — | — $/, "")} | ||
| 272 | + description={t("instances.selectSectionHelp")} | ||
| 273 | + class="border-border-line" | ||
| 274 | + /> | ||
| 275 | + <div class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"> | ||
| 276 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | ||
| 277 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | ||
| 278 | + <IconCalendarDays class="h-4 w-4" /> | ||
| 279 | + </span> | ||
| 280 | + <div class="min-w-0"> | ||
| 281 | + <p class="text-xs font-medium text-text-subtle">{t("instances.dersSaati")}</p> | ||
| 282 | + <Show | ||
| 283 | + when={canManage()} | ||
| 284 | + fallback={<p class="mono truncate text-sm font-semibold text-text-default">{inst().ders_saati}</p>} | ||
| 285 | + > | ||
| 286 | + <Input | ||
| 287 | + aria-label={t("instances.dersSaati")} | ||
| 288 | + class="h-7 w-20 px-2 py-0 text-sm" | ||
| 289 | + type="number" | ||
| 290 | + min={0} | ||
| 291 | + value={dersSaati()} | ||
| 292 | + disabled={savingPolicy()} | ||
| 293 | + onInput={(e) => setDersSaati(e.currentTarget.value)} | ||
| 294 | + onBlur={() => void saveDersSaati()} | ||
| 295 | + /> | ||
| 296 | + </Show> | ||
| 297 | + </div> | ||
| 298 | + </div> | ||
| 299 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | ||
| 300 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | ||
| 301 | + <IconSchool class="h-4 w-4" /> | ||
| 302 | + </span> | ||
| 303 | + <div class="min-w-0"> | ||
| 304 | + <p class="text-xs font-medium text-text-subtle">{t("instances.countsTowardKarne")}</p> | ||
| 305 | + <Show | ||
| 306 | + when={canManage()} | ||
| 307 | + fallback={ | ||
| 308 | + <p class="truncate text-sm font-semibold text-text-default"> | ||
| 309 | + {inst().counts_toward_karne ? t("common.yes") : t("common.no")} | ||
| 310 | + </p> | ||
| 311 | + } | ||
| 312 | + > | ||
| 313 | + <label class="inline-flex cursor-pointer items-center gap-2 text-xs"> | ||
| 314 | + <span class="relative shrink-0"> | ||
| 315 | + <input | ||
| 316 | + type="checkbox" | ||
| 317 | + class="peer sr-only" | ||
| 318 | + checked={countsTowardKarne()} | ||
| 319 | + disabled={savingPolicy()} | ||
| 320 | + aria-label={t("instances.countsTowardKarne")} | ||
| 321 | + onChange={(event) => void toggleKarne(event.currentTarget.checked)} | ||
| 322 | + /> | ||
| 323 | + <span class="block h-6 w-10 rounded-full bg-input ring-1 ring-inset ring-black/5 transition-colors peer-checked:bg-primary peer-disabled:opacity-60 peer-focus-visible:ring-2 peer-focus-visible:ring-ring dark:ring-white/10" /> | ||
| 324 | + <span class="pointer-events-none absolute left-1 top-1 h-4 w-4 rounded-full bg-white shadow-sm transition-transform peer-checked:translate-x-4" /> | ||
| 325 | + </span> | ||
| 326 | + </label> | ||
| 327 | + </Show> | ||
| 328 | + </div> | ||
| 329 | + </div> | ||
| 330 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | ||
| 331 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | ||
| 332 | + <IconUsers class="h-4 w-4" /> | ||
| 333 | + </span> | ||
| 334 | + <div class="min-w-0"> | ||
| 335 | + <p class="text-xs font-medium text-text-subtle">{t("courses.roster")}</p> | ||
| 336 | + <p class="mono truncate text-sm font-semibold text-text-default">{inst().enrollment_count}</p> | ||
| 337 | + </div> | ||
| 338 | + </div> | ||
| 339 | + <div class="flex min-w-0 items-center gap-3 rounded-xl border border-border-line bg-surface-base p-3"> | ||
| 340 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-surface-tint text-text-subtle"> | ||
| 341 | + <IconExam class="h-4 w-4" /> | ||
| 342 | + </span> | ||
| 343 | + <div class="min-w-0"> | ||
| 344 | + <p class="text-xs font-medium text-text-subtle">{t("courses.exams")}</p> | ||
| 345 | + <p class="mono truncate text-sm font-semibold text-text-default">{examCount()}</p> | ||
| 346 | + </div> | ||
| 347 | + </div> | ||
| 348 | + </div> | ||
| 349 | + </div> | ||
| 350 | + | ||
| 351 | + <ConfirmDialog | ||
| 352 | + open={removeTarget() !== null} | ||
| 353 | + onOpenChange={() => setRemoveTarget(null)} | ||
| 354 | + title={t("course.removeStudent")} | ||
| 355 | + variant="destructive" | ||
| 356 | + summary={`${t("course.removeStudentConfirm")} "${removeTarget()?.userName}"?`} | ||
| 357 | + onConfirm={async () => { | ||
| 358 | + const target = removeTarget(); | ||
| 359 | + if (!target) return; | ||
| 360 | + try { | ||
| 361 | + await deleteInstanceEnrollmentByUserId(id(), target.userId); | ||
| 362 | + await refetchRoster(); | ||
| 363 | + setFlash(t("common.deleted")); | ||
| 364 | + } catch (err) { | ||
| 365 | + setError(formatApiError(err)); | ||
| 366 | + } finally { | ||
| 367 | + setRemoveTarget(null); | ||
| 368 | + } | ||
| 369 | + }} | ||
| 370 | + /> | ||
| 371 | + | ||
| 372 | + <SidePanel | ||
| 373 | + open={showExamForm()} | ||
| 374 | + onOpenChange={(open) => { | ||
| 375 | + setShowExamForm(open); | ||
| 376 | + if (!open) { | ||
| 377 | + setCreatedExam(null); | ||
| 378 | + setExamCreateStep("details"); | ||
| 379 | + } | ||
| 380 | + }} | ||
| 381 | + title={createdExam() ? createdExam()!.title : t("courses.addExam")} | ||
| 382 | + description={createdExam() ? t("exams.step2Questions") : course.latest?.title} | ||
| 383 | + size={examCreateStep() === "questions" ? "wide" : "default"} | ||
| 384 | + > | ||
| 385 | + <div class="mb-4 flex rounded-xl border border-border-line bg-surface-tint p-1"> | ||
| 386 | + <button | ||
| 387 | + type="button" | ||
| 388 | + class={cn( | ||
| 389 | + "rounded-lg px-3 py-2 text-xs font-semibold transition-colors", | ||
| 390 | + examCreateStep() === "details" | ||
| 391 | + ? "bg-primary text-primary-foreground shadow-2xs" | ||
| 392 | + : "text-text-subtle hover:bg-surface-fill", | ||
| 393 | + )} | ||
| 394 | + onClick={() => setExamCreateStep("details")} | ||
| 395 | + > | ||
| 396 | + {t("exams.step1Details")} | ||
| 397 | + </button> | ||
| 398 | + <button | ||
| 399 | + type="button" | ||
| 400 | + disabled={!createdExam()} | ||
| 401 | + class={cn( | ||
| 402 | + "rounded-lg px-3 py-2 text-xs font-semibold transition-colors", | ||
| 403 | + examCreateStep() === "questions" | ||
| 404 | + ? "bg-primary text-primary-foreground shadow-2xs" | ||
| 405 | + : createdExam() | ||
| 406 | + ? "text-text-subtle hover:bg-surface-fill" | ||
| 407 | + : "opacity-40 cursor-not-allowed text-text-subtle", | ||
| 408 | + )} | ||
| 409 | + onClick={() => createdExam() && setExamCreateStep("questions")} | ||
| 410 | + > | ||
| 411 | + {t("exams.step2Questions")} | ||
| 412 | + </button> | ||
| 413 | + </div> | ||
| 414 | + | ||
| 415 | + <Show when={examCreateStep() === "details"}> | ||
| 416 | + <ExamForm | ||
| 417 | + initial={createdExam() ?? undefined} | ||
| 418 | + submitLabel={createdExam() ? t("common.update") : t("exams.nextQuestions")} | ||
| 419 | + onCancel={() => setShowExamForm(false)} | ||
| 420 | + onSubmit={async (values: ExamFormValues) => { | ||
| 421 | + const existing = createdExam(); | ||
| 422 | + if (existing) { | ||
| 423 | + // `term` is create-only: the backend cannot move a filed exam. | ||
| 424 | + const { term: _term, ...patch } = values; | ||
| 425 | + const updated = await patchExamById(existing.id, patch); | ||
| 426 | + setCreatedExam(updated); | ||
| 427 | + await refetchExams(); | ||
| 428 | + setExamCreateStep("questions"); | ||
| 429 | + setFlash(t("common.saved")); | ||
| 430 | + } else { | ||
| 431 | + const newExam = await postInstanceExam(id(), { | ||
| 432 | + ...values, | ||
| 433 | + description: values.description.trim() || undefined, | ||
| 434 | + }); | ||
| 435 | + setCreatedExam(newExam); | ||
| 436 | + await refetchExams(); | ||
| 437 | + setExamCreateStep("questions"); | ||
| 438 | + setFlash(t("common.created")); | ||
| 439 | + } | ||
| 440 | + }} | ||
| 441 | + /> | ||
| 442 | + </Show> | ||
| 443 | + | ||
| 444 | + <Show when={examCreateStep() === "questions" && createdExam()}> | ||
| 445 | + <div class="space-y-4"> | ||
| 446 | + <ExamQuestionsPanel examId={createdExam()!.id} courseId={inst().course} embedded /> | ||
| 447 | + <div class="flex justify-end border-t pt-3"> | ||
| 448 | + <Button type="button" variant="default" onClick={() => setShowExamForm(false)}> | ||
| 449 | + {t("exams.finishAndClose")} | ||
| 450 | + </Button> | ||
| 451 | + </div> | ||
| 452 | + </div> | ||
| 453 | + </Show> | ||
| 454 | + </SidePanel> | ||
| 455 | + | ||
| 456 | + <SidePanel open={showEnrollPanel()} onOpenChange={setShowEnrollPanel} title={t("courses.enroll")} description={course.latest?.title}> | ||
| 457 | + <form | ||
| 458 | + class="space-y-3" | ||
| 459 | + onSubmit={(e) => { | ||
| 460 | + e.preventDefault(); | ||
| 461 | + void (async () => { | ||
| 462 | + setError(""); | ||
| 463 | + setPending(true); | ||
| 464 | + try { | ||
| 465 | + const uid = enrollUserId().trim(); | ||
| 466 | + if (!uid) throw new Error(t("events.userId")); | ||
| 467 | + await postInstanceEnrollment(id(), uid); | ||
| 468 | + setEnrollUserId(""); | ||
| 469 | + setShowEnrollPanel(false); | ||
| 470 | + await refetchRoster(); | ||
| 471 | + setFlash(t("common.saved")); | ||
| 472 | + } catch (err) { | ||
| 473 | + setError(formatApiError(err)); | ||
| 474 | + } finally { | ||
| 475 | + setPending(false); | ||
| 476 | + } | ||
| 477 | + })(); | ||
| 478 | + }} | ||
| 479 | + > | ||
| 480 | + <UserSearchSelect | ||
| 481 | + id="instance-enroll-user" | ||
| 482 | + value={enrollUserId()} | ||
| 483 | + excludeIds={enrolledUserIds()} | ||
| 484 | + placeholder={t("form.selectStudent")} | ||
| 485 | + onChange={setEnrollUserId} | ||
| 486 | + role="student" | ||
| 487 | + /> | ||
| 488 | + <div class="flex flex-wrap gap-2"> | ||
| 489 | + <Button type="submit" class="rounded-xl" disabled={pending()}> | ||
| 490 | + {t("courses.enroll")} | ||
| 491 | + </Button> | ||
| 492 | + <Button type="button" variant="outline" class="rounded-xl" onClick={() => setShowEnrollPanel(false)}> | ||
| 493 | + {t("common.cancel")} | ||
| 494 | + </Button> | ||
| 495 | + </div> | ||
| 496 | + </form> | ||
| 497 | + </SidePanel> | ||
| 498 | + | ||
| 499 | + <Show when={flash()}> | ||
| 500 | + <Alert variant="success">{flash()}</Alert> | ||
| 501 | + </Show> | ||
| 502 | + <Show when={error()}> | ||
| 503 | + <p class="rounded-xl bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p> | ||
| 504 | + </Show> | ||
| 505 | + | ||
| 506 | + <Tabs value={tab()} onChange={setTab} class="space-y-4"> | ||
| 507 | + <TabsList class="flex w-full justify-start overflow-x-auto sm:grid sm:grid-cols-3 xl:grid-cols-5" aria-label={course.latest?.title ?? ""}> | ||
| 508 | + <TabsTrigger value="exams" class="min-w-0"><IconExam class="h-4 w-4" />{t("courses.exams")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{examCount()}</Badge></TabsTrigger> | ||
| 509 | + <TabsTrigger value="homework" class="min-w-0"><IconHomework class="h-4 w-4" />{t("homework.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{homeworkCount()}</Badge></TabsTrigger> | ||
| 510 | + <TabsTrigger value="sessions" class="min-w-0"><IconCalendarDays class="h-4 w-4" />{t("sessions.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{sessionCount()}</Badge></TabsTrigger> | ||
| 511 | + <TabsTrigger value="teachers" class="min-w-0"><IconSchool class="h-4 w-4" />{t("courses.teachers")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{inst().teachers.length}</Badge></TabsTrigger> | ||
| 512 | + <Show when={canManage()}> | ||
| 513 | + <TabsTrigger value="students" class="min-w-0"><IconUsers class="h-4 w-4" />{t("courses.roster")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[10px] group-data-selected:bg-background group-data-selected:text-foreground">{rosterCount()}</Badge></TabsTrigger> | ||
| 514 | + </Show> | ||
| 515 | + </TabsList> | ||
| 516 | + | ||
| 517 | + <TabsContent value="exams" class="space-y-3"> | ||
| 518 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 519 | + <Badge variant="secondary" class="rounded-full">{countDescription(examCount(), t("courses.examItem"))}</Badge> | ||
| 520 | + <Show when={canManage()}> | ||
| 521 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowExamForm(true)}> | ||
| 522 | + <IconPlus class="h-4 w-4" />{t("courses.addExam")} | ||
| 523 | + </Button> | ||
| 524 | + </Show> | ||
| 525 | + </div> | ||
| 526 | + <Suspense fallback={<DataTableSkeleton />}> | ||
| 527 | + <DataTable | ||
| 528 | + columns={examColumns()} | ||
| 529 | + data={exams() ?? []} | ||
| 530 | + filterColumn="title" | ||
| 531 | + enablePagination | ||
| 532 | + pageSize={10} | ||
| 533 | + empty={t("exams.empty")} | ||
| 534 | + onRowClick={(exam) => void navigate({ to: "/exams/$id", params: { id: exam.id } })} | ||
| 535 | + /> | ||
| 536 | + </Suspense> | ||
| 537 | + </TabsContent> | ||
| 538 | + | ||
| 539 | + <TabsContent value="homework" class="space-y-3"> | ||
| 540 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 541 | + <Badge variant="secondary" class="rounded-full">{countDescription(homeworkCount(), t("homework.item"))}</Badge> | ||
| 542 | + <Show when={canManage()}> | ||
| 543 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowHomeworkForm(true)}> | ||
| 544 | + <IconPlus class="h-4 w-4" />{t("homework.add")} | ||
| 545 | + </Button> | ||
| 546 | + </Show> | ||
| 547 | + </div> | ||
| 548 | + <CourseHomeworkPanel | ||
| 549 | + instanceId={id()} | ||
| 550 | + courseId={inst().course} | ||
| 551 | + canManage={canManage()} | ||
| 552 | + active={tab() === "homework"} | ||
| 553 | + createOpen={showHomeworkForm()} | ||
| 554 | + onCreateOpenChange={setShowHomeworkForm} | ||
| 555 | + onCountChange={setHomeworkCount} | ||
| 556 | + /> | ||
| 557 | + </TabsContent> | ||
| 558 | + | ||
| 559 | + <TabsContent value="sessions" class="space-y-3"> | ||
| 560 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 561 | + <Badge variant="secondary" class="rounded-full">{countDescription(sessionCount(), t("sessions.item"))}</Badge> | ||
| 562 | + <Show when={canManage()}> | ||
| 563 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowSessionForm(true)}> | ||
| 564 | + <IconPlus class="h-4 w-4" />{t("sessions.add")} | ||
| 565 | + </Button> | ||
| 566 | + </Show> | ||
| 567 | + </div> | ||
| 568 | + <CourseSessionsPanel | ||
| 569 | + instanceId={id()} | ||
| 570 | + roster={roster() ?? []} | ||
| 571 | + canManage={canManage()} | ||
| 572 | + active={tab() === "sessions"} | ||
| 573 | + createOpen={showSessionForm()} | ||
| 574 | + onCreateOpenChange={setShowSessionForm} | ||
| 575 | + onCountChange={setSessionCount} | ||
| 576 | + /> | ||
| 577 | + </TabsContent> | ||
| 578 | + | ||
| 579 | + <TabsContent value="teachers" class="space-y-3"> | ||
| 580 | + <div class="flex flex-wrap items-center gap-2 text-sm"> | ||
| 581 | + <Badge variant="secondary" class="rounded-full">{countDescription(inst().teachers.length, t("courses.teachers"))}</Badge> | ||
| 582 | + <Show when={canStaff()}> | ||
| 583 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowTeacherForm(true)}> | ||
| 584 | + <IconPlus class="h-4 w-4" />{t("courses.assignTeacher")} | ||
| 585 | + </Button> | ||
| 586 | + </Show> | ||
| 587 | + </div> | ||
| 588 | + <CourseTeachersPanel | ||
| 589 | + instanceId={id()} | ||
| 590 | + teachers={inst().teachers} | ||
| 591 | + canStaff={canStaff()} | ||
| 592 | + assignOpen={showTeacherForm()} | ||
| 593 | + onAssignOpenChange={setShowTeacherForm} | ||
| 594 | + onInstanceUpdated={refetchInstance} | ||
| 595 | + /> | ||
| 596 | + </TabsContent> | ||
| 597 | + | ||
| 598 | + <Show when={canManage()}> | ||
| 599 | + <TabsContent value="students" class="space-y-3"> | ||
| 600 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 601 | + <Badge variant="secondary" class="rounded-full">{countDescription(rosterCount(), t("courses.rosterItem"))}</Badge> | ||
| 602 | + <Button type="button" variant="outline" size="sm" class="ml-auto rounded-lg" onClick={() => setShowEnrollPanel(true)}> | ||
| 603 | + <IconPlus class="h-4 w-4" />{t("courses.enroll")} | ||
| 604 | + </Button> | ||
| 605 | + </div> | ||
| 606 | + <Suspense fallback={<DataTableSkeleton />}> | ||
| 607 | + <Show when={(roster() ?? []).length > 0} fallback={<EmptyState kind="people" title={t("exams.emptyRoster")} />}> | ||
| 608 | + <DataTable columns={rosterColumns()} data={roster() ?? []} filterColumn="username" enablePagination pageSize={10} /> | ||
| 609 | + </Show> | ||
| 610 | + </Suspense> | ||
| 611 | + </TabsContent> | ||
| 612 | + </Show> | ||
| 613 | + </Tabs> | ||
| 614 | + </div> | ||
| 615 | + )} | ||
| 616 | + </Show> | ||
| 617 | + </Suspense> | ||
| 618 | + ); | ||
| 619 | +} | ||
src/pages/marks-page.tsxmodified+42 -5
| @@ -1,19 +1,23 @@ | |||
| 1 | import { Show, Suspense, createEffect, createSignal } from "solid-js"; | 1 | import { Show, Suspense, createEffect, createSignal } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { useNavigate, useSearch } from "@tanstack/solid-router"; | 3 | import { useNavigate, useSearch } from "@tanstack/solid-router"; |
| 4 | -import { getMyAttendance, getMyMarks } from "@/api/reports"; | 4 | +import { getMyAttendance, getMyKarne, getMyMarks } from "@/api/reports"; |
| 5 | +import { getTerms } from "@/api/terms"; | ||
| 5 | import { formatApiError } from "@/api/client"; | 6 | import { formatApiError } from "@/api/client"; |
| 6 | import { Alert } from "@/components/ui/alert"; | 7 | import { Alert } from "@/components/ui/alert"; |
| 7 | import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; | 8 | import { AttendanceReportView } from "@/components/attendance/attendance-report-view"; |
| 9 | +import { KarneView } from "@/components/marks/karne-view"; | ||
| 8 | import { MarksReportView } from "@/components/marks/marks-report-view"; | 10 | import { MarksReportView } from "@/components/marks/marks-report-view"; |
| 9 | import { RouteGuard } from "@/components/layout/route-guard"; | 11 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 10 | import { PageHeader } from "@/components/layout/page-header"; | 12 | import { PageHeader } from "@/components/layout/page-header"; |
| 11 | import { EmptyState } from "@/components/ui/empty-state"; | 13 | import { EmptyState } from "@/components/ui/empty-state"; |
| 12 | -import { IconChart, IconClipboardCheck } from "@/components/ui/icons"; | 14 | +import { IconChart, IconClipboardCheck, IconSchool } from "@/components/ui/icons"; |
| 13 | import { PageSpinner } from "@/components/ui/page-spinner"; | 15 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 14 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | 16 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 15 | import { useT } from "@/stores/preferences-context"; | 17 | import { useT } from "@/stores/preferences-context"; |
| 16 | 18 | ||
| 19 | +type MarksTab = "marks" | "karne" | "attendance"; | ||
| 20 | + | ||
| 17 | export default function MarksPage() { | 21 | export default function MarksPage() { |
| 18 | return ( | 22 | return ( |
| 19 | <RouteGuard exactRole="student"> | 23 | <RouteGuard exactRole="student"> |
| @@ -26,10 +30,23 @@ function MarksContent() { | |||
| 26 | const t = useT(); | 30 | const t = useT(); |
| 27 | const navigate = useNavigate(); | 31 | const navigate = useNavigate(); |
| 28 | const routeSearch = useSearch({ from: "/marks" }); | 32 | const routeSearch = useSearch({ from: "/marks" }); |
| 29 | - const [tab, setTab] = createSignal<"marks" | "attendance">(routeSearch().tab); | 33 | + const [tab, setTab] = createSignal<MarksTab>(routeSearch().tab); |
| 30 | createEffect(() => setTab(routeSearch().tab)); | 34 | createEffect(() => setTab(routeSearch().tab)); |
| 31 | const [marks] = createResource(() => tab() === "marks" || null, () => getMyMarks()); | 35 | const [marks] = createResource(() => tab() === "marks" || null, () => getMyMarks()); |
| 32 | const [attendance] = createResource(() => tab() === "attendance" || null, () => getMyAttendance()); | 36 | const [attendance] = createResource(() => tab() === "attendance" || null, () => getMyAttendance()); |
| 37 | + const [terms] = createResource(() => tab() === "karne" || null, async () => (await getTerms({ limit: 100 })).items); | ||
| 38 | + // "" = let the backend pick the newest dönem; the picker fills in once the | ||
| 39 | + // term list lands, so the first read is not blocked on it. | ||
| 40 | + const [karneTerm, setKarneTerm] = createSignal(""); | ||
| 41 | + createEffect(() => { | ||
| 42 | + const list = terms(); | ||
| 43 | + if (!list || list.length === 0 || karneTerm()) return; | ||
| 44 | + setKarneTerm(list[0].id); | ||
| 45 | + }); | ||
| 46 | + const [karne] = createResource( | ||
| 47 | + () => (tab() === "karne" ? karneTerm() : null), | ||
| 48 | + (term) => getMyKarne(term || undefined), | ||
| 49 | + ); | ||
| 33 | 50 | ||
| 34 | return ( | 51 | return ( |
| 35 | <div class="space-y-5"> | 52 | <div class="space-y-5"> |
| @@ -42,16 +59,20 @@ function MarksContent() { | |||
| 42 | class="space-y-4" | 59 | class="space-y-4" |
| 43 | value={tab()} | 60 | value={tab()} |
| 44 | onChange={(value) => { | 61 | onChange={(value) => { |
| 45 | - const next = value === "attendance" ? "attendance" : "marks"; | 62 | + const next: MarksTab = value === "attendance" ? "attendance" : value === "karne" ? "karne" : "marks"; |
| 46 | setTab(next); | 63 | setTab(next); |
| 47 | void navigate({ to: "/marks", search: { tab: next } }); | 64 | void navigate({ to: "/marks", search: { tab: next } }); |
| 48 | }} | 65 | }} |
| 49 | > | 66 | > |
| 50 | - <TabsList class="grid w-full grid-cols-2 sm:w-fit"> | 67 | + <TabsList class="grid w-full grid-cols-3 sm:w-fit"> |
| 51 | <TabsTrigger value="marks" class="min-w-0"> | 68 | <TabsTrigger value="marks" class="min-w-0"> |
| 52 | <IconChart class="h-4 w-4" /> | 69 | <IconChart class="h-4 w-4" /> |
| 53 | {t("nav.group.grades")} | 70 | {t("nav.group.grades")} |
| 54 | </TabsTrigger> | 71 | </TabsTrigger> |
| 72 | + <TabsTrigger value="karne" class="min-w-0"> | ||
| 73 | + <IconSchool class="h-4 w-4" /> | ||
| 74 | + {t("karne.title")} | ||
| 75 | + </TabsTrigger> | ||
| 55 | <TabsTrigger value="attendance" class="min-w-0"> | 76 | <TabsTrigger value="attendance" class="min-w-0"> |
| 56 | <IconClipboardCheck class="h-4 w-4" /> | 77 | <IconClipboardCheck class="h-4 w-4" /> |
| 57 | {t("nav.attendance")} | 78 | {t("nav.attendance")} |
| @@ -66,6 +87,22 @@ function MarksContent() { | |||
| 66 | </Show> | 87 | </Show> |
| 67 | </Suspense> | 88 | </Suspense> |
| 68 | </TabsContent> | 89 | </TabsContent> |
| 90 | + <TabsContent value="karne" class="mt-0 border-0 bg-transparent p-0 shadow-none"> | ||
| 91 | + <Suspense fallback={<PageSpinner />}> | ||
| 92 | + <Show when={!karne.error} fallback={<Alert variant="destructive">{formatApiError(karne.error)}</Alert>}> | ||
| 93 | + <Show when={karne()} fallback={<EmptyState kind="exams" title={t("karne.empty")} />}> | ||
| 94 | + {(report) => ( | ||
| 95 | + <KarneView | ||
| 96 | + report={report()} | ||
| 97 | + terms={terms() ?? []} | ||
| 98 | + selectedTerm={karneTerm()} | ||
| 99 | + onTermChange={setKarneTerm} | ||
| 100 | + /> | ||
| 101 | + )} | ||
| 102 | + </Show> | ||
| 103 | + </Show> | ||
| 104 | + </Suspense> | ||
| 105 | + </TabsContent> | ||
| 69 | <TabsContent value="attendance" class="mt-0 border-0 bg-transparent p-0 shadow-none"> | 106 | <TabsContent value="attendance" class="mt-0 border-0 bg-transparent p-0 shadow-none"> |
| 70 | <Suspense fallback={<PageSpinner />}> | 107 | <Suspense fallback={<PageSpinner />}> |
| 71 | <Show when={!attendance.error} fallback={<Alert variant="destructive">{formatApiError(attendance.error)}</Alert>}> | 108 | <Show when={!attendance.error} fallback={<Alert variant="destructive">{formatApiError(attendance.error)}</Alert>}> |
src/pages/question-bank-page.tsxmodified+0 -1
| @@ -96,7 +96,6 @@ function QuestionBankContent() { | |||
| 96 | if (!user) return false; | 96 | if (!user) return false; |
| 97 | return ( | 97 | return ( |
| 98 | course.creator.id === user.id || | 98 | course.creator.id === user.id || |
| 99 | - (course.teachers ?? []).some((teacher) => teacher.id === user.id) || | ||
| 100 | hasMinRole(user.role, "manager") | 99 | hasMinRole(user.role, "manager") |
| 101 | ); | 100 | ); |
| 102 | }), | 101 | }), |
src/pages/settings-page.tsxmodified+61 -0
| @@ -67,6 +67,12 @@ function SettingsContent() { | |||
| 67 | const [mealSlots, setMealSlots] = createSignal<MealSlot[]>([]); | 67 | const [mealSlots, setMealSlots] = createSignal<MealSlot[]>([]); |
| 68 | const [dietaryTags, setDietaryTags] = createSignal<string[]>([]); | 68 | const [dietaryTags, setDietaryTags] = createSignal<string[]>([]); |
| 69 | const [mealCutoff, setMealCutoff] = createSignal(""); | 69 | const [mealCutoff, setMealCutoff] = createSignal(""); |
| 70 | + // Devamsızlık policy and the branş vocabulary, both school-varying. | ||
| 71 | + const [excuseKinds, setExcuseKinds] = createSignal<string[]>([]); | ||
| 72 | + const [branches, setBranches] = createSignal<string[]>([]); | ||
| 73 | + const [maxExcusedDays, setMaxExcusedDays] = createSignal(""); | ||
| 74 | + const [maxUnexcusedDays, setMaxUnexcusedDays] = createSignal(""); | ||
| 75 | + const [timezone, setTimezone] = createSignal(""); | ||
| 70 | const [error, setError] = createSignal(""); | 76 | const [error, setError] = createSignal(""); |
| 71 | const [saved, setSaved] = createSignal(false); | 77 | const [saved, setSaved] = createSignal(false); |
| 72 | const [pending, setPending] = createSignal(false); | 78 | const [pending, setPending] = createSignal(false); |
| @@ -86,6 +92,11 @@ function SettingsContent() { | |||
| 86 | meal_slots: mealSlots(), | 92 | meal_slots: mealSlots(), |
| 87 | dietary_tags: dietaryTags(), | 93 | dietary_tags: dietaryTags(), |
| 88 | meal_cancel_cutoff_minutes: mealCutoff() === "" ? null : Number(mealCutoff()), | 94 | meal_cancel_cutoff_minutes: mealCutoff() === "" ? null : Number(mealCutoff()), |
| 95 | + excuse_kinds: excuseKinds(), | ||
| 96 | + branches: branches(), | ||
| 97 | + max_excused_absent_days: maxExcusedDays() === "" ? null : Number(maxExcusedDays()), | ||
| 98 | + max_unexcused_absent_days: maxUnexcusedDays() === "" ? null : Number(maxUnexcusedDays()), | ||
| 99 | + timezone: timezone().trim() === "" ? null : timezone().trim(), | ||
| 89 | }); | 100 | }); |
| 90 | 101 | ||
| 91 | createEffect(() => { | 102 | createEffect(() => { |
| @@ -102,6 +113,11 @@ function SettingsContent() { | |||
| 102 | setMealSlots(next.meal_slots.map((slot) => ({ ...slot }))); | 113 | setMealSlots(next.meal_slots.map((slot) => ({ ...slot }))); |
| 103 | setDietaryTags([...next.dietary_tags]); | 114 | setDietaryTags([...next.dietary_tags]); |
| 104 | setMealCutoff(next.meal_cancel_cutoff_minutes == null ? "" : String(next.meal_cancel_cutoff_minutes)); | 115 | setMealCutoff(next.meal_cancel_cutoff_minutes == null ? "" : String(next.meal_cancel_cutoff_minutes)); |
| 116 | + setExcuseKinds([...(next.excuse_kinds ?? [])]); | ||
| 117 | + setBranches([...(next.branches ?? [])]); | ||
| 118 | + setMaxExcusedDays(next.max_excused_absent_days == null ? "" : String(next.max_excused_absent_days)); | ||
| 119 | + setMaxUnexcusedDays(next.max_unexcused_absent_days == null ? "" : String(next.max_unexcused_absent_days)); | ||
| 120 | + setTimezone(next.timezone ?? ""); | ||
| 105 | setBaseline({ ...next, max_file_bytes: fileBytes }); | 121 | setBaseline({ ...next, max_file_bytes: fileBytes }); |
| 106 | }); | 122 | }); |
| 107 | 123 | ||
| @@ -143,6 +159,8 @@ function SettingsContent() { | |||
| 143 | max_file_bytes: maxFileBytes, | 159 | max_file_bytes: maxFileBytes, |
| 144 | meal_slots: mealSlots().map((slot) => ({ ...slot, name: slot.name.trim() })), | 160 | meal_slots: mealSlots().map((slot) => ({ ...slot, name: slot.name.trim() })), |
| 145 | dietary_tags: dietaryTags().map((tag) => tag.trim()), | 161 | dietary_tags: dietaryTags().map((tag) => tag.trim()), |
| 162 | + excuse_kinds: excuseKinds().map((kind) => kind.trim()).filter(Boolean), | ||
| 163 | + branches: branches().map((branch) => branch.trim()).filter(Boolean), | ||
| 146 | }; | 164 | }; |
| 147 | const next = await patchSettings(dirtySettingsPatch(before, current)); | 165 | const next = await patchSettings(dirtySettingsPatch(before, current)); |
| 148 | mutate(next); | 166 | mutate(next); |
| @@ -586,6 +604,49 @@ function SettingsContent() { | |||
| 586 | </div> | 604 | </div> |
| 587 | </section> | 605 | </section> |
| 588 | 606 | ||
| 607 | + <section class="data-shell space-y-4 p-4"> | ||
| 608 | + <div> | ||
| 609 | + <h2 class="text-base font-semibold">{t("attendance.devamsizlik")}</h2> | ||
| 610 | + <p class="mt-1 text-sm text-muted-foreground">{t("settings.attendanceHelp")}</p> | ||
| 611 | + </div> | ||
| 612 | + <div class="grid gap-3 sm:grid-cols-3"> | ||
| 613 | + <div class="space-y-1.5"> | ||
| 614 | + <Label for="max-excused-days">{t("settings.maxExcusedDays")}</Label> | ||
| 615 | + <Input id="max-excused-days" type="number" min={0} value={maxExcusedDays()} onInput={(e) => setMaxExcusedDays(e.currentTarget.value)} /> | ||
| 616 | + </div> | ||
| 617 | + <div class="space-y-1.5"> | ||
| 618 | + <Label for="max-unexcused-days">{t("settings.maxUnexcusedDays")}</Label> | ||
| 619 | + <Input id="max-unexcused-days" type="number" min={0} value={maxUnexcusedDays()} onInput={(e) => setMaxUnexcusedDays(e.currentTarget.value)} /> | ||
| 620 | + </div> | ||
| 621 | + <div class="space-y-1.5"> | ||
| 622 | + <Label for="school-timezone">{t("settings.timezone")}</Label> | ||
| 623 | + <Input id="school-timezone" value={timezone()} placeholder="Europe/Istanbul" onInput={(e) => setTimezone(e.currentTarget.value)} /> | ||
| 624 | + </div> | ||
| 625 | + </div> | ||
| 626 | + <div class="grid gap-3 sm:grid-cols-2"> | ||
| 627 | + {/* Both are short comma-separated vocabularies; a full row | ||
| 628 | + editor would be more chrome than the two lists deserve. */} | ||
| 629 | + <div class="space-y-1.5"> | ||
| 630 | + <Label for="excuse-kinds">{t("settings.excuseKinds")}</Label> | ||
| 631 | + <Input | ||
| 632 | + id="excuse-kinds" | ||
| 633 | + value={excuseKinds().join(", ")} | ||
| 634 | + placeholder="raporlu, izinli" | ||
| 635 | + onInput={(e) => setExcuseKinds(e.currentTarget.value.split(",").map((part) => part.trim()).filter(Boolean))} | ||
| 636 | + /> | ||
| 637 | + </div> | ||
| 638 | + <div class="space-y-1.5"> | ||
| 639 | + <Label for="branches">{t("settings.branches")}</Label> | ||
| 640 | + <Input | ||
| 641 | + id="branches" | ||
| 642 | + value={branches().join(", ")} | ||
| 643 | + placeholder="Matematik, Fizik" | ||
| 644 | + onInput={(e) => setBranches(e.currentTarget.value.split(",").map((part) => part.trim()).filter(Boolean))} | ||
| 645 | + /> | ||
| 646 | + </div> | ||
| 647 | + </div> | ||
| 648 | + </section> | ||
| 649 | + | ||
| 589 | <section class="data-shell space-y-4 p-4"> | 650 | <section class="data-shell space-y-4 p-4"> |
| 590 | <div> | 651 | <div> |
| 591 | <h2 class="text-base font-semibold">{t("settings.aiPolicy")}</h2> | 652 | <h2 class="text-base font-semibold">{t("settings.aiPolicy")}</h2> |
src/pages/students-roster-page.tsxmodified+9 -9
| @@ -3,7 +3,7 @@ import type { ColumnDef } from "@tanstack/solid-table"; | |||
| 3 | import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; | 3 | import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; |
| 4 | import { createResource } from "@/lib/create-resource"; | 4 | import { createResource } from "@/lib/create-resource"; |
| 5 | import { getClassMembers, getClasses } from "@/api/classes"; | 5 | import { getClassMembers, getClasses } from "@/api/classes"; |
| 6 | -import { getTerms } from "@/api/terms"; | 6 | +import { getAcademicYears } from "@/api/academic-years"; |
| 7 | import { getUserSearch } from "@/api/users"; | 7 | import { getUserSearch } from "@/api/users"; |
| 8 | import { formatApiError, type ClassGroup, type PersonRef } from "@/api/client"; | 8 | import { formatApiError, type ClassGroup, type PersonRef } from "@/api/client"; |
| 9 | import { RouteGuard } from "@/components/layout/route-guard"; | 9 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -37,13 +37,13 @@ function StudentsRosterContent() { | |||
| 37 | const t = useT(); | 37 | const t = useT(); |
| 38 | const navigate = useNavigate(); | 38 | const navigate = useNavigate(); |
| 39 | const [classFilter, setClassFilter] = createSignal(""); | 39 | const [classFilter, setClassFilter] = createSignal(""); |
| 40 | - const [termFilter, setTermFilter] = createSignal(""); | 40 | + const [yearFilter, setYearFilter] = createSignal(""); |
| 41 | 41 | ||
| 42 | const [data, { refetch }] = createResource(async () => { | 42 | const [data, { refetch }] = createResource(async () => { |
| 43 | - const [students, classes, terms] = await Promise.all([ | 43 | + const [students, classes, years] = await Promise.all([ |
| 44 | getUserSearch("", undefined, "student"), | 44 | getUserSearch("", undefined, "student"), |
| 45 | getClasses(), | 45 | getClasses(), |
| 46 | - getTerms().catch(() => ({ items: [] })), | 46 | + getAcademicYears().catch(() => ({ items: [] })), |
| 47 | ]); | 47 | ]); |
| 48 | // No endpoint maps students to classes in bulk; one members read per class | 48 | // No endpoint maps students to classes in bulk; one members read per class |
| 49 | // is bounded by the class count, not the student count. | 49 | // is bounded by the class count, not the student count. |
| @@ -55,13 +55,13 @@ function StudentsRosterContent() { | |||
| 55 | for (const member of members) byStudent.set(member.user.id, [...(byStudent.get(member.user.id) ?? []), cls]); | 55 | for (const member of members) byStudent.set(member.user.id, [...(byStudent.get(member.user.id) ?? []), cls]); |
| 56 | } | 56 | } |
| 57 | const rows: StudentRow[] = students.items.map((person) => ({ person, classes: byStudent.get(person.id) ?? [] })); | 57 | const rows: StudentRow[] = students.items.map((person) => ({ person, classes: byStudent.get(person.id) ?? [] })); |
| 58 | - return { rows, classes: classes.items, terms: terms.items }; | 58 | + return { rows, classes: classes.items, years: years.items }; |
| 59 | }); | 59 | }); |
| 60 | 60 | ||
| 61 | const rows = createMemo(() => | 61 | const rows = createMemo(() => |
| 62 | (data()?.rows ?? []).filter((row) => { | 62 | (data()?.rows ?? []).filter((row) => { |
| 63 | if (classFilter() && !row.classes.some((cls) => cls.id === classFilter())) return false; | 63 | if (classFilter() && !row.classes.some((cls) => cls.id === classFilter())) return false; |
| 64 | - if (termFilter() && !row.classes.some((cls) => cls.term === termFilter())) return false; | 64 | + if (yearFilter() && !row.classes.some((cls) => cls.year === yearFilter())) return false; |
| 65 | return true; | 65 | return true; |
| 66 | }), | 66 | }), |
| 67 | ); | 67 | ); |
| @@ -151,9 +151,9 @@ function StudentsRosterContent() { | |||
| 151 | <option value="">{t("roster.classAll")}</option> | 151 | <option value="">{t("roster.classAll")}</option> |
| 152 | <For each={value().classes}>{(cls) => <option value={cls.id}>{cls.name}</option>}</For> | 152 | <For each={value().classes}>{(cls) => <option value={cls.id}>{cls.name}</option>}</For> |
| 153 | </Select> | 153 | </Select> |
| 154 | - <Select aria-label={t("roster.term")} value={termFilter()} onChange={(e) => setTermFilter(e.currentTarget.value)} wrapperClass="w-auto"> | 154 | + <Select aria-label={t("academicYears.year")} value={yearFilter()} onChange={(e) => setYearFilter(e.currentTarget.value)} wrapperClass="w-auto"> |
| 155 | - <option value="">{t("roster.termAll")}</option> | 155 | + <option value="">{t("common.all")}</option> |
| 156 | - <For each={value().terms}>{(term) => <option value={term.id}>{term.name}</option>}</For> | 156 | + <For each={value().years}>{(year) => <option value={year.id}>{year.name}</option>}</For> |
| 157 | </Select> | 157 | </Select> |
| 158 | </> | 158 | </> |
| 159 | } | 159 | } |
src/pages/terms-page.tsxmodified+30 -2
| @@ -1,8 +1,9 @@ | |||
| 1 | -import { Show, Suspense, createMemo, createSignal } from "solid-js"; | 1 | +import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import type { ColumnDef } from "@tanstack/solid-table"; | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | import { deleteTermById } from "@/api/terms"; | 4 | import { deleteTermById } from "@/api/terms"; |
| 5 | import { getTerms } from "@/api/terms"; | 5 | import { getTerms } from "@/api/terms"; |
| 6 | +import { getAcademicYears } from "@/api/academic-years"; | ||
| 6 | import { patchTermById } from "@/api/terms"; | 7 | import { patchTermById } from "@/api/terms"; |
| 7 | import { postTerm } from "@/api/terms"; | 8 | import { postTerm } from "@/api/terms"; |
| 8 | import { postTermArchive } from "@/api/terms"; | 9 | import { postTermArchive } from "@/api/terms"; |
| @@ -20,6 +21,7 @@ import { ErrorAlert } from "@/components/ui/error-alert"; | |||
| 20 | import { IconArchive, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; | 21 | import { IconArchive, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; |
| 21 | import { Input } from "@/components/ui/input"; | 22 | import { Input } from "@/components/ui/input"; |
| 22 | import { Label } from "@/components/ui/label"; | 23 | import { Label } from "@/components/ui/label"; |
| 24 | +import { Select } from "@/components/ui/select"; | ||
| 23 | import { SidePanel } from "@/components/ui/side-panel"; | 25 | import { SidePanel } from "@/components/ui/side-panel"; |
| 24 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 26 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 25 | import { createFlash } from "@/lib/flash"; | 27 | import { createFlash } from "@/lib/flash"; |
| @@ -58,9 +60,15 @@ function TermsContent() { | |||
| 58 | const t = useT(); | 60 | const t = useT(); |
| 59 | const { locale } = usePreferences(); | 61 | const { locale } = usePreferences(); |
| 60 | const [list, { refetch }] = createResource(async () => (await getTerms({ limit: 100 })).items); | 62 | const [list, { refetch }] = createResource(async () => (await getTerms({ limit: 100 })).items); |
| 63 | + // A dönem now sits inside an academic year, and an archived year refuses new | ||
| 64 | + // ones — so the create form cannot be filled without this list. | ||
| 65 | + const [years] = createResource(async () => (await getAcademicYears({ limit: 100 })).items); | ||
| 66 | + const openYears = createMemo(() => (years.latest ?? []).filter((year) => year.archived_at == null)); | ||
| 67 | + const yearName = (id: string) => years.latest?.find((year) => year.id === id)?.name ?? id; | ||
| 61 | const terms = () => list() ?? []; | 68 | const terms = () => list() ?? []; |
| 62 | const [panelOpen, setPanelOpen] = createSignal(false); | 69 | const [panelOpen, setPanelOpen] = createSignal(false); |
| 63 | const [name, setName] = createSignal(""); | 70 | const [name, setName] = createSignal(""); |
| 71 | + const [yearId, setYearId] = createSignal(""); | ||
| 64 | const [starts, setStarts] = createSignal(""); | 72 | const [starts, setStarts] = createSignal(""); |
| 65 | const [ends, setEnds] = createSignal(""); | 73 | const [ends, setEnds] = createSignal(""); |
| 66 | const [editing, setEditing] = createSignal<Term | null>(null); | 74 | const [editing, setEditing] = createSignal<Term | null>(null); |
| @@ -74,6 +82,12 @@ function TermsContent() { | |||
| 74 | header: t("settings.name"), | 82 | header: t("settings.name"), |
| 75 | cell: (cell) => <span class="font-medium">{cell.row.original.name}</span>, | 83 | cell: (cell) => <span class="font-medium">{cell.row.original.name}</span>, |
| 76 | }, | 84 | }, |
| 85 | + { | ||
| 86 | + id: "year", | ||
| 87 | + accessorFn: (row) => yearName(row.year), | ||
| 88 | + header: t("academicYears.year"), | ||
| 89 | + cell: (cell) => <span class="text-sm text-muted-foreground">{yearName(cell.row.original.year)}</span>, | ||
| 90 | + }, | ||
| 77 | { | 91 | { |
| 78 | accessorKey: "starts_at", | 92 | accessorKey: "starts_at", |
| 79 | header: t("events.starts"), | 93 | header: t("events.starts"), |
| @@ -131,6 +145,7 @@ function TermsContent() { | |||
| 131 | 145 | ||
| 132 | const resetForm = () => { | 146 | const resetForm = () => { |
| 133 | setName(""); | 147 | setName(""); |
| 148 | + setYearId(""); | ||
| 134 | setStarts(""); | 149 | setStarts(""); |
| 135 | setEnds(""); | 150 | setEnds(""); |
| 136 | setEditing(null); | 151 | setEditing(null); |
| @@ -178,6 +193,10 @@ function TermsContent() { | |||
| 178 | setError(t("form.timeOrder")); | 193 | setError(t("form.timeOrder")); |
| 179 | return; | 194 | return; |
| 180 | } | 195 | } |
| 196 | + if (!editing() && !yearId()) { | ||
| 197 | + setError(t("academicYears.year")); | ||
| 198 | + return; | ||
| 199 | + } | ||
| 181 | setPending(true); | 200 | setPending(true); |
| 182 | try { | 201 | try { |
| 183 | const current = editing(); | 202 | const current = editing(); |
| @@ -185,7 +204,7 @@ function TermsContent() { | |||
| 185 | await patchTermById(current.id, { name: name().trim(), starts_at, ends_at }); | 204 | await patchTermById(current.id, { name: name().trim(), starts_at, ends_at }); |
| 186 | setFlash(t("common.saved")); | 205 | setFlash(t("common.saved")); |
| 187 | } else { | 206 | } else { |
| 188 | - await postTerm({ name: name().trim(), starts_at, ends_at }); | 207 | + await postTerm({ name: name().trim(), year: yearId(), starts_at, ends_at }); |
| 189 | setFlash(t("common.created")); | 208 | setFlash(t("common.created")); |
| 190 | } | 209 | } |
| 191 | resetForm(); | 210 | resetForm(); |
| @@ -249,6 +268,15 @@ function TermsContent() { | |||
| 249 | <Label for="term-name">{t("settings.name")}</Label> | 268 | <Label for="term-name">{t("settings.name")}</Label> |
| 250 | <Input id="term-name" class="rounded-lg" required maxlength={100} value={name()} onInput={(e) => setName(e.currentTarget.value)} /> | 269 | <Input id="term-name" class="rounded-lg" required maxlength={100} value={name()} onInput={(e) => setName(e.currentTarget.value)} /> |
| 251 | </div> | 270 | </div> |
| 271 | + <Show when={!editing()}> | ||
| 272 | + <div class="space-y-1.5"> | ||
| 273 | + <Label for="term-year">{t("academicYears.year")}</Label> | ||
| 274 | + <Select id="term-year" class="rounded-lg" value={yearId()} onChange={(e) => setYearId(e.currentTarget.value)}> | ||
| 275 | + <option value="">{t("academicYears.unassigned")}</option> | ||
| 276 | + <For each={openYears()}>{(year) => <option value={year.id}>{year.name}</option>}</For> | ||
| 277 | + </Select> | ||
| 278 | + </div> | ||
| 279 | + </Show> | ||
| 252 | <div class="space-y-1.5"> | 280 | <div class="space-y-1.5"> |
| 253 | <Label for="term-starts">{t("events.starts")}</Label> | 281 | <Label for="term-starts">{t("events.starts")}</Label> |
| 254 | <DatePicker id="term-starts" placeholder={t("form.datePlaceholder")} required value={starts()} onChange={setStarts} /> | 282 | <DatePicker id="term-starts" placeholder={t("form.datePlaceholder")} required value={starts()} onChange={setStarts} /> |
src/routes/router.tsxmodified+23 -1
| @@ -40,6 +40,8 @@ const QuestionBankPage = lazyRoute(() => import("@/pages/question-bank-page")); | |||
| 40 | const BankQuestionDetailPage = lazyRoute(() => import("@/pages/bank-question-detail-page")); | 40 | const BankQuestionDetailPage = lazyRoute(() => import("@/pages/bank-question-detail-page")); |
| 41 | const CoursesPage = lazyRoute(() => import("@/pages/courses-page")); | 41 | const CoursesPage = lazyRoute(() => import("@/pages/courses-page")); |
| 42 | const CourseDetailPage = lazyRoute(() => import("@/pages/course-detail-page")); | 42 | const CourseDetailPage = lazyRoute(() => import("@/pages/course-detail-page")); |
| 43 | +const InstanceDetailPage = lazyRoute(() => import("@/pages/instance-detail-page")); | ||
| 44 | +const AcademicYearsPage = lazyRoute(() => import("@/pages/academic-years-page")); | ||
| 43 | const ClassesPage = lazyRoute(() => import("@/pages/classes-page")); | 45 | const ClassesPage = lazyRoute(() => import("@/pages/classes-page")); |
| 44 | const ClassDetailPage = lazyRoute(() => import("@/pages/class-detail-page")); | 46 | const ClassDetailPage = lazyRoute(() => import("@/pages/class-detail-page")); |
| 45 | const MarksPage = lazyRoute(() => import("@/pages/marks-page")); | 47 | const MarksPage = lazyRoute(() => import("@/pages/marks-page")); |
| @@ -217,11 +219,23 @@ const courseDetailRoute = createRoute({ | |||
| 217 | component: CourseDetailPage, | 219 | component: CourseDetailPage, |
| 218 | }); | 220 | }); |
| 219 | 221 | ||
| 222 | +// A şube×ders instance: where exams, homework, lessons and the roster live. | ||
| 223 | +const instanceDetailRoute = createRoute({ | ||
| 224 | + getParentRoute: () => rootRoute, | ||
| 225 | + path: "/instances/$id", | ||
| 226 | + component: InstanceDetailPage, | ||
| 227 | +}); | ||
| 228 | + | ||
| 220 | const marksRoute = createRoute({ | 229 | const marksRoute = createRoute({ |
| 221 | getParentRoute: () => rootRoute, | 230 | getParentRoute: () => rootRoute, |
| 222 | path: "/marks", | 231 | path: "/marks", |
| 223 | validateSearch: (search: Record<string, unknown>) => ({ | 232 | validateSearch: (search: Record<string, unknown>) => ({ |
| 224 | - tab: search.tab === "attendance" ? "attendance" as const : "marks" as const, | 233 | + tab: |
| 234 | + search.tab === "attendance" | ||
| 235 | + ? ("attendance" as const) | ||
| 236 | + : search.tab === "karne" | ||
| 237 | + ? ("karne" as const) | ||
| 238 | + : ("marks" as const), | ||
| 225 | }), | 239 | }), |
| 226 | component: MarksPage, | 240 | component: MarksPage, |
| 227 | }); | 241 | }); |
| @@ -300,6 +314,12 @@ const termsRoute = createRoute({ | |||
| 300 | component: TermsPage, | 314 | component: TermsPage, |
| 301 | }); | 315 | }); |
| 302 | 316 | ||
| 317 | +const academicYearsRoute = createRoute({ | ||
| 318 | + getParentRoute: () => rootRoute, | ||
| 319 | + path: "/management/academic-years", | ||
| 320 | + component: AcademicYearsPage, | ||
| 321 | +}); | ||
| 322 | + | ||
| 303 | const liveMonitorRoute = createRoute({ | 323 | const liveMonitorRoute = createRoute({ |
| 304 | getParentRoute: () => rootRoute, | 324 | getParentRoute: () => rootRoute, |
| 305 | path: "/exams/$id/live", | 325 | path: "/exams/$id/live", |
| @@ -511,6 +531,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 511 | studiesRoute, | 531 | studiesRoute, |
| 512 | clubsRoute, | 532 | clubsRoute, |
| 513 | courseDetailRoute, | 533 | courseDetailRoute, |
| 534 | + instanceDetailRoute, | ||
| 514 | marksRoute, | 535 | marksRoute, |
| 515 | messagesRoute, | 536 | messagesRoute, |
| 516 | pomodoroRoute, | 537 | pomodoroRoute, |
| @@ -524,6 +545,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 524 | classesRoute, | 545 | classesRoute, |
| 525 | classDetailRoute, | 546 | classDetailRoute, |
| 526 | termsRoute, | 547 | termsRoute, |
| 548 | + academicYearsRoute, | ||
| 527 | adminUsersRoute, | 549 | adminUsersRoute, |
| 528 | adminUserDetailRoute, | 550 | adminUserDetailRoute, |
| 529 | guideRoute, | 551 | guideRoute, |