🗓️ grade templates, section overrides, weekly plans and holidays UI
Browse files at this commitc748801ba2d62c6114b890fb619fe5735c9cf321Parent: f409644- feat
- 🗓️ grade templates, section overrides, weekly plans and holidays UI
27 changed files +2033 -25
- src/components/courses/course-offerings-panel.tsx +163 -0
- src/components/courses/offering-panel.tsx +257 -0
- src/components/exams/exam-questions-panel.tsx +25 -2
- src/components/homework/course-homework-panel.tsx +4 -4
- src/components/instances/exam-weights-editor.tsx +138 -0
- src/components/instances/instance-settings-panel.tsx +240 -0
- src/components/instances/instance-weekly-plan-panel.tsx +126 -0
- src/components/instances/materialize-panel.tsx +132 -0
- src/components/instances/override-badge.tsx +12 -0
- src/components/instances/subject-set-editor.tsx +95 -0
- src/components/instances/weekly-plan-table.tsx +54 -0
- src/components/instances/weekly-slot-form.tsx +94 -0
- src/components/layout/nav-items.test.ts +1 -1
- src/components/layout/nav-items.ts +2 -0
- src/i18n/locales/en.ts +96 -0
- src/i18n/locales/tr.ts +96 -0
- src/i18n/messages.ts +97 -1
- src/lib/holiday-kind.ts +16 -0
- src/lib/weekly-plan.test.ts +25 -0
- src/lib/weekly-plan.ts +33 -0
- src/pages/course-detail-page.tsx +15 -1
- src/pages/exam-detail-page.tsx +1 -1
- src/pages/exams-page.tsx +2 -0
- src/pages/holidays-page.tsx +233 -0
- src/pages/homework-page.tsx +4 -5
- src/pages/instance-detail-page.tsx +64 -10
- src/routes/router.tsx +8 -0
src/components/courses/course-offerings-panel.tsxadded+163 -0
| @@ -0,0 +1,163 @@ | |||
| 1 | +import { Show, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import { createResource } from "@/lib/create-resource"; | ||
| 3 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 4 | +import { getCourseSubjects } from "@/api/courses"; | ||
| 5 | +import { getLimits } from "@/api/limits"; | ||
| 6 | +import { deleteOfferingById, getOfferings } from "@/api/offerings"; | ||
| 7 | +import { getSettings } from "@/api/settings"; | ||
| 8 | +import { formatApiError, type Offering } from "@/api/client"; | ||
| 9 | +import { OfferingPanel } from "@/components/courses/offering-panel"; | ||
| 10 | +import { Alert } from "@/components/ui/alert"; | ||
| 11 | +import { Button } from "@/components/ui/button"; | ||
| 12 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 13 | +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | ||
| 14 | +import { IconEdit, IconEye, IconPlus, IconTrash } from "@/components/ui/icons"; | ||
| 15 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 16 | +import { createFlash } from "@/lib/flash"; | ||
| 17 | +import { gradeLevelLabel } from "@/lib/grade-level"; | ||
| 18 | +import { useT } from "@/stores/preferences-context"; | ||
| 19 | + | ||
| 20 | +/** A catalog course's grade templates; manager+ edits them. */ | ||
| 21 | +export function CourseOfferingsPanel(props: { courseId: string; courseTitle: string; canEdit: boolean; active: boolean }) { | ||
| 22 | + const t = useT(); | ||
| 23 | + const [flash, setFlash] = createFlash(); | ||
| 24 | + const [error, setError] = createSignal(""); | ||
| 25 | + const [panelOpen, setPanelOpen] = createSignal(false); | ||
| 26 | + const [selected, setSelected] = createSignal<Offering | null>(null); | ||
| 27 | + const [deleting, setDeleting] = createSignal<Offering | null>(null); | ||
| 28 | + | ||
| 29 | + const source = () => (props.active ? props.courseId : null); | ||
| 30 | + const [offerings, { refetch }] = createResource(source, async (courseId) => | ||
| 31 | + (await getOfferings({ course: courseId })).items.slice().sort((a, b) => a.grade_level - b.grade_level), | ||
| 32 | + ); | ||
| 33 | + const [subjects] = createResource(() => (panelOpen() ? props.courseId : null), async (courseId) => (await getCourseSubjects(courseId)).items); | ||
| 34 | + const [settings] = createResource(() => (panelOpen() ? true : null), () => getSettings()); | ||
| 35 | + const [limits] = createResource(() => (props.active ? true : null), () => getLimits()); | ||
| 36 | + | ||
| 37 | + const open = (offering: Offering | null) => { | ||
| 38 | + setSelected(offering); | ||
| 39 | + setPanelOpen(true); | ||
| 40 | + }; | ||
| 41 | + | ||
| 42 | + const inherited = (value: string | number | null, fallback: string) => | ||
| 43 | + value == null || value === "" ? <span class="text-muted-foreground">{fallback}</span> : String(value); | ||
| 44 | + | ||
| 45 | + const columns = createMemo<ColumnDef<Offering>[]>(() => [ | ||
| 46 | + { | ||
| 47 | + id: "grade", | ||
| 48 | + accessorFn: (row) => row.grade_level, | ||
| 49 | + header: t("classGroups.grade"), | ||
| 50 | + meta: { cellClass: "font-medium whitespace-nowrap" }, | ||
| 51 | + cell: (cell) => gradeLevelLabel(cell.row.original.grade_level, t), | ||
| 52 | + }, | ||
| 53 | + { | ||
| 54 | + id: "title", | ||
| 55 | + accessorFn: (row) => row.title ?? props.courseTitle, | ||
| 56 | + header: t("form.title"), | ||
| 57 | + cell: (cell) => inherited(cell.row.original.title, props.courseTitle), | ||
| 58 | + }, | ||
| 59 | + { | ||
| 60 | + id: "hours", | ||
| 61 | + accessorFn: (row) => row.default_ders_saati ?? 1, | ||
| 62 | + header: t("instances.dersSaati"), | ||
| 63 | + cell: (cell) => inherited(cell.row.original.default_ders_saati, "1"), | ||
| 64 | + }, | ||
| 65 | + { | ||
| 66 | + id: "karne", | ||
| 67 | + accessorFn: (row) => row.default_counts_toward_karne, | ||
| 68 | + header: t("instances.countsTowardKarne"), | ||
| 69 | + cell: (cell) => { | ||
| 70 | + const value = cell.row.original.default_counts_toward_karne; | ||
| 71 | + return value == null ? <span class="text-muted-foreground">{t("common.yes")}</span> : value ? t("common.yes") : t("common.no"); | ||
| 72 | + }, | ||
| 73 | + }, | ||
| 74 | + { | ||
| 75 | + id: "actions", | ||
| 76 | + header: t("common.actions"), | ||
| 77 | + meta: { headerClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", cellClass: "text-center" }, | ||
| 78 | + cell: (cell) => ( | ||
| 79 | + <TableRowActions | ||
| 80 | + label={t("common.actions")} | ||
| 81 | + actions={[ | ||
| 82 | + props.canEdit | ||
| 83 | + ? { label: t("offerings.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => open(cell.row.original) } | ||
| 84 | + : { label: t("common.view"), icon: <IconEye class="h-4 w-4" />, onSelect: () => open(cell.row.original) }, | ||
| 85 | + ...(props.canEdit | ||
| 86 | + ? [{ label: t("offerings.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleting(cell.row.original) }] | ||
| 87 | + : []), | ||
| 88 | + ]} | ||
| 89 | + /> | ||
| 90 | + ), | ||
| 91 | + }, | ||
| 92 | + ]); | ||
| 93 | + | ||
| 94 | + return ( | ||
| 95 | + <div class="space-y-3"> | ||
| 96 | + <Show when={flash()}><Alert variant="success">{flash()}</Alert></Show> | ||
| 97 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 98 | + <Show when={!offerings.loading || offerings.latest} fallback={<DataTableSkeleton />}> | ||
| 99 | + <DataTable | ||
| 100 | + columns={columns()} | ||
| 101 | + data={offerings.latest ?? []} | ||
| 102 | + title={t("offerings.tab")} | ||
| 103 | + description={t("offerings.help")} | ||
| 104 | + empty={t("offerings.empty")} | ||
| 105 | + onRowClick={(offering) => open(offering)} | ||
| 106 | + actions={ | ||
| 107 | + <Show when={props.canEdit}> | ||
| 108 | + <Button type="button" size="sm" class="rounded-lg" onClick={() => open(null)}> | ||
| 109 | + <IconPlus class="h-4 w-4" /> | ||
| 110 | + {t("offerings.new")} | ||
| 111 | + </Button> | ||
| 112 | + </Show> | ||
| 113 | + } | ||
| 114 | + /> | ||
| 115 | + </Show> | ||
| 116 | + | ||
| 117 | + <OfferingPanel | ||
| 118 | + open={panelOpen()} | ||
| 119 | + onOpenChange={(value) => { | ||
| 120 | + setPanelOpen(value); | ||
| 121 | + if (!value) setSelected(null); | ||
| 122 | + }} | ||
| 123 | + courseId={props.courseId} | ||
| 124 | + courseTitle={props.courseTitle} | ||
| 125 | + offering={selected()} | ||
| 126 | + canEdit={props.canEdit} | ||
| 127 | + courseSubjects={subjects.latest ?? []} | ||
| 128 | + examKinds={(settings.latest?.exam_kinds ?? []).map((kind) => kind.name)} | ||
| 129 | + limits={limits.latest ?? undefined} | ||
| 130 | + onSaved={async (saved) => { | ||
| 131 | + const created = selected() === null; | ||
| 132 | + await refetch(); | ||
| 133 | + setFlash(created ? t("common.created") : t("common.saved")); | ||
| 134 | + // A new template stays open on itself, so its topics, week and | ||
| 135 | + // weights can be filled in right away. | ||
| 136 | + setSelected(saved); | ||
| 137 | + }} | ||
| 138 | + /> | ||
| 139 | + | ||
| 140 | + <ConfirmDialog | ||
| 141 | + open={deleting() !== null} | ||
| 142 | + onOpenChange={(value) => !value && setDeleting(null)} | ||
| 143 | + title={t("offerings.delete")} | ||
| 144 | + summary={t("offerings.deleteConfirm", { grade: deleting() ? gradeLevelLabel(deleting()!.grade_level, t) : "" })} | ||
| 145 | + variant="destructive" | ||
| 146 | + onConfirm={async () => { | ||
| 147 | + const target = deleting(); | ||
| 148 | + if (!target) return; | ||
| 149 | + setError(""); | ||
| 150 | + try { | ||
| 151 | + await deleteOfferingById(target.id); | ||
| 152 | + await refetch(); | ||
| 153 | + setFlash(t("common.deleted")); | ||
| 154 | + } catch (err) { | ||
| 155 | + setError(formatApiError(err)); | ||
| 156 | + } finally { | ||
| 157 | + setDeleting(null); | ||
| 158 | + } | ||
| 159 | + }} | ||
| 160 | + /> | ||
| 161 | + </div> | ||
| 162 | + ); | ||
| 163 | +} | ||
src/components/courses/offering-panel.tsxadded+257 -0
| @@ -0,0 +1,257 @@ | |||
| 1 | +import { Show, createEffect, createSignal } from "solid-js"; | ||
| 2 | +import { createResource } from "@/lib/create-resource"; | ||
| 3 | +import { | ||
| 4 | + deleteOfferingExamWeightByKind, | ||
| 5 | + deleteOfferingSubjectById, | ||
| 6 | + deleteOfferingWeeklySlotById, | ||
| 7 | + getOfferingExamWeights, | ||
| 8 | + getOfferingSubjects, | ||
| 9 | + getOfferingWeeklyPlan, | ||
| 10 | + patchOfferingById, | ||
| 11 | + patchOfferingExamWeight, | ||
| 12 | + postOffering, | ||
| 13 | + postOfferingSubject, | ||
| 14 | + postOfferingWeeklySlot, | ||
| 15 | + type UpdateOfferingBody, | ||
| 16 | +} from "@/api/offerings"; | ||
| 17 | +import { formatApiError, type ExamWeightEntry, type Limits, type Offering, type Subject, type WeeklySlot } from "@/api/client"; | ||
| 18 | +import { GradeLevelSelect } from "@/components/classes/grade-level-select"; | ||
| 19 | +import { ExamWeightsEditor } from "@/components/instances/exam-weights-editor"; | ||
| 20 | +import { SubjectSetEditor } from "@/components/instances/subject-set-editor"; | ||
| 21 | +import { WeeklyPlanTable } from "@/components/instances/weekly-plan-table"; | ||
| 22 | +import { WeeklySlotForm } from "@/components/instances/weekly-slot-form"; | ||
| 23 | +import { Alert } from "@/components/ui/alert"; | ||
| 24 | +import { Button } from "@/components/ui/button"; | ||
| 25 | +import { IconPlus } from "@/components/ui/icons"; | ||
| 26 | +import { Input } from "@/components/ui/input"; | ||
| 27 | +import { Label } from "@/components/ui/label"; | ||
| 28 | +import { Select } from "@/components/ui/select"; | ||
| 29 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 30 | +import { Textarea } from "@/components/ui/textarea"; | ||
| 31 | +import { gradeLevelLabel } from "@/lib/grade-level"; | ||
| 32 | +import { useT } from "@/stores/preferences-context"; | ||
| 33 | + | ||
| 34 | +const SECTION = "space-y-3 border-t border-border-hairline pt-4"; | ||
| 35 | +const SECTION_HEAD = "flex flex-wrap items-start justify-between gap-2"; | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | + * One grade template of a catalog course: `offering` null creates it (grade | ||
| 39 | + * plus defaults), set edits its defaults and its topic set, template week and | ||
| 40 | + * exam weights. Blank fields inherit — sent as null, never as "". | ||
| 41 | + */ | ||
| 42 | +export function OfferingPanel(props: { | ||
| 43 | + open: boolean; | ||
| 44 | + onOpenChange: (open: boolean) => void; | ||
| 45 | + courseId: string; | ||
| 46 | + courseTitle: string; | ||
| 47 | + offering: Offering | null; | ||
| 48 | + canEdit: boolean; | ||
| 49 | + courseSubjects: Subject[]; | ||
| 50 | + examKinds: string[]; | ||
| 51 | + limits?: Limits; | ||
| 52 | + onSaved: (offering: Offering) => void | Promise<void>; | ||
| 53 | +}) { | ||
| 54 | + const t = useT(); | ||
| 55 | + const [gradeLevel, setGradeLevel] = createSignal<number | null>(null); | ||
| 56 | + const [title, setTitle] = createSignal(""); | ||
| 57 | + const [description, setDescription] = createSignal(""); | ||
| 58 | + const [hours, setHours] = createSignal(""); | ||
| 59 | + const [karne, setKarne] = createSignal<"" | "yes" | "no">(""); | ||
| 60 | + const [error, setError] = createSignal(""); | ||
| 61 | + const [pending, setPending] = createSignal(false); | ||
| 62 | + const [addingSlot, setAddingSlot] = createSignal(false); | ||
| 63 | + const [weightEditing, setWeightEditing] = createSignal<ExamWeightEntry | "new" | null>(null); | ||
| 64 | + const [sectionError, setSectionError] = createSignal(""); | ||
| 65 | + | ||
| 66 | + const editingId = () => (props.open && props.offering ? props.offering.id : null); | ||
| 67 | + const [subjects, { refetch: refetchSubjects }] = createResource(editingId, (id) => getOfferingSubjects(id)); | ||
| 68 | + const [slots, { refetch: refetchSlots }] = createResource(editingId, (id) => getOfferingWeeklyPlan(id)); | ||
| 69 | + const [weights, { refetch: refetchWeights }] = createResource(editingId, async (id) => (await getOfferingExamWeights(id)).weights); | ||
| 70 | + | ||
| 71 | + createEffect(() => { | ||
| 72 | + if (!props.open) return; | ||
| 73 | + const o = props.offering; | ||
| 74 | + setGradeLevel(o ? o.grade_level : null); | ||
| 75 | + setTitle(o?.title ?? ""); | ||
| 76 | + setDescription(o?.description ?? ""); | ||
| 77 | + setHours(o?.default_ders_saati != null ? String(o.default_ders_saati) : ""); | ||
| 78 | + setKarne(o?.default_counts_toward_karne == null ? "" : o.default_counts_toward_karne ? "yes" : "no"); | ||
| 79 | + setError(""); | ||
| 80 | + setSectionError(""); | ||
| 81 | + }); | ||
| 82 | + | ||
| 83 | + const submit = async (event: SubmitEvent) => { | ||
| 84 | + event.preventDefault(); | ||
| 85 | + const level = gradeLevel(); | ||
| 86 | + if (level === null) { | ||
| 87 | + setError(t("form.fieldRequired")); | ||
| 88 | + return; | ||
| 89 | + } | ||
| 90 | + const hoursText = hours().trim(); | ||
| 91 | + const hoursValue = hoursText === "" ? null : Number(hoursText); | ||
| 92 | + const minHours = props.limits?.course.min_ders_saati ?? 1; | ||
| 93 | + const maxHours = props.limits?.course.max_ders_saati ?? 40; | ||
| 94 | + if (hoursValue !== null && (!Number.isInteger(hoursValue) || hoursValue < minHours || hoursValue > maxHours)) { | ||
| 95 | + setError(t("instances.dersSaatiInvalid")); | ||
| 96 | + return; | ||
| 97 | + } | ||
| 98 | + const fields: UpdateOfferingBody = { | ||
| 99 | + title: title().trim() || null, | ||
| 100 | + description: description().trim() || null, | ||
| 101 | + default_ders_saati: hoursValue, | ||
| 102 | + default_counts_toward_karne: karne() === "" ? null : karne() === "yes", | ||
| 103 | + }; | ||
| 104 | + setError(""); | ||
| 105 | + setPending(true); | ||
| 106 | + try { | ||
| 107 | + const saved = props.offering | ||
| 108 | + ? await patchOfferingById(props.offering.id, fields) | ||
| 109 | + : await postOffering({ course: props.courseId, grade_level: level, ...fields }); | ||
| 110 | + await props.onSaved(saved); | ||
| 111 | + } catch (err) { | ||
| 112 | + setError(formatApiError(err)); | ||
| 113 | + } finally { | ||
| 114 | + setPending(false); | ||
| 115 | + } | ||
| 116 | + }; | ||
| 117 | + | ||
| 118 | + const guard = async (action: () => Promise<unknown>) => { | ||
| 119 | + setSectionError(""); | ||
| 120 | + try { | ||
| 121 | + await action(); | ||
| 122 | + } catch (err) { | ||
| 123 | + setSectionError(formatApiError(err)); | ||
| 124 | + } | ||
| 125 | + }; | ||
| 126 | + | ||
| 127 | + return ( | ||
| 128 | + <SidePanel | ||
| 129 | + guardUnsaved | ||
| 130 | + size="wide" | ||
| 131 | + open={props.open} | ||
| 132 | + onOpenChange={props.onOpenChange} | ||
| 133 | + title={props.offering ? `${props.courseTitle} · ${gradeLevelLabel(props.offering.grade_level, t)}` : t("offerings.new")} | ||
| 134 | + description={t("offerings.help")} | ||
| 135 | + > | ||
| 136 | + <div class="space-y-4"> | ||
| 137 | + <form class="space-y-3" noValidate onSubmit={submit}> | ||
| 138 | + <div class="space-y-1.5"> | ||
| 139 | + <Label for="offering-grade">{t("classGroups.grade")}</Label> | ||
| 140 | + <GradeLevelSelect | ||
| 141 | + id="offering-grade" | ||
| 142 | + value={gradeLevel()} | ||
| 143 | + min={props.limits?.course.min_grade_level} | ||
| 144 | + max={props.limits?.course.max_grade_level} | ||
| 145 | + disabled={!!props.offering || !props.canEdit} | ||
| 146 | + onChange={setGradeLevel} | ||
| 147 | + /> | ||
| 148 | + </div> | ||
| 149 | + <div class="space-y-1.5"> | ||
| 150 | + <Label for="offering-title">{t("form.title")}</Label> | ||
| 151 | + <Input id="offering-title" maxlength={props.limits?.course.max_title_len} disabled={!props.canEdit} placeholder={t("offerings.titlePlaceholder", { title: props.courseTitle })} value={title()} onInput={(e) => setTitle(e.currentTarget.value)} /> | ||
| 152 | + </div> | ||
| 153 | + <div class="space-y-1.5"> | ||
| 154 | + <Label for="offering-description">{t("form.description")}</Label> | ||
| 155 | + <Textarea id="offering-description" rows={3} maxlength={props.limits?.course.max_description_len} disabled={!props.canEdit} placeholder={t("offerings.descriptionPlaceholder")} value={description()} onInput={(e) => setDescription(e.currentTarget.value)} /> | ||
| 156 | + </div> | ||
| 157 | + <div class="grid gap-3 sm:grid-cols-2"> | ||
| 158 | + <div class="space-y-1.5"> | ||
| 159 | + <Label for="offering-hours">{t("offerings.defaultDersSaati")}</Label> | ||
| 160 | + <Input id="offering-hours" type="number" inputMode="numeric" min={props.limits?.course.min_ders_saati} max={props.limits?.course.max_ders_saati} disabled={!props.canEdit} placeholder="1" value={hours()} onInput={(e) => setHours(e.currentTarget.value)} /> | ||
| 161 | + <p class="text-xs text-muted-foreground">{t("offerings.defaultDersSaatiHint")}</p> | ||
| 162 | + </div> | ||
| 163 | + <div class="space-y-1.5"> | ||
| 164 | + <Label for="offering-karne">{t("offerings.defaultKarne")}</Label> | ||
| 165 | + <Select id="offering-karne" value={karne()} disabled={!props.canEdit} onChange={(e) => setKarne(e.currentTarget.value as "" | "yes" | "no")}> | ||
| 166 | + <option value="">{t("offerings.inheritDefault")}</option> | ||
| 167 | + <option value="yes">{t("common.yes")}</option> | ||
| 168 | + <option value="no">{t("common.no")}</option> | ||
| 169 | + </Select> | ||
| 170 | + </div> | ||
| 171 | + </div> | ||
| 172 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 173 | + <Show when={props.canEdit}> | ||
| 174 | + <div class="flex gap-2"> | ||
| 175 | + <Button type="submit" disabled={pending()}>{props.offering ? t("common.save") : t("common.create")}</Button> | ||
| 176 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | ||
| 177 | + </div> | ||
| 178 | + </Show> | ||
| 179 | + </form> | ||
| 180 | + | ||
| 181 | + <Show when={props.offering}> | ||
| 182 | + {(offering) => ( | ||
| 183 | + <> | ||
| 184 | + <Show when={sectionError()}><Alert variant="destructive">{sectionError()}</Alert></Show> | ||
| 185 | + | ||
| 186 | + <section class={SECTION}> | ||
| 187 | + <div> | ||
| 188 | + <h3 class="text-sm font-semibold">{t("instances.subjectsTitle")}</h3> | ||
| 189 | + <p class="text-xs text-muted-foreground">{t("offerings.subjectsHelp")}</p> | ||
| 190 | + </div> | ||
| 191 | + <SubjectSetEditor | ||
| 192 | + selected={subjects.latest ?? []} | ||
| 193 | + available={props.courseSubjects} | ||
| 194 | + canEdit={props.canEdit} | ||
| 195 | + onAdd={async (subjectId) => { await postOfferingSubject(offering().id, subjectId); await refetchSubjects(); }} | ||
| 196 | + onRemove={async (subject) => { await deleteOfferingSubjectById(offering().id, subject.id); await refetchSubjects(); }} | ||
| 197 | + /> | ||
| 198 | + </section> | ||
| 199 | + | ||
| 200 | + <section class={SECTION}> | ||
| 201 | + <div class={SECTION_HEAD}> | ||
| 202 | + <div> | ||
| 203 | + <h3 class="text-sm font-semibold">{t("weeklyPlan.title")}</h3> | ||
| 204 | + <p class="text-xs text-muted-foreground">{t("offerings.weeklyPlanHelp")}</p> | ||
| 205 | + </div> | ||
| 206 | + <Show when={props.canEdit}> | ||
| 207 | + <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setAddingSlot(true)}> | ||
| 208 | + <IconPlus class="h-4 w-4" /> | ||
| 209 | + {t("weeklyPlan.addSlot")} | ||
| 210 | + </Button> | ||
| 211 | + </Show> | ||
| 212 | + </div> | ||
| 213 | + <WeeklyPlanTable | ||
| 214 | + slots={slots.latest ?? []} | ||
| 215 | + onRemove={props.canEdit ? (slot: WeeklySlot) => void guard(async () => { await deleteOfferingWeeklySlotById(offering().id, slot.id); await refetchSlots(); }) : undefined} | ||
| 216 | + /> | ||
| 217 | + </section> | ||
| 218 | + | ||
| 219 | + <section class={SECTION}> | ||
| 220 | + <div class={SECTION_HEAD}> | ||
| 221 | + <div> | ||
| 222 | + <h3 class="text-sm font-semibold">{t("instances.examWeightsTitle")}</h3> | ||
| 223 | + <p class="text-xs text-muted-foreground">{t("offerings.weightsHelp")}</p> | ||
| 224 | + </div> | ||
| 225 | + <Show when={props.canEdit}> | ||
| 226 | + <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setWeightEditing("new")}> | ||
| 227 | + <IconPlus class="h-4 w-4" /> | ||
| 228 | + {t("instances.addWeight")} | ||
| 229 | + </Button> | ||
| 230 | + </Show> | ||
| 231 | + </div> | ||
| 232 | + <ExamWeightsEditor | ||
| 233 | + weights={weights.latest ?? []} | ||
| 234 | + kinds={props.examKinds} | ||
| 235 | + canEdit={props.canEdit} | ||
| 236 | + editing={weightEditing()} | ||
| 237 | + onEditingChange={setWeightEditing} | ||
| 238 | + onSet={async (entry) => { await patchOfferingExamWeight(offering().id, entry); await refetchWeights(); }} | ||
| 239 | + onRemove={async (kind) => { await deleteOfferingExamWeightByKind(offering().id, kind); await refetchWeights(); }} | ||
| 240 | + /> | ||
| 241 | + </section> | ||
| 242 | + | ||
| 243 | + <WeeklySlotForm | ||
| 244 | + open={addingSlot()} | ||
| 245 | + onOpenChange={setAddingSlot} | ||
| 246 | + minMinute={props.limits?.weekly_plan.min_slot_minute} | ||
| 247 | + maxMinute={props.limits?.weekly_plan.max_slot_minute} | ||
| 248 | + maxTopicLen={props.limits?.course.max_session_topic_len} | ||
| 249 | + onSubmit={async (body) => { await postOfferingWeeklySlot(offering().id, body); await refetchSlots(); }} | ||
| 250 | + /> | ||
| 251 | + </> | ||
| 252 | + )} | ||
| 253 | + </Show> | ||
| 254 | + </div> | ||
| 255 | + </SidePanel> | ||
| 256 | + ); | ||
| 257 | +} | ||
src/components/exams/exam-questions-panel.tsxmodified+25 -2
| @@ -4,6 +4,7 @@ import { deleteExamChoiceImage } from "@/api/exams"; | |||
| 4 | import { deleteExamQuestionImage } from "@/api/exams"; | 4 | import { deleteExamQuestionImage } from "@/api/exams"; |
| 5 | import { deleteExamQuestionById } from "@/api/exams"; | 5 | import { deleteExamQuestionById } from "@/api/exams"; |
| 6 | import { getCourseSubjects } from "@/api/courses"; | 6 | import { getCourseSubjects } from "@/api/courses"; |
| 7 | +import { getInstanceSubjects } from "@/api/instances"; | ||
| 7 | import { getExamQuestionImageBlob } from "@/api/exams"; | 8 | import { getExamQuestionImageBlob } from "@/api/exams"; |
| 8 | import { getExamQuestions } from "@/api/exams"; | 9 | import { getExamQuestions } from "@/api/exams"; |
| 9 | import { postExamQuestionFromBank } from "@/api/exams"; | 10 | import { postExamQuestionFromBank } from "@/api/exams"; |
| @@ -40,6 +41,12 @@ export function ExamQuestionsPanel(props: { | |||
| 40 | examId: string; | 41 | examId: string; |
| 41 | /** The exam's catalog course; null until the instance behind the exam resolves. */ | 42 | /** The exam's catalog course; null until the instance behind the exam resolves. */ |
| 42 | courseId: string | null; | 43 | courseId: string | null; |
| 44 | + /** | ||
| 45 | + * The exam's instance. A question's subject must sit in the instance's | ||
| 46 | + * resolved subject set (the offering's, or the section's own override), so | ||
| 47 | + * the picker offers that set; the catalog list only names older questions. | ||
| 48 | + */ | ||
| 49 | + instanceId?: string | null; | ||
| 43 | readOnly?: boolean; | 50 | readOnly?: boolean; |
| 44 | embedded?: boolean; | 51 | embedded?: boolean; |
| 45 | createOpen?: boolean; | 52 | createOpen?: boolean; |
| @@ -53,7 +60,7 @@ export function ExamQuestionsPanel(props: { | |||
| 53 | // Solid only skips a fetch on null/undefined/false — an empty string would | 60 | // Solid only skips a fetch on null/undefined/false — an empty string would |
| 54 | // still ask for `/courses//subjects`. A subject list that cannot load only | 61 | // still ask for `/courses//subjects`. A subject list that cannot load only |
| 55 | // costs the name lookup (ids stay readable), so it must not throw into the page. | 62 | // costs the name lookup (ids stay readable), so it must not throw into the page. |
| 56 | - const [subjects] = createResource( | 63 | + const [catalogSubjects] = createResource( |
| 57 | () => props.courseId || null, | 64 | () => props.courseId || null, |
| 58 | async (courseId) => { | 65 | async (courseId) => { |
| 59 | try { | 66 | try { |
| @@ -63,6 +70,22 @@ export function ExamQuestionsPanel(props: { | |||
| 63 | } | 70 | } |
| 64 | }, | 71 | }, |
| 65 | ); | 72 | ); |
| 73 | + const [sectionSubjects] = createResource( | ||
| 74 | + () => props.instanceId || null, | ||
| 75 | + async (instanceId) => { | ||
| 76 | + try { | ||
| 77 | + return (await getInstanceSubjects(instanceId)).subjects; | ||
| 78 | + } catch { | ||
| 79 | + return null; | ||
| 80 | + } | ||
| 81 | + }, | ||
| 82 | + ); | ||
| 83 | + // What a new or edited question may pick: the section's resolved set once it | ||
| 84 | + // loads, the catalog list when no instance is known. | ||
| 85 | + const subjects = Object.assign( | ||
| 86 | + () => (props.instanceId ? sectionSubjects() ?? catalogSubjects() : catalogSubjects()), | ||
| 87 | + { get loading() { return catalogSubjects.loading || sectionSubjects.loading; } }, | ||
| 88 | + ); | ||
| 66 | const [questions, { refetch }] = createResource(() => props.examId, async (examId) => { | 89 | const [questions, { refetch }] = createResource(() => props.examId, async (examId) => { |
| 67 | try { | 90 | try { |
| 68 | return (await getExamQuestions(examId)).items; | 91 | return (await getExamQuestions(examId)).items; |
| @@ -102,7 +125,7 @@ export function ExamQuestionsPanel(props: { | |||
| 102 | // has not been saved to it, so it must not offer "save another copy". | 125 | // has not been saved to it, so it must not offer "save another copy". |
| 103 | const isSavedToBank = (question: ExamQuestion) => Boolean(question.banked_as) || bankedIds().includes(question.id); | 126 | const isSavedToBank = (question: ExamQuestion) => Boolean(question.banked_as) || bankedIds().includes(question.id); |
| 104 | const isFromBank = (question: ExamQuestion) => Boolean(question.from_bank); | 127 | const isFromBank = (question: ExamQuestion) => Boolean(question.from_bank); |
| 105 | - const subjectName = (subjectId: string) => subjects()?.find((subject) => subject.id === subjectId)?.name ?? subjectId; | 128 | + const subjectName = (subjectId: string) => catalogSubjects()?.find((subject) => subject.id === subjectId)?.name ?? subjectId; |
| 106 | const totalPages = createMemo(() => Math.max(1, Math.ceil(questionList().length / QUESTION_PAGE_SIZE))); | 129 | const totalPages = createMemo(() => Math.max(1, Math.ceil(questionList().length / QUESTION_PAGE_SIZE))); |
| 107 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | 130 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); |
| 108 | const pageItems = createMemo(() => { | 131 | const pageItems = createMemo(() => { |
src/components/homework/course-homework-panel.tsxmodified+4 -4
| @@ -3,8 +3,7 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import { useNavigate } from "@tanstack/solid-router"; | 3 | import { useNavigate } from "@tanstack/solid-router"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | import { deleteHomeworkById, patchHomeworkById } from "@/api/homework"; | 5 | import { deleteHomeworkById, patchHomeworkById } from "@/api/homework"; |
| 6 | -import { getCourseSubjects } from "@/api/courses"; | 6 | +import { getInstanceHomework, getInstanceSubjects, postInstanceHomework } from "@/api/instances"; |
| 7 | -import { getInstanceHomework, postInstanceHomework } from "@/api/instances"; | ||
| 8 | import { getTime } from "@/api/time"; | 7 | import { getTime } from "@/api/time"; |
| 9 | import { formatApiError } from "@/api/client"; | 8 | import { formatApiError } from "@/api/client"; |
| 10 | import type { Homework, Subject } from "@/api/client"; | 9 | import type { Homework, Subject } from "@/api/client"; |
| @@ -71,9 +70,10 @@ export function CourseHomeworkPanel(props: { | |||
| 71 | () => (props.active ? props.instanceId : null), | 70 | () => (props.active ? props.instanceId : null), |
| 72 | async (instanceId) => (instanceId ? (await getInstanceHomework(instanceId)).items : []), | 71 | async (instanceId) => (instanceId ? (await getInstanceHomework(instanceId)).items : []), |
| 73 | ); | 72 | ); |
| 73 | + // A homework subject must sit in the section's resolved subject set. | ||
| 74 | const [subjects] = createResource( | 74 | const [subjects] = createResource( |
| 75 | - () => (props.active ? props.courseId : null), | 75 | + () => (props.active ? props.instanceId : null), |
| 76 | - async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), | 76 | + async (instanceId) => (instanceId ? (await getInstanceSubjects(instanceId)).subjects : []), |
| 77 | ); | 77 | ); |
| 78 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | 78 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); |
| 79 | const [editing, setEditing] = createSignal<Homework | null>(null); | 79 | const [editing, setEditing] = createSignal<Homework | null>(null); |
src/components/instances/exam-weights-editor.tsxadded+138 -0
| @@ -0,0 +1,138 @@ | |||
| 1 | +import { For, Show, createEffect, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 3 | +import { formatApiError } from "@/api/client"; | ||
| 4 | +import type { ExamWeightEntry } from "@/api/client"; | ||
| 5 | +import { Alert } from "@/components/ui/alert"; | ||
| 6 | +import { Button } from "@/components/ui/button"; | ||
| 7 | +import { DataTable } from "@/components/ui/data-table"; | ||
| 8 | +import { IconEdit, IconTrash } from "@/components/ui/icons"; | ||
| 9 | +import { Input } from "@/components/ui/input"; | ||
| 10 | +import { Label } from "@/components/ui/label"; | ||
| 11 | +import { Select } from "@/components/ui/select"; | ||
| 12 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 13 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 14 | +import { examKindLabel } from "@/lib/exam-labels"; | ||
| 15 | +import { useT } from "@/stores/preferences-context"; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * An exam-kind weight map. `editing` opens the set-a-weight panel (the parent | ||
| 19 | + * owns its header button); rows can be edited or removed when `canEdit`. | ||
| 20 | + */ | ||
| 21 | +export function ExamWeightsEditor(props: { | ||
| 22 | + weights: ExamWeightEntry[]; | ||
| 23 | + /** The kinds the school runs (settings.exam_kinds), for the picker. */ | ||
| 24 | + kinds: string[]; | ||
| 25 | + canEdit: boolean; | ||
| 26 | + onSet: (entry: ExamWeightEntry) => Promise<void>; | ||
| 27 | + onRemove?: (kind: string) => Promise<void>; | ||
| 28 | + editing: ExamWeightEntry | "new" | null; | ||
| 29 | + onEditingChange: (entry: ExamWeightEntry | "new" | null) => void; | ||
| 30 | +}) { | ||
| 31 | + const t = useT(); | ||
| 32 | + const [kind, setKind] = createSignal(""); | ||
| 33 | + const [weight, setWeight] = createSignal(""); | ||
| 34 | + const [error, setError] = createSignal(""); | ||
| 35 | + const [pending, setPending] = createSignal(false); | ||
| 36 | + const [removeError, setRemoveError] = createSignal(""); | ||
| 37 | + | ||
| 38 | + const remove = async (kind: string) => { | ||
| 39 | + setRemoveError(""); | ||
| 40 | + try { | ||
| 41 | + await props.onRemove?.(kind); | ||
| 42 | + } catch (err) { | ||
| 43 | + setRemoveError(formatApiError(err)); | ||
| 44 | + } | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + createEffect(() => { | ||
| 48 | + const target = props.editing; | ||
| 49 | + if (target === null) return; | ||
| 50 | + setKind(target === "new" ? props.kinds.find((k) => !props.weights.some((w) => w.kind === k)) ?? props.kinds[0] ?? "" : target.kind); | ||
| 51 | + setWeight(target === "new" ? "" : String(target.weight)); | ||
| 52 | + setError(""); | ||
| 53 | + }); | ||
| 54 | + | ||
| 55 | + const save = async (event: SubmitEvent) => { | ||
| 56 | + event.preventDefault(); | ||
| 57 | + const value = Number(weight().trim()); | ||
| 58 | + if (!Number.isInteger(value) || value < 1 || value > 100) { | ||
| 59 | + setError(t("instances.weightInvalid")); | ||
| 60 | + return; | ||
| 61 | + } | ||
| 62 | + setPending(true); | ||
| 63 | + try { | ||
| 64 | + await props.onSet({ kind: kind(), weight: value }); | ||
| 65 | + props.onEditingChange(null); | ||
| 66 | + } catch (err) { | ||
| 67 | + setError(formatApiError(err)); | ||
| 68 | + } finally { | ||
| 69 | + setPending(false); | ||
| 70 | + } | ||
| 71 | + }; | ||
| 72 | + | ||
| 73 | + const columns = createMemo<ColumnDef<ExamWeightEntry>[]>(() => [ | ||
| 74 | + { | ||
| 75 | + id: "kind", | ||
| 76 | + accessorFn: (row) => examKindLabel(row.kind, t), | ||
| 77 | + header: t("instances.examKind"), | ||
| 78 | + meta: { cellClass: "font-medium" }, | ||
| 79 | + }, | ||
| 80 | + { | ||
| 81 | + id: "weight", | ||
| 82 | + accessorFn: (row) => row.weight, | ||
| 83 | + header: t("instances.weight"), | ||
| 84 | + meta: { cellClass: "tabular-nums" }, | ||
| 85 | + }, | ||
| 86 | + ...(props.canEdit | ||
| 87 | + ? [ | ||
| 88 | + { | ||
| 89 | + id: "actions", | ||
| 90 | + header: t("common.actions"), | ||
| 91 | + meta: { headerClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", cellClass: "text-center" }, | ||
| 92 | + cell: (cell) => ( | ||
| 93 | + <TableRowActions | ||
| 94 | + label={t("common.actions")} | ||
| 95 | + actions={[ | ||
| 96 | + { label: t("instances.setWeight"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => props.onEditingChange(cell.row.original) }, | ||
| 97 | + ...(props.onRemove | ||
| 98 | + ? [{ label: t("instances.removeWeight"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => void remove(cell.row.original.kind) }] | ||
| 99 | + : []), | ||
| 100 | + ]} | ||
| 101 | + /> | ||
| 102 | + ), | ||
| 103 | + } satisfies ColumnDef<ExamWeightEntry>, | ||
| 104 | + ] | ||
| 105 | + : []), | ||
| 106 | + ]); | ||
| 107 | + | ||
| 108 | + return ( | ||
| 109 | + <> | ||
| 110 | + <Show when={removeError()}><Alert variant="destructive">{removeError()}</Alert></Show> | ||
| 111 | + <DataTable columns={columns()} data={props.weights} empty={t("common.noMatches")} /> | ||
| 112 | + <SidePanel | ||
| 113 | + open={props.editing !== null} | ||
| 114 | + onOpenChange={(open) => !open && props.onEditingChange(null)} | ||
| 115 | + title={props.editing === "new" ? t("instances.addWeight") : t("instances.setWeight")} | ||
| 116 | + description={t("instances.examWeightsHelp")} | ||
| 117 | + > | ||
| 118 | + <form class="space-y-4" noValidate onSubmit={save}> | ||
| 119 | + <div class="space-y-1.5"> | ||
| 120 | + <Label for="weight-kind">{t("instances.examKind")}</Label> | ||
| 121 | + <Select id="weight-kind" value={kind()} disabled={props.editing !== "new"} onChange={(e) => setKind(e.currentTarget.value)}> | ||
| 122 | + <For each={props.kinds}>{(k) => <option value={k}>{examKindLabel(k, t)}</option>}</For> | ||
| 123 | + </Select> | ||
| 124 | + </div> | ||
| 125 | + <div class="space-y-1.5"> | ||
| 126 | + <Label for="weight-value">{t("instances.weight")}</Label> | ||
| 127 | + <Input id="weight-value" type="number" inputMode="numeric" min={1} max={100} value={weight()} onInput={(e) => setWeight(e.currentTarget.value)} /> | ||
| 128 | + </div> | ||
| 129 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 130 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | ||
| 131 | + <Button type="submit" disabled={pending() || !kind()}>{t("common.save")}</Button> | ||
| 132 | + <Button type="button" variant="outline" onClick={() => props.onEditingChange(null)}>{t("common.cancel")}</Button> | ||
| 133 | + </div> | ||
| 134 | + </form> | ||
| 135 | + </SidePanel> | ||
| 136 | + </> | ||
| 137 | + ); | ||
| 138 | +} | ||
src/components/instances/instance-settings-panel.tsxadded+240 -0
| @@ -0,0 +1,240 @@ | |||
| 1 | +import { Show, createEffect, createSignal } from "solid-js"; | ||
| 2 | +import { | ||
| 3 | + deleteInstanceExamWeightByKind, | ||
| 4 | + deleteInstanceExamWeights, | ||
| 5 | + deleteInstanceSubjectById, | ||
| 6 | + deleteInstanceSubjects, | ||
| 7 | + patchInstanceById, | ||
| 8 | + patchInstanceExamWeight, | ||
| 9 | + postInstanceReset, | ||
| 10 | + postInstanceSubject, | ||
| 11 | +} from "@/api/instances"; | ||
| 12 | +import { formatApiError, type ExamWeightEntry, type Instance, type InstanceOverrideField, type Subject } from "@/api/client"; | ||
| 13 | +import { ExamWeightsEditor } from "@/components/instances/exam-weights-editor"; | ||
| 14 | +import { OverrideBadge } from "@/components/instances/override-badge"; | ||
| 15 | +import { SubjectSetEditor } from "@/components/instances/subject-set-editor"; | ||
| 16 | +import { Alert } from "@/components/ui/alert"; | ||
| 17 | +import { Button } from "@/components/ui/button"; | ||
| 18 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 19 | +import { DataSection } from "@/components/ui/data-section"; | ||
| 20 | +import { IconEdit, IconPlus, IconRotateCcw } from "@/components/ui/icons"; | ||
| 21 | +import { Input } from "@/components/ui/input"; | ||
| 22 | +import { Label } from "@/components/ui/label"; | ||
| 23 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 24 | +import { Textarea } from "@/components/ui/textarea"; | ||
| 25 | +import { useT } from "@/stores/preferences-context"; | ||
| 26 | + | ||
| 27 | +type ResetTarget = { fields: InstanceOverrideField[]; label: string; run?: () => Promise<void> }; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * What a section overrides of its grade template: title/description, hours | ||
| 31 | + * and the karne flag, the topic set and the exam weights. Every value is the | ||
| 32 | + * resolved one; a badge tells an own override from an inherited value, and | ||
| 33 | + * "reset" hands a field back to the template. | ||
| 34 | + */ | ||
| 35 | +export function InstanceSettingsPanel(props: { | ||
| 36 | + instance: Instance; | ||
| 37 | + canManage: boolean; | ||
| 38 | + /** The catalog course's subjects — what a section's own set may hold. */ | ||
| 39 | + courseSubjects: Subject[]; | ||
| 40 | + /** settings.exam_kinds names. */ | ||
| 41 | + examKinds: string[]; | ||
| 42 | + maxTitleLen?: number; | ||
| 43 | + maxDescriptionLen?: number; | ||
| 44 | + onChanged: () => unknown; | ||
| 45 | +}) { | ||
| 46 | + const t = useT(); | ||
| 47 | + const [error, setError] = createSignal(""); | ||
| 48 | + const [editingContent, setEditingContent] = createSignal(false); | ||
| 49 | + const [title, setTitle] = createSignal(""); | ||
| 50 | + const [description, setDescription] = createSignal(""); | ||
| 51 | + const [contentError, setContentError] = createSignal(""); | ||
| 52 | + const [pending, setPending] = createSignal(false); | ||
| 53 | + const [reset, setReset] = createSignal<ResetTarget | null>(null); | ||
| 54 | + const [weightEditing, setWeightEditing] = createSignal<ExamWeightEntry | "new" | null>(null); | ||
| 55 | + | ||
| 56 | + createEffect(() => { | ||
| 57 | + if (!editingContent()) return; | ||
| 58 | + setTitle(props.instance.title); | ||
| 59 | + setDescription(props.instance.description); | ||
| 60 | + setContentError(""); | ||
| 61 | + }); | ||
| 62 | + | ||
| 63 | + const act = async (action: () => Promise<unknown>) => { | ||
| 64 | + setError(""); | ||
| 65 | + try { | ||
| 66 | + await action(); | ||
| 67 | + await props.onChanged(); | ||
| 68 | + } catch (err) { | ||
| 69 | + setError(formatApiError(err)); | ||
| 70 | + throw err; | ||
| 71 | + } | ||
| 72 | + }; | ||
| 73 | + | ||
| 74 | + // For editors that show their own error: write, then reload the instance. | ||
| 75 | + const mutate = async (action: () => Promise<unknown>) => { | ||
| 76 | + await action(); | ||
| 77 | + await props.onChanged(); | ||
| 78 | + }; | ||
| 79 | + | ||
| 80 | + const saveContent = async (event: SubmitEvent) => { | ||
| 81 | + event.preventDefault(); | ||
| 82 | + const nextTitle = title().trim(); | ||
| 83 | + if (!nextTitle) { | ||
| 84 | + setContentError(t("form.fieldRequired")); | ||
| 85 | + return; | ||
| 86 | + } | ||
| 87 | + // PATCH only what changed: sending an unchanged inherited value would | ||
| 88 | + // silently freeze it as the section's own override. | ||
| 89 | + const body: { title?: string; description?: string } = {}; | ||
| 90 | + if (nextTitle !== props.instance.title) body.title = nextTitle; | ||
| 91 | + if (description().trim() !== props.instance.description) body.description = description().trim(); | ||
| 92 | + if (!body.title && body.description === undefined) { | ||
| 93 | + setEditingContent(false); | ||
| 94 | + return; | ||
| 95 | + } | ||
| 96 | + setPending(true); | ||
| 97 | + try { | ||
| 98 | + await patchInstanceById(props.instance.id, body); | ||
| 99 | + await props.onChanged(); | ||
| 100 | + setEditingContent(false); | ||
| 101 | + } catch (err) { | ||
| 102 | + setContentError(formatApiError(err)); | ||
| 103 | + } finally { | ||
| 104 | + setPending(false); | ||
| 105 | + } | ||
| 106 | + }; | ||
| 107 | + | ||
| 108 | + const resetButton = (target: ResetTarget) => ( | ||
| 109 | + <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setReset(target)}> | ||
| 110 | + <IconRotateCcw class="h-4 w-4" /> | ||
| 111 | + {t("override.reset")} | ||
| 112 | + </Button> | ||
| 113 | + ); | ||
| 114 | + | ||
| 115 | + const row = (label: string, value: string, own: boolean, field: InstanceOverrideField) => ( | ||
| 116 | + <div class="flex flex-wrap items-center justify-between gap-3 border-b border-border-hairline py-2.5 last:border-b-0"> | ||
| 117 | + <div class="min-w-0 flex-1"> | ||
| 118 | + <p class="text-xs font-medium text-text-subtle">{label}</p> | ||
| 119 | + <p class="truncate text-sm text-text-default" title={value}>{value || "—"}</p> | ||
| 120 | + </div> | ||
| 121 | + <div class="flex shrink-0 items-center gap-2"> | ||
| 122 | + <OverrideBadge own={own} /> | ||
| 123 | + <Show when={props.canManage && own}> | ||
| 124 | + {resetButton({ fields: [field], label })} | ||
| 125 | + </Show> | ||
| 126 | + </div> | ||
| 127 | + </div> | ||
| 128 | + ); | ||
| 129 | + | ||
| 130 | + return ( | ||
| 131 | + <div class="space-y-4"> | ||
| 132 | + <p class="text-sm text-muted-foreground">{t("instances.settingsHelp")}</p> | ||
| 133 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 134 | + | ||
| 135 | + <DataSection | ||
| 136 | + title={t("instances.contentTitle")} | ||
| 137 | + description={t("instances.contentHelp")} | ||
| 138 | + actions={ | ||
| 139 | + <Show when={props.canManage}> | ||
| 140 | + <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setEditingContent(true)}> | ||
| 141 | + <IconEdit class="h-4 w-4" /> | ||
| 142 | + {t("instances.editContent")} | ||
| 143 | + </Button> | ||
| 144 | + </Show> | ||
| 145 | + } | ||
| 146 | + > | ||
| 147 | + <div> | ||
| 148 | + {row(t("form.title"), props.instance.title, props.instance.title_overridden, "title")} | ||
| 149 | + {row(t("form.description"), props.instance.description, props.instance.description_overridden, "description")} | ||
| 150 | + </div> | ||
| 151 | + </DataSection> | ||
| 152 | + | ||
| 153 | + <DataSection title={t("instances.policyTitle")}> | ||
| 154 | + <div> | ||
| 155 | + {row(t("instances.dersSaati"), String(props.instance.ders_saati), props.instance.ders_saati_overridden, "ders_saati")} | ||
| 156 | + {row(t("instances.countsTowardKarne"), props.instance.counts_toward_karne ? t("common.yes") : t("common.no"), props.instance.counts_toward_karne_overridden, "counts_toward_karne")} | ||
| 157 | + </div> | ||
| 158 | + </DataSection> | ||
| 159 | + | ||
| 160 | + <DataSection | ||
| 161 | + title={t("instances.subjectsTitle")} | ||
| 162 | + description={`${t("instances.subjectsHelp")} ${props.instance.subjects_inherited ? t("instances.subjectsInheritedHint") : t("instances.subjectsOwnHint")}`} | ||
| 163 | + actions={ | ||
| 164 | + <Show when={props.canManage && !props.instance.subjects_inherited}> | ||
| 165 | + {resetButton({ fields: ["subjects"], label: t("instances.subjectsTitle"), run: () => deleteInstanceSubjects(props.instance.id) })} | ||
| 166 | + </Show> | ||
| 167 | + } | ||
| 168 | + > | ||
| 169 | + <OverrideBadge own={!props.instance.subjects_inherited} /> | ||
| 170 | + <SubjectSetEditor | ||
| 171 | + selected={props.instance.subjects} | ||
| 172 | + available={props.courseSubjects} | ||
| 173 | + canEdit={props.canManage} | ||
| 174 | + onAdd={(subjectId) => mutate(() => postInstanceSubject(props.instance.id, subjectId))} | ||
| 175 | + onRemove={(subject) => mutate(() => deleteInstanceSubjectById(props.instance.id, subject.id))} | ||
| 176 | + /> | ||
| 177 | + </DataSection> | ||
| 178 | + | ||
| 179 | + <DataSection | ||
| 180 | + title={t("instances.examWeightsTitle")} | ||
| 181 | + description={`${t("instances.examWeightsHelp")} ${props.instance.exam_weights_inherited ? t("instances.examWeightsInheritedHint") : t("instances.examWeightsOwnHint")}`} | ||
| 182 | + actions={ | ||
| 183 | + <Show when={props.canManage}> | ||
| 184 | + <Show when={!props.instance.exam_weights_inherited}> | ||
| 185 | + {resetButton({ fields: ["exam_weights"], label: t("instances.examWeightsTitle"), run: () => deleteInstanceExamWeights(props.instance.id) })} | ||
| 186 | + </Show> | ||
| 187 | + <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setWeightEditing("new")}> | ||
| 188 | + <IconPlus class="h-4 w-4" /> | ||
| 189 | + {t("instances.addWeight")} | ||
| 190 | + </Button> | ||
| 191 | + </Show> | ||
| 192 | + } | ||
| 193 | + > | ||
| 194 | + <OverrideBadge own={!props.instance.exam_weights_inherited} /> | ||
| 195 | + <ExamWeightsEditor | ||
| 196 | + weights={props.instance.exam_weights} | ||
| 197 | + kinds={props.examKinds} | ||
| 198 | + canEdit={props.canManage} | ||
| 199 | + editing={weightEditing()} | ||
| 200 | + onEditingChange={setWeightEditing} | ||
| 201 | + onSet={(entry) => mutate(() => patchInstanceExamWeight(props.instance.id, entry))} | ||
| 202 | + onRemove={props.instance.exam_weights_inherited ? undefined : (kind) => mutate(() => deleteInstanceExamWeightByKind(props.instance.id, kind))} | ||
| 203 | + /> | ||
| 204 | + </DataSection> | ||
| 205 | + | ||
| 206 | + <SidePanel guardUnsaved open={editingContent()} onOpenChange={setEditingContent} title={t("instances.editContent")} description={t("instances.contentHelp")}> | ||
| 207 | + <form class="space-y-4" noValidate onSubmit={saveContent}> | ||
| 208 | + <div class="space-y-1.5"> | ||
| 209 | + <Label for="instance-title">{t("form.title")}</Label> | ||
| 210 | + <Input id="instance-title" maxlength={props.maxTitleLen} value={title()} error={contentError() && !title().trim() ? contentError() : undefined} onInput={(e) => setTitle(e.currentTarget.value)} /> | ||
| 211 | + </div> | ||
| 212 | + <div class="space-y-1.5"> | ||
| 213 | + <Label for="instance-description">{t("form.description")}</Label> | ||
| 214 | + <Textarea id="instance-description" rows={4} maxlength={props.maxDescriptionLen} value={description()} onInput={(e) => setDescription(e.currentTarget.value)} /> | ||
| 215 | + </div> | ||
| 216 | + <Show when={contentError() && title().trim()}><Alert variant="destructive">{contentError()}</Alert></Show> | ||
| 217 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | ||
| 218 | + <Button type="submit" disabled={pending()}>{t("common.save")}</Button> | ||
| 219 | + <Button type="button" variant="outline" onClick={() => setEditingContent(false)}>{t("common.cancel")}</Button> | ||
| 220 | + </div> | ||
| 221 | + </form> | ||
| 222 | + </SidePanel> | ||
| 223 | + | ||
| 224 | + <ConfirmDialog | ||
| 225 | + open={reset() !== null} | ||
| 226 | + onOpenChange={(open) => !open && setReset(null)} | ||
| 227 | + title={t("override.resetConfirmTitle")} | ||
| 228 | + description={t("override.resetConfirmHint")} | ||
| 229 | + summary={reset()?.label ?? ""} | ||
| 230 | + confirmLabel={t("override.reset")} | ||
| 231 | + onConfirm={async () => { | ||
| 232 | + const target = reset(); | ||
| 233 | + if (!target) return; | ||
| 234 | + await act(() => (target.run ? target.run() : postInstanceReset(props.instance.id, target.fields))).catch(() => undefined); | ||
| 235 | + setReset(null); | ||
| 236 | + }} | ||
| 237 | + /> | ||
| 238 | + </div> | ||
| 239 | + ); | ||
| 240 | +} | ||
src/components/instances/instance-weekly-plan-panel.tsxadded+126 -0
| @@ -0,0 +1,126 @@ | |||
| 1 | +import { Show, createSignal } from "solid-js"; | ||
| 2 | +import { | ||
| 3 | + deleteInstanceWeeklyPlan, | ||
| 4 | + deleteInstanceWeeklySlotById, | ||
| 5 | + postInstanceWeeklySlot, | ||
| 6 | +} from "@/api/instances"; | ||
| 7 | +import { formatApiError, type Instance, type Limits, type MaterializeReport, type WeeklySlot } from "@/api/client"; | ||
| 8 | +import { MaterializePanel } from "@/components/instances/materialize-panel"; | ||
| 9 | +import { OverrideBadge } from "@/components/instances/override-badge"; | ||
| 10 | +import { WeeklyPlanTable } from "@/components/instances/weekly-plan-table"; | ||
| 11 | +import { WeeklySlotForm } from "@/components/instances/weekly-slot-form"; | ||
| 12 | +import { Alert } from "@/components/ui/alert"; | ||
| 13 | +import { Button } from "@/components/ui/button"; | ||
| 14 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 15 | +import { DataSection } from "@/components/ui/data-section"; | ||
| 16 | +import { IconCalendarCheck, IconPlus, IconRotateCcw } from "@/components/ui/icons"; | ||
| 17 | +import { useT } from "@/stores/preferences-context"; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * A section's resolved weekly plan. Editing a slot takes the plan own; the | ||
| 21 | + * reset brings the grade template's week back. Generating lessons expands | ||
| 22 | + * whichever plan resolves into dated sessions. | ||
| 23 | + */ | ||
| 24 | +export function InstanceWeeklyPlanPanel(props: { | ||
| 25 | + instance: Instance; | ||
| 26 | + canManage: boolean; | ||
| 27 | + /** The sessions module is on, so generated lessons have somewhere to go. */ | ||
| 28 | + canGenerate: boolean; | ||
| 29 | + limits?: Limits["weekly_plan"]; | ||
| 30 | + maxTopicLen?: number; | ||
| 31 | + onChanged: () => unknown; | ||
| 32 | + onLessonsCreated: (report: MaterializeReport) => void; | ||
| 33 | +}) { | ||
| 34 | + const t = useT(); | ||
| 35 | + const [adding, setAdding] = createSignal(false); | ||
| 36 | + const [generating, setGenerating] = createSignal(false); | ||
| 37 | + const [resetOpen, setResetOpen] = createSignal(false); | ||
| 38 | + const [error, setError] = createSignal(""); | ||
| 39 | + const own = () => !props.instance.weekly_plan_inherited; | ||
| 40 | + | ||
| 41 | + const remove = async (slot: WeeklySlot) => { | ||
| 42 | + setError(""); | ||
| 43 | + try { | ||
| 44 | + await deleteInstanceWeeklySlotById(props.instance.id, slot.id); | ||
| 45 | + await props.onChanged(); | ||
| 46 | + } catch (err) { | ||
| 47 | + setError(formatApiError(err)); | ||
| 48 | + } | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + return ( | ||
| 52 | + <DataSection | ||
| 53 | + title={t("weeklyPlan.title")} | ||
| 54 | + description={own() ? t("weeklyPlan.ownHint") : t("weeklyPlan.inheritedHint")} | ||
| 55 | + actions={ | ||
| 56 | + <Show when={props.canManage}> | ||
| 57 | + <Show when={own()}> | ||
| 58 | + <Button type="button" size="sm" variant="outline" class="rounded-lg" onClick={() => setResetOpen(true)}> | ||
| 59 | + <IconRotateCcw class="h-4 w-4" /> | ||
| 60 | + {t("override.reset")} | ||
| 61 | + </Button> | ||
| 62 | + </Show> | ||
| 63 | + <Show when={props.canGenerate}> | ||
| 64 | + <Button | ||
| 65 | + type="button" | ||
| 66 | + size="sm" | ||
| 67 | + variant="outline" | ||
| 68 | + class="rounded-lg" | ||
| 69 | + disabled={props.instance.weekly_plan.length === 0 || props.instance.teachers.length === 0} | ||
| 70 | + title={props.instance.teachers.length === 0 ? t("weeklyPlan.noTeacherHint") : undefined} | ||
| 71 | + onClick={() => setGenerating(true)} | ||
| 72 | + > | ||
| 73 | + <IconCalendarCheck class="h-4 w-4" /> | ||
| 74 | + {t("weeklyPlan.generate")} | ||
| 75 | + </Button> | ||
| 76 | + </Show> | ||
| 77 | + <Button type="button" size="sm" class="rounded-lg" onClick={() => setAdding(true)}> | ||
| 78 | + <IconPlus class="h-4 w-4" /> | ||
| 79 | + {t("weeklyPlan.addSlot")} | ||
| 80 | + </Button> | ||
| 81 | + </Show> | ||
| 82 | + } | ||
| 83 | + > | ||
| 84 | + <div class="flex items-center gap-2"> | ||
| 85 | + <OverrideBadge own={own()} /> | ||
| 86 | + </div> | ||
| 87 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 88 | + <WeeklyPlanTable slots={props.instance.weekly_plan} onRemove={props.canManage ? (slot) => void remove(slot) : undefined} /> | ||
| 89 | + | ||
| 90 | + <WeeklySlotForm | ||
| 91 | + open={adding()} | ||
| 92 | + onOpenChange={setAdding} | ||
| 93 | + minMinute={props.limits?.min_slot_minute} | ||
| 94 | + maxMinute={props.limits?.max_slot_minute} | ||
| 95 | + maxTopicLen={props.maxTopicLen} | ||
| 96 | + onSubmit={async (body) => { | ||
| 97 | + await postInstanceWeeklySlot(props.instance.id, body); | ||
| 98 | + await props.onChanged(); | ||
| 99 | + }} | ||
| 100 | + /> | ||
| 101 | + <MaterializePanel | ||
| 102 | + instanceId={props.instance.id} | ||
| 103 | + open={generating()} | ||
| 104 | + onOpenChange={setGenerating} | ||
| 105 | + maxDays={props.limits?.max_materialize_days} | ||
| 106 | + onApplied={props.onLessonsCreated} | ||
| 107 | + /> | ||
| 108 | + <ConfirmDialog | ||
| 109 | + open={resetOpen()} | ||
| 110 | + onOpenChange={setResetOpen} | ||
| 111 | + title={t("override.resetConfirmTitle")} | ||
| 112 | + description={t("override.resetConfirmHint")} | ||
| 113 | + summary={t("weeklyPlan.title")} | ||
| 114 | + confirmLabel={t("override.reset")} | ||
| 115 | + onConfirm={async () => { | ||
| 116 | + try { | ||
| 117 | + await deleteInstanceWeeklyPlan(props.instance.id); | ||
| 118 | + await props.onChanged(); | ||
| 119 | + } catch (err) { | ||
| 120 | + setError(formatApiError(err)); | ||
| 121 | + } | ||
| 122 | + }} | ||
| 123 | + /> | ||
| 124 | + </DataSection> | ||
| 125 | + ); | ||
| 126 | +} | ||
src/components/instances/materialize-panel.tsxadded+132 -0
| @@ -0,0 +1,132 @@ | |||
| 1 | +import { For, Show, createEffect, createSignal } from "solid-js"; | ||
| 2 | +import { postInstanceWeeklyPlanMaterialize } from "@/api/instances"; | ||
| 3 | +import { formatApiError, type MaterializeReport } from "@/api/client"; | ||
| 4 | +import { Alert } from "@/components/ui/alert"; | ||
| 5 | +import { Button } from "@/components/ui/button"; | ||
| 6 | +import { DatePicker } from "@/components/ui/date-picker"; | ||
| 7 | +import { Label } from "@/components/ui/label"; | ||
| 8 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 9 | +import { dateInputToEndOfDayMs, dateTimeInputToMs, isoDateToInput } from "@/lib/datetime-input"; | ||
| 10 | +import { useT } from "@/stores/preferences-context"; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * Turns a section's resolved weekly plan into dated lessons. Always previews | ||
| 14 | + * first (a dry run writes nothing), then the same range is applied — the call | ||
| 15 | + * is additive and idempotent, so a retry never doubles a lesson. | ||
| 16 | + */ | ||
| 17 | +export function MaterializePanel(props: { | ||
| 18 | + instanceId: string; | ||
| 19 | + open: boolean; | ||
| 20 | + onOpenChange: (open: boolean) => void; | ||
| 21 | + /** limits.weekly_plan.max_materialize_days */ | ||
| 22 | + maxDays?: number; | ||
| 23 | + onApplied: (report: MaterializeReport) => void | Promise<void>; | ||
| 24 | +}) { | ||
| 25 | + const t = useT(); | ||
| 26 | + const [from, setFrom] = createSignal(""); | ||
| 27 | + const [to, setTo] = createSignal(""); | ||
| 28 | + const [preview, setPreview] = createSignal<MaterializeReport | null>(null); | ||
| 29 | + const [error, setError] = createSignal(""); | ||
| 30 | + const [pending, setPending] = createSignal(false); | ||
| 31 | + | ||
| 32 | + createEffect(() => { | ||
| 33 | + if (!props.open) return; | ||
| 34 | + setFrom(""); | ||
| 35 | + setTo(""); | ||
| 36 | + setPreview(null); | ||
| 37 | + setError(""); | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + const range = () => { | ||
| 41 | + const fromMs = dateTimeInputToMs(from(), "00:00"); | ||
| 42 | + const toMs = dateInputToEndOfDayMs(to()); | ||
| 43 | + if (fromMs === null || toMs === null || toMs < fromMs) return null; | ||
| 44 | + return { from: fromMs, to: toMs }; | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + const run = async (apply: boolean) => { | ||
| 48 | + const body = range(); | ||
| 49 | + if (!body) { | ||
| 50 | + setError(t("weeklyPlan.rangeInvalid")); | ||
| 51 | + return; | ||
| 52 | + } | ||
| 53 | + const days = Math.round((body.to - body.from) / 86_400_000); | ||
| 54 | + if (props.maxDays && days > props.maxDays) { | ||
| 55 | + setError(t("weeklyPlan.rangeTooLong", { days: props.maxDays })); | ||
| 56 | + return; | ||
| 57 | + } | ||
| 58 | + setError(""); | ||
| 59 | + setPending(true); | ||
| 60 | + try { | ||
| 61 | + const report = await postInstanceWeeklyPlanMaterialize(props.instanceId, { ...body, apply }); | ||
| 62 | + if (apply) { | ||
| 63 | + props.onOpenChange(false); | ||
| 64 | + await props.onApplied(report); | ||
| 65 | + } else { | ||
| 66 | + setPreview(report); | ||
| 67 | + } | ||
| 68 | + } catch (err) { | ||
| 69 | + setError(formatApiError(err)); | ||
| 70 | + } finally { | ||
| 71 | + setPending(false); | ||
| 72 | + } | ||
| 73 | + }; | ||
| 74 | + | ||
| 75 | + return ( | ||
| 76 | + <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("weeklyPlan.generate")} description={t("weeklyPlan.generateHelp")}> | ||
| 77 | + <div class="space-y-4"> | ||
| 78 | + <div class="grid grid-cols-2 gap-2"> | ||
| 79 | + <div class="space-y-1.5"> | ||
| 80 | + <Label for="materialize-from">{t("weeklyPlan.from")}</Label> | ||
| 81 | + <DatePicker id="materialize-from" placeholder={t("form.datePlaceholder")} value={from()} onChange={(value) => { setFrom(value); setPreview(null); }} /> | ||
| 82 | + </div> | ||
| 83 | + <div class="space-y-1.5"> | ||
| 84 | + <Label for="materialize-to">{t("weeklyPlan.to")}</Label> | ||
| 85 | + <DatePicker id="materialize-to" placeholder={t("form.datePlaceholder")} value={to()} onChange={(value) => { setTo(value); setPreview(null); }} /> | ||
| 86 | + </div> | ||
| 87 | + </div> | ||
| 88 | + | ||
| 89 | + <Show when={preview()}> | ||
| 90 | + {(report) => ( | ||
| 91 | + <div class="space-y-3 rounded-xl border border-border-line bg-surface-tint p-3 text-sm"> | ||
| 92 | + <p class="font-medium"> | ||
| 93 | + {t("weeklyPlan.previewSummary", { | ||
| 94 | + candidates: report().candidates, | ||
| 95 | + existing: report().skipped_existing, | ||
| 96 | + holiday: report().skipped_holiday, | ||
| 97 | + })} | ||
| 98 | + </p> | ||
| 99 | + <Show when={report().candidates === 0}> | ||
| 100 | + <p class="text-muted-foreground">{t("weeklyPlan.nothingToCreate")}</p> | ||
| 101 | + </Show> | ||
| 102 | + <Show when={report().blocked.length > 0}> | ||
| 103 | + <div class="space-y-1"> | ||
| 104 | + <p class="text-xs font-medium text-text-subtle">{t("weeklyPlan.blockedDays")}</p> | ||
| 105 | + <ul class="flex flex-wrap gap-1.5 text-xs"> | ||
| 106 | + <For each={report().blocked}> | ||
| 107 | + {(day) => <li class="rounded-md border border-border-line bg-surface-base px-2 py-0.5 font-mono">{isoDateToInput(day.date)}</li>} | ||
| 108 | + </For> | ||
| 109 | + </ul> | ||
| 110 | + </div> | ||
| 111 | + </Show> | ||
| 112 | + </div> | ||
| 113 | + )} | ||
| 114 | + </Show> | ||
| 115 | + | ||
| 116 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 117 | + | ||
| 118 | + <div class="flex flex-wrap gap-2 border-t border-border-hairline pt-4"> | ||
| 119 | + <Show | ||
| 120 | + when={preview() && preview()!.candidates > 0} | ||
| 121 | + fallback={<Button type="button" disabled={pending() || !from() || !to()} onClick={() => void run(false)}>{t("weeklyPlan.preview")}</Button>} | ||
| 122 | + > | ||
| 123 | + <Button type="button" disabled={pending()} onClick={() => void run(true)}> | ||
| 124 | + {t("weeklyPlan.apply", { count: preview()!.candidates })} | ||
| 125 | + </Button> | ||
| 126 | + </Show> | ||
| 127 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | ||
| 128 | + </div> | ||
| 129 | + </div> | ||
| 130 | + </SidePanel> | ||
| 131 | + ); | ||
| 132 | +} | ||
src/components/instances/override-badge.tsxadded+12 -0
| @@ -0,0 +1,12 @@ | |||
| 1 | +import { Badge } from "@/components/ui/badge"; | ||
| 2 | +import { useT } from "@/stores/preferences-context"; | ||
| 3 | + | ||
| 4 | +/** Whether a resolved value is the section's own override or inherited. */ | ||
| 5 | +export function OverrideBadge(props: { own: boolean }) { | ||
| 6 | + const t = useT(); | ||
| 7 | + return ( | ||
| 8 | + <Badge variant={props.own ? "info" : "outline"} class="shrink-0 rounded-md text-[11px] font-medium"> | ||
| 9 | + {props.own ? t("override.own") : t("override.inherited")} | ||
| 10 | + </Badge> | ||
| 11 | + ); | ||
| 12 | +} | ||
src/components/instances/subject-set-editor.tsxadded+95 -0
| @@ -0,0 +1,95 @@ | |||
| 1 | +import { For, Show, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import { formatApiError } from "@/api/client"; | ||
| 3 | +import type { Subject } from "@/api/client"; | ||
| 4 | +import { Alert } from "@/components/ui/alert"; | ||
| 5 | +import { Button } from "@/components/ui/button"; | ||
| 6 | +import { IconPlus, IconX } from "@/components/ui/icons"; | ||
| 7 | +import { SearchableSelect } from "@/components/ui/searchable-select"; | ||
| 8 | +import { useT } from "@/stores/preferences-context"; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * A selected-topic set (a grade template's, or a section's own) drawn as | ||
| 12 | + * chips; editors add from the catalog course's subjects and remove chips. | ||
| 13 | + */ | ||
| 14 | +export function SubjectSetEditor(props: { | ||
| 15 | + selected: Subject[]; | ||
| 16 | + /** The catalog course's subjects — the only ones a set may hold. */ | ||
| 17 | + available: Subject[]; | ||
| 18 | + canEdit: boolean; | ||
| 19 | + onAdd: (subjectId: string) => Promise<void>; | ||
| 20 | + onRemove: (subject: Subject) => Promise<void>; | ||
| 21 | +}) { | ||
| 22 | + const t = useT(); | ||
| 23 | + const [pick, setPick] = createSignal(""); | ||
| 24 | + const [pending, setPending] = createSignal(false); | ||
| 25 | + const [error, setError] = createSignal(""); | ||
| 26 | + const addable = createMemo(() => { | ||
| 27 | + const taken = new Set(props.selected.map((subject) => subject.id)); | ||
| 28 | + return props.available.filter((subject) => !taken.has(subject.id)); | ||
| 29 | + }); | ||
| 30 | + | ||
| 31 | + const run = async (action: () => Promise<void>) => { | ||
| 32 | + if (pending()) return; | ||
| 33 | + setError(""); | ||
| 34 | + setPending(true); | ||
| 35 | + try { | ||
| 36 | + await action(); | ||
| 37 | + } catch (err) { | ||
| 38 | + setError(formatApiError(err)); | ||
| 39 | + } finally { | ||
| 40 | + setPending(false); | ||
| 41 | + } | ||
| 42 | + }; | ||
| 43 | + | ||
| 44 | + return ( | ||
| 45 | + <div class="space-y-3"> | ||
| 46 | + <Show when={props.selected.length > 0} fallback={<p class="text-sm text-muted-foreground">{t("instances.noSubjects")}</p>}> | ||
| 47 | + <ul class="flex flex-wrap gap-1.5"> | ||
| 48 | + <For each={props.selected}> | ||
| 49 | + {(subject) => ( | ||
| 50 | + <li class="inline-flex items-center gap-1 rounded-md border border-border-line bg-surface-tint py-1 pl-2.5 pr-1 text-sm"> | ||
| 51 | + <span class="max-w-[16rem] truncate" title={subject.description || subject.name}>{subject.name}</span> | ||
| 52 | + <Show when={props.canEdit}> | ||
| 53 | + <button | ||
| 54 | + type="button" | ||
| 55 | + class="inline-flex h-5 w-5 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-destructive-text disabled:opacity-50" | ||
| 56 | + aria-label={`${t("instances.removeSubject")}: ${subject.name}`} | ||
| 57 | + disabled={pending()} | ||
| 58 | + onClick={() => void run(() => props.onRemove(subject))} | ||
| 59 | + > | ||
| 60 | + <IconX class="h-3.5 w-3.5" /> | ||
| 61 | + </button> | ||
| 62 | + </Show> | ||
| 63 | + </li> | ||
| 64 | + )} | ||
| 65 | + </For> | ||
| 66 | + </ul> | ||
| 67 | + </Show> | ||
| 68 | + <Show when={props.canEdit}> | ||
| 69 | + <Show when={addable().length > 0} fallback={<p class="text-xs text-muted-foreground">{t("instances.allSubjectsSelected")}</p>}> | ||
| 70 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 71 | + <SearchableSelect | ||
| 72 | + class="min-w-56 flex-1 sm:max-w-sm" | ||
| 73 | + value={pick()} | ||
| 74 | + onChange={setPick} | ||
| 75 | + placeholder={t("instances.addSubject")} | ||
| 76 | + options={addable().map((subject) => ({ value: subject.id, label: subject.name }))} | ||
| 77 | + /> | ||
| 78 | + <Button | ||
| 79 | + type="button" | ||
| 80 | + size="sm" | ||
| 81 | + variant="outline" | ||
| 82 | + class="rounded-lg" | ||
| 83 | + disabled={!pick() || pending()} | ||
| 84 | + onClick={() => void run(async () => { await props.onAdd(pick()); setPick(""); })} | ||
| 85 | + > | ||
| 86 | + <IconPlus class="h-4 w-4" /> | ||
| 87 | + {t("instances.addSubject")} | ||
| 88 | + </Button> | ||
| 89 | + </div> | ||
| 90 | + </Show> | ||
| 91 | + </Show> | ||
| 92 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 93 | + </div> | ||
| 94 | + ); | ||
| 95 | +} | ||
src/components/instances/weekly-plan-table.tsxadded+54 -0
| @@ -0,0 +1,54 @@ | |||
| 1 | +import { createMemo } from "solid-js"; | ||
| 2 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 3 | +import type { WeeklySlot } from "@/api/client"; | ||
| 4 | +import { DataTable } from "@/components/ui/data-table"; | ||
| 5 | +import { IconTrash } from "@/components/ui/icons"; | ||
| 6 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 7 | +import { minutesToHHmm, sortSlots, weekdayLabel } from "@/lib/weekly-plan"; | ||
| 8 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 9 | + | ||
| 10 | +/** A weekly plan's slots, weekday first; removable when `onRemove` is given. */ | ||
| 11 | +export function WeeklyPlanTable(props: { slots: WeeklySlot[]; onRemove?: (slot: WeeklySlot) => void; empty?: string }) { | ||
| 12 | + const t = useT(); | ||
| 13 | + const { locale } = usePreferences(); | ||
| 14 | + const rows = createMemo(() => sortSlots(props.slots)); | ||
| 15 | + const columns = createMemo<ColumnDef<WeeklySlot>[]>(() => [ | ||
| 16 | + { | ||
| 17 | + id: "weekday", | ||
| 18 | + accessorFn: (row) => row.weekday, | ||
| 19 | + header: t("weeklyPlan.weekday"), | ||
| 20 | + meta: { cellClass: "font-medium whitespace-nowrap" }, | ||
| 21 | + cell: (cell) => weekdayLabel(cell.row.original.weekday, locale()), | ||
| 22 | + }, | ||
| 23 | + { | ||
| 24 | + id: "time", | ||
| 25 | + accessorFn: (row) => row.starts_at, | ||
| 26 | + header: t("weeklyPlan.time"), | ||
| 27 | + meta: { cellClass: "font-mono whitespace-nowrap" }, | ||
| 28 | + cell: (cell) => `${minutesToHHmm(cell.row.original.starts_at)}–${minutesToHHmm(cell.row.original.ends_at)}`, | ||
| 29 | + }, | ||
| 30 | + { | ||
| 31 | + id: "topic", | ||
| 32 | + accessorFn: (row) => row.topic ?? "", | ||
| 33 | + header: t("weeklyPlan.topic"), | ||
| 34 | + meta: { cellClass: "text-muted-foreground" }, | ||
| 35 | + cell: (cell) => cell.row.original.topic || "—", | ||
| 36 | + }, | ||
| 37 | + ...(props.onRemove | ||
| 38 | + ? [ | ||
| 39 | + { | ||
| 40 | + id: "actions", | ||
| 41 | + header: t("common.actions"), | ||
| 42 | + meta: { headerClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", cellClass: "text-center" }, | ||
| 43 | + cell: (cell) => ( | ||
| 44 | + <TableRowActions | ||
| 45 | + label={t("common.actions")} | ||
| 46 | + actions={[{ label: t("weeklyPlan.removeSlot"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => props.onRemove?.(cell.row.original) }]} | ||
| 47 | + /> | ||
| 48 | + ), | ||
| 49 | + } satisfies ColumnDef<WeeklySlot>, | ||
| 50 | + ] | ||
| 51 | + : []), | ||
| 52 | + ]); | ||
| 53 | + return <DataTable columns={columns()} data={rows()} empty={props.empty ?? t("weeklyPlan.empty")} />; | ||
| 54 | +} | ||
src/components/instances/weekly-slot-form.tsxadded+94 -0
| @@ -0,0 +1,94 @@ | |||
| 1 | +import { For, Show, createEffect, createSignal } from "solid-js"; | ||
| 2 | +import { formatApiError } from "@/api/client"; | ||
| 3 | +import type { CreateWeeklySlotBody } from "@/api/offerings"; | ||
| 4 | +import { Alert } from "@/components/ui/alert"; | ||
| 5 | +import { Button } from "@/components/ui/button"; | ||
| 6 | +import { Input } from "@/components/ui/input"; | ||
| 7 | +import { Label } from "@/components/ui/label"; | ||
| 8 | +import { Select } from "@/components/ui/select"; | ||
| 9 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 10 | +import { WEEKDAYS, hhmmToMinutes, weekdayLabel } from "@/lib/weekly-plan"; | ||
| 11 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 12 | + | ||
| 13 | +/** The add-a-lesson-time form a weekly plan (offering or section) shares. */ | ||
| 14 | +export function WeeklySlotForm(props: { | ||
| 15 | + open: boolean; | ||
| 16 | + onOpenChange: (open: boolean) => void; | ||
| 17 | + onSubmit: (body: CreateWeeklySlotBody) => Promise<void>; | ||
| 18 | + /** Inclusive minute bounds from limits.weekly_plan. */ | ||
| 19 | + minMinute?: number; | ||
| 20 | + maxMinute?: number; | ||
| 21 | + maxTopicLen?: number; | ||
| 22 | +}) { | ||
| 23 | + const t = useT(); | ||
| 24 | + const { locale } = usePreferences(); | ||
| 25 | + const [weekday, setWeekday] = createSignal("1"); | ||
| 26 | + const [starts, setStarts] = createSignal(""); | ||
| 27 | + const [ends, setEnds] = createSignal(""); | ||
| 28 | + const [topic, setTopic] = createSignal(""); | ||
| 29 | + const [error, setError] = createSignal(""); | ||
| 30 | + const [pending, setPending] = createSignal(false); | ||
| 31 | + | ||
| 32 | + createEffect(() => { | ||
| 33 | + if (!props.open) return; | ||
| 34 | + setStarts(""); | ||
| 35 | + setEnds(""); | ||
| 36 | + setTopic(""); | ||
| 37 | + setError(""); | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + const submit = async (event: SubmitEvent) => { | ||
| 41 | + event.preventDefault(); | ||
| 42 | + const startsAt = hhmmToMinutes(starts()); | ||
| 43 | + const endsAt = hhmmToMinutes(ends()); | ||
| 44 | + const min = props.minMinute ?? 0; | ||
| 45 | + const max = props.maxMinute ?? 24 * 60; | ||
| 46 | + if (startsAt === null || endsAt === null || endsAt <= startsAt || startsAt < min || endsAt > max) { | ||
| 47 | + setError(t("weeklyPlan.timeInvalid")); | ||
| 48 | + return; | ||
| 49 | + } | ||
| 50 | + setError(""); | ||
| 51 | + setPending(true); | ||
| 52 | + try { | ||
| 53 | + await props.onSubmit({ weekday: Number(weekday()), starts_at: startsAt, ends_at: endsAt, topic: topic().trim() || null }); | ||
| 54 | + props.onOpenChange(false); | ||
| 55 | + } catch (err) { | ||
| 56 | + setError(formatApiError(err)); | ||
| 57 | + } finally { | ||
| 58 | + setPending(false); | ||
| 59 | + } | ||
| 60 | + }; | ||
| 61 | + | ||
| 62 | + return ( | ||
| 63 | + <SidePanel guardUnsaved open={props.open} onOpenChange={props.onOpenChange} title={t("weeklyPlan.addSlot")} description={t("weeklyPlan.help")}> | ||
| 64 | + <form class="space-y-4" noValidate onSubmit={submit}> | ||
| 65 | + <div class="space-y-1.5"> | ||
| 66 | + <Label for="slot-weekday">{t("weeklyPlan.weekday")}</Label> | ||
| 67 | + <Select id="slot-weekday" value={weekday()} onChange={(e) => setWeekday(e.currentTarget.value)}> | ||
| 68 | + <For each={WEEKDAYS}>{(day) => <option value={String(day)}>{weekdayLabel(day, locale())}</option>}</For> | ||
| 69 | + </Select> | ||
| 70 | + </div> | ||
| 71 | + <div class="grid grid-cols-2 gap-2"> | ||
| 72 | + <div class="space-y-1.5"> | ||
| 73 | + <Label for="slot-starts">{t("weeklyPlan.starts")}</Label> | ||
| 74 | + <Input id="slot-starts" class="h-9 font-mono placeholder:text-muted-foreground/45" inputMode="numeric" placeholder="09:00" value={starts()} onInput={(e) => setStarts(e.currentTarget.value)} /> | ||
| 75 | + </div> | ||
| 76 | + <div class="space-y-1.5"> | ||
| 77 | + <Label for="slot-ends">{t("weeklyPlan.ends")}</Label> | ||
| 78 | + <Input id="slot-ends" class="h-9 font-mono placeholder:text-muted-foreground/45" inputMode="numeric" placeholder="09:40" value={ends()} onInput={(e) => setEnds(e.currentTarget.value)} /> | ||
| 79 | + </div> | ||
| 80 | + </div> | ||
| 81 | + <div class="space-y-1.5"> | ||
| 82 | + <Label for="slot-topic">{t("weeklyPlan.topic")}</Label> | ||
| 83 | + <Input id="slot-topic" maxlength={props.maxTopicLen} value={topic()} onInput={(e) => setTopic(e.currentTarget.value)} /> | ||
| 84 | + <p class="text-xs text-muted-foreground">{t("weeklyPlan.topicHint")}</p> | ||
| 85 | + </div> | ||
| 86 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 87 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | ||
| 88 | + <Button type="submit" disabled={pending()}>{t("common.save")}</Button> | ||
| 89 | + <Button type="button" variant="outline" onClick={() => props.onOpenChange(false)}>{t("common.cancel")}</Button> | ||
| 90 | + </div> | ||
| 91 | + </form> | ||
| 92 | + </SidePanel> | ||
| 93 | + ); | ||
| 94 | +} | ||
src/components/layout/nav-items.test.tsmodified+1 -1
| @@ -35,7 +35,7 @@ test("admin's sidebar splits into short labelled sections with the soon shelf la | |||
| 35 | })), | 35 | })), |
| 36 | ).toEqual([ | 36 | ).toEqual([ |
| 37 | { id: "ai", items: ["ai-studio", "ai-study", "ai-insights", "ai-celebi"] }, | 37 | { id: "ai", items: ["ai-studio", "ai-study", "ai-insights", "ai-celebi"] }, |
| 38 | - { id: "school", items: ["students-roster", "teachers-roster", "class-groups", "academic-years", "terms", "schedule"] }, | 38 | + { id: "school", items: ["students-roster", "teachers-roster", "class-groups", "academic-years", "terms", "holidays", "schedule"] }, |
| 39 | { id: "teaching", items: ["courses", "homework", "exams", "question-bank", "questions", "notes", "whiteboards"] }, | 39 | { id: "teaching", items: ["courses", "homework", "exams", "question-bank", "questions", "notes", "whiteboards"] }, |
| 40 | { id: "tracking", items: ["student-attendance", "student-marks", "student-pomodoros"] }, | 40 | { id: "tracking", items: ["student-attendance", "student-marks", "student-pomodoros"] }, |
| 41 | { id: "services", items: ["events", "appointments", "school-meals"] }, | 41 | { id: "services", items: ["events", "appointments", "school-meals"] }, |
src/components/layout/nav-items.tsmodified+2 -0
| @@ -6,6 +6,7 @@ import { | |||
| 6 | IconBriefcase, | 6 | IconBriefcase, |
| 7 | IconCalendarBlank, | 7 | IconCalendarBlank, |
| 8 | IconCalendarCheck, | 8 | IconCalendarCheck, |
| 9 | + IconCalendarX, | ||
| 9 | IconCalendarDays, | 10 | IconCalendarDays, |
| 10 | IconCalendarStar, | 11 | IconCalendarStar, |
| 11 | IconChalkboardTeacher, | 12 | IconChalkboardTeacher, |
| @@ -160,6 +161,7 @@ const ADMIN_GROUPS: NavGroup[] = [ | |||
| 160 | { id: "class-groups", to: "/management/classes", labelKey: "nav.classGroups", Icon: IconSchool, minRole: "teacher", module: "classes" }, | 161 | { id: "class-groups", to: "/management/classes", labelKey: "nav.classGroups", Icon: IconSchool, minRole: "teacher", module: "classes" }, |
| 161 | { id: "academic-years", to: "/management/academic-years", labelKey: "nav.academicYears", Icon: IconCalendarBlank, minRole: "manager" }, | 162 | { id: "academic-years", to: "/management/academic-years", labelKey: "nav.academicYears", Icon: IconCalendarBlank, minRole: "manager" }, |
| 162 | { id: "terms", to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarCheck, minRole: "manager" }, | 163 | { id: "terms", to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarCheck, minRole: "manager" }, |
| 164 | + { id: "holidays", to: "/management/holidays", labelKey: "nav.holidays", Icon: IconCalendarX, minRole: "manager" }, | ||
| 163 | { id: "schedule", to: "/calendar", labelKey: "nav.schedule", Icon: IconCalendarDays, minRole: "manager" }, | 165 | { id: "schedule", to: "/calendar", labelKey: "nav.schedule", Icon: IconCalendarDays, minRole: "manager" }, |
| 164 | ], | 166 | ], |
| 165 | }, | 167 | }, |
src/i18n/locales/en.tsmodified+96 -0
| @@ -2461,4 +2461,100 @@ export const en: Dict = { | |||
| 2461 | "grade.select": "Select a grade", | 2461 | "grade.select": "Select a grade", |
| 2462 | "instances.teachers": "Teachers", | 2462 | "instances.teachers": "Teachers", |
| 2463 | "instances.sectionsTruncated": "Showing {shown} of {total} sections; the full list is on the Classes page.", | 2463 | "instances.sectionsTruncated": "Showing {shown} of {total} sections; the full list is on the Classes page.", |
| 2464 | + "override.inherited": "Inherited", | ||
| 2465 | + "override.own": "Section's own", | ||
| 2466 | + "override.reset": "Reset to template", | ||
| 2467 | + "override.resetConfirmTitle": "Reset to the template?", | ||
| 2468 | + "override.resetConfirmHint": "The section's own value is removed; from now on it follows the grade template.", | ||
| 2469 | + "instances.settingsTab": "Section settings", | ||
| 2470 | + "instances.settingsHelp": "This section inherits from the course's grade template. Changes here affect this section only.", | ||
| 2471 | + "instances.contentTitle": "Title and description", | ||
| 2472 | + "instances.contentHelp": "The course name this section shows. Fields left alone come from the template.", | ||
| 2473 | + "instances.editContent": "Edit title and description", | ||
| 2474 | + "instances.policyTitle": "Weekly hours and report card", | ||
| 2475 | + "instances.subjectsTitle": "Topics", | ||
| 2476 | + "instances.subjectsHelp": "The topics this section teaches. Exam questions and homework can only pick from these.", | ||
| 2477 | + "instances.subjectsInheritedHint": "The template's topics apply. Adding or removing one starts a set of the section's own.", | ||
| 2478 | + "instances.subjectsOwnHint": "The section uses its own set of topics.", | ||
| 2479 | + "instances.addSubject": "Add topic", | ||
| 2480 | + "instances.noSubjects": "No topics selected.", | ||
| 2481 | + "instances.allSubjectsSelected": "Every topic of the course is already selected.", | ||
| 2482 | + "instances.removeSubject": "Remove topic", | ||
| 2483 | + "instances.examWeightsTitle": "Exam weights", | ||
| 2484 | + "instances.examWeightsHelp": "How much each exam kind weighs in the report-card average (1–100).", | ||
| 2485 | + "instances.examWeightsInheritedHint": "The template's weights apply. Changing one starts a table of the section's own.", | ||
| 2486 | + "instances.examWeightsOwnHint": "The section uses its own weights; kinds without a row weigh 1.", | ||
| 2487 | + "instances.weight": "Weight", | ||
| 2488 | + "instances.setWeight": "Change weight", | ||
| 2489 | + "instances.removeWeight": "Remove row", | ||
| 2490 | + "instances.weightInvalid": "The weight must be a whole number from 1 to 100.", | ||
| 2491 | + "instances.examKind": "Exam kind", | ||
| 2492 | + "instances.addWeight": "Add weight", | ||
| 2493 | + "weeklyPlan.tab": "Weekly plan", | ||
| 2494 | + "weeklyPlan.title": "Weekly timetable", | ||
| 2495 | + "weeklyPlan.help": "The lesson times that repeat every week.", | ||
| 2496 | + "weeklyPlan.empty": "No lesson times yet.", | ||
| 2497 | + "weeklyPlan.addSlot": "Add lesson time", | ||
| 2498 | + "weeklyPlan.weekday": "Day", | ||
| 2499 | + "weeklyPlan.time": "Time", | ||
| 2500 | + "weeklyPlan.starts": "Starts", | ||
| 2501 | + "weeklyPlan.ends": "Ends", | ||
| 2502 | + "weeklyPlan.topic": "Topic", | ||
| 2503 | + "weeklyPlan.topicHint": "Optional. Left empty, generated lessons carry the course title.", | ||
| 2504 | + "weeklyPlan.timeInvalid": "Enter times as HH:mm; the end must be after the start.", | ||
| 2505 | + "weeklyPlan.removeSlot": "Remove lesson time", | ||
| 2506 | + "weeklyPlan.ownHint": "This section uses its own weekly plan.", | ||
| 2507 | + "weeklyPlan.inheritedHint": "The grade template's week applies. Adding or removing a time starts a plan of the section's own.", | ||
| 2508 | + "weeklyPlan.generate": "Generate lessons", | ||
| 2509 | + "weeklyPlan.generateHelp": "Turns the weekly plan into dated lessons over the chosen dates. Holidays and already scheduled times are skipped; no lesson is ever deleted.", | ||
| 2510 | + "weeklyPlan.from": "First day", | ||
| 2511 | + "weeklyPlan.to": "Last day", | ||
| 2512 | + "weeklyPlan.preview": "Preview", | ||
| 2513 | + "weeklyPlan.apply": "Create {count} lessons", | ||
| 2514 | + "weeklyPlan.previewSummary": "{candidates} lessons to create · {existing} already scheduled · {holiday} fall on a holiday", | ||
| 2515 | + "weeklyPlan.appliedSummary": "{count} lessons created.", | ||
| 2516 | + "weeklyPlan.blockedDays": "Days skipped for a holiday", | ||
| 2517 | + "weeklyPlan.rangeInvalid": "Pick a valid date range; the last day cannot come before the first.", | ||
| 2518 | + "weeklyPlan.rangeTooLong": "At most {days} days can be generated at once.", | ||
| 2519 | + "weeklyPlan.nothingToCreate": "There are no new lessons to create in this range.", | ||
| 2520 | + "weeklyPlan.noTeacherHint": "A teacher must be assigned to the section to generate lessons.", | ||
| 2521 | + "offerings.tab": "Grade templates", | ||
| 2522 | + "offerings.help": "This course's defaults per grade. Sections at that grade follow them unless they set their own.", | ||
| 2523 | + "offerings.new": "New template", | ||
| 2524 | + "offerings.empty": "No grade templates yet. Attaching the course to a class creates an empty one for its grade.", | ||
| 2525 | + "offerings.edit": "Edit template", | ||
| 2526 | + "offerings.delete": "Delete template", | ||
| 2527 | + "offerings.deleteConfirm": "Delete the {grade} template? It cannot be deleted while a class at that grade teaches the course.", | ||
| 2528 | + "offerings.titlePlaceholder": "Empty uses the course name: {title}", | ||
| 2529 | + "offerings.descriptionPlaceholder": "Empty uses the course description.", | ||
| 2530 | + "offerings.defaultDersSaati": "Default weekly hours", | ||
| 2531 | + "offerings.defaultDersSaatiHint": "Empty means 1 hour.", | ||
| 2532 | + "offerings.defaultKarne": "Counts toward report card", | ||
| 2533 | + "offerings.inheritDefault": "Default (counted)", | ||
| 2534 | + "offerings.detailsTitle": "Template details", | ||
| 2535 | + "offerings.subjectsHelp": "The topics every section at this grade teaches.", | ||
| 2536 | + "offerings.weightsHelp": "Each exam kind's report-card weight at this grade. Kinds without a row use the school setting.", | ||
| 2537 | + "offerings.weeklyPlanHelp": "The default weekly lesson times of every section at this grade.", | ||
| 2538 | + "offerings.hours": "{count} h", | ||
| 2539 | + "nav.holidays": "Holiday calendar", | ||
| 2540 | + "holidays.title": "Holiday calendar", | ||
| 2541 | + "holidays.subtitle": "The school's non-teaching days. Generating lessons from a weekly plan skips them.", | ||
| 2542 | + "holidays.new": "New holiday", | ||
| 2543 | + "holidays.edit": "Edit holiday", | ||
| 2544 | + "holidays.delete": "Delete holiday", | ||
| 2545 | + "holidays.name": "Name", | ||
| 2546 | + "holidays.kind": "Kind", | ||
| 2547 | + "holidays.kind.resmi": "Public holiday", | ||
| 2548 | + "holidays.kind.dini": "Religious holiday", | ||
| 2549 | + "holidays.kind.idari": "Administrative leave", | ||
| 2550 | + "holidays.kind.ara": "School break", | ||
| 2551 | + "holidays.firstDay": "First day", | ||
| 2552 | + "holidays.lastDay": "Last day", | ||
| 2553 | + "holidays.range": "Dates", | ||
| 2554 | + "holidays.days": "{count} days", | ||
| 2555 | + "holidays.empty": "No holidays yet.", | ||
| 2556 | + "holidays.deleteConfirm": "Delete \"{name}\"? Lessons already generated on those days stay.", | ||
| 2557 | + "holidays.rangeInvalid": "Pick a valid date range; the last day cannot come before the first.", | ||
| 2558 | + "search.hint.holidays": "Matches the holiday name and kind.", | ||
| 2559 | + "holidays.dayCount": "Days", | ||
| 2464 | }; | 2560 | }; |
src/i18n/locales/tr.tsmodified+96 -0
| @@ -2457,4 +2457,100 @@ export const tr: Dict = { | |||
| 2457 | "grade.select": "Seviye seçin", | 2457 | "grade.select": "Seviye seçin", |
| 2458 | "instances.teachers": "Öğretmenler", | 2458 | "instances.teachers": "Öğretmenler", |
| 2459 | "instances.sectionsTruncated": "{total} şubeden ilk {shown} tanesi gösteriliyor; tamamı Sınıflar sayfasında.", | 2459 | "instances.sectionsTruncated": "{total} şubeden ilk {shown} tanesi gösteriliyor; tamamı Sınıflar sayfasında.", |
| 2460 | + "override.inherited": "Şablondan", | ||
| 2461 | + "override.own": "Şubeye özel", | ||
| 2462 | + "override.reset": "Şablona dön", | ||
| 2463 | + "override.resetConfirmTitle": "Şablona dönülsün mü?", | ||
| 2464 | + "override.resetConfirmHint": "Şubeye özel değer kaldırılır; şube bundan sonra sınıf seviyesi şablonunu izler.", | ||
| 2465 | + "instances.settingsTab": "Şube ayarları", | ||
| 2466 | + "instances.settingsHelp": "Bu şube, dersin sınıf seviyesi şablonundan miras alır. Burada yaptığın değişiklikler yalnızca bu şubeyi etkiler.", | ||
| 2467 | + "instances.contentTitle": "Başlık ve açıklama", | ||
| 2468 | + "instances.contentHelp": "Şubede görünen ders adı. Boş bırakılan alanlar şablondan gelir.", | ||
| 2469 | + "instances.editContent": "Başlık ve açıklamayı düzenle", | ||
| 2470 | + "instances.policyTitle": "Ders saati ve karne", | ||
| 2471 | + "instances.subjectsTitle": "Konular", | ||
| 2472 | + "instances.subjectsHelp": "Bu şubede işlenen konular. Sınav soruları ve ödevler yalnızca bu konulardan seçilebilir.", | ||
| 2473 | + "instances.subjectsInheritedHint": "Şablonun konu seti uygulanıyor. Konu eklemek ya da çıkarmak şubeye özel bir set başlatır.", | ||
| 2474 | + "instances.subjectsOwnHint": "Şube kendi konu setini kullanıyor.", | ||
| 2475 | + "instances.addSubject": "Konu ekle", | ||
| 2476 | + "instances.noSubjects": "Seçili konu yok.", | ||
| 2477 | + "instances.allSubjectsSelected": "Dersin bütün konuları zaten seçili.", | ||
| 2478 | + "instances.removeSubject": "Konuyu çıkar", | ||
| 2479 | + "instances.examWeightsTitle": "Sınav ağırlıkları", | ||
| 2480 | + "instances.examWeightsHelp": "Karne ortalamasında her sınav türünün ağırlığı (1–100).", | ||
| 2481 | + "instances.examWeightsInheritedHint": "Şablonun ağırlıkları uygulanıyor. Bir ağırlığı değiştirmek şubeye özel bir tablo başlatır.", | ||
| 2482 | + "instances.examWeightsOwnHint": "Şube kendi ağırlıklarını kullanıyor; satırı olmayan türler 1 sayılır.", | ||
| 2483 | + "instances.weight": "Ağırlık", | ||
| 2484 | + "instances.setWeight": "Ağırlığı değiştir", | ||
| 2485 | + "instances.removeWeight": "Satırı kaldır", | ||
| 2486 | + "instances.weightInvalid": "Ağırlık 1 ile 100 arasında bir tam sayı olmalı.", | ||
| 2487 | + "instances.examKind": "Sınav türü", | ||
| 2488 | + "instances.addWeight": "Ağırlık ekle", | ||
| 2489 | + "weeklyPlan.tab": "Haftalık plan", | ||
| 2490 | + "weeklyPlan.title": "Haftalık ders planı", | ||
| 2491 | + "weeklyPlan.help": "Her hafta tekrarlayan ders saatleri.", | ||
| 2492 | + "weeklyPlan.empty": "Henüz ders saati yok.", | ||
| 2493 | + "weeklyPlan.addSlot": "Ders saati ekle", | ||
| 2494 | + "weeklyPlan.weekday": "Gün", | ||
| 2495 | + "weeklyPlan.time": "Saat", | ||
| 2496 | + "weeklyPlan.starts": "Başlangıç", | ||
| 2497 | + "weeklyPlan.ends": "Bitiş", | ||
| 2498 | + "weeklyPlan.topic": "Konu", | ||
| 2499 | + "weeklyPlan.topicHint": "İsteğe bağlı. Boş bırakılırsa üretilen dersler ders başlığını taşır.", | ||
| 2500 | + "weeklyPlan.timeInvalid": "Saatleri SS:DD biçiminde gir; bitiş başlangıçtan sonra olmalı.", | ||
| 2501 | + "weeklyPlan.removeSlot": "Ders saatini kaldır", | ||
| 2502 | + "weeklyPlan.ownHint": "Bu şube kendi haftalık planını kullanıyor.", | ||
| 2503 | + "weeklyPlan.inheritedHint": "Sınıf seviyesi şablonunun haftası uygulanıyor. Ders saati eklemek ya da kaldırmak şubeye özel bir plan başlatır.", | ||
| 2504 | + "weeklyPlan.generate": "Dersleri oluştur", | ||
| 2505 | + "weeklyPlan.generateHelp": "Haftalık planı seçilen tarih aralığında tarihli derslere dönüştürür. Tatiller ve zaten planlanmış saatler atlanır; hiçbir ders silinmez.", | ||
| 2506 | + "weeklyPlan.from": "İlk gün", | ||
| 2507 | + "weeklyPlan.to": "Son gün", | ||
| 2508 | + "weeklyPlan.preview": "Önizle", | ||
| 2509 | + "weeklyPlan.apply": "{count} dersi oluştur", | ||
| 2510 | + "weeklyPlan.previewSummary": "{candidates} ders oluşturulacak · {existing} zaten planlı · {holiday} tatile denk geliyor", | ||
| 2511 | + "weeklyPlan.appliedSummary": "{count} ders oluşturuldu.", | ||
| 2512 | + "weeklyPlan.blockedDays": "Tatil nedeniyle atlanan günler", | ||
| 2513 | + "weeklyPlan.rangeInvalid": "Geçerli bir tarih aralığı seç; son gün ilk günden önce olamaz.", | ||
| 2514 | + "weeklyPlan.rangeTooLong": "Bir seferde en fazla {days} günlük aralık seçilebilir.", | ||
| 2515 | + "weeklyPlan.nothingToCreate": "Bu aralıkta oluşturulacak yeni ders yok.", | ||
| 2516 | + "weeklyPlan.noTeacherHint": "Ders üretmek için şubeye bir öğretmen atanmış olmalı.", | ||
| 2517 | + "offerings.tab": "Seviye şablonları", | ||
| 2518 | + "offerings.help": "Her sınıf seviyesi için bu dersin varsayılanları. O seviyedeki şubeler kendi değerlerini belirlemedikçe bunları izler.", | ||
| 2519 | + "offerings.new": "Yeni şablon", | ||
| 2520 | + "offerings.empty": "Henüz seviye şablonu yok. Ders bir şubeye eklendiğinde o seviye için boş bir şablon oluşur.", | ||
| 2521 | + "offerings.edit": "Şablonu düzenle", | ||
| 2522 | + "offerings.delete": "Şablonu sil", | ||
| 2523 | + "offerings.deleteConfirm": "{grade} şablonu silinsin mi? Bu seviyede dersi işleyen şube varken silinemez.", | ||
| 2524 | + "offerings.titlePlaceholder": "Boşsa ders adı: {title}", | ||
| 2525 | + "offerings.descriptionPlaceholder": "Boşsa dersin açıklaması kullanılır.", | ||
| 2526 | + "offerings.defaultDersSaati": "Varsayılan haftalık ders saati", | ||
| 2527 | + "offerings.defaultDersSaatiHint": "Boşsa 1 saat.", | ||
| 2528 | + "offerings.defaultKarne": "Karneye dahil", | ||
| 2529 | + "offerings.inheritDefault": "Varsayılan (dahil)", | ||
| 2530 | + "offerings.detailsTitle": "Şablon bilgileri", | ||
| 2531 | + "offerings.subjectsHelp": "Bu seviyedeki şubelerin işlediği konular.", | ||
| 2532 | + "offerings.weightsHelp": "Bu seviyede her sınav türünün karnedeki ağırlığı. Satırı olmayan türler okul ayarlarındaki ağırlığı kullanır.", | ||
| 2533 | + "offerings.weeklyPlanHelp": "Bu seviyedeki şubelerin varsayılan haftalık ders saatleri.", | ||
| 2534 | + "offerings.hours": "{count} saat", | ||
| 2535 | + "nav.holidays": "Tatil takvimi", | ||
| 2536 | + "holidays.title": "Tatil takvimi", | ||
| 2537 | + "holidays.subtitle": "Okulun ders yapılmayan günleri. Haftalık plandan ders üretilirken bu günler atlanır.", | ||
| 2538 | + "holidays.new": "Yeni tatil", | ||
| 2539 | + "holidays.edit": "Tatili düzenle", | ||
| 2540 | + "holidays.delete": "Tatili sil", | ||
| 2541 | + "holidays.name": "Ad", | ||
| 2542 | + "holidays.kind": "Tür", | ||
| 2543 | + "holidays.kind.resmi": "Resmî tatil", | ||
| 2544 | + "holidays.kind.dini": "Dinî bayram", | ||
| 2545 | + "holidays.kind.idari": "İdari izin", | ||
| 2546 | + "holidays.kind.ara": "Ara tatil", | ||
| 2547 | + "holidays.firstDay": "İlk gün", | ||
| 2548 | + "holidays.lastDay": "Son gün", | ||
| 2549 | + "holidays.range": "Tarihler", | ||
| 2550 | + "holidays.days": "{count} gün", | ||
| 2551 | + "holidays.empty": "Henüz tatil eklenmedi.", | ||
| 2552 | + "holidays.deleteConfirm": "\"{name}\" silinsin mi? O günlere önceden üretilmiş dersler yerinde kalır.", | ||
| 2553 | + "holidays.rangeInvalid": "Geçerli bir tarih aralığı seç; son gün ilk günden önce olamaz.", | ||
| 2554 | + "search.hint.holidays": "Tatil adı ve türüyle eşleşir.", | ||
| 2555 | + "holidays.dayCount": "Gün sayısı", | ||
| 2460 | }; | 2556 | }; |
src/i18n/messages.tsmodified+97 -1
| @@ -2440,7 +2440,103 @@ export type MessageKey = | |||
| 2440 | | "grade.level" | 2440 | | "grade.level" |
| 2441 | | "grade.select" | 2441 | | "grade.select" |
| 2442 | | "instances.teachers" | 2442 | | "instances.teachers" |
| 2443 | - | "instances.sectionsTruncated"; | 2443 | + | "instances.sectionsTruncated" |
| 2444 | + | "override.inherited" | ||
| 2445 | + | "override.own" | ||
| 2446 | + | "override.reset" | ||
| 2447 | + | "override.resetConfirmTitle" | ||
| 2448 | + | "override.resetConfirmHint" | ||
| 2449 | + | "instances.settingsTab" | ||
| 2450 | + | "instances.settingsHelp" | ||
| 2451 | + | "instances.contentTitle" | ||
| 2452 | + | "instances.contentHelp" | ||
| 2453 | + | "instances.editContent" | ||
| 2454 | + | "instances.policyTitle" | ||
| 2455 | + | "instances.subjectsTitle" | ||
| 2456 | + | "instances.subjectsHelp" | ||
| 2457 | + | "instances.subjectsInheritedHint" | ||
| 2458 | + | "instances.subjectsOwnHint" | ||
| 2459 | + | "instances.addSubject" | ||
| 2460 | + | "instances.noSubjects" | ||
| 2461 | + | "instances.allSubjectsSelected" | ||
| 2462 | + | "instances.removeSubject" | ||
| 2463 | + | "instances.examWeightsTitle" | ||
| 2464 | + | "instances.examWeightsHelp" | ||
| 2465 | + | "instances.examWeightsInheritedHint" | ||
| 2466 | + | "instances.examWeightsOwnHint" | ||
| 2467 | + | "instances.weight" | ||
| 2468 | + | "instances.setWeight" | ||
| 2469 | + | "instances.removeWeight" | ||
| 2470 | + | "instances.weightInvalid" | ||
| 2471 | + | "instances.examKind" | ||
| 2472 | + | "instances.addWeight" | ||
| 2473 | + | "weeklyPlan.tab" | ||
| 2474 | + | "weeklyPlan.title" | ||
| 2475 | + | "weeklyPlan.help" | ||
| 2476 | + | "weeklyPlan.empty" | ||
| 2477 | + | "weeklyPlan.addSlot" | ||
| 2478 | + | "weeklyPlan.weekday" | ||
| 2479 | + | "weeklyPlan.time" | ||
| 2480 | + | "weeklyPlan.starts" | ||
| 2481 | + | "weeklyPlan.ends" | ||
| 2482 | + | "weeklyPlan.topic" | ||
| 2483 | + | "weeklyPlan.topicHint" | ||
| 2484 | + | "weeklyPlan.timeInvalid" | ||
| 2485 | + | "weeklyPlan.removeSlot" | ||
| 2486 | + | "weeklyPlan.ownHint" | ||
| 2487 | + | "weeklyPlan.inheritedHint" | ||
| 2488 | + | "weeklyPlan.generate" | ||
| 2489 | + | "weeklyPlan.generateHelp" | ||
| 2490 | + | "weeklyPlan.from" | ||
| 2491 | + | "weeklyPlan.to" | ||
| 2492 | + | "weeklyPlan.preview" | ||
| 2493 | + | "weeklyPlan.apply" | ||
| 2494 | + | "weeklyPlan.previewSummary" | ||
| 2495 | + | "weeklyPlan.appliedSummary" | ||
| 2496 | + | "weeklyPlan.blockedDays" | ||
| 2497 | + | "weeklyPlan.rangeInvalid" | ||
| 2498 | + | "weeklyPlan.rangeTooLong" | ||
| 2499 | + | "weeklyPlan.nothingToCreate" | ||
| 2500 | + | "weeklyPlan.noTeacherHint" | ||
| 2501 | + | "offerings.tab" | ||
| 2502 | + | "offerings.help" | ||
| 2503 | + | "offerings.new" | ||
| 2504 | + | "offerings.empty" | ||
| 2505 | + | "offerings.edit" | ||
| 2506 | + | "offerings.delete" | ||
| 2507 | + | "offerings.deleteConfirm" | ||
| 2508 | + | "offerings.titlePlaceholder" | ||
| 2509 | + | "offerings.descriptionPlaceholder" | ||
| 2510 | + | "offerings.defaultDersSaati" | ||
| 2511 | + | "offerings.defaultDersSaatiHint" | ||
| 2512 | + | "offerings.defaultKarne" | ||
| 2513 | + | "offerings.inheritDefault" | ||
| 2514 | + | "offerings.detailsTitle" | ||
| 2515 | + | "offerings.subjectsHelp" | ||
| 2516 | + | "offerings.weightsHelp" | ||
| 2517 | + | "offerings.weeklyPlanHelp" | ||
| 2518 | + | "offerings.hours" | ||
| 2519 | + | "nav.holidays" | ||
| 2520 | + | "holidays.title" | ||
| 2521 | + | "holidays.subtitle" | ||
| 2522 | + | "holidays.new" | ||
| 2523 | + | "holidays.edit" | ||
| 2524 | + | "holidays.delete" | ||
| 2525 | + | "holidays.name" | ||
| 2526 | + | "holidays.kind" | ||
| 2527 | + | "holidays.kind.resmi" | ||
| 2528 | + | "holidays.kind.dini" | ||
| 2529 | + | "holidays.kind.idari" | ||
| 2530 | + | "holidays.kind.ara" | ||
| 2531 | + | "holidays.firstDay" | ||
| 2532 | + | "holidays.lastDay" | ||
| 2533 | + | "holidays.range" | ||
| 2534 | + | "holidays.days" | ||
| 2535 | + | "holidays.empty" | ||
| 2536 | + | "holidays.deleteConfirm" | ||
| 2537 | + | "holidays.rangeInvalid" | ||
| 2538 | + | "search.hint.holidays" | ||
| 2539 | + | "holidays.dayCount"; | ||
| 2444 | 2540 | ||
| 2445 | export type Dict = Record<MessageKey, string>; | 2541 | export type Dict = Record<MessageKey, string>; |
| 2446 | 2542 | ||
src/lib/holiday-kind.tsadded+16 -0
| @@ -0,0 +1,16 @@ | |||
| 1 | +import type { MessageKey } from "@/i18n/messages"; | ||
| 2 | + | ||
| 3 | +type Translate = (key: MessageKey, params?: Record<string, string>) => string; | ||
| 4 | + | ||
| 5 | +const HOLIDAY_KIND_KEYS: Record<string, MessageKey> = { | ||
| 6 | + resmi: "holidays.kind.resmi", | ||
| 7 | + dini: "holidays.kind.dini", | ||
| 8 | + idari: "holidays.kind.idari", | ||
| 9 | + ara: "holidays.kind.ara", | ||
| 10 | +}; | ||
| 11 | + | ||
| 12 | +/** The published holiday kinds (limits.holiday.kinds) in the reader's words. */ | ||
| 13 | +export function holidayKindLabel(kind: string, t: Translate): string { | ||
| 14 | + const key = HOLIDAY_KIND_KEYS[kind]; | ||
| 15 | + return key ? t(key) : kind; | ||
| 16 | +} | ||
src/lib/weekly-plan.test.tsadded+25 -0
| @@ -0,0 +1,25 @@ | |||
| 1 | +import { describe, expect, test } from "vitest"; | ||
| 2 | +import { hhmmToMinutes, minutesToHHmm, sortSlots, weekdayLabel } from "./weekly-plan"; | ||
| 3 | + | ||
| 4 | +describe("weekly plan helpers", () => { | ||
| 5 | + test("minutes and HH:mm round-trip", () => { | ||
| 6 | + expect(minutesToHHmm(540)).toBe("09:00"); | ||
| 7 | + expect(minutesToHHmm(0)).toBe("00:00"); | ||
| 8 | + expect(hhmmToMinutes("09:40")).toBe(580); | ||
| 9 | + expect(hhmmToMinutes("9:05")).toBe(545); | ||
| 10 | + expect(hhmmToMinutes("24:00")).toBeNull(); | ||
| 11 | + expect(hhmmToMinutes("09:60")).toBeNull(); | ||
| 12 | + expect(hhmmToMinutes("nine")).toBeNull(); | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + test("weekday 1 is Monday and 7 is Sunday", () => { | ||
| 16 | + expect(weekdayLabel(1, "en")).toBe("Monday"); | ||
| 17 | + expect(weekdayLabel(7, "en")).toBe("Sunday"); | ||
| 18 | + expect(weekdayLabel(1, "tr")).toBe("Pazartesi"); | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + test("slots sort by weekday, then start", () => { | ||
| 22 | + const slot = (id: string, weekday: number, starts_at: number) => ({ id, weekday, starts_at, ends_at: starts_at + 40 }); | ||
| 23 | + expect(sortSlots([slot("c", 2, 540), slot("b", 1, 600), slot("a", 1, 540)]).map((s) => s.id)).toEqual(["a", "b", "c"]); | ||
| 24 | + }); | ||
| 25 | +}); | ||
src/lib/weekly-plan.tsadded+33 -0
| @@ -0,0 +1,33 @@ | |||
| 1 | +import type { Locale } from "@/i18n/messages"; | ||
| 2 | +import type { WeeklySlot } from "@/api/client"; | ||
| 3 | + | ||
| 4 | +/** 540 → "09:00". */ | ||
| 5 | +export function minutesToHHmm(minutes: number): string { | ||
| 6 | + const pad = (n: number) => String(n).padStart(2, "0"); | ||
| 7 | + return `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}`; | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +/** "09:00" → 540, or null when the text is not a valid HH:mm. */ | ||
| 11 | +export function hhmmToMinutes(text: string): number | null { | ||
| 12 | + const match = text.trim().match(/^(\d{1,2}):(\d{2})$/); | ||
| 13 | + if (!match) return null; | ||
| 14 | + const hours = Number(match[1]); | ||
| 15 | + const minutes = Number(match[2]); | ||
| 16 | + if (hours > 23 || minutes > 59) return null; | ||
| 17 | + return hours * 60 + minutes; | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +/** The backend's weekdays: 1 = Monday .. 7 = Sunday. */ | ||
| 21 | +export const WEEKDAYS = [1, 2, 3, 4, 5, 6, 7] as const; | ||
| 22 | + | ||
| 23 | +/** Localized weekday name for a 1 (Monday) .. 7 (Sunday) weekday. */ | ||
| 24 | +export function weekdayLabel(weekday: number, locale: Locale): string { | ||
| 25 | + // 2024-01-01 was a Monday, so day `weekday` of that week names it. | ||
| 26 | + const date = new Date(Date.UTC(2024, 0, weekday)); | ||
| 27 | + return new Intl.DateTimeFormat(locale === "tr" ? "tr-TR" : "en-GB", { weekday: "long", timeZone: "UTC" }).format(date); | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +/** Weekday first, then start time — the order the backend lists a plan in. */ | ||
| 31 | +export function sortSlots(slots: WeeklySlot[]): WeeklySlot[] { | ||
| 32 | + return slots.slice().sort((a, b) => a.weekday - b.weekday || a.starts_at - b.starts_at); | ||
| 33 | +} | ||
src/pages/course-detail-page.tsxmodified+15 -1
| @@ -12,6 +12,7 @@ import { formatApiError } from "@/api/client"; | |||
| 12 | import type { CourseKind, CourseMembership, CourseSectionRef } from "@/api/client"; | 12 | import type { CourseKind, CourseMembership, CourseSectionRef } from "@/api/client"; |
| 13 | import { CourseEditPanel } from "@/components/courses/course-edit-panel"; | 13 | import { CourseEditPanel } from "@/components/courses/course-edit-panel"; |
| 14 | import { CourseNotesPanel } from "@/components/courses/course-notes-panel"; | 14 | import { CourseNotesPanel } from "@/components/courses/course-notes-panel"; |
| 15 | +import { CourseOfferingsPanel } from "@/components/courses/course-offerings-panel"; | ||
| 15 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; | 16 | import { CourseSubjectsPanel } from "@/components/courses/course-subjects-panel"; |
| 16 | import { RouteGuard } from "@/components/layout/route-guard"; | 17 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 17 | import { PageHeader } from "@/components/layout/page-header"; | 18 | import { PageHeader } from "@/components/layout/page-header"; |
| @@ -21,7 +22,7 @@ import { Button } from "@/components/ui/button"; | |||
| 21 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 22 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 22 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | 23 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; |
| 23 | import { EmptyState } from "@/components/ui/empty-state"; | 24 | import { EmptyState } from "@/components/ui/empty-state"; |
| 24 | -import { IconBook, IconEdit, IconNote, IconPlus, IconSchool, IconTrash, IconUsers } from "@/components/ui/icons"; | 25 | +import { IconBook, IconEdit, IconListChecks, IconNote, IconPlus, IconSchool, IconTrash, IconUsers } from "@/components/ui/icons"; |
| 25 | import { createFlash } from "@/lib/flash"; | 26 | import { createFlash } from "@/lib/flash"; |
| 26 | import { PageSpinner } from "@/components/ui/page-spinner"; | 27 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 27 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | 28 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| @@ -76,6 +77,7 @@ function CourseDetailContent() { | |||
| 76 | ...(tabOn.subjects() ? ["subjects"] : []), | 77 | ...(tabOn.subjects() ? ["subjects"] : []), |
| 77 | ...(tabOn.sections() ? ["sections"] : []), | 78 | ...(tabOn.sections() ? ["sections"] : []), |
| 78 | ...(tabOn.notes() ? ["notes"] : []), | 79 | ...(tabOn.notes() ? ["notes"] : []), |
| 80 | + ...(hasOfferings() ? ["offerings"] : []), | ||
| 79 | ...(hasMembers() ? ["members"] : []), | 81 | ...(hasMembers() ? ["members"] : []), |
| 80 | ]; | 82 | ]; |
| 81 | // A tab not on offer falls back to the first one that is, without | 83 | // A tab not on offer falls back to the first one that is, without |
| @@ -103,6 +105,9 @@ function CourseDetailContent() { | |||
| 103 | // A club/etüt keeps its own school-wide member list; a regular ders does not | 105 | // A club/etüt keeps its own school-wide member list; a regular ders does not |
| 104 | // — its students come from the şube that attached it. | 106 | // — its students come from the şube that attached it. |
| 105 | const hasMembers = () => course()?.kind === "club" || course()?.kind === "study"; | 107 | const hasMembers = () => course()?.kind === "club" || course()?.kind === "study"; |
| 108 | + // Only a class-delivered ders has a grade axis, so only it has templates; | ||
| 109 | + // staff read them, the office edits them. | ||
| 110 | + const hasOfferings = () => course()?.kind === "course" && hasMinRole(auth.user()?.role ?? "student", "teacher"); | ||
| 106 | 111 | ||
| 107 | // The şubeler teaching this course ride the catalog row itself, already | 112 | // The şubeler teaching this course ride the catalog row itself, already |
| 108 | // narrowed to the sections this reader reaches and capped at | 113 | // narrowed to the sections this reader reaches and capped at |
| @@ -389,6 +394,9 @@ function CourseDetailContent() { | |||
| 389 | <Show when={tabOn.notes()}> | 394 | <Show when={tabOn.notes()}> |
| 390 | <TabsTrigger value="notes" onClick={(event) => { event.preventDefault(); setCourseTab("notes"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none"><IconNote class="h-4 w-4" />{t("courseNotes.title")}<Show when={noteCount() != null}><span class="ml-0.5 tabular-nums">{noteCount()}</span></Show></TabsTrigger> | 395 | <TabsTrigger value="notes" onClick={(event) => { event.preventDefault(); setCourseTab("notes"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none"><IconNote class="h-4 w-4" />{t("courseNotes.title")}<Show when={noteCount() != null}><span class="ml-0.5 tabular-nums">{noteCount()}</span></Show></TabsTrigger> |
| 391 | </Show> | 396 | </Show> |
| 397 | + <Show when={hasOfferings()}> | ||
| 398 | + <TabsTrigger value="offerings" onClick={(event) => { event.preventDefault(); setCourseTab("offerings"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none"><IconListChecks class="h-4 w-4" />{t("offerings.tab")}</TabsTrigger> | ||
| 399 | + </Show> | ||
| 392 | <Show when={hasMembers()}> | 400 | <Show when={hasMembers()}> |
| 393 | <TabsTrigger value="members" onClick={(event) => { event.preventDefault(); setCourseTab("members"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none"><IconUsers class="h-4 w-4" />{t("courses.members")}</TabsTrigger> | 401 | <TabsTrigger value="members" onClick={(event) => { event.preventDefault(); setCourseTab("members"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none"><IconUsers class="h-4 w-4" />{t("courses.members")}</TabsTrigger> |
| 394 | </Show> | 402 | </Show> |
| @@ -439,6 +447,12 @@ function CourseDetailContent() { | |||
| 439 | <TabsContent value="notes" forceMount class="space-y-3" /> | 447 | <TabsContent value="notes" forceMount class="space-y-3" /> |
| 440 | </Show> | 448 | </Show> |
| 441 | 449 | ||
| 450 | + <Show when={hasOfferings()}> | ||
| 451 | + <TabsContent value="offerings" class="space-y-3"> | ||
| 452 | + <CourseOfferingsPanel courseId={id()} courseTitle={c().title} canEdit={isOffice()} active={courseTab() === "offerings"} /> | ||
| 453 | + </TabsContent> | ||
| 454 | + </Show> | ||
| 455 | + | ||
| 442 | <Show when={hasMembers()}> | 456 | <Show when={hasMembers()}> |
| 443 | <TabsContent value="members" forceMount class="space-y-3"> | 457 | <TabsContent value="members" forceMount class="space-y-3"> |
| 444 | <Show when={canManageCatalog()} fallback={<EmptyState kind="people" title={t("common.accessDenied")} />}> | 458 | <Show when={canManageCatalog()} fallback={<EmptyState kind="people" title={t("common.accessDenied")} />}> |
src/pages/exam-detail-page.tsxmodified+1 -1
| @@ -709,7 +709,7 @@ function ExamDetailContent() { | |||
| 709 | </TabsContent> | 709 | </TabsContent> |
| 710 | 710 | ||
| 711 | <TabsContent value="questions" forceMount class="data-shell p-4"> | 711 | <TabsContent value="questions" forceMount class="data-shell p-4"> |
| 712 | - <ExamQuestionsPanel examId={id()} courseId={instance()?.course ?? null} readOnly={isFinished()} embedded /> | 712 | + <ExamQuestionsPanel examId={id()} courseId={instance()?.course ?? null} instanceId={instance()?.id ?? null} readOnly={isFinished()} embedded /> |
| 713 | </TabsContent> | 713 | </TabsContent> |
| 714 | 714 | ||
| 715 | {/* No frame around the tab: the table draws its toolbar (search, | 715 | {/* No frame around the tab: the table draws its toolbar (search, |
src/pages/exams-page.tsxmodified+2 -0
| @@ -527,6 +527,7 @@ function ExamsContent() { | |||
| 527 | <ExamQuestionsPanel | 527 | <ExamQuestionsPanel |
| 528 | examId={createdExam()!.id} | 528 | examId={createdExam()!.id} |
| 529 | courseId={examCourseId(createdExam()!)} | 529 | courseId={examCourseId(createdExam()!)} |
| 530 | + instanceId={createdExam()!.class_course} | ||
| 530 | embedded | 531 | embedded |
| 531 | /> | 532 | /> |
| 532 | <div class="flex flex-wrap items-center justify-end gap-3 border-t pt-3"> | 533 | <div class="flex flex-wrap items-center justify-end gap-3 border-t pt-3"> |
| @@ -610,6 +611,7 @@ function ExamsContent() { | |||
| 610 | <ExamQuestionsPanel | 611 | <ExamQuestionsPanel |
| 611 | examId={exam().id} | 612 | examId={exam().id} |
| 612 | courseId={examCourseId(exam())} | 613 | courseId={examCourseId(exam())} |
| 614 | + instanceId={exam().class_course} | ||
| 613 | embedded | 615 | embedded |
| 614 | /> | 616 | /> |
| 615 | </Show> | 617 | </Show> |
src/pages/holidays-page.tsxadded+233 -0
| @@ -0,0 +1,233 @@ | |||
| 1 | +import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import { createResource } from "@/lib/create-resource"; | ||
| 3 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 4 | +import { deleteHolidayById, getHolidays, patchHolidayById, postHoliday } from "@/api/holidays"; | ||
| 5 | +import { getLimits } from "@/api/limits"; | ||
| 6 | +import { formatApiError, type Holiday } from "@/api/client"; | ||
| 7 | +import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 8 | +import { Alert } from "@/components/ui/alert"; | ||
| 9 | +import { Badge } from "@/components/ui/badge"; | ||
| 10 | +import { Button } from "@/components/ui/button"; | ||
| 11 | +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | ||
| 12 | +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | ||
| 13 | +import { DatePicker } from "@/components/ui/date-picker"; | ||
| 14 | +import { ErrorAlert } from "@/components/ui/error-alert"; | ||
| 15 | +import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; | ||
| 16 | +import { Input } from "@/components/ui/input"; | ||
| 17 | +import { Label } from "@/components/ui/label"; | ||
| 18 | +import { Select } from "@/components/ui/select"; | ||
| 19 | +import { SidePanel } from "@/components/ui/side-panel"; | ||
| 20 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 21 | +import { dateInputFromMs, dateInputToEndOfDayMs, dateTimeInputToMs } from "@/lib/datetime-input"; | ||
| 22 | +import { createFlash } from "@/lib/flash"; | ||
| 23 | +import { formatDate } from "@/lib/format"; | ||
| 24 | +import { holidayKindLabel } from "@/lib/holiday-kind"; | ||
| 25 | +import { matchesSearch } from "@/lib/search-text"; | ||
| 26 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 27 | + | ||
| 28 | +const DAY_MS = 86_400_000; | ||
| 29 | + | ||
| 30 | +export default function HolidaysPage() { | ||
| 31 | + return ( | ||
| 32 | + <RouteGuard minRole="manager"> | ||
| 33 | + <HolidaysContent /> | ||
| 34 | + </RouteGuard> | ||
| 35 | + ); | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +function HolidaysContent() { | ||
| 39 | + const t = useT(); | ||
| 40 | + const { locale } = usePreferences(); | ||
| 41 | + const [list, { refetch }] = createResource(async () => (await getHolidays()).items); | ||
| 42 | + const [limits] = createResource(() => getLimits()); | ||
| 43 | + const kinds = () => limits.latest?.holiday.kinds ?? ["resmi", "dini", "idari", "ara"]; | ||
| 44 | + | ||
| 45 | + const [panelOpen, setPanelOpen] = createSignal(false); | ||
| 46 | + const [editing, setEditing] = createSignal<Holiday | null>(null); | ||
| 47 | + const [deleteTarget, setDeleteTarget] = createSignal<Holiday | null>(null); | ||
| 48 | + const [name, setName] = createSignal(""); | ||
| 49 | + const [kind, setKind] = createSignal(""); | ||
| 50 | + const [firstDay, setFirstDay] = createSignal(""); | ||
| 51 | + const [lastDay, setLastDay] = createSignal(""); | ||
| 52 | + const [error, setError] = createSignal(""); | ||
| 53 | + const [pending, setPending] = createSignal(false); | ||
| 54 | + const [flash, setFlash] = createFlash(); | ||
| 55 | + | ||
| 56 | + const openForm = (holiday: Holiday | null) => { | ||
| 57 | + setEditing(holiday); | ||
| 58 | + setName(holiday?.name ?? ""); | ||
| 59 | + setKind(holiday?.kind ?? kinds()[0] ?? ""); | ||
| 60 | + setFirstDay(holiday ? dateInputFromMs(holiday.starts_at) : ""); | ||
| 61 | + setLastDay(holiday ? dateInputFromMs(holiday.ends_at) : ""); | ||
| 62 | + setError(""); | ||
| 63 | + setPanelOpen(true); | ||
| 64 | + }; | ||
| 65 | + | ||
| 66 | + const save = async (event: SubmitEvent) => { | ||
| 67 | + event.preventDefault(); | ||
| 68 | + if (!name().trim()) { | ||
| 69 | + setError(t("form.fieldRequired")); | ||
| 70 | + return; | ||
| 71 | + } | ||
| 72 | + // A holiday blocks whole school days: the first day from midnight, the | ||
| 73 | + // last day through its final minute. | ||
| 74 | + const starts_at = dateTimeInputToMs(firstDay(), "00:00"); | ||
| 75 | + const ends_at = dateInputToEndOfDayMs(lastDay()); | ||
| 76 | + if (starts_at === null || ends_at === null || ends_at < starts_at) { | ||
| 77 | + setError(t("holidays.rangeInvalid")); | ||
| 78 | + return; | ||
| 79 | + } | ||
| 80 | + const body = { name: name().trim(), kind: kind(), starts_at, ends_at }; | ||
| 81 | + setError(""); | ||
| 82 | + setPending(true); | ||
| 83 | + try { | ||
| 84 | + const current = editing(); | ||
| 85 | + if (current) await patchHolidayById(current.id, body); | ||
| 86 | + else await postHoliday(body); | ||
| 87 | + setPanelOpen(false); | ||
| 88 | + setFlash(current ? t("common.saved") : t("common.created")); | ||
| 89 | + await refetch(); | ||
| 90 | + } catch (err) { | ||
| 91 | + setError(formatApiError(err)); | ||
| 92 | + } finally { | ||
| 93 | + setPending(false); | ||
| 94 | + } | ||
| 95 | + }; | ||
| 96 | + | ||
| 97 | + const dayCount = (holiday: Holiday) => Math.max(1, Math.round((holiday.ends_at - holiday.starts_at) / DAY_MS)); | ||
| 98 | + const rangeText = (holiday: Holiday) => { | ||
| 99 | + const first = formatDate(holiday.starts_at, locale()); | ||
| 100 | + const last = formatDate(holiday.ends_at, locale()); | ||
| 101 | + return first === last ? first : `${first} – ${last}`; | ||
| 102 | + }; | ||
| 103 | + | ||
| 104 | + const columns = createMemo<ColumnDef<Holiday>[]>(() => [ | ||
| 105 | + { | ||
| 106 | + accessorKey: "name", | ||
| 107 | + header: t("holidays.name"), | ||
| 108 | + meta: { cellClass: "font-medium" }, | ||
| 109 | + }, | ||
| 110 | + { | ||
| 111 | + id: "kind", | ||
| 112 | + accessorFn: (row) => holidayKindLabel(row.kind, t), | ||
| 113 | + header: t("holidays.kind"), | ||
| 114 | + cell: (cell) => <Badge variant="outline" class="rounded-md">{holidayKindLabel(cell.row.original.kind, t)}</Badge>, | ||
| 115 | + }, | ||
| 116 | + { | ||
| 117 | + id: "range", | ||
| 118 | + accessorFn: (row) => row.starts_at, | ||
| 119 | + header: t("holidays.range"), | ||
| 120 | + meta: { cellClass: "whitespace-nowrap" }, | ||
| 121 | + cell: (cell) => rangeText(cell.row.original), | ||
| 122 | + }, | ||
| 123 | + { | ||
| 124 | + id: "days", | ||
| 125 | + accessorFn: (row) => dayCount(row), | ||
| 126 | + header: t("holidays.dayCount"), | ||
| 127 | + meta: { cellClass: "tabular-nums whitespace-nowrap" }, | ||
| 128 | + cell: (cell) => t("holidays.days", { count: String(dayCount(cell.row.original)) }), | ||
| 129 | + }, | ||
| 130 | + { | ||
| 131 | + id: "actions", | ||
| 132 | + header: t("common.actions"), | ||
| 133 | + meta: { headerClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", cellClass: "text-center" }, | ||
| 134 | + cell: (cell) => ( | ||
| 135 | + <TableRowActions | ||
| 136 | + label={t("common.actions")} | ||
| 137 | + actions={[ | ||
| 138 | + { label: t("common.edit"), icon: <IconEdit class="h-4 w-4" />, onSelect: () => openForm(cell.row.original) }, | ||
| 139 | + { label: t("holidays.delete"), icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => setDeleteTarget(cell.row.original) }, | ||
| 140 | + ]} | ||
| 141 | + /> | ||
| 142 | + ), | ||
| 143 | + }, | ||
| 144 | + ]); | ||
| 145 | + | ||
| 146 | + return ( | ||
| 147 | + <div class="space-y-5"> | ||
| 148 | + <Show when={flash()}><Alert variant="success">{flash()}</Alert></Show> | ||
| 149 | + <Show when={error() && !panelOpen()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 150 | + | ||
| 151 | + <section class="data-shell space-y-4 p-0"> | ||
| 152 | + <Suspense fallback={<DataTableSkeleton columns={5} rows={6} />}> | ||
| 153 | + <Show when={list.error}> | ||
| 154 | + <ErrorAlert message={formatApiError(list.error)} onRetry={() => void refetch()} /> | ||
| 155 | + </Show> | ||
| 156 | + <DataTable | ||
| 157 | + urlState | ||
| 158 | + title={t("holidays.title")} | ||
| 159 | + description={t("holidays.subtitle")} | ||
| 160 | + actions={ | ||
| 161 | + <Button type="button" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => openForm(null)}> | ||
| 162 | + <IconPlus class="h-4 w-4" /> | ||
| 163 | + {t("holidays.new")} | ||
| 164 | + </Button> | ||
| 165 | + } | ||
| 166 | + columns={columns()} | ||
| 167 | + data={list.latest ?? []} | ||
| 168 | + searchPredicate={(holiday, needle) => matchesSearch(needle, holiday.name, holidayKindLabel(holiday.kind, t))} | ||
| 169 | + filterPlaceholder={t("common.searchPlaceholder")} | ||
| 170 | + filterHint={t("search.hint.holidays")} | ||
| 171 | + enablePagination | ||
| 172 | + pageSize={20} | ||
| 173 | + storageKey="holidays" | ||
| 174 | + empty={t("holidays.empty")} | ||
| 175 | + onRowClick={(holiday) => openForm(holiday)} | ||
| 176 | + /> | ||
| 177 | + </Suspense> | ||
| 178 | + </section> | ||
| 179 | + | ||
| 180 | + <SidePanel guardUnsaved open={panelOpen()} onOpenChange={setPanelOpen} title={editing() ? t("holidays.edit") : t("holidays.new")} description={t("holidays.subtitle")}> | ||
| 181 | + <form class="space-y-4" noValidate onSubmit={save}> | ||
| 182 | + <div class="space-y-1.5"> | ||
| 183 | + <Label for="holiday-name">{t("holidays.name")}<span class="ml-0.5 text-destructive-text">*</span></Label> | ||
| 184 | + <Input id="holiday-name" maxlength={limits.latest?.holiday.max_name_len} placeholder="29 Ekim Cumhuriyet Bayramı" value={name()} onInput={(e) => setName(e.currentTarget.value)} /> | ||
| 185 | + </div> | ||
| 186 | + <div class="space-y-1.5"> | ||
| 187 | + <Label for="holiday-kind">{t("holidays.kind")}</Label> | ||
| 188 | + <Select id="holiday-kind" value={kind()} onChange={(e) => setKind(e.currentTarget.value)}> | ||
| 189 | + <For each={kinds()}>{(k) => <option value={k}>{holidayKindLabel(k, t)}</option>}</For> | ||
| 190 | + </Select> | ||
| 191 | + </div> | ||
| 192 | + <div class="grid grid-cols-2 gap-2"> | ||
| 193 | + <div class="space-y-1.5"> | ||
| 194 | + <Label for="holiday-first">{t("holidays.firstDay")}</Label> | ||
| 195 | + <DatePicker id="holiday-first" placeholder={t("form.datePlaceholder")} value={firstDay()} onChange={(value) => { setFirstDay(value); if (!lastDay()) setLastDay(value); }} /> | ||
| 196 | + </div> | ||
| 197 | + <div class="space-y-1.5"> | ||
| 198 | + <Label for="holiday-last">{t("holidays.lastDay")}</Label> | ||
| 199 | + <DatePicker id="holiday-last" placeholder={t("form.datePlaceholder")} value={lastDay()} onChange={setLastDay} /> | ||
| 200 | + </div> | ||
| 201 | + </div> | ||
| 202 | + <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show> | ||
| 203 | + <div class="flex gap-2 border-t border-border-hairline pt-4"> | ||
| 204 | + <Button type="submit" disabled={pending()}>{editing() ? t("common.save") : t("common.create")}</Button> | ||
| 205 | + <Button type="button" variant="outline" onClick={() => setPanelOpen(false)}>{t("common.cancel")}</Button> | ||
| 206 | + </div> | ||
| 207 | + </form> | ||
| 208 | + </SidePanel> | ||
| 209 | + | ||
| 210 | + <ConfirmDialog | ||
| 211 | + open={deleteTarget() !== null} | ||
| 212 | + onOpenChange={(open) => !open && setDeleteTarget(null)} | ||
| 213 | + title={t("holidays.delete")} | ||
| 214 | + summary={t("holidays.deleteConfirm", { name: deleteTarget()?.name ?? "" })} | ||
| 215 | + variant="destructive" | ||
| 216 | + onConfirm={async () => { | ||
| 217 | + const target = deleteTarget(); | ||
| 218 | + if (!target) return; | ||
| 219 | + setError(""); | ||
| 220 | + try { | ||
| 221 | + await deleteHolidayById(target.id); | ||
| 222 | + await refetch(); | ||
| 223 | + setFlash(t("common.deleted")); | ||
| 224 | + } catch (err) { | ||
| 225 | + setError(formatApiError(err)); | ||
| 226 | + } finally { | ||
| 227 | + setDeleteTarget(null); | ||
| 228 | + } | ||
| 229 | + }} | ||
| 230 | + /> | ||
| 231 | + </div> | ||
| 232 | + ); | ||
| 233 | +} | ||
src/pages/homework-page.tsxmodified+4 -5
| @@ -2,8 +2,7 @@ import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js | |||
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { useLocation, useNavigate } from "@tanstack/solid-router"; | 3 | import { useLocation, useNavigate } from "@tanstack/solid-router"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | -import { getCourseSubjects } from "@/api/courses"; | 5 | +import { getInstanceSubjects, postInstanceHomework } from "@/api/instances"; |
| 6 | -import { postInstanceHomework } from "@/api/instances"; | ||
| 7 | import { loadInstanceOptions } from "@/lib/instance-options"; | 6 | import { loadInstanceOptions } from "@/lib/instance-options"; |
| 8 | import { loadInstanceLabels } from "@/lib/instance-labels"; | 7 | import { loadInstanceLabels } from "@/lib/instance-labels"; |
| 9 | import { getHomework } from "@/api/homework"; | 8 | import { getHomework } from "@/api/homework"; |
| @@ -104,10 +103,10 @@ function HomeworkContent() { | |||
| 104 | .map((id) => ({ value: id, label: courseNames()[id] })); | 103 | .map((id) => ({ value: id, label: courseNames()[id] })); |
| 105 | return [{ value: "all", label: t("common.all") }, ...known.map((row) => ({ value: row.id, label: row.label })), ...extra]; | 104 | return [{ value: "all", label: t("common.all") }, ...known.map((row) => ({ value: row.id, label: row.label })), ...extra]; |
| 106 | }); | 105 | }); |
| 107 | - const selectedCourse = createMemo(() => manageableCourses().find((row) => row.id === selectedCourseId())?.course ?? null); | 106 | + // A homework subject must sit in the chosen section's resolved subject set. |
| 108 | const [subjects] = createResource( | 107 | const [subjects] = createResource( |
| 109 | - () => selectedCourse(), | 108 | + () => selectedCourseId() || null, |
| 110 | - async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), | 109 | + async (instanceId) => (instanceId ? (await getInstanceSubjects(instanceId)).subjects : []), |
| 111 | ); | 110 | ); |
| 112 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); | 111 | const [serverTime] = createResource(() => getTime().catch(() => ({ now: Date.now() }))); |
| 113 | const courseName = (id: string) => courseNames()[id] ?? "—"; | 112 | const courseName = (id: string) => courseNames()[id] ?? "—"; |
src/pages/instance-detail-page.tsxmodified+64 -10
| @@ -3,7 +3,8 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import { useLocation, useNavigate, useParams } from "@tanstack/solid-router"; | 3 | import { useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | import { getClassById } from "@/api/classes"; | 5 | import { getClassById } from "@/api/classes"; |
| 6 | -import { getCourseById } from "@/api/courses"; | 6 | +import { getCourseById, getCourseSubjects } from "@/api/courses"; |
| 7 | +import { getLimits } from "@/api/limits"; | ||
| 7 | import { | 8 | import { |
| 8 | deleteInstanceEnrollmentByUserId, | 9 | deleteInstanceEnrollmentByUserId, |
| 9 | getInstanceById, | 10 | getInstanceById, |
| @@ -15,7 +16,7 @@ import { | |||
| 15 | } from "@/api/instances"; | 16 | } from "@/api/instances"; |
| 16 | import { getSettings } from "@/api/settings"; | 17 | import { getSettings } from "@/api/settings"; |
| 17 | import { formatApiError } from "@/api/client"; | 18 | import { formatApiError } from "@/api/client"; |
| 18 | -import type { Enrollment, Exam } from "@/api/client"; | 19 | +import type { Enrollment, Exam, MaterializeReport } from "@/api/client"; |
| 19 | import { patchExamById } from "@/api/exams"; | 20 | import { patchExamById } from "@/api/exams"; |
| 20 | import { ExamLink } from "@/components/exams/exam-link"; | 21 | import { ExamLink } from "@/components/exams/exam-link"; |
| 21 | import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; | 22 | import { ExamForm, type ExamFormValues } from "@/components/exams/exam-form"; |
| @@ -23,6 +24,8 @@ import { ExamQuestionsPanel } from "@/components/exams/exam-questions-panel"; | |||
| 23 | import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel"; | 24 | import { CourseTeachersPanel } from "@/components/courses/course-teachers-panel"; |
| 24 | import { CourseHomeworkPanel } from "@/components/homework/course-homework-panel"; | 25 | import { CourseHomeworkPanel } from "@/components/homework/course-homework-panel"; |
| 25 | import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; | 26 | import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; |
| 27 | +import { InstanceSettingsPanel } from "@/components/instances/instance-settings-panel"; | ||
| 28 | +import { InstanceWeeklyPlanPanel } from "@/components/instances/instance-weekly-plan-panel"; | ||
| 26 | import { RouteGuard } from "@/components/layout/route-guard"; | 29 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 27 | import { PageHeader } from "@/components/layout/page-header"; | 30 | import { PageHeader } from "@/components/layout/page-header"; |
| 28 | import { Breadcrumbs } from "@/components/layout/breadcrumbs"; | 31 | import { Breadcrumbs } from "@/components/layout/breadcrumbs"; |
| @@ -31,7 +34,7 @@ import { Badge } from "@/components/ui/badge"; | |||
| 31 | import { Button } from "@/components/ui/button"; | 34 | import { Button } from "@/components/ui/button"; |
| 32 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 35 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 33 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | 36 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; |
| 34 | -import { IconAlert, IconCalendarDays, IconExam, IconHomework, IconPlus, IconSchool, IconTrash, IconUsers } from "@/components/ui/icons"; | 37 | +import { IconAlert, IconCalendarDays, IconClock, IconExam, IconHomework, IconPlus, IconSchool, IconSettings, IconTrash, IconUsers } from "@/components/ui/icons"; |
| 35 | import { Input } from "@/components/ui/input"; | 38 | import { Input } from "@/components/ui/input"; |
| 36 | import { PageSpinner } from "@/components/ui/page-spinner"; | 39 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 37 | import { SidePanel } from "@/components/ui/side-panel"; | 40 | import { SidePanel } from "@/components/ui/side-panel"; |
| @@ -91,8 +94,9 @@ function InstanceDetailContent() { | |||
| 91 | ...(tabOn.exams() ? ["exams"] : []), | 94 | ...(tabOn.exams() ? ["exams"] : []), |
| 92 | ...(tabOn.homework() ? ["homework"] : []), | 95 | ...(tabOn.homework() ? ["homework"] : []), |
| 93 | ...(tabOn.sessions() ? ["sessions"] : []), | 96 | ...(tabOn.sessions() ? ["sessions"] : []), |
| 97 | + "plan", | ||
| 94 | "teachers", | 98 | "teachers", |
| 95 | - ...(canManage() ? ["students"] : []), | 99 | + ...(canManage() ? ["students", "settings"] : []), |
| 96 | ]; | 100 | ]; |
| 97 | return tabs.includes(requestedTab()) ? requestedTab() : tabs[0]; | 101 | return tabs.includes(requestedTab()) ? requestedTab() : tabs[0]; |
| 98 | }; | 102 | }; |
| @@ -100,6 +104,14 @@ function InstanceDetailContent() { | |||
| 100 | const [course] = createResource(() => instance()?.course ?? null, (courseId) => getCourseById(courseId)); | 104 | const [course] = createResource(() => instance()?.course ?? null, (courseId) => getCourseById(courseId)); |
| 101 | const [klass] = createResource(() => instance()?.class ?? null, (classId) => getClassById(classId).catch(() => null)); | 105 | const [klass] = createResource(() => instance()?.class ?? null, (classId) => getClassById(classId).catch(() => null)); |
| 102 | const [settings] = createResource(() => getSettings()); | 106 | const [settings] = createResource(() => getSettings()); |
| 107 | + const [limits] = createResource(() => (canManage() ? true : null), () => getLimits()); | ||
| 108 | + // Only the settings tab edits the topic set, so only it loads the catalog's. | ||
| 109 | + const [courseSubjects] = createResource( | ||
| 110 | + () => (canManage() && tab() === "settings" ? instance()?.course ?? null : null), | ||
| 111 | + async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []), | ||
| 112 | + ); | ||
| 113 | + // The section's resolved weight map, in the shape examWeight() reads. | ||
| 114 | + const sectionWeights = () => instance()?.exam_weights.map((entry) => ({ name: entry.kind, weight: entry.weight })) ?? settings()?.exam_kinds; | ||
| 103 | 115 | ||
| 104 | // Manager+, an assigned teacher, or the şube's homeroom teacher may run it. | 116 | // Manager+, an assigned teacher, or the şube's homeroom teacher may run it. |
| 105 | const canManage = () => { | 117 | const canManage = () => { |
| @@ -147,6 +159,10 @@ function InstanceDetailContent() { | |||
| 147 | const [savingPolicy, setSavingPolicy] = createSignal(false); | 159 | const [savingPolicy, setSavingPolicy] = createSignal(false); |
| 148 | const [karneConfirm, setKarneConfirm] = createSignal<boolean | null>(null); | 160 | const [karneConfirm, setKarneConfirm] = createSignal<boolean | null>(null); |
| 149 | const [policySaved, setPolicySaved] = createSignal<"dersSaati" | "karne" | null>(null); | 161 | const [policySaved, setPolicySaved] = createSignal<"dersSaati" | "karne" | null>(null); |
| 162 | + // A header edit sets the section's own override without refetching the | ||
| 163 | + // instance; the settings tab reads these so its badges stay truthful. | ||
| 164 | + const [dersSaatiOwn, setDersSaatiOwn] = createSignal(false); | ||
| 165 | + const [karneOwn, setKarneOwn] = createSignal(false); | ||
| 150 | let policySavedTimer: number | undefined; | 166 | let policySavedTimer: number | undefined; |
| 151 | onCleanup(() => window.clearTimeout(policySavedTimer)); | 167 | onCleanup(() => window.clearTimeout(policySavedTimer)); |
| 152 | const flashPolicySaved = (which: "dersSaati" | "karne") => { | 168 | const flashPolicySaved = (which: "dersSaati" | "karne") => { |
| @@ -160,6 +176,8 @@ function InstanceDetailContent() { | |||
| 160 | setCountsTowardKarne(i.counts_toward_karne); | 176 | setCountsTowardKarne(i.counts_toward_karne); |
| 161 | setDersSaati(String(i.ders_saati)); | 177 | setDersSaati(String(i.ders_saati)); |
| 162 | setSavedDersSaati(i.ders_saati); | 178 | setSavedDersSaati(i.ders_saati); |
| 179 | + setDersSaatiOwn(i.ders_saati_overridden); | ||
| 180 | + setKarneOwn(i.counts_toward_karne_overridden); | ||
| 163 | }); | 181 | }); |
| 164 | const dersSaatiDirty = () => dersSaati().trim() !== String(savedDersSaati() ?? ""); | 182 | const dersSaatiDirty = () => dersSaati().trim() !== String(savedDersSaati() ?? ""); |
| 165 | 183 | ||
| @@ -169,6 +187,7 @@ function InstanceDetailContent() { | |||
| 169 | setSavingPolicy(true); | 187 | setSavingPolicy(true); |
| 170 | try { | 188 | try { |
| 171 | await patchInstanceById(id(), { counts_toward_karne: next }); | 189 | await patchInstanceById(id(), { counts_toward_karne: next }); |
| 190 | + setKarneOwn(true); | ||
| 172 | flashPolicySaved("karne"); | 191 | flashPolicySaved("karne"); |
| 173 | } catch (err) { | 192 | } catch (err) { |
| 174 | setCountsTowardKarne(!next); | 193 | setCountsTowardKarne(!next); |
| @@ -193,6 +212,7 @@ function InstanceDetailContent() { | |||
| 193 | await patchInstanceById(id(), { ders_saati: value }); | 212 | await patchInstanceById(id(), { ders_saati: value }); |
| 194 | setSavedDersSaati(value); | 213 | setSavedDersSaati(value); |
| 195 | setDersSaati(String(value)); | 214 | setDersSaati(String(value)); |
| 215 | + setDersSaatiOwn(true); | ||
| 196 | flashPolicySaved("dersSaati"); | 216 | flashPolicySaved("dersSaati"); |
| 197 | } catch (err) { | 217 | } catch (err) { |
| 198 | setError(formatApiError(err)); | 218 | setError(formatApiError(err)); |
| @@ -279,7 +299,7 @@ function InstanceDetailContent() { | |||
| 279 | cell: (cell) => ( | 299 | cell: (cell) => ( |
| 280 | <Badge variant="outline" class="rounded-full capitalize"> | 300 | <Badge variant="outline" class="rounded-full capitalize"> |
| 281 | {examKindLabel(String(cell.row.original.kind), t)} | 301 | {examKindLabel(String(cell.row.original.kind), t)} |
| 282 | - <Show when={examWeight(cell.row.original, settings()?.exam_kinds)}> | 302 | + <Show when={examWeight(cell.row.original, sectionWeights())}> |
| 283 | {(weight) => <span class="ml-1 text-text-subtle">({t("courses.weight")}: {weight()})</span>} | 303 | {(weight) => <span class="ml-1 text-text-subtle">({t("courses.weight")}: {weight()})</span>} |
| 284 | </Show> | 304 | </Show> |
| 285 | </Badge> | 305 | </Badge> |
| @@ -324,8 +344,8 @@ function InstanceDetailContent() { | |||
| 324 | ]} | 344 | ]} |
| 325 | /> | 345 | /> |
| 326 | <PageHeader | 346 | <PageHeader |
| 327 | - title={`${course.latest?.title ?? ""} — ${klass.latest?.name ?? ""}`.replace(/^ — | — $/, "")} | 347 | + title={`${inst().title} — ${klass.latest?.name ?? ""}`.replace(/^ — | — $/, "")} |
| 328 | - description={t("instances.selectSectionHelp")} | 348 | + description={inst().description || t("instances.selectSectionHelp")} |
| 329 | class="border-border-line" | 349 | class="border-border-line" |
| 330 | /> | 350 | /> |
| 331 | <div class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"> | 351 | <div class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"> |
| @@ -442,7 +462,7 @@ function InstanceDetailContent() { | |||
| 442 | onOpenChange={(open) => !open && setKarneConfirm(null)} | 462 | onOpenChange={(open) => !open && setKarneConfirm(null)} |
| 443 | title={t("instances.karneConfirmTitle")} | 463 | title={t("instances.karneConfirmTitle")} |
| 444 | description={karneConfirm() ? t("instances.karneOnHint") : t("instances.karneOffHint")} | 464 | description={karneConfirm() ? t("instances.karneOnHint") : t("instances.karneOffHint")} |
| 445 | - summary={`${course.latest?.title ?? ""} — ${klass.latest?.name ?? ""}`.replace(/^ — | — $/, "")} | 465 | + summary={`${inst().title} — ${klass.latest?.name ?? ""}`.replace(/^ — | — $/, "")} |
| 446 | confirmLabel={karneConfirm() ? t("instances.karneTurnOn") : t("instances.karneTurnOff")} | 466 | confirmLabel={karneConfirm() ? t("instances.karneTurnOn") : t("instances.karneTurnOff")} |
| 447 | onConfirm={async () => { | 467 | onConfirm={async () => { |
| 448 | const next = karneConfirm(); | 468 | const next = karneConfirm(); |
| @@ -548,7 +568,7 @@ function InstanceDetailContent() { | |||
| 548 | 568 | ||
| 549 | <Show when={examCreateStep() === "questions" && createdExam()}> | 569 | <Show when={examCreateStep() === "questions" && createdExam()}> |
| 550 | <div class="space-y-4"> | 570 | <div class="space-y-4"> |
| 551 | - <ExamQuestionsPanel examId={createdExam()!.id} courseId={inst().course} embedded /> | 571 | + <ExamQuestionsPanel examId={createdExam()!.id} courseId={inst().course} instanceId={inst().id} embedded /> |
| 552 | <div class="flex justify-end border-t pt-3"> | 572 | <div class="flex justify-end border-t pt-3"> |
| 553 | <Button type="button" variant="default" onClick={() => setShowExamForm(false)}> | 573 | <Button type="button" variant="default" onClick={() => setShowExamForm(false)}> |
| 554 | {t("exams.finishAndClose")} | 574 | {t("exams.finishAndClose")} |
| @@ -609,7 +629,7 @@ function InstanceDetailContent() { | |||
| 609 | </Show> | 629 | </Show> |
| 610 | 630 | ||
| 611 | <Tabs value={tab()} onChange={setTab} class="space-y-4"> | 631 | <Tabs value={tab()} onChange={setTab} class="space-y-4"> |
| 612 | - <TabsList class="flex w-full justify-start overflow-x-auto sm:grid sm:grid-cols-3 xl:grid-cols-5" aria-label={course.latest?.title ?? ""}> | 632 | + <TabsList class="flex w-full justify-start overflow-x-auto sm:grid sm:grid-cols-4 xl:grid-cols-7" aria-label={inst().title}> |
| 613 | <Show when={tabOn.exams()}> | 633 | <Show when={tabOn.exams()}> |
| 614 | <TabsTrigger value="exams" class="min-w-0"><IconExam class="h-4 w-4" />{t("courses.exams")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{examCount()}</Badge></TabsTrigger> | 634 | <TabsTrigger value="exams" class="min-w-0"><IconExam class="h-4 w-4" />{t("courses.exams")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{examCount()}</Badge></TabsTrigger> |
| 615 | </Show> | 635 | </Show> |
| @@ -619,9 +639,11 @@ function InstanceDetailContent() { | |||
| 619 | <Show when={tabOn.sessions()}> | 639 | <Show when={tabOn.sessions()}> |
| 620 | <TabsTrigger value="sessions" class="min-w-0"><IconCalendarDays class="h-4 w-4" />{t("sessions.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{sessionCount()}</Badge></TabsTrigger> | 640 | <TabsTrigger value="sessions" class="min-w-0"><IconCalendarDays class="h-4 w-4" />{t("sessions.title")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{sessionCount()}</Badge></TabsTrigger> |
| 621 | </Show> | 641 | </Show> |
| 642 | + <TabsTrigger value="plan" class="min-w-0"><IconClock class="h-4 w-4" />{t("weeklyPlan.tab")}</TabsTrigger> | ||
| 622 | <TabsTrigger value="teachers" class="min-w-0"><IconSchool class="h-4 w-4" />{t("courses.teachers")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{inst().teachers.length}</Badge></TabsTrigger> | 643 | <TabsTrigger value="teachers" class="min-w-0"><IconSchool class="h-4 w-4" />{t("courses.teachers")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{inst().teachers.length}</Badge></TabsTrigger> |
| 623 | <Show when={canManage()}> | 644 | <Show when={canManage()}> |
| 624 | <TabsTrigger value="students" class="min-w-0"><IconUsers class="h-4 w-4" />{t("courses.roster")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{rosterCount()}</Badge></TabsTrigger> | 645 | <TabsTrigger value="students" class="min-w-0"><IconUsers class="h-4 w-4" />{t("courses.roster")}<Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">{rosterCount()}</Badge></TabsTrigger> |
| 646 | + <TabsTrigger value="settings" class="min-w-0"><IconSettings class="h-4 w-4" />{t("instances.settingsTab")}</TabsTrigger> | ||
| 625 | </Show> | 647 | </Show> |
| 626 | </TabsList> | 648 | </TabsList> |
| 627 | 649 | ||
| @@ -680,6 +702,21 @@ function InstanceDetailContent() { | |||
| 680 | </TabsContent> | 702 | </TabsContent> |
| 681 | </Show> | 703 | </Show> |
| 682 | 704 | ||
| 705 | + <TabsContent value="plan" class="space-y-3"> | ||
| 706 | + <InstanceWeeklyPlanPanel | ||
| 707 | + instance={inst()} | ||
| 708 | + canManage={canManage()} | ||
| 709 | + canGenerate={tabOn.sessions()} | ||
| 710 | + limits={limits.latest?.weekly_plan} | ||
| 711 | + maxTopicLen={limits.latest?.course.max_session_topic_len} | ||
| 712 | + onChanged={refetchInstance} | ||
| 713 | + onLessonsCreated={(report: MaterializeReport) => { | ||
| 714 | + setFlash(t("weeklyPlan.appliedSummary", { count: report.created.length })); | ||
| 715 | + setTab("sessions"); | ||
| 716 | + }} | ||
| 717 | + /> | ||
| 718 | + </TabsContent> | ||
| 719 | + | ||
| 683 | <TabsContent value="teachers" class="space-y-3"> | 720 | <TabsContent value="teachers" class="space-y-3"> |
| 684 | <CourseTeachersPanel | 721 | <CourseTeachersPanel |
| 685 | instanceId={id()} | 722 | instanceId={id()} |
| @@ -710,6 +747,23 @@ function InstanceDetailContent() { | |||
| 710 | /> | 747 | /> |
| 711 | </Suspense> | 748 | </Suspense> |
| 712 | </TabsContent> | 749 | </TabsContent> |
| 750 | + <TabsContent value="settings" class="space-y-3"> | ||
| 751 | + <InstanceSettingsPanel | ||
| 752 | + instance={{ | ||
| 753 | + ...inst(), | ||
| 754 | + ders_saati: savedDersSaati() ?? inst().ders_saati, | ||
| 755 | + ders_saati_overridden: dersSaatiOwn(), | ||
| 756 | + counts_toward_karne: countsTowardKarne(), | ||
| 757 | + counts_toward_karne_overridden: karneOwn(), | ||
| 758 | + }} | ||
| 759 | + canManage={canManage()} | ||
| 760 | + courseSubjects={courseSubjects() ?? []} | ||
| 761 | + examKinds={(settings()?.exam_kinds ?? []).map((kind) => kind.name)} | ||
| 762 | + maxTitleLen={limits.latest?.course.max_title_len} | ||
| 763 | + maxDescriptionLen={limits.latest?.course.max_description_len} | ||
| 764 | + onChanged={refetchInstance} | ||
| 765 | + /> | ||
| 766 | + </TabsContent> | ||
| 713 | </Show> | 767 | </Show> |
| 714 | </Tabs> | 768 | </Tabs> |
| 715 | </div> | 769 | </div> |
src/routes/router.tsxmodified+8 -0
| @@ -60,6 +60,7 @@ const AdminUsersPage = lazyRoute(() => import("@/pages/admin-users-page")); | |||
| 60 | const AdminUserDetailPage = lazyRoute(() => import("@/pages/admin-user-detail-page")); | 60 | const AdminUserDetailPage = lazyRoute(() => import("@/pages/admin-user-detail-page")); |
| 61 | const SettingsPage = lazyRoute(() => import("@/pages/settings-page")); | 61 | const SettingsPage = lazyRoute(() => import("@/pages/settings-page")); |
| 62 | const TermsPage = lazyRoute(() => import("@/pages/terms-page")); | 62 | const TermsPage = lazyRoute(() => import("@/pages/terms-page")); |
| 63 | +const HolidaysPage = lazyRoute(() => import("@/pages/holidays-page")); | ||
| 63 | const GuidePage = lazyRoute(() => import("@/pages/guide-page")); | 64 | const GuidePage = lazyRoute(() => import("@/pages/guide-page")); |
| 64 | const MyStudentsPage = lazyRoute(() => import("@/pages/my-students-page")); | 65 | const MyStudentsPage = lazyRoute(() => import("@/pages/my-students-page")); |
| 65 | const QuestionsPage = lazyRoute(() => import("@/pages/questions-page")); | 66 | const QuestionsPage = lazyRoute(() => import("@/pages/questions-page")); |
| @@ -329,6 +330,12 @@ const termsRoute = createRoute({ | |||
| 329 | component: TermsPage, | 330 | component: TermsPage, |
| 330 | }); | 331 | }); |
| 331 | 332 | ||
| 333 | +const holidaysRoute = createRoute({ | ||
| 334 | + getParentRoute: () => rootRoute, | ||
| 335 | + path: "/management/holidays", | ||
| 336 | + component: HolidaysPage, | ||
| 337 | +}); | ||
| 338 | + | ||
| 332 | const academicYearsRoute = createRoute({ | 339 | const academicYearsRoute = createRoute({ |
| 333 | getParentRoute: () => rootRoute, | 340 | getParentRoute: () => rootRoute, |
| 334 | path: "/management/academic-years", | 341 | path: "/management/academic-years", |
| @@ -629,6 +636,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 629 | classesRoute, | 636 | classesRoute, |
| 630 | classDetailRoute, | 637 | classDetailRoute, |
| 631 | termsRoute, | 638 | termsRoute, |
| 639 | + holidaysRoute, | ||
| 632 | academicYearsRoute, | 640 | academicYearsRoute, |
| 633 | adminUsersRoute, | 641 | adminUsersRoute, |
| 634 | adminUserDetailRoute, | 642 | adminUserDetailRoute, |