🎓 follow the backend's grade ladder and per-section course rows
Browse files at this commit167d960f88502ad06c3b152db62925d529045873Parent: 50dd157- fix
- 🎓 follow the backend's grade ladder and per-section course rows
38 changed files +490 -243
- src/api/__tests__/academic-years/academic-years.test.ts +1 -1
- src/api/__tests__/classes/classes.test.ts +15 -15
- src/api/classes/deleteClassBlueprintByGrade.ts +2 -2
- src/api/classes/getClassBlueprintByGrade.ts +3 -4
- src/api/classes/getClassBlueprintStatus.ts +2 -2
- src/api/classes/patchClassBlueprintByGrade.ts +2 -2
- src/api/classes/patchClassById.ts +3 -2
- src/api/classes/postClass.ts +2 -1
- src/api/classes/postClassBlueprint.ts +1 -1
- src/api/client/client.ts +32 -0
- src/api/client/types.ts +154 -13
- src/api/reports/getMyCourses.ts +8 -6
- src/components/ai/note-studio-panel.tsx +5 -5
- src/components/classes/blueprint-panel.tsx +15 -13
- src/components/classes/blueprints-tab.tsx +13 -10
- src/components/classes/class-edit-panel.tsx +7 -5
- src/components/classes/grade-level-select.tsx +35 -0
- src/components/users/profile-memberships.tsx +11 -9
- src/i18n/locales/en.ts +9 -4
- src/i18n/locales/tr.ts +9 -4
- src/i18n/messages.ts +6 -1
- src/lib/command-search.test.ts +3 -6
- src/lib/command-search.ts +3 -4
- src/lib/grade-level.ts +27 -0
- src/lib/question-generation.ts +7 -4
- src/lib/student-directory.ts +1 -3
- src/pages/academic-years-page.tsx +15 -19
- src/pages/calendar-page.test.tsx +0 -1
- src/pages/calendar-page.tsx +2 -3
- src/pages/class-detail-page.tsx +7 -5
- src/pages/classes-page.test.tsx +5 -4
- src/pages/classes-page.tsx +27 -21
- src/pages/course-detail-page.tsx +47 -58
- src/pages/courses-page.test.tsx +5 -7
- src/pages/courses-page.tsx +2 -2
- src/pages/dashboard-page.test.tsx +0 -1
- src/pages/dashboard-page.tsx +2 -2
- src/pages/profile-page.tsx +2 -3
src/api/__tests__/academic-years/academic-years.test.tsmodified+1 -1
| @@ -41,7 +41,7 @@ describe("academic years API", () => { | ||
| 41 | 41 | name: "2026-2027", |
| 42 | 42 | starts_at: 1780000000000, |
| 43 | 43 | ends_at: 1810000000000, |
| 44 | - grade_promotions: [{ from_grade: "5", to_grade: "6" }], | |
| 44 | + grade_promotions: [{ from_grade: 5, to_grade: 6 }], | |
| 45 | 45 | }; |
| 46 | 46 | |
| 47 | 47 | await postAcademicYear(body); |
src/api/__tests__/classes/classes.test.tsmodified+15 -15
| @@ -33,7 +33,7 @@ describe("classes API", () => { | ||
| 33 | 33 | it("postClass POSTs /classes and returns the create envelope", async () => { |
| 34 | 34 | const envelope = { class: { id: "c1" }, skipped: [], stocked_from: null }; |
| 35 | 35 | mockFetchSuccess(envelope); |
| 36 | - const body = { name: "9-A", grade: "9", year: "y1" }; | |
| 36 | + const body = { name: "9-A", grade_level: 9, year: "y1" }; | |
| 37 | 37 | const created = await postClass(body); |
| 38 | 38 | expect(created).toEqual(envelope); |
| 39 | 39 | expect(created.class.id).toBe("c1"); |
| @@ -75,7 +75,7 @@ describe("classes API", () => { | ||
| 75 | 75 | |
| 76 | 76 | it("patchClassById PATCHes /classes/:id with the body", async () => { |
| 77 | 77 | mockFetchSuccess({ id: "c1" }); |
| 78 | - const body = { name: "9-B", grade: null, term_id: null }; | |
| 78 | + const body = { name: "9-B", grade_level: 10, year: null }; | |
| 79 | 79 | await patchClassById("c1", body); |
| 80 | 80 | const [url, init] = lastFetchCall(); |
| 81 | 81 | expect(url).toBe("/api/classes/c1"); |
| @@ -144,8 +144,8 @@ describe("classes API", () => { | ||
| 144 | 144 | }); |
| 145 | 145 | |
| 146 | 146 | it("postClassBlueprint POSTs /classes/blueprints with the body", async () => { |
| 147 | - mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, matched: 2, skipped: [] }); | |
| 148 | - const body = { grade: "9", course_ids: ["co1", "co2"] }; | |
| 147 | + mockFetchSuccess({ blueprint: { grade_level: 9, courses: [], creator: {} }, matched: 2, skipped: [] }); | |
| 148 | + const body = { grade_level: 9, course_ids: ["co1", "co2"] }; | |
| 149 | 149 | await postClassBlueprint(body); |
| 150 | 150 | const [url, init] = lastFetchCall(); |
| 151 | 151 | expect(url).toBe("/api/classes/blueprints"); |
| @@ -160,17 +160,17 @@ describe("classes API", () => { | ||
| 160 | 160 | expect(url).toBe("/api/classes/blueprints?limit=20&offset=40"); |
| 161 | 161 | }); |
| 162 | 162 | |
| 163 | - it("getClassBlueprintByGrade encodes the grade, which is the record key", async () => { | |
| 164 | - mockFetchSuccess({ grade: "9/A", courses: [], creator: {} }); | |
| 165 | - await getClassBlueprintByGrade("9/A"); | |
| 163 | + it("getClassBlueprintByGrade keys the blueprint by its grade level", async () => { | |
| 164 | + mockFetchSuccess({ grade_level: 0, courses: [], creator: {} }); | |
| 165 | + await getClassBlueprintByGrade(0); | |
| 166 | 166 | const [url] = lastFetchCall(); |
| 167 | - expect(url).toBe("/api/classes/blueprints/9%2FA"); | |
| 167 | + expect(url).toBe("/api/classes/blueprints/0"); | |
| 168 | 168 | }); |
| 169 | 169 | |
| 170 | 170 | it("patchClassBlueprintByGrade PATCHes the whole course set", async () => { |
| 171 | - mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, matched: 2, skipped: [] }); | |
| 171 | + mockFetchSuccess({ blueprint: { grade_level: 9, courses: [], creator: {} }, matched: 2, skipped: [] }); | |
| 172 | 172 | const body = { course_ids: ["co1"] }; |
| 173 | - await patchClassBlueprintByGrade("9", body); | |
| 173 | + await patchClassBlueprintByGrade(9, body); | |
| 174 | 174 | const [url, init] = lastFetchCall(); |
| 175 | 175 | expect(url).toBe("/api/classes/blueprints/9"); |
| 176 | 176 | expect(init?.method).toBe("PATCH"); |
| @@ -179,9 +179,9 @@ describe("classes API", () => { | ||
| 179 | 179 | |
| 180 | 180 | it("deleteClassBlueprintByGrade DELETEs /classes/blueprints/:grade", async () => { |
| 181 | 181 | mockFetch204(); |
| 182 | - await deleteClassBlueprintByGrade("9/A"); | |
| 182 | + await deleteClassBlueprintByGrade(11); | |
| 183 | 183 | const [url, init] = lastFetchCall(); |
| 184 | - expect(url).toBe("/api/classes/blueprints/9%2FA"); | |
| 184 | + expect(url).toBe("/api/classes/blueprints/11"); | |
| 185 | 185 | expect(init?.method).toBe("DELETE"); |
| 186 | 186 | }); |
| 187 | 187 | |
| @@ -195,12 +195,12 @@ describe("classes API", () => { | ||
| 195 | 195 | }); |
| 196 | 196 | |
| 197 | 197 | it("getClassBlueprintStatus GETs /classes/blueprints/:grade/status", async () => { |
| 198 | - const mockStatus = { grade: "9/A", courses: ["co1"], matched: 3, sections: [] }; | |
| 198 | + const mockStatus = { grade_level: 9, courses: ["co1"], matched: 3, sections: [] }; | |
| 199 | 199 | mockFetchSuccess(mockStatus); |
| 200 | - const result = await getClassBlueprintStatus("9/A"); | |
| 200 | + const result = await getClassBlueprintStatus(9); | |
| 201 | 201 | expect(result).toEqual(mockStatus); |
| 202 | 202 | const [url, init] = lastFetchCall(); |
| 203 | - expect(url).toBe("/api/classes/blueprints/9%2FA/status"); | |
| 203 | + expect(url).toBe("/api/classes/blueprints/9/status"); | |
| 204 | 204 | expect(init?.method).toBe("GET"); |
| 205 | 205 | }); |
| 206 | 206 | }); |
src/api/classes/deleteClassBlueprintByGrade.tsmodified+2 -2
| @@ -2,6 +2,6 @@ import { client } from "../client"; | ||
| 2 | 2 | |
| 3 | 3 | // Detaches every course this blueprint attached, across every class at the |
| 4 | 4 | // grade, then drops the template. Hand-attached courses stay. |
| 5 | -export function deleteClassBlueprintByGrade(grade: string): Promise<void> { | |
| 6 | - return client<void>(`/classes/blueprints/${encodeURIComponent(grade)}`, { method: "DELETE" }); | |
| 5 | +export function deleteClassBlueprintByGrade(gradeLevel: number): Promise<void> { | |
| 6 | + return client<void>(`/classes/blueprints/${gradeLevel}`, { method: "DELETE" }); | |
| 7 | 7 | } |
src/api/classes/getClassBlueprintByGrade.tsmodified+3 -4
| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { ClassBlueprint } from "../client"; |
| 3 | 3 | |
| 4 | -// The grade label is the record key and is free text, so it must be encoded — | |
| 5 | -// a grade like "9/A" would otherwise read as a second path segment. | |
| 6 | -export function getClassBlueprintByGrade(grade: string, signal?: AbortSignal): Promise<ClassBlueprint> { | |
| 7 | - return client<ClassBlueprint>(`/classes/blueprints/${encodeURIComponent(grade)}`, { signal }); | |
| 4 | +// The grade level (0..12) is the record key. | |
| 5 | +export function getClassBlueprintByGrade(gradeLevel: number, signal?: AbortSignal): Promise<ClassBlueprint> { | |
| 6 | + return client<ClassBlueprint>(`/classes/blueprints/${gradeLevel}`, { signal }); | |
| 8 | 7 | } |
src/api/classes/getClassBlueprintStatus.tsmodified+2 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { BlueprintStatus } from "../client"; |
| 3 | 3 | |
| 4 | -export function getClassBlueprintStatus(grade: string, signal?: AbortSignal): Promise<BlueprintStatus> { | |
| 5 | - return client<BlueprintStatus>(`/classes/blueprints/${encodeURIComponent(grade)}/status`, { signal }); | |
| 4 | +export function getClassBlueprintStatus(gradeLevel: number, signal?: AbortSignal): Promise<BlueprintStatus> { | |
| 5 | + return client<BlueprintStatus>(`/classes/blueprints/${gradeLevel}/status`, { signal }); | |
| 6 | 6 | } |
src/api/classes/patchClassBlueprintByGrade.tsmodified+2 -2
| @@ -9,10 +9,10 @@ export type UpdateBlueprintBody = { course_ids: string[] }; | ||
| 9 | 9 | // A 409 means the blueprint changed since it was read — there is no version to |
| 10 | 10 | // echo back, so re-read it and let the user resubmit from the fresh list. |
| 11 | 11 | export function patchClassBlueprintByGrade( |
| 12 | - grade: string, | |
| 12 | + gradeLevel: number, | |
| 13 | 13 | body: UpdateBlueprintBody, |
| 14 | 14 | ): Promise<BlueprintResult> { |
| 15 | - return client<BlueprintResult>(`/classes/blueprints/${encodeURIComponent(grade)}`, { | |
| 15 | + return client<BlueprintResult>(`/classes/blueprints/${gradeLevel}`, { | |
| 16 | 16 | method: "PATCH", |
| 17 | 17 | body, |
| 18 | 18 | }); |
src/api/classes/patchClassById.tsmodified+3 -2
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { ClassGroup } from "../client"; |
| 3 | 3 | |
| 4 | -// Omit a field to keep it; send null on grade/year/teacher_id to clear/unlink it. | |
| 4 | +// Omit a field to keep it; send null on year/teacher_id to clear/unlink it. The | |
| 5 | +// grade is required on every class, so `grade_level` can be reset, never cleared. | |
| 5 | 6 | export type UpdateClassBody = { |
| 6 | 7 | name?: string; |
| 7 | - grade?: string | null; | |
| 8 | + grade_level?: number; | |
| 8 | 9 | /** The academic year (`getAcademicYears`) the şube sits in. */ |
| 9 | 10 | year?: string | null; |
| 10 | 11 | teacher_id?: string | null; |
src/api/classes/postClass.tsmodified+2 -1
| @@ -3,7 +3,8 @@ import type { CreateClassResponse } from "../client"; | ||
| 3 | 3 | |
| 4 | 4 | // `year` is the academic year (`getAcademicYears`) — what binds the şube to a |
| 5 | 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 }; | |
| 6 | +// `grade_level` is the rung on the grade ladder, 0 (anaokulu) .. 12; required. | |
| 7 | +export type CreateClassBody = { name: string; grade_level: number; year?: string; teacher_id?: string }; | |
| 7 | 8 | |
| 8 | 9 | // The 201 is a create envelope, not the bare class: its `class` is what the |
| 9 | 10 | // route navigates to, and its `skipped` is the blueprint fallout the caller |
src/api/classes/postClassBlueprint.tsmodified+1 -1
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { BlueprintResult } from "../client"; |
| 3 | 3 | |
| 4 | -export type CreateBlueprintBody = { grade: string; course_ids: string[] }; | |
| 4 | +export type CreateBlueprintBody = { grade_level: number; course_ids: string[] }; | |
| 5 | 5 | |
| 6 | 6 | // Manager+. Creates the blueprint and immediately applies it to every existing |
| 7 | 7 | // class at that grade; pairs that could not land come back in `skipped`. |
src/api/client/client.tsmodified+32 -0
| @@ -356,6 +356,38 @@ const API_ERROR_CODE_MESSAGES: Record<string, LocalizedMessage> = { | ||
| 356 | 356 | tr: "Öğrenci eklenirken şubenin derslerinden biri kaldırıldı. Sayfayı yenileyip tekrar dene.", |
| 357 | 357 | }, |
| 358 | 358 | student_number_taken: STUDENT_NUMBER_TAKEN, |
| 359 | + session_time_taken: { | |
| 360 | + en: "Another lesson of this section already starts at this time. Pick a different start time.", | |
| 361 | + tr: "Bu şubenin başka bir dersi zaten bu saatte başlıyor. Farklı bir başlangıç saati seç.", | |
| 362 | + }, | |
| 363 | + offering_exists: { | |
| 364 | + en: "This course already has a template for this grade. Edit the existing template instead.", | |
| 365 | + tr: "Bu dersin bu seviye için zaten bir şablonu var. Bunun yerine mevcut şablonu düzenle.", | |
| 366 | + }, | |
| 367 | + offering_in_use: { | |
| 368 | + en: "Classes still teach from this template. Detach the course from those classes first.", | |
| 369 | + tr: "Bu şablondan hâlâ ders işleyen şubeler var. Önce dersi o şubelerden çıkar.", | |
| 370 | + }, | |
| 371 | + slot_overlap: { | |
| 372 | + en: "Another slot on this day overlaps this time window. Pick a different time.", | |
| 373 | + tr: "Bu gündeki başka bir ders saati bu zaman aralığıyla çakışıyor. Farklı bir saat seç.", | |
| 374 | + }, | |
| 375 | + slot_cap: { | |
| 376 | + en: "This weekly plan already holds the maximum number of slots. Remove one before adding another.", | |
| 377 | + tr: "Bu haftalık plan en fazla ders saati sayısına ulaştı. Yenisini eklemeden önce birini kaldır.", | |
| 378 | + }, | |
| 379 | + unknown_exam_kind: { | |
| 380 | + en: "This exam kind is not one the school uses. Pick a kind from the school settings.", | |
| 381 | + tr: "Bu sınav türü okulun kullandığı türlerden biri değil. Okul ayarlarındaki türlerden birini seç.", | |
| 382 | + }, | |
| 383 | + instance_has_no_weekly_plan: { | |
| 384 | + en: "This section has no weekly plan yet. Add slots before generating lessons.", | |
| 385 | + tr: "Bu şubenin henüz haftalık planı yok. Ders üretmeden önce ders saati ekle.", | |
| 386 | + }, | |
| 387 | + instance_has_no_teacher: { | |
| 388 | + en: "No teacher is assigned to this section. Assign a teacher before generating lessons.", | |
| 389 | + tr: "Bu şubeye atanmış öğretmen yok. Ders üretmeden önce bir öğretmen ata.", | |
| 390 | + }, | |
| 359 | 391 | not_ready: { |
| 360 | 392 | en: "This audio is not ready yet. Wait for it to finish and try again.", |
| 361 | 393 | tr: "Bu ses kaydı henüz hazır değil. Tamamlanmasını bekleyip tekrar dene.", |
src/api/client/types.tsmodified+154 -13
| @@ -110,9 +110,20 @@ export type EarnedBadge = { id: string; earned_at: number }; | ||
| 110 | 110 | |
| 111 | 111 | export type AvatarMeta = { content_type: string; size: number }; |
| 112 | 112 | |
| 113 | -export type ProfileClassRef = { id: string; name: string; grade: string | null }; | |
| 113 | +export type ProfileClassRef = { id: string; name: string; grade_level: number }; | |
| 114 | 114 | |
| 115 | -export type ProfileCourseRef = { id: string; title: string; kind: CourseKind }; | |
| 115 | +// One class section a profile lists, never the catalog row: `id` is the | |
| 116 | +// instance id, `title` its resolved title. `class`, `class_name` and | |
| 117 | +// `grade_level` read null for a viewer below the classes-block bar. | |
| 118 | +export type ProfileCourseRef = { | |
| 119 | + id: string; | |
| 120 | + course: string; | |
| 121 | + class: string | null; | |
| 122 | + class_name: string | null; | |
| 123 | + title: string; | |
| 124 | + grade_level: number | null; | |
| 125 | + kind: CourseKind; | |
| 126 | +}; | |
| 116 | 127 | |
| 117 | 128 | // Lifetime counters behind the badge ladders, plus the two live totals the |
| 118 | 129 | // capped `classes`/`courses` lists would otherwise hide. |
| @@ -335,17 +346,80 @@ export type Course = { | ||
| 335 | 346 | class_course_count: number; |
| 336 | 347 | // Individual club/etut memberships on the catalog row itself. |
| 337 | 348 | course_membership_count: number; |
| 349 | + // The sections teaching it, capped at limits.course.max_course_sections | |
| 350 | + // (class_course_count keeps the true total) and filtered to what the | |
| 351 | + // reader reaches. | |
| 352 | + sections: CourseSectionRef[]; | |
| 338 | 353 | }; |
| 339 | 354 | |
| 355 | +// One class section of a catalog course, as a course row or GET /courses/me | |
| 356 | +// lists it: `id` is the instance id, `title` and `ders_saati` resolved. | |
| 357 | +export type CourseSectionRef = { | |
| 358 | + id: string; | |
| 359 | + course: string; | |
| 360 | + class: string; | |
| 361 | + class_name: string; | |
| 362 | + title: string; | |
| 363 | + grade_level: number; | |
| 364 | + ders_saati: number; | |
| 365 | + teachers: PersonRef[]; | |
| 366 | + enrollment_count: number; | |
| 367 | +}; | |
| 368 | + | |
| 369 | +/** One exam kind's effective weight. */ | |
| 370 | +export type ExamWeightEntry = { kind: string; weight: number }; | |
| 371 | + | |
| 372 | +/** | |
| 373 | + * One slot of a weekly plan. `starts_at`/`ends_at` are minutes past midnight | |
| 374 | + * (540 = 09:00), `weekday` 1..7 (Monday first). | |
| 375 | + */ | |
| 376 | +export type WeeklySlot = { | |
| 377 | + id: string; | |
| 378 | + weekday: number; | |
| 379 | + starts_at: number; | |
| 380 | + ends_at: number; | |
| 381 | + topic?: string | null; | |
| 382 | +}; | |
| 383 | + | |
| 384 | +/** The override fields POST /instances/{id}/reset clears back to inherit. */ | |
| 385 | +export type InstanceOverrideField = | |
| 386 | + | "title" | |
| 387 | + | "description" | |
| 388 | + | "ders_saati" | |
| 389 | + | "counts_toward_karne" | |
| 390 | + | "subjects" | |
| 391 | + | "exam_weights" | |
| 392 | + | "weekly_plan"; | |
| 393 | + | |
| 340 | 394 | // One catalog course as one sube teaches it. This is what carries the roster, |
| 341 | 395 | // the exams, the sessions and the karne weight. |
| 396 | +// | |
| 397 | +// Every content field is resolved: a scalar runs section override -> the | |
| 398 | +// grade-level offering -> catalog/constant, and `*_overridden` tells the | |
| 399 | +// section's own value from an inherited one. The three sets (subjects, exam | |
| 400 | +// weights, weekly plan) follow a flag: `*_inherited: false` means the | |
| 401 | +// section's own rows are authoritative, even when empty. | |
| 342 | 402 | export type Instance = { |
| 343 | 403 | id: string; |
| 344 | 404 | class: string; |
| 345 | 405 | course: string; |
| 406 | + // The grade-level template (GET /offerings/{id}) unset fields inherit from. | |
| 407 | + offering: string; | |
| 408 | + title: string; | |
| 409 | + title_overridden: boolean; | |
| 410 | + description: string; | |
| 411 | + description_overridden: boolean; | |
| 346 | 412 | // Weekly lesson hours; the instance's weight in the year's karne average. |
| 347 | 413 | ders_saati: number; |
| 414 | + ders_saati_overridden: boolean; | |
| 348 | 415 | counts_toward_karne: boolean; |
| 416 | + counts_toward_karne_overridden: boolean; | |
| 417 | + subjects_inherited: boolean; | |
| 418 | + subjects: Subject[]; | |
| 419 | + exam_weights_inherited: boolean; | |
| 420 | + exam_weights: ExamWeightEntry[]; | |
| 421 | + weekly_plan_inherited: boolean; | |
| 422 | + weekly_plan: WeeklySlot[]; | |
| 349 | 423 | enrollment_count: number; |
| 350 | 424 | teachers: PersonRef[]; |
| 351 | 425 | }; |
| @@ -360,10 +434,10 @@ export type CourseMembership = { | ||
| 360 | 434 | created_at: number; |
| 361 | 435 | }; |
| 362 | 436 | |
| 363 | -/** One sınıf-geçme pair: the grade label students move to at rollover. */ | |
| 437 | +/** One sınıf-geçme pair: the grade level (0..12) students move to at rollover. */ | |
| 364 | 438 | export type GradePromotion = { |
| 365 | - from_grade: string; | |
| 366 | - to_grade: string; | |
| 439 | + from_grade: number; | |
| 440 | + to_grade: number; | |
| 367 | 441 | }; |
| 368 | 442 | |
| 369 | 443 | // An academic year: the calendar structure dönemler and şubeler hang off. |
| @@ -423,7 +497,8 @@ export type ClassGroup = { | ||
| 423 | 497 | // GET /classes/user/{user}). |
| 424 | 498 | creator: PersonRef | null; |
| 425 | 499 | name: string; |
| 426 | - grade: string | null; | |
| 500 | + // The class's rung on the grade ladder, 0 (anaokulu) .. 12. Required. | |
| 501 | + grade_level: number; | |
| 427 | 502 | // The academic year (AcademicYear id) the sube sits in; what binds it to a |
| 428 | 503 | // karne and to the rollover. Null when none is set. |
| 429 | 504 | year: string | null; |
| @@ -436,7 +511,7 @@ export type ClassGroup = { | ||
| 436 | 511 | // that stocked it. `skipped` is empty when the template took every course, and |
| 437 | 512 | // always empty when no template covered the grade; `stocked_from` is null in |
| 438 | 513 | // that second case. |
| 439 | -export type CreateClassResponse = { class: ClassGroup; skipped: BlueprintSkip[]; stocked_from: string | null }; | |
| 514 | +export type CreateClassResponse = { class: ClassGroup; skipped: BlueprintSkip[]; stocked_from: number | null }; | |
| 440 | 515 | |
| 441 | 516 | export type ClassMember = { |
| 442 | 517 | id: string; |
| @@ -451,9 +526,13 @@ export type ClassMember = { | ||
| 451 | 526 | source_class_group: string | null; |
| 452 | 527 | }; |
| 453 | 528 | |
| 454 | -// The instance as the class routes return it: an Instance plus who attached | |
| 455 | -// the course to the sube. | |
| 456 | -export type ClassCourse = Instance & { | |
| 529 | +// The instance as the class routes return it: the resolved scalars plus who | |
| 530 | +// attached the course to the sube. The override flags and the three resolved | |
| 531 | +// sets live on GET /instances/{id} only. | |
| 532 | +export type ClassCourse = Pick< | |
| 533 | + Instance, | |
| 534 | + "id" | "class" | "course" | "title" | "description" | "ders_saati" | "counts_toward_karne" | "enrollment_count" | "teachers" | |
| 535 | +> & { | |
| 457 | 536 | attached_by: PersonRef; |
| 458 | 537 | }; |
| 459 | 538 | |
| @@ -461,7 +540,7 @@ export type ClassCourse = Instance & { | ||
| 461 | 540 | // grade label is the record's key, so there is at most one per grade. Creating |
| 462 | 541 | // or editing one applies it to every existing class at that grade right away. |
| 463 | 542 | export type ClassBlueprint = { |
| 464 | - grade: string; | |
| 543 | + grade_level: number; | |
| 465 | 544 | courses: string[]; |
| 466 | 545 | creator: PersonRef; |
| 467 | 546 | }; |
| @@ -493,13 +572,62 @@ export type BlueprintSectionStatus = { | ||
| 493 | 572 | |
| 494 | 573 | /** Every section at a grade with the template courses it is missing. */ |
| 495 | 574 | export type BlueprintStatus = { |
| 496 | - grade: string; | |
| 575 | + grade_level: number; | |
| 497 | 576 | /** The template every section below is measured against. */ |
| 498 | 577 | courses: string[]; |
| 499 | 578 | matched: number; |
| 500 | 579 | sections: BlueprintSectionStatus[]; |
| 501 | 580 | }; |
| 502 | 581 | |
| 582 | +// A school-wide non-teaching day range. The materializer skips every day it | |
| 583 | +// reaches into; lessons already on those days stay. | |
| 584 | +export type Holiday = { | |
| 585 | + id: string; | |
| 586 | + name: string; | |
| 587 | + /** First blocked instant, UTC unix-millis. */ | |
| 588 | + starts_at: number; | |
| 589 | + /** Last blocked instant, UTC unix-millis. */ | |
| 590 | + ends_at: number; | |
| 591 | + /** One of limits.holiday.kinds. */ | |
| 592 | + kind: string; | |
| 593 | + creator: PersonRef; | |
| 594 | + created_at: number; | |
| 595 | +}; | |
| 596 | + | |
| 597 | +// A grade-level template of a catalog course: what every section at that | |
| 598 | +// grade inherits. Null fields inherit themselves (the catalog title/ | |
| 599 | +// description, 1 weekly hour, counted toward the karne). | |
| 600 | +export type Offering = { | |
| 601 | + id: string; | |
| 602 | + course: string; | |
| 603 | + grade_level: number; | |
| 604 | + title: string | null; | |
| 605 | + description: string | null; | |
| 606 | + default_ders_saati: number | null; | |
| 607 | + default_counts_toward_karne: boolean | null; | |
| 608 | + created_by: PersonRef; | |
| 609 | + created_at: number; | |
| 610 | + updated_at: number; | |
| 611 | +}; | |
| 612 | + | |
| 613 | +/** One day the materializer left out because a holiday covers it. */ | |
| 614 | +export type BlockedDay = { date: string; holiday: string }; | |
| 615 | + | |
| 616 | +// What POST /instances/{id}/weekly-plan/materialize answers. `created` is | |
| 617 | +// empty on a dry run; `candidates` is what an apply would try to write. | |
| 618 | +export type MaterializeReport = { | |
| 619 | + from: number; | |
| 620 | + to: number; | |
| 621 | + applied: boolean; | |
| 622 | + slots: number; | |
| 623 | + candidates: number; | |
| 624 | + created: CourseSession[]; | |
| 625 | + skipped_existing: number; | |
| 626 | + skipped_holiday: number; | |
| 627 | + blocked: BlockedDay[]; | |
| 628 | + range_days: number; | |
| 629 | +}; | |
| 630 | + | |
| 503 | 631 | export type CourseSession = { |
| 504 | 632 | id: string; |
| 505 | 633 | /** The instance this lesson belongs to. */ |
| @@ -891,12 +1019,25 @@ export type Limits = { | ||
| 891 | 1019 | max_session_topic_len: number; |
| 892 | 1020 | max_term_name_len: number; |
| 893 | 1021 | max_class_name_len: number; |
| 894 | - max_class_grade_len: number; | |
| 1022 | + // The grade ladder: 0 (anaokulu) .. 12. | |
| 1023 | + min_grade_level: number; | |
| 1024 | + max_grade_level: number; | |
| 895 | 1025 | max_class_members: number; |
| 896 | 1026 | max_class_courses: number; |
| 897 | 1027 | max_academic_year_name_len: number; |
| 898 | 1028 | min_ders_saati: number; |
| 899 | 1029 | max_ders_saati: number; |
| 1030 | + // How many sections a catalog course row embeds in `sections`. | |
| 1031 | + max_course_sections: number; | |
| 1032 | + }; | |
| 1033 | + holiday: { max_name_len: number; kinds: string[] }; | |
| 1034 | + weekly_plan: { | |
| 1035 | + // Inclusive bounds for a slot's minutes past midnight. | |
| 1036 | + min_slot_minute: number; | |
| 1037 | + max_slot_minute: number; | |
| 1038 | + max_weekly_slots: number; | |
| 1039 | + max_materialize_days: number; | |
| 1040 | + max_materialize_sessions: number; | |
| 900 | 1041 | }; |
| 901 | 1042 | exam: { |
| 902 | 1043 | max_title_len: number; |
src/api/reports/getMyCourses.tsmodified+8 -6
| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | -import { normalizePage, type Page } from "../client"; | |
| 3 | -import type { Course } from "../client"; | |
| 4 | -import { courseListQuery, type CourseListParams } from "../courses/getCourses"; | |
| 2 | +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; | |
| 3 | +import type { CourseSectionRef } from "../client"; | |
| 5 | 4 | |
| 6 | -export async function getMyCourses(params?: CourseListParams, signal?: AbortSignal): Promise<Page<Course>> { | |
| 7 | - const data = await client<unknown>(`/courses/me${courseListQuery(params)}`, { signal }); | |
| 8 | - return normalizePage<Course>(data); | |
| 5 | +// One row per class section the caller reaches (şube roster, homeroom, taught, | |
| 6 | +// or a hand-placed enrollment) — `id` is the instance id, never the catalog | |
| 7 | +// course's; `course` names the catalog row. | |
| 8 | +export async function getMyCourses(params?: PageParams, signal?: AbortSignal): Promise<Page<CourseSectionRef>> { | |
| 9 | + const data = await client<unknown>(`/courses/me${pageQuery(params)}`, { signal }); | |
| 10 | + return normalizePage<CourseSectionRef>(data); | |
| 9 | 11 | } |
src/components/ai/note-studio-panel.tsxmodified+5 -5
| @@ -3,8 +3,7 @@ import { Link, useNavigate } from "@tanstack/solid-router"; | ||
| 3 | 3 | import { createResource } from "@/lib/create-resource"; |
| 4 | 4 | import { getCourseNotes } from "@/api/course-notes"; |
| 5 | 5 | import { getCourses } from "@/api/courses"; |
| 6 | -import { getMyCourses } from "@/api/reports"; | |
| 7 | -import { formatApiError, type CourseNote, type Role } from "@/api/client"; | |
| 6 | +import { formatApiError, type CourseNote } from "@/api/client"; | |
| 8 | 7 | import { PodcastPanel } from "@/components/notes/podcast-panel"; |
| 9 | 8 | import { RagOutputsPanel } from "@/components/notes/rag-outputs-panel"; |
| 10 | 9 | import { StudioOutputLibrary } from "@/components/ai/studio-output-library"; |
| @@ -36,8 +35,9 @@ function readRailWidth(): number { | ||
| 36 | 35 | type StudioNote = CourseNote & { courseTitle: string; courseCreatorId: string }; |
| 37 | 36 | |
| 38 | 37 | /** Every lesson note the account can produce from, with its course. */ |
| 39 | -async function loadStudioNotes(role: Role): Promise<StudioNote[]> { | |
| 40 | - const courses = role === "student" ? await getMyCourses({ limit: 100 }) : await getCourses({ limit: 100 }); | |
| 38 | +async function loadStudioNotes(): Promise<StudioNote[]> { | |
| 39 | + // GET /courses is already scoped to what the caller teaches or takes. | |
| 40 | + const courses = await getCourses({ limit: 100 }); | |
| 41 | 41 | const rows = await Promise.all( |
| 42 | 42 | courses.items.map(async (course) => { |
| 43 | 43 | try { |
| @@ -57,7 +57,7 @@ async function loadStudioNotes(role: Role): Promise<StudioNote[]> { | ||
| 57 | 57 | |
| 58 | 58 | function useStudioNotes() { |
| 59 | 59 | const auth = useAuth(); |
| 60 | - return createResource(() => auth.user()?.role ?? null, loadStudioNotes); | |
| 60 | + return createResource(() => auth.user()?.role ?? null, () => loadStudioNotes()); | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
src/components/classes/blueprint-panel.tsxmodified+15 -13
| @@ -7,6 +7,7 @@ import { | ||
| 7 | 7 | import { ApiError, formatApiError, type BlueprintResult, type ClassBlueprint, type Course } from "@/api/client"; |
| 8 | 8 | import { Alert } from "@/components/ui/alert"; |
| 9 | 9 | import { Button } from "@/components/ui/button"; |
| 10 | +import { GradeLevelSelect } from "@/components/classes/grade-level-select"; | |
| 10 | 11 | import { Input } from "@/components/ui/input"; |
| 11 | 12 | import { Label } from "@/components/ui/label"; |
| 12 | 13 | import { SidePanel } from "@/components/ui/side-panel"; |
| @@ -21,11 +22,12 @@ export function BlueprintPanel(props: { | ||
| 21 | 22 | blueprint: ClassBlueprint | null; |
| 22 | 23 | courses: Course[]; |
| 23 | 24 | maxCourses: number; |
| 24 | - maxGradeLen: number; | |
| 25 | + minGradeLevel?: number; | |
| 26 | + maxGradeLevel?: number; | |
| 25 | 27 | onSaved: (result: BlueprintResult) => void; |
| 26 | 28 | }) { |
| 27 | 29 | const t = useT(); |
| 28 | - const [grade, setGrade] = createSignal(""); | |
| 30 | + const [gradeLevel, setGradeLevel] = createSignal<number | null>(null); | |
| 29 | 31 | const [selected, setSelected] = createSignal<string[]>([]); |
| 30 | 32 | const [filter, setFilter] = createSignal(""); |
| 31 | 33 | const [error, setError] = createSignal(""); |
| @@ -40,7 +42,7 @@ export function BlueprintPanel(props: { | ||
| 40 | 42 | createEffect(() => { |
| 41 | 43 | if (!props.open) return; |
| 42 | 44 | const bp = props.blueprint; |
| 43 | - setGrade(bp?.grade ?? ""); | |
| 45 | + setGradeLevel(bp ? bp.grade_level : null); | |
| 44 | 46 | setSelected(bp?.courses ? [...bp.courses] : []); |
| 45 | 47 | setFilter(""); |
| 46 | 48 | setError(""); |
| @@ -62,7 +64,7 @@ export function BlueprintPanel(props: { | ||
| 62 | 64 | |
| 63 | 65 | // A losing race has no version token to retry with, so re-read the blueprint, |
| 64 | 66 | // reseed the checkboxes from the server's list, and let the user resubmit. |
| 65 | - const reseedFromServer = async (g: string) => { | |
| 67 | + const reseedFromServer = async (g: number) => { | |
| 66 | 68 | try { |
| 67 | 69 | const fresh = await getClassBlueprintByGrade(g); |
| 68 | 70 | setSelected([...fresh.courses]); |
| @@ -75,15 +77,15 @@ export function BlueprintPanel(props: { | ||
| 75 | 77 | |
| 76 | 78 | const submit = async (e: Event) => { |
| 77 | 79 | e.preventDefault(); |
| 78 | - const g = grade().trim(); | |
| 79 | - if (!g) return; | |
| 80 | + const g = gradeLevel(); | |
| 81 | + if (g === null) return; | |
| 80 | 82 | setError(""); |
| 81 | 83 | setWarning(""); |
| 82 | 84 | setPending(true); |
| 83 | 85 | try { |
| 84 | 86 | const result = editing() |
| 85 | 87 | ? await patchClassBlueprintByGrade(g, { course_ids: selected() }) |
| 86 | - : await postClassBlueprint({ grade: g, course_ids: selected() }); | |
| 88 | + : await postClassBlueprint({ grade_level: g, course_ids: selected() }); | |
| 87 | 89 | props.onSaved(result); |
| 88 | 90 | } catch (err) { |
| 89 | 91 | if (err instanceof ApiError && err.status === 409) { |
| @@ -115,13 +117,13 @@ export function BlueprintPanel(props: { | ||
| 115 | 117 | |
| 116 | 118 | <div class="space-y-1.5"> |
| 117 | 119 | <Label for="bp-grade">{t("classBlueprints.grade")}</Label> |
| 118 | - <Input | |
| 120 | + <GradeLevelSelect | |
| 119 | 121 | id="bp-grade" |
| 120 | - class="h-10" | |
| 121 | - maxlength={props.maxGradeLen} | |
| 122 | - value={grade()} | |
| 122 | + value={gradeLevel()} | |
| 123 | + min={props.minGradeLevel} | |
| 124 | + max={props.maxGradeLevel} | |
| 123 | 125 | disabled={editing()} |
| 124 | - onInput={(e) => setGrade(e.currentTarget.value)} | |
| 126 | + onChange={setGradeLevel} | |
| 125 | 127 | /> |
| 126 | 128 | <p class="text-xs text-muted-foreground">{t("classBlueprints.gradeHint")}</p> |
| 127 | 129 | </div> |
| @@ -170,7 +172,7 @@ export function BlueprintPanel(props: { | ||
| 170 | 172 | </Show> |
| 171 | 173 | |
| 172 | 174 | <div class="flex justify-end"> |
| 173 | - <Button type="submit" class="w-full sm:w-auto" disabled={pending() || !grade().trim()}> | |
| 175 | + <Button type="submit" class="w-full sm:w-auto" disabled={pending() || gradeLevel() === null}> | |
| 174 | 176 | {t("common.save")} |
| 175 | 177 | </Button> |
| 176 | 178 | </div> |
src/components/classes/blueprints-tab.tsxmodified+13 -10
| @@ -15,6 +15,7 @@ import { IconClipboardCheck, IconEdit, IconPlus, IconTrash } from "@/components/ | ||
| 15 | 15 | import { SidePanel } from "@/components/ui/side-panel"; |
| 16 | 16 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 17 | 17 | import { createFlash } from "@/lib/flash"; |
| 18 | +import { gradeLevelLabel } from "@/lib/grade-level"; | |
| 18 | 19 | import { personLabel } from "@/lib/person"; |
| 19 | 20 | import { useT } from "@/stores/preferences-context"; |
| 20 | 21 | |
| @@ -47,7 +48,8 @@ export function BlueprintsTab(props: { | ||
| 47 | 48 | const columns = createMemo<ColumnDef<ClassBlueprint>[]>(() => [ |
| 48 | 49 | { |
| 49 | 50 | id: "grade", |
| 50 | - accessorFn: (row) => row.grade, | |
| 51 | + accessorFn: (row) => gradeLevelLabel(row.grade_level, t), | |
| 52 | + sortingFn: (a, b) => a.original.grade_level - b.original.grade_level, | |
| 51 | 53 | header: t("classBlueprints.grade"), |
| 52 | 54 | meta: { cellClass: "font-medium" }, |
| 53 | 55 | }, |
| @@ -97,7 +99,7 @@ export function BlueprintsTab(props: { | ||
| 97 | 99 | { |
| 98 | 100 | label: t("classBlueprints.status"), |
| 99 | 101 | icon: <IconClipboardCheck class="h-4 w-4" />, |
| 100 | - onSelect: () => void checkStatus(cell.row.original.grade), | |
| 102 | + onSelect: () => void checkStatus(cell.row.original.grade_level), | |
| 101 | 103 | }, |
| 102 | 104 | ]} |
| 103 | 105 | /> |
| @@ -113,10 +115,10 @@ export function BlueprintsTab(props: { | ||
| 113 | 115 | setEditing(null); |
| 114 | 116 | await refetch(); |
| 115 | 117 | setSkipped(result.skipped); |
| 116 | - // A grade label nobody carries is saved just the same, so it must not | |
| 118 | + // A grade no class sits on is saved just the same, so it must not | |
| 117 | 119 | // read as "applied" — that is the one outcome the admin needs to fix. |
| 118 | 120 | if (result.matched === 0) { |
| 119 | - setUnmatchedGrade(result.blueprint.grade); | |
| 121 | + setUnmatchedGrade(gradeLevelLabel(result.blueprint.grade_level, t)); | |
| 120 | 122 | return; |
| 121 | 123 | } |
| 122 | 124 | setUnmatchedGrade(null); |
| @@ -128,7 +130,7 @@ export function BlueprintsTab(props: { | ||
| 128 | 130 | if (!bp) return; |
| 129 | 131 | setError(""); |
| 130 | 132 | try { |
| 131 | - await deleteClassBlueprintByGrade(bp.grade); | |
| 133 | + await deleteClassBlueprintByGrade(bp.grade_level); | |
| 132 | 134 | setDeleting(null); |
| 133 | 135 | await refetch(); |
| 134 | 136 | setFlash(t("classBlueprints.deleted")); |
| @@ -136,10 +138,10 @@ export function BlueprintsTab(props: { | ||
| 136 | 138 | setError(formatApiError(err)); |
| 137 | 139 | } |
| 138 | 140 | }; |
| 139 | - const checkStatus = async (grade: string) => { | |
| 141 | + const checkStatus = async (gradeLevel: number) => { | |
| 140 | 142 | setError(""); |
| 141 | 143 | try { |
| 142 | - setStatus(await getClassBlueprintStatus(grade)); | |
| 144 | + setStatus(await getClassBlueprintStatus(gradeLevel)); | |
| 143 | 145 | } catch (err) { |
| 144 | 146 | setError(formatApiError(err)); |
| 145 | 147 | } |
| @@ -221,7 +223,8 @@ export function BlueprintsTab(props: { | ||
| 221 | 223 | blueprint={editing()} |
| 222 | 224 | courses={courses.latest ?? []} |
| 223 | 225 | maxCourses={limits.latest?.course.max_class_courses ?? 50} |
| 224 | - maxGradeLen={limits.latest?.course.max_class_grade_len ?? 20} | |
| 226 | + minGradeLevel={limits.latest?.course.min_grade_level} | |
| 227 | + maxGradeLevel={limits.latest?.course.max_grade_level} | |
| 225 | 228 | onSaved={(result) => void handleSaved(result)} |
| 226 | 229 | /> |
| 227 | 230 | |
| @@ -235,7 +238,7 @@ export function BlueprintsTab(props: { | ||
| 235 | 238 | <SidePanel |
| 236 | 239 | open={status() != null} |
| 237 | 240 | onOpenChange={(open) => !open && setStatus(null)} |
| 238 | - title={t("classBlueprints.statusTitle", { grade: status()?.grade ?? "" })} | |
| 241 | + title={t("classBlueprints.statusTitle", { grade: status() ? gradeLevelLabel(status()!.grade_level, t) : "" })} | |
| 239 | 242 | size="wide" |
| 240 | 243 | > |
| 241 | 244 | <Show when={status()}> |
| @@ -256,7 +259,7 @@ export function BlueprintsTab(props: { | ||
| 256 | 259 | open={deleting() !== null} |
| 257 | 260 | onOpenChange={(open) => !open && setDeleting(null)} |
| 258 | 261 | title={t("classBlueprints.delete")} |
| 259 | - summary={t("classBlueprints.deleteConfirm", { grade: deleting()?.grade ?? "" })} | |
| 262 | + summary={t("classBlueprints.deleteConfirm", { grade: deleting() ? gradeLevelLabel(deleting()!.grade_level, t) : "" })} | |
| 260 | 263 | variant="destructive" |
| 261 | 264 | onConfirm={remove} |
| 262 | 265 | /> |
src/components/classes/class-edit-panel.tsxmodified+7 -5
| @@ -3,6 +3,7 @@ import { patchClassById } from "@/api/classes"; | ||
| 3 | 3 | import { formatApiError, type AcademicYear, type ClassGroup } from "@/api/client"; |
| 4 | 4 | import { Alert } from "@/components/ui/alert"; |
| 5 | 5 | import { Button } from "@/components/ui/button"; |
| 6 | +import { GradeLevelSelect } from "@/components/classes/grade-level-select"; | |
| 6 | 7 | import { Input } from "@/components/ui/input"; |
| 7 | 8 | import { Label } from "@/components/ui/label"; |
| 8 | 9 | import { Select } from "@/components/ui/select"; |
| @@ -23,11 +24,12 @@ export function ClassEditPanel(props: { | ||
| 23 | 24 | onSaved: (cls: ClassGroup) => void | Promise<void>; |
| 24 | 25 | years: AcademicYear[]; |
| 25 | 26 | maxNameLen?: number; |
| 26 | - maxGradeLen?: number; | |
| 27 | + minGradeLevel?: number; | |
| 28 | + maxGradeLevel?: number; | |
| 27 | 29 | }) { |
| 28 | 30 | const t = useT(); |
| 29 | 31 | const [name, setName] = createSignal(""); |
| 30 | - const [grade, setGrade] = createSignal(""); | |
| 32 | + const [gradeLevel, setGradeLevel] = createSignal<number | null>(null); | |
| 31 | 33 | const [yearId, setYearId] = createSignal(""); |
| 32 | 34 | const [teacherId, setTeacherId] = createSignal(""); |
| 33 | 35 | const [error, setError] = createSignal(""); |
| @@ -38,7 +40,7 @@ export function ClassEditPanel(props: { | ||
| 38 | 40 | const c = props.cls; |
| 39 | 41 | if (!props.open || !c) return; |
| 40 | 42 | setName(c.name); |
| 41 | - setGrade(c.grade ?? ""); | |
| 43 | + setGradeLevel(c.grade_level); | |
| 42 | 44 | setYearId(c.year ?? ""); |
| 43 | 45 | setTeacherId(c.teacher?.id ?? ""); |
| 44 | 46 | setError(""); |
| @@ -51,7 +53,7 @@ export function ClassEditPanel(props: { | ||
| 51 | 53 | setError(""); |
| 52 | 54 | setPending(true); |
| 53 | 55 | try { |
| 54 | - const saved = await patchClassById(c.id, { name: name().trim(), grade: grade().trim() || null, year: yearId() || null, teacher_id: teacherId() || null }); | |
| 56 | + const saved = await patchClassById(c.id, { name: name().trim(), ...(gradeLevel() !== null ? { grade_level: gradeLevel()! } : {}), year: yearId() || null, teacher_id: teacherId() || null }); | |
| 55 | 57 | props.onOpenChange(false); |
| 56 | 58 | await props.onSaved(saved); |
| 57 | 59 | } catch (err) { |
| @@ -66,7 +68,7 @@ export function ClassEditPanel(props: { | ||
| 66 | 68 | <form class="space-y-4" onSubmit={submit}> |
| 67 | 69 | <div class="space-y-3"> |
| 68 | 70 | <div class="space-y-1.5"><Label for="edit-class-name">{t("classGroups.className")}</Label><Input id="edit-class-name" maxlength={props.maxNameLen} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div> |
| 69 | - <div class="space-y-1.5"><Label for="edit-class-grade">{t("classGroups.grade")}</Label><Input id="edit-class-grade" maxlength={props.maxGradeLen} value={grade()} onInput={(e) => setGrade(e.currentTarget.value)} /></div> | |
| 71 | + <div class="space-y-1.5"><Label for="edit-class-grade">{t("classGroups.grade")}</Label><GradeLevelSelect id="edit-class-grade" value={gradeLevel()} min={props.minGradeLevel} max={props.maxGradeLevel} onChange={setGradeLevel} /></div> | |
| 70 | 72 | <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={props.years}>{(year) => <option value={year.id}>{year.name}</option>}</For></Select></div> |
| 71 | 73 | <UserSearchSelect id="edit-class-teacher" label={t("classGroups.homeroomTeacher")} value={teacherId()} initialUser={props.cls?.teacher} onChange={setTeacherId} placeholder={t("classGroups.selectTeacher")} role="teacher" /> |
| 72 | 74 | </div> |
src/components/classes/grade-level-select.tsxadded+35 -0
| @@ -0,0 +1,35 @@ | ||
| 1 | +import { For } from "solid-js"; | |
| 2 | +import { Select } from "@/components/ui/select"; | |
| 3 | +import { gradeLevelLabel, gradeLevels } from "@/lib/grade-level"; | |
| 4 | +import { useT } from "@/stores/preferences-context"; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * A pick on the grade ladder (0 = anaokulu .. 12). `value` null shows the | |
| 8 | + * placeholder row — the ladder is required on a class, so a form checks it. | |
| 9 | + */ | |
| 10 | +export function GradeLevelSelect(props: { | |
| 11 | + id: string; | |
| 12 | + value: number | null; | |
| 13 | + onChange: (level: number | null) => void; | |
| 14 | + min?: number; | |
| 15 | + max?: number; | |
| 16 | + disabled?: boolean; | |
| 17 | + error?: boolean; | |
| 18 | +}) { | |
| 19 | + const t = useT(); | |
| 20 | + return ( | |
| 21 | + <Select | |
| 22 | + id={props.id} | |
| 23 | + value={props.value === null ? "" : String(props.value)} | |
| 24 | + disabled={props.disabled} | |
| 25 | + aria-invalid={props.error || undefined} | |
| 26 | + onChange={(e) => { | |
| 27 | + const raw = e.currentTarget.value; | |
| 28 | + props.onChange(raw === "" ? null : Number(raw)); | |
| 29 | + }} | |
| 30 | + > | |
| 31 | + <option value="">{t("grade.select")}</option> | |
| 32 | + <For each={gradeLevels(props.min, props.max)}>{(level) => <option value={String(level)}>{gradeLevelLabel(level, t)}</option>}</For> | |
| 33 | + </Select> | |
| 34 | + ); | |
| 35 | +} |
src/components/users/profile-memberships.tsxmodified+11 -9
| @@ -8,6 +8,7 @@ import { TablePagination } from "@/components/ui/table-pagination"; | ||
| 8 | 8 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 9 | 9 | import { cn } from "@/lib/cn"; |
| 10 | 10 | import { personLabel } from "@/lib/person"; |
| 11 | +import { gradeLevelLabel } from "@/lib/grade-level"; | |
| 11 | 12 | import { useT } from "@/stores/preferences-context"; |
| 12 | 13 | |
| 13 | 14 | const PAGE_SIZE = 5; |
| @@ -78,13 +79,9 @@ export function ProfileMemberships(props: { | ||
| 78 | 79 | : t("classGroups.noTeacher")} |
| 79 | 80 | </span> |
| 80 | 81 | </span> |
| 81 | - <Show when={c.grade}> | |
| 82 | - {(g) => ( | |
| 83 | - <Badge variant="secondary" class="shrink-0 rounded-md"> | |
| 84 | - {g()} | |
| 85 | - </Badge> | |
| 86 | - )} | |
| 87 | - </Show> | |
| 82 | + <Badge variant="secondary" class="shrink-0 rounded-md"> | |
| 83 | + {gradeLevelLabel(c.grade_level, t)} | |
| 84 | + </Badge> | |
| 88 | 85 | </li> |
| 89 | 86 | )} |
| 90 | 87 | </For> |
| @@ -112,7 +109,7 @@ export function ProfileMemberships(props: { | ||
| 112 | 109 | <li> |
| 113 | 110 | <Link |
| 114 | 111 | to="/courses/$id" |
| 115 | - params={{ id: c.id }} | |
| 112 | + params={{ id: c.course }} | |
| 116 | 113 | class="flex items-center gap-3 rounded-lg border border-border/60 px-3 py-2.5 transition-colors hover:border-primary/40 hover:bg-muted/40" |
| 117 | 114 | > |
| 118 | 115 | <span |
| @@ -123,7 +120,12 @@ export function ProfileMemberships(props: { | ||
| 123 | 120 | > |
| 124 | 121 | <IconBook class="h-4 w-4" /> |
| 125 | 122 | </span> |
| 126 | - <span class="min-w-0 flex-1 truncate text-sm font-medium">{c.title}</span> | |
| 123 | + <span class="min-w-0 flex-1"> | |
| 124 | + <span class="block truncate text-sm font-medium">{c.title}</span> | |
| 125 | + <Show when={c.class_name}> | |
| 126 | + {(name) => <span class="block truncate text-xs text-muted-foreground">{name()}</span>} | |
| 127 | + </Show> | |
| 128 | + </span> | |
| 127 | 129 | <Badge variant="outline" class="shrink-0 rounded-md">{courseKindLabel(c.kind, t)}</Badge> |
| 128 | 130 | </Link> |
| 129 | 131 | </li> |
src/i18n/locales/en.tsmodified+9 -4
| @@ -116,13 +116,13 @@ export const en: Dict = { | ||
| 116 | 116 | "classBlueprints.filterCourses": "Filter courses", |
| 117 | 117 | "classBlueprints.noCourseMatch": "No course matches that filter.", |
| 118 | 118 | "classBlueprints.savedMatched": "Blueprint saved and applied to {count} class(es) at this grade.", |
| 119 | - "classBlueprints.noMatch": "Blueprint saved, but no class carries the grade \"{grade}\", so nothing was attached. Grades must match exactly — \"9\", \"9 \" and \"9-A\" are three different grades.", | |
| 119 | + "classBlueprints.noMatch": "Blueprint saved, but no class is at {grade}, so nothing was attached.", | |
| 120 | 120 | "classBlueprints.delete": "Delete blueprint", |
| 121 | 121 | "classBlueprints.deleteConfirm": |
| 122 | - "Delete the blueprint for grade {grade}? The courses it attached are detached from every class at this grade. Hand-attached courses stay.", | |
| 122 | + "Delete the {grade} blueprint? The courses it attached are detached from every class at this grade. Hand-attached courses stay.", | |
| 123 | 123 | "classBlueprints.deleted": "Blueprint deleted.", |
| 124 | 124 | "classBlueprints.status": "Check sync", |
| 125 | - "classBlueprints.statusTitle": "Sync status for grade {grade}", | |
| 125 | + "classBlueprints.statusTitle": "Sync status for {grade}", | |
| 126 | 126 | "classBlueprints.statusEmpty": "Every section at this grade carries the full template.", |
| 127 | 127 | "classBlueprints.statusSection": "Section", |
| 128 | 128 | "classBlueprints.statusMissing": "Missing courses", |
| @@ -130,7 +130,7 @@ export const en: Dict = { | ||
| 130 | 130 | "classBlueprints.applyHint": "Attaches this grade's blueprint courses to this class.", |
| 131 | 131 | "classBlueprints.applyNoGrade": "Assign a grade to this class first.", |
| 132 | 132 | "classBlueprints.applied": "Blueprint applied.", |
| 133 | - "classBlueprints.noBlueprintForGrade": "There is no blueprint for grade {grade} yet.", | |
| 133 | + "classBlueprints.noBlueprintForGrade": "There is no blueprint for {grade} yet.", | |
| 134 | 134 | "classBlueprints.conflictExists": "A blueprint already exists for this grade. Edit it from the list instead.", |
| 135 | 135 | "classBlueprints.staleReload": |
| 136 | 136 | "This blueprint changed while you were editing. The list has been refreshed — review it and save again.", |
| @@ -2456,4 +2456,9 @@ export const en: Dict = { | ||
| 2456 | 2456 | "errors.audienceOnlyDescription": "This view is shown only to the student or parent signed in to their own account; staff accounts do not open it.", |
| 2457 | 2457 | "errors.audienceOnlyWithAlternative": "This view is shown only to the student or parent signed in to their own account. The school-wide view of the same data is under management.", |
| 2458 | 2458 | "errors.openStaffView": "Open the management view", |
| 2459 | + "grade.kindergarten": "Kindergarten", | |
| 2460 | + "grade.level": "Grade {level}", | |
| 2461 | + "grade.select": "Select a grade", | |
| 2462 | + "instances.teachers": "Teachers", | |
| 2463 | + "instances.sectionsTruncated": "Showing {shown} of {total} sections; the full list is on the Classes page.", | |
| 2459 | 2464 | }; |
src/i18n/locales/tr.tsmodified+9 -4
| @@ -112,13 +112,13 @@ export const tr: Dict = { | ||
| 112 | 112 | "classBlueprints.filterCourses": "Derslerde ara", |
| 113 | 113 | "classBlueprints.noCourseMatch": "Bu aramayla eşleşen ders yok.", |
| 114 | 114 | "classBlueprints.savedMatched": "Şablon kaydedildi ve bu seviyedeki {count} şubeye uygulandı.", |
| 115 | - "classBlueprints.noMatch": "Şablon kaydedildi ama \"{grade}\" seviyesinde hiç şube yok, bu yüzden hiçbir şubeye ders eklenmedi. Seviye tam eşleşmeli — \"9\", \"9 \" ve \"9-A\" üç farklı seviyedir.", | |
| 115 | + "classBlueprints.noMatch": "Şablon kaydedildi ama {grade} seviyesinde hiç şube yok, bu yüzden hiçbir şubeye ders eklenmedi.", | |
| 116 | 116 | "classBlueprints.delete": "Şablonu sil", |
| 117 | 117 | "classBlueprints.deleteConfirm": |
| 118 | - "{grade} seviyesinin şablonu silinsin mi? Şablonun eklediği dersler bu seviyedeki her şubeden çıkarılır. Elle eklenen dersler kalır.", | |
| 118 | + "{grade} şablonu silinsin mi? Şablonun eklediği dersler bu seviyedeki her şubeden çıkarılır. Elle eklenen dersler kalır.", | |
| 119 | 119 | "classBlueprints.deleted": "Şablon silindi.", |
| 120 | 120 | "classBlueprints.status": "Eşitleme kontrolü", |
| 121 | - "classBlueprints.statusTitle": "{grade} seviyesi eşitleme durumu", | |
| 121 | + "classBlueprints.statusTitle": "{grade} eşitleme durumu", | |
| 122 | 122 | "classBlueprints.statusEmpty": "Bu seviyedeki her şube şablonun tamamını taşıyor.", |
| 123 | 123 | "classBlueprints.statusSection": "Şube", |
| 124 | 124 | "classBlueprints.statusMissing": "Eksik dersler", |
| @@ -126,7 +126,7 @@ export const tr: Dict = { | ||
| 126 | 126 | "classBlueprints.applyHint": "Bu seviyenin şablon derslerini bu şubeye ekler.", |
| 127 | 127 | "classBlueprints.applyNoGrade": "Önce bu şubeye bir seviye ata.", |
| 128 | 128 | "classBlueprints.applied": "Şablon uygulandı.", |
| 129 | - "classBlueprints.noBlueprintForGrade": "{grade} seviyesi için henüz bir şablon yok.", | |
| 129 | + "classBlueprints.noBlueprintForGrade": "{grade} için henüz bir şablon yok.", | |
| 130 | 130 | "classBlueprints.conflictExists": "Bu seviye için zaten bir şablon var. Bunun yerine listeden düzenle.", |
| 131 | 131 | "classBlueprints.staleReload": |
| 132 | 132 | "Sen düzenlerken bu şablon değişti. Liste yenilendi — gözden geçirip tekrar kaydet.", |
| @@ -2452,4 +2452,9 @@ export const tr: Dict = { | ||
| 2452 | 2452 | "errors.audienceOnlyDescription": "Bu görünüm yalnızca kendi hesabıyla giriş yapan öğrenci ya da veliye gösterilir; personel hesaplarında açılmaz.", |
| 2453 | 2453 | "errors.audienceOnlyWithAlternative": "Bu görünüm yalnızca kendi hesabıyla giriş yapan öğrenci ya da veliye gösterilir. Aynı bilgilerin okul geneli görünümü yönetim bölümünde.", |
| 2454 | 2454 | "errors.openStaffView": "Yönetim görünümünü aç", |
| 2455 | + "grade.kindergarten": "Anaokulu", | |
| 2456 | + "grade.level": "{level}. sınıf", | |
| 2457 | + "grade.select": "Seviye seçin", | |
| 2458 | + "instances.teachers": "Öğretmenler", | |
| 2459 | + "instances.sectionsTruncated": "{total} şubeden ilk {shown} tanesi gösteriliyor; tamamı Sınıflar sayfasında.", | |
| 2455 | 2460 | }; |
src/i18n/messages.tsmodified+6 -1
| @@ -2435,7 +2435,12 @@ export type MessageKey = | ||
| 2435 | 2435 | | "errors.parentOnlyTitle" |
| 2436 | 2436 | | "errors.audienceOnlyDescription" |
| 2437 | 2437 | | "errors.audienceOnlyWithAlternative" |
| 2438 | - | "errors.openStaffView"; | |
| 2438 | + | "errors.openStaffView" | |
| 2439 | + | "grade.kindergarten" | |
| 2440 | + | "grade.level" | |
| 2441 | + | "grade.select" | |
| 2442 | + | "instances.teachers" | |
| 2443 | + | "instances.sectionsTruncated"; | |
| 2439 | 2444 | |
| 2440 | 2445 | export type Dict = Record<MessageKey, string>; |
| 2441 | 2446 |
src/lib/command-search.test.tsmodified+3 -6
| @@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; | ||
| 2 | 2 | |
| 3 | 3 | const api = vi.hoisted(() => ({ |
| 4 | 4 | getCourses: vi.fn(), |
| 5 | - getMyCourses: vi.fn(), | |
| 6 | 5 | getExams: vi.fn(), |
| 7 | 6 | getHomework: vi.fn(), |
| 8 | 7 | getEvents: vi.fn(), |
| @@ -11,7 +10,6 @@ const api = vi.hoisted(() => ({ | ||
| 11 | 10 | })); |
| 12 | 11 | |
| 13 | 12 | vi.mock("@/api/courses", () => ({ getCourses: api.getCourses })); |
| 14 | -vi.mock("@/api/reports", () => ({ getMyCourses: api.getMyCourses })); | |
| 15 | 13 | vi.mock("@/api/exams", () => ({ getExams: api.getExams })); |
| 16 | 14 | vi.mock("@/api/homework", () => ({ getHomework: api.getHomework })); |
| 17 | 15 | vi.mock("@/api/events", () => ({ getEvents: api.getEvents })); |
| @@ -66,7 +64,6 @@ describe("loadCommandRecords", () => { | ||
| 66 | 64 | beforeEach(() => { |
| 67 | 65 | resetCommandRecordCache(); |
| 68 | 66 | api.getCourses.mockResolvedValue(page([{ id: "c1", title: "Biyoloji", description: "", kind: "course" }])); |
| 69 | - api.getMyCourses.mockResolvedValue(page([{ id: "c9", title: "Fizik", description: "", kind: "course" }])); | |
| 70 | 67 | api.getExams.mockResolvedValue( |
| 71 | 68 | page([ |
| 72 | 69 | { id: "e1", title: "Yazılı", description: "", class_course: "i1", starts_at: 5 }, |
| @@ -81,10 +78,10 @@ describe("loadCommandRecords", () => { | ||
| 81 | 78 | afterEach(() => vi.clearAllMocks()); |
| 82 | 79 | |
| 83 | 80 | test("a student reads their own courses and only exams in their own sections", async () => { |
| 81 | + // GET /courses is already scoped to the student's own courses. | |
| 84 | 82 | const out = await loadCommandRecords("student", ["course", "exam"]); |
| 85 | - expect(api.getMyCourses).toHaveBeenCalled(); | |
| 86 | - expect(api.getCourses).not.toHaveBeenCalled(); | |
| 87 | - expect(out.map((r) => r.id)).toEqual(["c9", "e1"]); | |
| 83 | + expect(api.getCourses).toHaveBeenCalled(); | |
| 84 | + expect(out.map((r) => r.id)).toEqual(["c1", "e1"]); | |
| 88 | 85 | expect(out[1].context).toBe("Biyoloji — 10-B"); |
| 89 | 86 | }); |
| 90 | 87 |
src/lib/command-search.tsmodified+3 -4
| @@ -3,7 +3,6 @@ import { getExams } from "@/api/exams"; | ||
| 3 | 3 | import { getEvents } from "@/api/events"; |
| 4 | 4 | import { getHomework } from "@/api/homework"; |
| 5 | 5 | import { getMyInstances } from "@/api/instances"; |
| 6 | -import { getMyCourses } from "@/api/reports"; | |
| 7 | 6 | import type { Role } from "@/api/client"; |
| 8 | 7 | import { LIST_CAP, loadCappedList } from "@/lib/capped-list"; |
| 9 | 8 | import { loadInstanceLabels } from "@/lib/instance-labels"; |
| @@ -71,9 +70,9 @@ export function filterCommandRecords( | ||
| 71 | 70 | return out; |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | -async function loadCourses(role: Role): Promise<CommandRecord[]> { | |
| 75 | - // As on /courses: a student's list is their own enrolments. | |
| 76 | - const page = role === "student" ? await getMyCourses() : await getCourses(); | |
| 73 | +async function loadCourses(): Promise<CommandRecord[]> { | |
| 74 | + // GET /courses is already scoped: a student's list is their own enrolments. | |
| 75 | + const page = await getCourses(); | |
| 77 | 76 | return page.items.map((course) => ({ |
| 78 | 77 | kind: "course", |
| 79 | 78 | id: course.id, |
src/lib/grade-level.tsadded+27 -0
| @@ -0,0 +1,27 @@ | ||
| 1 | +import type { MessageKey } from "@/i18n/messages"; | |
| 2 | + | |
| 3 | +type Translate = (key: MessageKey, params?: Record<string, string>) => string; | |
| 4 | + | |
| 5 | +/** The grade ladder the backend accepts: 0 (anaokulu) through 12. */ | |
| 6 | +export const MIN_GRADE_LEVEL = 0; | |
| 7 | +export const MAX_GRADE_LEVEL = 12; | |
| 8 | + | |
| 9 | +/** "Anaokulu" at the floor, "9. sınıf" elsewhere. */ | |
| 10 | +export function gradeLevelLabel(level: number, t: Translate): string { | |
| 11 | + return level === 0 ? t("grade.kindergarten") : t("grade.level", { level: String(level) }); | |
| 12 | +} | |
| 13 | + | |
| 14 | +/** Every rung between the published bounds, lowest first. */ | |
| 15 | +export function gradeLevels(min = MIN_GRADE_LEVEL, max = MAX_GRADE_LEVEL): number[] { | |
| 16 | + const levels: number[] = []; | |
| 17 | + for (let level = min; level <= max; level++) levels.push(level); | |
| 18 | + return levels; | |
| 19 | +} | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * The backend's own text for a rung ("Anaokulu", "1".."12") — what a RAG | |
| 23 | + * scope pair names as `sinif`. Not a display string; use gradeLevelLabel. | |
| 24 | + */ | |
| 25 | +export function gradeLevelWireLabel(level: number): string { | |
| 26 | + return level === 0 ? "Anaokulu" : String(level); | |
| 27 | +} |
src/lib/question-generation.tsmodified+7 -4
| @@ -2,6 +2,7 @@ import { getClasses } from "@/api/classes"; | ||
| 2 | 2 | import type { ClassGroup, Course } from "@/api/client"; |
| 3 | 3 | import { getCourseById } from "@/api/courses"; |
| 4 | 4 | import { getMyInstances } from "@/api/instances"; |
| 5 | +import { gradeLevelWireLabel } from "@/lib/grade-level"; | |
| 5 | 6 | import { FAN_OUT_LIMIT, mapConcurrent } from "@/lib/map-concurrent"; |
| 6 | 7 | |
| 7 | 8 | /** Pages one request may name; a wider range is almost always a typo. */ |
| @@ -54,7 +55,7 @@ export async function loadStudyScopes(): Promise<StudyScopeOption[]> { | ||
| 54 | 55 | getMyInstances({ limit: 200 }), |
| 55 | 56 | getClasses({ limit: 200 }).catch(() => ({ items: [] as ClassGroup[] })), |
| 56 | 57 | ]); |
| 57 | - const gradeOf = new Map(classes.items.map((klass) => [klass.id, klass.grade])); | |
| 58 | + const gradeOf = new Map(classes.items.map((klass) => [klass.id, gradeLevelWireLabel(klass.grade_level)])); | |
| 58 | 59 | const courseIds = [...new Set(instances.items.map((instance) => instance.course))]; |
| 59 | 60 | const courses = await mapConcurrent(courseIds, FAN_OUT_LIMIT, (id) => getCourseById(id).catch(() => null)); |
| 60 | 61 | const courseById = new Map(courses.filter((course): course is Course => course !== null).map((course) => [course.id, course])); |
| @@ -63,10 +64,12 @@ export async function loadStudyScopes(): Promise<StudyScopeOption[]> { | ||
| 63 | 64 | for (const instance of instances.items) { |
| 64 | 65 | const course = courseById.get(instance.course); |
| 65 | 66 | if (!course) continue; |
| 66 | - const sinif = course.kind === "course" ? gradeOf.get(instance.class)?.trim() || null : null; | |
| 67 | - const key = `${course.title}\u0000${sinif ?? ""}`; | |
| 67 | + const sinif = course.kind === "course" ? gradeOf.get(instance.class) ?? null : null; | |
| 68 | + // The backend names a section's pair by its resolved title, not the catalog's. | |
| 69 | + const ders = instance.title || course.title; | |
| 70 | + const key = `${ders}\u0000${sinif ?? ""}`; | |
| 68 | 71 | if (!options.has(key)) { |
| 69 | - options.set(key, { key, ders: course.title, sinif, course, label: sinif ? `${course.title} · ${sinif}` : course.title }); | |
| 72 | + options.set(key, { key, ders, sinif, course, label: sinif ? `${ders} · ${sinif}` : ders }); | |
| 70 | 73 | } |
| 71 | 74 | } |
| 72 | 75 | return [...options.values()].sort((a, b) => a.label.localeCompare(b.label, "tr")); |
src/lib/student-directory.tsmodified+1 -3
| @@ -29,9 +29,7 @@ const collator = new Intl.Collator("tr", { numeric: true, sensitivity: "base" }) | ||
| 29 | 29 | |
| 30 | 30 | /** Class order a school reads rosters in: grade (9 before 10), then the şube name. */ |
| 31 | 31 | export function compareClasses(a: ClassGroup, b: ClassGroup): number { |
| 32 | - const gradeA = Number.parseInt(a.grade ?? a.name, 10); | |
| 33 | - const gradeB = Number.parseInt(b.grade ?? b.name, 10); | |
| 34 | - if (Number.isFinite(gradeA) && Number.isFinite(gradeB) && gradeA !== gradeB) return gradeA - gradeB; | |
| 32 | + if (a.grade_level !== b.grade_level) return a.grade_level - b.grade_level; | |
| 35 | 33 | return collator.compare(a.name, b.name); |
| 36 | 34 | } |
| 37 | 35 |
src/pages/academic-years-page.tsxmodified+15 -19
| @@ -30,6 +30,7 @@ import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 30 | 30 | import { createFlash } from "@/lib/flash"; |
| 31 | 31 | import { formatDate } from "@/lib/format"; |
| 32 | 32 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 33 | +import { GradeLevelSelect } from "@/components/classes/grade-level-select"; | |
| 33 | 34 | |
| 34 | 35 | const YEAR_PAGE_SIZE = 10; |
| 35 | 36 | |
| @@ -70,7 +71,8 @@ function AcademicYearsContent() { | ||
| 70 | 71 | const [name, setName] = createSignal(""); |
| 71 | 72 | const [starts, setStarts] = createSignal(""); |
| 72 | 73 | const [ends, setEnds] = createSignal(""); |
| 73 | - const [promotions, setPromotions] = createSignal<GradePromotion[]>([]); | |
| 74 | + // A row being written may still have a half unpicked. | |
| 75 | + const [promotions, setPromotions] = createSignal<{ from_grade: number | null; to_grade: number | null }[]>([]); | |
| 74 | 76 | const [editing, setEditing] = createSignal<AcademicYear | null>(null); |
| 75 | 77 | const [deleteTarget, setDeleteTarget] = createSignal<AcademicYear | null>(null); |
| 76 | 78 | const [detail, setDetail] = createSignal<AcademicYear | null>(null); |
| @@ -120,9 +122,9 @@ function AcademicYearsContent() { | ||
| 120 | 122 | } |
| 121 | 123 | // A blank half is a half-written rule, not a policy — drop it rather than |
| 122 | 124 | // sending a promotion the rollover cannot act on. |
| 123 | - const grade_promotions = promotions() | |
| 124 | - .map((pair) => ({ from_grade: pair.from_grade.trim(), to_grade: pair.to_grade.trim() })) | |
| 125 | - .filter((pair) => pair.from_grade && pair.to_grade); | |
| 125 | + const grade_promotions = promotions().filter( | |
| 126 | + (pair): pair is GradePromotion => pair.from_grade !== null && pair.to_grade !== null, | |
| 127 | + ); | |
| 126 | 128 | |
| 127 | 129 | setPending(true); |
| 128 | 130 | try { |
| @@ -346,7 +348,7 @@ function AcademicYearsContent() { | ||
| 346 | 348 | size="sm" |
| 347 | 349 | variant="outline" |
| 348 | 350 | class="rounded-lg" |
| 349 | - onClick={() => setPromotions((rows) => [...rows, { from_grade: "", to_grade: "" }])} | |
| 351 | + onClick={() => setPromotions((rows) => [...rows, { from_grade: null, to_grade: null }])} | |
| 350 | 352 | > |
| 351 | 353 | <IconPlus class="h-4 w-4" /> |
| 352 | 354 | {t("academicYears.addPromotion")} |
| @@ -355,24 +357,18 @@ function AcademicYearsContent() { | ||
| 355 | 357 | <For each={promotions()}> |
| 356 | 358 | {(pair, index) => ( |
| 357 | 359 | <div class="grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] items-center gap-2"> |
| 358 | - <Input | |
| 359 | - aria-label={t("academicYears.fromGrade")} | |
| 360 | - class="h-9 rounded-md" | |
| 361 | - maxlength={20} | |
| 360 | + <GradeLevelSelect | |
| 361 | + id={`promotion-from-${index()}`} | |
| 362 | 362 | value={pair.from_grade} |
| 363 | - placeholder={t("academicYears.fromGrade")} | |
| 364 | - onInput={(e) => | |
| 365 | - setPromotions((rows) => rows.map((row, i) => (i === index() ? { ...row, from_grade: e.currentTarget.value } : row))) | |
| 363 | + onChange={(level) => | |
| 364 | + setPromotions((rows) => rows.map((row, i) => (i === index() ? { ...row, from_grade: level } : row))) | |
| 366 | 365 | } |
| 367 | 366 | /> |
| 368 | - <Input | |
| 369 | - aria-label={t("academicYears.toGrade")} | |
| 370 | - class="h-9 rounded-md" | |
| 371 | - maxlength={20} | |
| 367 | + <GradeLevelSelect | |
| 368 | + id={`promotion-to-${index()}`} | |
| 372 | 369 | value={pair.to_grade} |
| 373 | - placeholder={t("academicYears.toGrade")} | |
| 374 | - onInput={(e) => | |
| 375 | - setPromotions((rows) => rows.map((row, i) => (i === index() ? { ...row, to_grade: e.currentTarget.value } : row))) | |
| 370 | + onChange={(level) => | |
| 371 | + setPromotions((rows) => rows.map((row, i) => (i === index() ? { ...row, to_grade: level } : row))) | |
| 376 | 372 | } |
| 377 | 373 | /> |
| 378 | 374 | <Button |
src/pages/calendar-page.test.tsxmodified+0 -1
| @@ -25,7 +25,6 @@ vi.mock("@/api/exams", () => ({ getExams })); | ||
| 25 | 25 | vi.mock("@/api/homework", () => ({ getHomework: vi.fn(async () => page([])) })); |
| 26 | 26 | vi.mock("@/api/appointments", () => ({ getAppointments: vi.fn(async () => page([])) })); |
| 27 | 27 | vi.mock("@/api/courses", () => ({ getCourses: vi.fn(async () => page([])) })); |
| 28 | -vi.mock("@/api/reports", () => ({ getMyCourses: vi.fn(async () => page([])) })); | |
| 29 | 28 | vi.mock("@/api/instances", () => ({ |
| 30 | 29 | getMyInstances: vi.fn(async () => page([])), |
| 31 | 30 | getInstanceSessions: vi.fn(async () => page([])), |
src/pages/calendar-page.tsxmodified+2 -3
| @@ -8,7 +8,6 @@ import { getHomework } from "@/api/homework"; | ||
| 8 | 8 | import { getAppointments } from "@/api/appointments"; |
| 9 | 9 | import { getCourses } from "@/api/courses"; |
| 10 | 10 | import { getInstanceSessions, getMyInstances } from "@/api/instances"; |
| 11 | -import { getMyCourses } from "@/api/reports"; | |
| 12 | 11 | import type { Appointment, AppointmentStatus, Course } from "@/api/client"; |
| 13 | 12 | import { appointmentStatusClass, appointmentStatusDotClass, appointmentStatusLabelKey } from "@/lib/appointment-status"; |
| 14 | 13 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -214,12 +213,12 @@ function CalendarContent() { | ||
| 214 | 213 | // own `kind` is what separates them. |
| 215 | 214 | const [sessions] = board.createResource( |
| 216 | 215 | () => auth.user()?.role ?? null, |
| 217 | - async (role) => { | |
| 216 | + async () => { | |
| 218 | 217 | // Sessions hang off the instance (şube × ders) now; the catalog course is |
| 219 | 218 | // still what says whether a meeting is a ders, an etüt or a kulüp. |
| 220 | 219 | const [instances, courses] = await Promise.all([ |
| 221 | 220 | getMyInstances({ limit: 200 }), |
| 222 | - role === "student" ? getMyCourses() : getCourses(), | |
| 221 | + getCourses(), | |
| 223 | 222 | ]); |
| 224 | 223 | const byId = new Map<string, Course>(courses.items.map((course) => [course.id, course])); |
| 225 | 224 | const pages = await mapConcurrent( |
src/pages/class-detail-page.tsxmodified+7 -5
| @@ -43,6 +43,7 @@ import { matchesSearch } from "@/lib/search-text"; | ||
| 43 | 43 | import { createUrlString } from "@/lib/url-state"; |
| 44 | 44 | import { useAuth } from "@/stores/auth-context"; |
| 45 | 45 | import { useT } from "@/stores/preferences-context"; |
| 46 | +import { gradeLevelLabel } from "@/lib/grade-level"; | |
| 46 | 47 | import { RecordNotFound } from "@/components/layout/record-not-found"; |
| 47 | 48 | import { isNotFoundError } from "@/lib/record-list-path"; |
| 48 | 49 | |
| @@ -297,9 +298,9 @@ function ClassDetailContent() { | ||
| 297 | 298 | size="sm" |
| 298 | 299 | variant="outline" |
| 299 | 300 | class={cn(ACTION_BUTTON, "w-full")} |
| 300 | - disabled={pending() || !c().grade} | |
| 301 | - title={c().grade ? t("classBlueprints.applyHint") : t("classBlueprints.applyNoGrade")} | |
| 302 | - onClick={() => void applyBlueprint(c().grade ?? "")} | |
| 301 | + disabled={pending()} | |
| 302 | + title={t("classBlueprints.applyHint")} | |
| 303 | + onClick={() => void applyBlueprint(gradeLevelLabel(c().grade_level, t))} | |
| 303 | 304 | > |
| 304 | 305 | <IconListChecks class="h-4 w-4" /> |
| 305 | 306 | {t("classBlueprints.apply")} |
| @@ -332,7 +333,7 @@ function ClassDetailContent() { | ||
| 332 | 333 | <div class="grid gap-3 border-t border-border-hairline pt-3 pb-1 text-sm grid-cols-2 lg:grid-cols-5"> |
| 333 | 334 | <div class={TILE}> |
| 334 | 335 | <p class={TILE_LABEL}>{t("classGroups.grade")}</p> |
| 335 | - <p class={TILE_VALUE}>{c().grade || "—"}</p> | |
| 336 | + <p class={TILE_VALUE}>{gradeLevelLabel(c().grade_level, t)}</p> | |
| 336 | 337 | </div> |
| 337 | 338 | <div class={TILE}> |
| 338 | 339 | <p class={TILE_LABEL}>{t("academicYears.year")}</p> |
| @@ -428,7 +429,8 @@ function ClassDetailContent() { | ||
| 428 | 429 | onOpenChange={setEditing} |
| 429 | 430 | years={years.latest ?? []} |
| 430 | 431 | maxNameLen={limits.latest?.course.max_class_name_len} |
| 431 | - maxGradeLen={limits.latest?.course.max_class_grade_len} | |
| 432 | + minGradeLevel={limits.latest?.course.min_grade_level} | |
| 433 | + maxGradeLevel={limits.latest?.course.max_grade_level} | |
| 432 | 434 | onSaved={async () => { setFlash(t("common.saved")); await refresh(refetchClass); }} |
| 433 | 435 | /> |
| 434 | 436 |
src/pages/classes-page.test.tsxmodified+5 -4
| @@ -29,12 +29,12 @@ vi.mock("@/stores/auth-context", () => ({ | ||
| 29 | 29 | vi.mock("@/api/classes", () => ({ getClasses, getClassMembers, postClass })); |
| 30 | 30 | vi.mock("@/api/academic-years", () => ({ getAcademicYears: vi.fn(async () => ({ items: [] })) })); |
| 31 | 31 | vi.mock("@/api/limits", () => ({ |
| 32 | - getLimits: vi.fn(async () => ({ course: { max_class_name_len: 60, max_class_grade_len: 10 } })), | |
| 32 | + getLimits: vi.fn(async () => ({ course: { max_class_name_len: 60, min_grade_level: 0, max_grade_level: 12 } })), | |
| 33 | 33 | })); |
| 34 | 34 | vi.mock("@/api/courses", () => ({ getCourses })); |
| 35 | 35 | vi.mock("@/api/users", () => ({ getUserSearch: vi.fn(async () => ({ items: [] })) })); |
| 36 | 36 | |
| 37 | -const createdClass = { id: "c-new", creator: null, name: "9-A", grade: "9", year: null, teacher: null }; | |
| 37 | +const createdClass = { id: "c-new", creator: null, name: "9-A", grade_level: 9, year: null, teacher: null }; | |
| 38 | 38 | |
| 39 | 39 | afterEach(() => { |
| 40 | 40 | cleanup(); |
| @@ -48,6 +48,7 @@ async function openCreateForm() { | ||
| 48 | 48 | |
| 49 | 49 | fireEvent.click(await screen.findByRole("button", { name: /New class/ })); |
| 50 | 50 | fireEvent.input(await screen.findByLabelText(/^Name/), { target: { value: "9-A" } }); |
| 51 | + fireEvent.change(document.getElementById("class-grade")!, { target: { value: "9" } }); | |
| 51 | 52 | fireEvent.click(screen.getByRole("button", { name: "Create" })); |
| 52 | 53 | } |
| 53 | 54 | |
| @@ -61,14 +62,14 @@ test("creating a class opens the class the server made", async () => { | ||
| 61 | 62 | await waitFor(() => |
| 62 | 63 | expect(navigate).toHaveBeenCalledWith({ to: "/management/classes/$id", params: { id: "c-new" } }), |
| 63 | 64 | ); |
| 64 | - expect(postClass).toHaveBeenCalledWith({ name: "9-A", grade: undefined, year: undefined, teacher_id: undefined }); | |
| 65 | + expect(postClass).toHaveBeenCalledWith({ name: "9-A", grade_level: 9, year: undefined, teacher_id: undefined }); | |
| 65 | 66 | }); |
| 66 | 67 | |
| 67 | 68 | test("a create whose blueprint left pairs behind holds the page until the report closes", async () => { |
| 68 | 69 | postClass.mockResolvedValue({ |
| 69 | 70 | class: createdClass, |
| 70 | 71 | skipped: [{ class: "c-new", class_name: "9-A", course: "k1", reason: "the class is already at its course ceiling" }], |
| 71 | - stocked_from: "9", | |
| 72 | + stocked_from: 9, | |
| 72 | 73 | }); |
| 73 | 74 | getCourses.mockResolvedValue({ items: [{ id: "k1", title: "Algebra" }] }); |
| 74 | 75 |
src/pages/classes-page.tsxmodified+27 -21
| @@ -32,6 +32,8 @@ import { compareClasses } from "@/lib/student-directory"; | ||
| 32 | 32 | import { createUrlString } from "@/lib/url-state"; |
| 33 | 33 | import { useAuth } from "@/stores/auth-context"; |
| 34 | 34 | import { useT } from "@/stores/preferences-context"; |
| 35 | +import { GradeLevelSelect } from "@/components/classes/grade-level-select"; | |
| 36 | +import { gradeLevelLabel } from "@/lib/grade-level"; | |
| 35 | 37 | |
| 36 | 38 | // A class's member count has no aggregate field on ClassGroup and no bulk |
| 37 | 39 | // endpoint — each card's count is one `getClassMembers(id, {limit:1})` read |
| @@ -54,7 +56,8 @@ function ClassesContent() { | ||
| 54 | 56 | const [gradeFilter, setGradeFilter] = createUrlString("grade", "all"); |
| 55 | 57 | const [showForm, setShowForm] = createSignal(false); |
| 56 | 58 | const [name, setName] = createSignal(""); |
| 57 | - const [grade, setGrade] = createSignal(""); | |
| 59 | + const [gradeLevel, setGradeLevel] = createSignal<number | null>(null); | |
| 60 | + const [gradeError, setGradeError] = createSignal(""); | |
| 58 | 61 | const [yearId, setYearId] = createSignal(""); |
| 59 | 62 | const [teacherId, setTeacherId] = createSignal(""); |
| 60 | 63 | const [error, setError] = createSignal(""); |
| @@ -75,15 +78,8 @@ function ClassesContent() { | ||
| 75 | 78 | const listData = () => list.latest ?? list() ?? []; |
| 76 | 79 | const yearName = (id: string | null) => (id ? years.latest?.find((year) => year.id === id)?.name ?? "—" : t("academicYears.unassigned")); |
| 77 | 80 | |
| 78 | - // Grade tabs mirror Figma's Tümü/Lise/Ortaokul row structurally, but the | |
| 79 | - // labels are read from whatever `grade` values this school actually uses | |
| 80 | - // (freeform text on ClassGroup) instead of assuming a Turkish lise/ortaokul | |
| 81 | - // split that may not hold for every institution. | |
| 82 | - const grades = createMemo(() => { | |
| 83 | - const seen = new Set<string>(); | |
| 84 | - for (const cls of listData()) if (cls.grade) seen.add(cls.grade); | |
| 85 | - return [...seen].sort((a, b) => a.localeCompare(b, "tr")); | |
| 86 | - }); | |
| 81 | + // The grade filter offers only the rungs this school's classes sit on. | |
| 82 | + const grades = createMemo(() => [...new Set(listData().map((cls) => cls.grade_level))].sort((a, b) => a - b)); | |
| 87 | 83 | |
| 88 | 84 | const memberCountIds = createMemo(() => { |
| 89 | 85 | const ids = listData().map((cls) => cls.id); |
| @@ -104,7 +100,7 @@ function ClassesContent() { | ||
| 104 | 100 | // Class by class (9-A, 9-B, 10-A…) until a column header re-sorts it. |
| 105 | 101 | const gradeFiltered = createMemo(() => { |
| 106 | 102 | const g = gradeFilter(); |
| 107 | - return (g === "all" ? listData() : listData().filter((cls) => cls.grade === g)).slice().sort(compareClasses); | |
| 103 | + return (g === "all" ? listData() : listData().filter((cls) => String(cls.grade_level) === g)).slice().sort(compareClasses); | |
| 108 | 104 | }); |
| 109 | 105 | // A fresh array once the member counts land: the table redraws a row only |
| 110 | 106 | // when its data changes, so the counts would otherwise stay "—". |
| @@ -145,7 +141,7 @@ function ClassesContent() { | ||
| 145 | 141 | } catch (err) { |
| 146 | 142 | // A 404 here means no blueprint covers this grade, not a missing class. |
| 147 | 143 | setRowError(err instanceof ApiError && err.status === 404 |
| 148 | - ? t("classBlueprints.noBlueprintForGrade", { grade: cls.grade ?? "" }) | |
| 144 | + ? t("classBlueprints.noBlueprintForGrade", { grade: gradeLevelLabel(cls.grade_level, t) }) | |
| 149 | 145 | : formatApiError(err)); |
| 150 | 146 | } finally { |
| 151 | 147 | setPending(false); |
| @@ -162,12 +158,12 @@ function ClassesContent() { | ||
| 162 | 158 | }, |
| 163 | 159 | { |
| 164 | 160 | id: "grade", |
| 165 | - accessorFn: (row) => row.grade ?? "", | |
| 161 | + accessorFn: (row) => row.grade_level, | |
| 166 | 162 | header: t("classGroups.grade"), |
| 167 | 163 | size: 90, |
| 168 | 164 | minSize: 80, |
| 169 | 165 | meta: { cellClass: "whitespace-nowrap text-center", align: "center" }, |
| 170 | - cell: (cell) => cell.row.original.grade || "—", | |
| 166 | + cell: (cell) => gradeLevelLabel(cell.row.original.grade_level, t), | |
| 171 | 167 | }, |
| 172 | 168 | { |
| 173 | 169 | id: "year", |
| @@ -213,7 +209,7 @@ function ClassesContent() { | ||
| 213 | 209 | { |
| 214 | 210 | label: t("classBlueprints.apply"), |
| 215 | 211 | icon: <IconListChecks class="h-4 w-4" />, |
| 216 | - disabled: pending() || !cell.row.original.grade, | |
| 212 | + disabled: pending(), | |
| 217 | 213 | onSelect: () => void applyBlueprint(cell.row.original), |
| 218 | 214 | }, |
| 219 | 215 | { label: t("classGroups.deleteClass"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteTarget(cell.row.original) }, |
| @@ -236,15 +232,20 @@ function ClassesContent() { | ||
| 236 | 232 | document.getElementById("class-name")?.focus(); |
| 237 | 233 | return; |
| 238 | 234 | } |
| 235 | + const level = gradeLevel(); | |
| 236 | + if (level === null) { | |
| 237 | + setGradeError(t("form.fieldRequired")); | |
| 238 | + return; | |
| 239 | + } | |
| 239 | 240 | setPending(true); |
| 240 | 241 | try { |
| 241 | 242 | const created = await postClass({ |
| 242 | 243 | name: name().trim(), |
| 243 | - grade: grade().trim() || undefined, | |
| 244 | + grade_level: level, | |
| 244 | 245 | year: yearId() || undefined, |
| 245 | 246 | teacher_id: teacherId() || undefined, |
| 246 | 247 | }); |
| 247 | - setName(""); setGrade(""); setYearId(""); setTeacherId(""); setShowForm(false); | |
| 248 | + setName(""); setGradeLevel(null); setYearId(""); setTeacherId(""); setShowForm(false); | |
| 248 | 249 | // Reloading the list is housekeeping for a page we are leaving anyway: a |
| 249 | 250 | // failure here used to be reported as if the class had not been created, |
| 250 | 251 | // and it swallowed the navigation to the class that plainly existed. |
| @@ -297,7 +298,11 @@ function ClassesContent() { | ||
| 297 | 298 | <form class="space-y-4" noValidate onSubmit={createClass}> |
| 298 | 299 | <div class="space-y-3"> |
| 299 | 300 | <div class="space-y-1.5"><Label for="class-name">{t("classGroups.className")}<span class="ml-0.5 text-destructive-text">*</span></Label><Input id="class-name" required aria-required="true" maxlength={limits.latest?.course.max_class_name_len} value={name()} error={nameError()} onInput={(e) => { setName(e.currentTarget.value); setNameError(""); }} /></div> |
| 300 | - <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> | |
| 301 | + <div class="space-y-1.5"> | |
| 302 | + <Label for="class-grade">{t("classGroups.grade")}<span class="ml-0.5 text-destructive-text">*</span></Label> | |
| 303 | + <GradeLevelSelect id="class-grade" value={gradeLevel()} error={!!gradeError()} min={limits.latest?.course.min_grade_level} max={limits.latest?.course.max_grade_level} onChange={(level) => { setGradeLevel(level); setGradeError(""); }} /> | |
| 304 | + <Show when={gradeError()}><p class="text-xs font-medium text-destructive-text">{gradeError()}</p></Show> | |
| 305 | + </div> | |
| 301 | 306 | <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> |
| 302 | 307 | <UserSearchSelect id="class-teacher" label={t("classGroups.homeroomTeacher")} value={teacherId()} onChange={setTeacherId} placeholder={t("classGroups.selectTeacher")} role="teacher" /> |
| 303 | 308 | </div> |
| @@ -312,7 +317,8 @@ function ClassesContent() { | ||
| 312 | 317 | onOpenChange={(open) => { if (!open) setEditTarget(null); }} |
| 313 | 318 | years={years.latest ?? []} |
| 314 | 319 | maxNameLen={limits.latest?.course.max_class_name_len} |
| 315 | - maxGradeLen={limits.latest?.course.max_class_grade_len} | |
| 320 | + minGradeLevel={limits.latest?.course.min_grade_level} | |
| 321 | + maxGradeLevel={limits.latest?.course.max_grade_level} | |
| 316 | 322 | onSaved={async () => { setFlash(t("common.saved")); await refreshList(); }} |
| 317 | 323 | /> |
| 318 | 324 | |
| @@ -380,7 +386,7 @@ function ClassesContent() { | ||
| 380 | 386 | columns={columns()} |
| 381 | 387 | data={rows()} |
| 382 | 388 | tableClass="table-fixed min-w-[48rem]" |
| 383 | - searchPredicate={(cls, needle) => matchesSearch(needle, cls.name, cls.grade, cls.teacher ? personLabel(cls.teacher) : null)} | |
| 389 | + searchPredicate={(cls, needle) => matchesSearch(needle, cls.name, gradeLevelLabel(cls.grade_level, t), cls.teacher ? personLabel(cls.teacher) : null)} | |
| 384 | 390 | filterPlaceholder={t("classGroups.searchPlaceholder")} |
| 385 | 391 | filterHint={t("search.hint.classes")} |
| 386 | 392 | enablePagination |
| @@ -395,7 +401,7 @@ function ClassesContent() { | ||
| 395 | 401 | <Show when={grades().length > 0}> |
| 396 | 402 | <DropdownSelect |
| 397 | 403 | labelPrefix={t("classGroups.grade")} |
| 398 | - options={[{ value: "all", label: t("common.all") }, ...grades().map((g) => ({ value: g, label: g }))]} | |
| 404 | + options={[{ value: "all", label: t("common.all") }, ...grades().map((g) => ({ value: String(g), label: gradeLevelLabel(g, t) }))]} | |
| 399 | 405 | value={gradeFilter()} |
| 400 | 406 | onChange={setGradeFilter} |
| 401 | 407 | /> |
src/pages/course-detail-page.tsxmodified+47 -58
| @@ -7,11 +7,9 @@ import { deleteCourseMemberByUserId } from "@/api/courses"; | ||
| 7 | 7 | import { getCourseById } from "@/api/courses"; |
| 8 | 8 | import { getCourseMembers } from "@/api/courses"; |
| 9 | 9 | import { postCourseMember } from "@/api/courses"; |
| 10 | -import { getClasses, getClassInstances, getMyClasses } from "@/api/classes"; | |
| 11 | -import { getMyInstances } from "@/api/instances"; | |
| 12 | -import { getMyCourses } from "@/api/reports"; | |
| 10 | +import { getCourses } from "@/api/courses"; | |
| 13 | 11 | import { formatApiError } from "@/api/client"; |
| 14 | -import type { ClassCourse, ClassGroup, CourseKind, CourseMembership, Instance } from "@/api/client"; | |
| 12 | +import type { CourseKind, CourseMembership, CourseSectionRef } from "@/api/client"; | |
| 15 | 13 | import { CourseEditPanel } from "@/components/courses/course-edit-panel"; |
| 16 | 14 | import { CourseNotesPanel } from "@/components/courses/course-notes-panel"; |
| 17 | 15 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; |
| @@ -19,7 +17,6 @@ import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 19 | 17 | import { PageHeader } from "@/components/layout/page-header"; |
| 20 | 18 | import { Breadcrumbs } from "@/components/layout/breadcrumbs"; |
| 21 | 19 | import { Alert } from "@/components/ui/alert"; |
| 22 | -import { Badge } from "@/components/ui/badge"; | |
| 23 | 20 | import { Button } from "@/components/ui/button"; |
| 24 | 21 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 25 | 22 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; |
| @@ -38,9 +35,9 @@ import { hasMinRole } from "@/lib/roles"; | ||
| 38 | 35 | import { createUrlString } from "@/lib/url-state"; |
| 39 | 36 | import { cn } from "@/lib/cn"; |
| 40 | 37 | import { matchesSearch } from "@/lib/search-text"; |
| 38 | +import { gradeLevelLabel } from "@/lib/grade-level"; | |
| 39 | +import { personLabel } from "@/lib/person"; | |
| 41 | 40 | |
| 42 | -/** One row of the "taught in" list: an instance plus the şube's name. */ | |
| 43 | -type SectionRow = { instance: Instance | ClassCourse; className: string }; | |
| 44 | 41 | |
| 45 | 42 | // Literal class names so Tailwind sees every column count the tab strip can take. |
| 46 | 43 | const TAB_GRID_COLS: Record<number, string> = { 1: "sm:grid-cols-1", 2: "sm:grid-cols-2", 3: "sm:grid-cols-3", 4: "sm:grid-cols-4" }; |
| @@ -88,9 +85,10 @@ function CourseDetailContent() { | ||
| 88 | 85 | return tabs.length === 0 || tabs.includes(requestedTab()) ? requestedTab() : tabs[0]; |
| 89 | 86 | }; |
| 90 | 87 | const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); |
| 88 | + // GET /courses is already scoped to a student's own courses. | |
| 91 | 89 | const [mine] = createResource( |
| 92 | 90 | () => (auth.user()?.role === "student" ? true : null), |
| 93 | - async (enabled) => (enabled ? (await getMyCourses()).items : []), | |
| 91 | + async (enabled) => (enabled ? (await getCourses()).items : []), | |
| 94 | 92 | ); |
| 95 | 93 | |
| 96 | 94 | // Catalog rights: the creator or a manager+. Teaching rights now live on the |
| @@ -106,37 +104,14 @@ function CourseDetailContent() { | ||
| 106 | 104 | // — its students come from the şube that attached it. |
| 107 | 105 | const hasMembers = () => course()?.kind === "club" || course()?.kind === "study"; |
| 108 | 106 | |
| 109 | - // The şubeler teaching this course. A student or teacher reads their own set | |
| 110 | - // in one call; the office has no course-scoped instance route, so it walks | |
| 111 | - // the class list instead (one call per class, capped by the page limit). | |
| 112 | - const [sections] = createResource( | |
| 113 | - () => (course() && tabOn.sections() ? { courseId: id(), office: isOffice() } : null), | |
| 114 | - async (args): Promise<SectionRow[]> => { | |
| 115 | - if (!args) return []; | |
| 116 | - if (!args.office) { | |
| 117 | - // `/instances/me` is the one instance list a student or teacher can | |
| 118 | - // read; `/classes/me` names the şubeler behind it (one call each). | |
| 119 | - const [instances, classes] = await Promise.all([ | |
| 120 | - getMyInstances({ limit: 200 }), | |
| 121 | - getMyClasses({ limit: 200 }).catch(() => ({ items: [] as ClassGroup[] })), | |
| 122 | - ]); | |
| 123 | - const names = new Map(classes.items.map((klass) => [klass.id, klass.name])); | |
| 124 | - return instances.items | |
| 125 | - .filter((instance) => instance.course === args.courseId) | |
| 126 | - .map((instance) => ({ instance, className: names.get(instance.class) ?? "—" })); | |
| 127 | - } | |
| 128 | - const classes = (await getClasses({ limit: 200 })).items; | |
| 129 | - const perClass = await Promise.all( | |
| 130 | - classes.map(async (klass) => { | |
| 131 | - const instances = (await getClassInstances(klass.id, { limit: 200 })).items; | |
| 132 | - return instances | |
| 133 | - .filter((instance) => instance.course === args.courseId) | |
| 134 | - .map((instance) => ({ instance, className: klass.name })); | |
| 135 | - }), | |
| 136 | - ); | |
| 137 | - return perClass.flat(); | |
| 138 | - }, | |
| 139 | - ); | |
| 107 | + // The şubeler teaching this course ride the catalog row itself, already | |
| 108 | + // narrowed to the sections this reader reaches and capped at | |
| 109 | + // limits.course.max_course_sections; class_course_count keeps the total. | |
| 110 | + const sections = () => course()?.sections ?? []; | |
| 111 | + const sectionsTruncated = () => { | |
| 112 | + const c = course(); | |
| 113 | + return !!c && isOffice() && c.class_course_count > c.sections.length; | |
| 114 | + }; | |
| 140 | 115 | |
| 141 | 116 | const [members, { refetch: refetchMembers }] = createResource( |
| 142 | 117 | () => (hasMembers() && canManageCatalog() ? id() : null), |
| @@ -166,47 +141,56 @@ function CourseDetailContent() { | ||
| 166 | 141 | const courseKindLabel = (value: CourseKind | undefined) => |
| 167 | 142 | value === "study" ? t("courses.kind.study") : value === "club" ? t("courses.kind.club") : t("courses.kind.course"); |
| 168 | 143 | const courseListSearch = (value: CourseKind | undefined) => (value ? ({ kind: value } as never) : ({} as never)); |
| 169 | - const sectionCount = createMemo(() => sections()?.length ?? 0); | |
| 144 | + const sectionCount = createMemo(() => sections().length); | |
| 170 | 145 | const visibleSections = createMemo(() => { |
| 171 | 146 | const query = sectionSearch().trim(); |
| 172 | - return query ? (sections() ?? []).filter((section) => matchesSearch(query, section.className)) : sections() ?? []; | |
| 147 | + return query | |
| 148 | + ? sections().filter((section) => matchesSearch(query, section.class_name, section.title, ...section.teachers.map(personLabel))) | |
| 149 | + : sections(); | |
| 173 | 150 | }); |
| 174 | 151 | const memberUserIds = () => (members() ?? []).map((row) => row.user.id); |
| 175 | 152 | |
| 176 | - const sectionColumns = createMemo<ColumnDef<SectionRow>[]>(() => [ | |
| 153 | + const sectionColumns = createMemo<ColumnDef<CourseSectionRef>[]>(() => [ | |
| 177 | 154 | { |
| 178 | 155 | id: "class", |
| 179 | - accessorFn: (row) => row.className, | |
| 156 | + accessorFn: (row) => row.class_name, | |
| 180 | 157 | header: t("classGroups.className"), |
| 181 | 158 | meta: { cellClass: "font-medium" }, |
| 182 | 159 | cell: (cell) => ( |
| 183 | - <Link to="/instances/$id" params={{ id: cell.row.original.instance.id }} class="hover:text-primary-text hover:underline"> | |
| 184 | - {cell.row.original.className} | |
| 160 | + <Link to="/instances/$id" params={{ id: cell.row.original.id }} class="hover:text-primary-text hover:underline"> | |
| 161 | + {cell.row.original.class_name} | |
| 185 | 162 | </Link> |
| 186 | 163 | ), |
| 187 | 164 | }, |
| 165 | + { | |
| 166 | + id: "title", | |
| 167 | + accessorFn: (row) => row.title, | |
| 168 | + header: t("form.title"), | |
| 169 | + }, | |
| 170 | + { | |
| 171 | + id: "grade", | |
| 172 | + accessorFn: (row) => row.grade_level, | |
| 173 | + header: t("classGroups.grade"), | |
| 174 | + cell: (cell) => gradeLevelLabel(cell.row.original.grade_level, t), | |
| 175 | + }, | |
| 176 | + { | |
| 177 | + id: "teachers", | |
| 178 | + accessorFn: (row) => row.teachers.map(personLabel).join(", "), | |
| 179 | + header: t("instances.teachers"), | |
| 180 | + cell: (cell) => cell.row.original.teachers.map(personLabel).join(", ") || "—", | |
| 181 | + }, | |
| 188 | 182 | { |
| 189 | 183 | id: "dersSaati", |
| 190 | - accessorFn: (row) => row.instance.ders_saati, | |
| 184 | + accessorFn: (row) => row.ders_saati, | |
| 191 | 185 | header: t("instances.dersSaati"), |
| 192 | 186 | meta: { cellClass: "" }, |
| 193 | 187 | }, |
| 194 | 188 | { |
| 195 | 189 | id: "roster", |
| 196 | - accessorFn: (row) => row.instance.enrollment_count, | |
| 190 | + accessorFn: (row) => row.enrollment_count, | |
| 197 | 191 | header: t("courses.roster"), |
| 198 | 192 | meta: { cellClass: "" }, |
| 199 | 193 | }, |
| 200 | - { | |
| 201 | - id: "karne", | |
| 202 | - accessorFn: (row) => (row.instance.counts_toward_karne ? t("common.yes") : t("common.no")), | |
| 203 | - header: t("instances.countsTowardKarne"), | |
| 204 | - cell: (cell) => ( | |
| 205 | - <Badge variant={cell.row.original.instance.counts_toward_karne ? "secondary" : "outline"} class="rounded-full"> | |
| 206 | - {cell.row.original.instance.counts_toward_karne ? t("common.yes") : t("common.no")} | |
| 207 | - </Badge> | |
| 208 | - ), | |
| 209 | - }, | |
| 210 | 194 | ]); |
| 211 | 195 | |
| 212 | 196 | const memberColumns = createMemo<ColumnDef<CourseMembership>[]>(() => [ |
| @@ -439,8 +423,13 @@ function CourseDetailContent() { | ||
| 439 | 423 | enablePagination |
| 440 | 424 | pageSize={10} |
| 441 | 425 | empty={t("common.noMatches")} |
| 442 | - onRowClick={(row) => void navigate({ to: "/instances/$id", params: { id: row.instance.id } })} | |
| 426 | + onRowClick={(row) => void navigate({ to: "/instances/$id", params: { id: row.id } })} | |
| 443 | 427 | /> |
| 428 | + <Show when={sectionsTruncated()}> | |
| 429 | + <p class="text-xs text-muted-foreground"> | |
| 430 | + {t("instances.sectionsTruncated", { shown: String(sections().length), total: String(course()?.class_course_count ?? 0) })} | |
| 431 | + </p> | |
| 432 | + </Show> | |
| 444 | 433 | </Show> |
| 445 | 434 | </Suspense> |
| 446 | 435 | </TabsContent> |
src/pages/courses-page.test.tsxmodified+5 -7
| @@ -3,9 +3,8 @@ import type { JSX } from "solid-js"; | ||
| 3 | 3 | import CoursesPage from "@/pages/courses-page"; |
| 4 | 4 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 5 | 5 | |
| 6 | -const { getCourses, getMyCourses, navigate } = vi.hoisted(() => ({ | |
| 6 | +const { getCourses, navigate } = vi.hoisted(() => ({ | |
| 7 | 7 | getCourses: vi.fn(), |
| 8 | - getMyCourses: vi.fn(), | |
| 9 | 8 | navigate: vi.fn(), |
| 10 | 9 | })); |
| 11 | 10 | |
| @@ -27,7 +26,6 @@ vi.mock("@/api/courses", () => ({ | ||
| 27 | 26 | getCourses, |
| 28 | 27 | postCourse: vi.fn(), |
| 29 | 28 | })); |
| 30 | -vi.mock("@/api/reports", () => ({ getMyCourses })); | |
| 31 | 29 | vi.mock("@/api/limits", () => ({ getLimits: vi.fn() })); |
| 32 | 30 | |
| 33 | 31 | afterEach(() => { |
| @@ -35,8 +33,9 @@ afterEach(() => { | ||
| 35 | 33 | vi.clearAllMocks(); |
| 36 | 34 | }); |
| 37 | 35 | |
| 36 | +// GET /courses is scoped server-side: a student reads only what they take. | |
| 38 | 37 | test("student class directory uses only enrolled-course data", async () => { |
| 39 | - getMyCourses.mockResolvedValue({ | |
| 38 | + getCourses.mockResolvedValue({ | |
| 40 | 39 | items: [ |
| 41 | 40 | { |
| 42 | 41 | id: "course-1", |
| @@ -75,13 +74,12 @@ test("student class directory uses only enrolled-course data", async () => { | ||
| 75 | 74 | |
| 76 | 75 | expect(await screen.findByRole("button", { name: /^Algebra/ })).toBeTruthy(); |
| 77 | 76 | expect(screen.getAllByText("Enrolled")).toHaveLength(3); |
| 78 | - expect(getMyCourses).toHaveBeenCalledWith(); | |
| 79 | - expect(getCourses).not.toHaveBeenCalled(); | |
| 77 | + expect(getCourses).toHaveBeenCalledWith(); | |
| 80 | 78 | |
| 81 | 79 | fireEvent.click(screen.getByRole("tab", { name: "Study" })); |
| 82 | 80 | expect(await screen.findByRole("button", { name: /^Study Lab/ })).toBeTruthy(); |
| 83 | 81 | expect(screen.queryByRole("button", { name: /^Algebra/ })).toBeNull(); |
| 84 | - expect(getMyCourses).toHaveBeenCalledTimes(1); | |
| 82 | + expect(getCourses).toHaveBeenCalledTimes(1); | |
| 85 | 83 | const tabNavigation = navigate.mock.calls.at(-1)?.[0] as { to: string; replace: boolean; search: (prev: Record<string, unknown>) => Record<string, unknown> }; |
| 86 | 84 | expect(tabNavigation.to).toBe("/courses"); |
| 87 | 85 | expect(tabNavigation.replace).toBe(true); |
src/pages/courses-page.tsxmodified+2 -2
| @@ -3,7 +3,6 @@ import { createResource } from "@/lib/create-resource"; | ||
| 3 | 3 | import { useNavigate, useSearch } from "@tanstack/solid-router"; |
| 4 | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | 5 | import { deleteCourseById, getCourses, postCourse } from "@/api/courses"; |
| 6 | -import { getMyCourses } from "@/api/reports"; | |
| 7 | 6 | import { getLimits } from "@/api/limits"; |
| 8 | 7 | import { formatApiError, type Course, type CourseKind } from "@/api/client"; |
| 9 | 8 | import { CourseEditPanel } from "@/components/courses/course-edit-panel"; |
| @@ -72,7 +71,8 @@ function CoursesContent() { | ||
| 72 | 71 | const [limits, { refetch: refetchLimits }] = createResource(() => canCreate() ? getLimits() : null); |
| 73 | 72 | const [list, { refetch }] = createResource( |
| 74 | 73 | () => auth.user()?.role ?? null, |
| 75 | - async (role) => role === "student" ? getMyCourses() : getCourses(), | |
| 74 | + // Scoped server-side: a student reads only the courses they take. | |
| 75 | + () => getCourses(), | |
| 76 | 76 | ); |
| 77 | 77 | const listData = () => list.latest ?? list(); |
| 78 | 78 | // A memo: the table must see one array per change, not a fresh one per read. |
src/pages/dashboard-page.test.tsxmodified+0 -1
| @@ -78,7 +78,6 @@ vi.mock("@/api/sessions", () => ({ | ||
| 78 | 78 | getSessionAttendance: async () => ({ items: [], total: 0, limit: 1, offset: 0 }), |
| 79 | 79 | })); |
| 80 | 80 | vi.mock("@/api/reports", () => ({ |
| 81 | - getMyCourses: async () => page([course]), | |
| 82 | 81 | getMyMarks: async () => (calls.push("marks"), { |
| 83 | 82 | overall_average: 82.5, |
| 84 | 83 | courses: [{ |
src/pages/dashboard-page.tsxmodified+2 -2
| @@ -15,7 +15,7 @@ import { getMealMenus } from "@/api/meals"; | ||
| 15 | 15 | import { getMyStudents } from "@/api/parents"; |
| 16 | 16 | import { getPaymentStatementByUserId } from "@/api/payments"; |
| 17 | 17 | import { getPomodoroMe } from "@/api/pomodoro"; |
| 18 | -import { getMyAttendance, getMyCourses, getMyMarks, getUserAttendance } from "@/api/reports"; | |
| 18 | +import { getMyAttendance, getMyMarks, getUserAttendance } from "@/api/reports"; | |
| 19 | 19 | import { getTime } from "@/api/time/getTime"; |
| 20 | 20 | import { getUsers } from "@/api/users"; |
| 21 | 21 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -179,7 +179,7 @@ function DashboardContent() { | ||
| 179 | 179 | // excludes studies and clubs has to be counted here over the whole list. |
| 180 | 180 | const [courses] = createResource( |
| 181 | 181 | () => role() === "parent" || !on("courses") ? null : role(), |
| 182 | - (currentRole) => quiet(currentRole === "student" ? getMyCourses() : getCourses()), | |
| 182 | + () => quiet(getCourses()), | |
| 183 | 183 | ); |
| 184 | 184 | const courseTitleOf = (courseId: string) => courses()?.items.find((course) => course.id === courseId)?.title ?? "…"; |
| 185 | 185 | const courseCount = () => (courses.error ? "—" : String((courses()?.items ?? []).filter((course) => course.kind === "course").length)); |
src/pages/profile-page.tsxmodified+2 -3
| @@ -26,6 +26,7 @@ import { genderLabel } from "@/lib/gender"; | ||
| 26 | 26 | import { personLabel } from "@/lib/person"; |
| 27 | 27 | import { studentInfoSource } from "@/lib/student-info-access"; |
| 28 | 28 | import { useAuth } from "@/stores/auth-context"; |
| 29 | +import { gradeLevelLabel } from "@/lib/grade-level"; | |
| 29 | 30 | import { useT } from "@/stores/preferences-context"; |
| 30 | 31 | |
| 31 | 32 | export default function ProfilePage() { |
| @@ -189,9 +190,7 @@ function ProfileContent() { | ||
| 189 | 190 | <IconSchool class="h-4 w-4 text-muted-foreground" /> |
| 190 | 191 | {c().name} |
| 191 | 192 | </span> |
| 192 | - <Show when={c().grade}> | |
| 193 | - {(g) => <Badge variant="secondary" class="rounded-md">{g()}</Badge>} | |
| 194 | - </Show> | |
| 193 | + <Badge variant="secondary" class="rounded-md">{gradeLevelLabel(c().grade_level, t)}</Badge> | |
| 195 | 194 | <span class="text-muted-foreground"> |
| 196 | 195 | ·{" "} |
| 197 | 196 | {currentClass()?.teacher |