From d2570ac8ffcc8f88590fad56a4a9f3fac3e31e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sat, 12 Sep 2026 00:33:53 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20module=20and=20note?= =?UTF-8?q?=20intelligence=20workflows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add module catalog APIs and shared module context - add course-note RAG retrieval and output deletion flows - add term archive controls and blueprint status integration - refine responsive navigation, settings, and note panels - extend API and navigation test coverage --- src/api/__tests__/classes/classes.test.ts | 11 ++ .../course-notes/course-notes.test.ts | 25 ++++- src/api/__tests__/modules/modules.test.ts | 37 ++++++ src/api/__tests__/terms/terms.test.ts | 27 ++++- src/api/classes/getClassBlueprintStatus.ts | 6 + src/api/classes/index.ts | 1 + src/api/client/client.ts | 12 ++ src/api/client/types.ts | 55 +++++++++ .../course-notes/deleteCourseNoteRagOutput.ts | 5 + src/api/course-notes/getCourseNoteRag.ts | 12 ++ src/api/course-notes/index.ts | 2 + src/api/modules/getModules.ts | 6 + src/api/modules/getModulesCatalog.ts | 6 + src/api/modules/index.ts | 2 + src/api/terms/index.ts | 2 + src/api/terms/postTermArchive.ts | 6 + src/api/terms/postTermUnarchive.ts | 6 + src/components/classes/blueprints-tab.tsx | 56 ++++++++- src/components/layout/app-shell.tsx | 24 ++-- src/components/layout/command-palette.tsx | 4 +- src/components/layout/mobile-nav-sheet.tsx | 4 +- src/components/layout/mobile-tab-bar.tsx | 4 +- src/components/layout/nav-items.test.ts | 21 +++- src/components/layout/nav-items.ts | 76 ++++++++----- src/components/layout/side-nav.tsx | 6 +- src/components/notes/note-reader-panel.tsx | 4 + src/components/notes/rag-outputs-panel.tsx | 106 ++++++++++++++++++ src/i18n/messages.ts | 36 ++++++ src/lib/note-source.ts | 9 +- src/pages/settings-page.tsx | 40 ++++++- src/pages/terms-page.tsx | 39 ++++++- src/routes/router.tsx | 9 +- src/stores/modules-context.tsx | 61 ++++++++++ 33 files changed, 664 insertions(+), 56 deletions(-) create mode 100644 src/api/__tests__/modules/modules.test.ts create mode 100644 src/api/classes/getClassBlueprintStatus.ts create mode 100644 src/api/course-notes/deleteCourseNoteRagOutput.ts create mode 100644 src/api/course-notes/getCourseNoteRag.ts create mode 100644 src/api/modules/getModules.ts create mode 100644 src/api/modules/getModulesCatalog.ts create mode 100644 src/api/modules/index.ts create mode 100644 src/api/terms/postTermArchive.ts create mode 100644 src/api/terms/postTermUnarchive.ts create mode 100644 src/components/notes/rag-outputs-panel.tsx create mode 100644 src/stores/modules-context.tsx diff --git a/src/api/__tests__/classes/classes.test.ts b/src/api/__tests__/classes/classes.test.ts index 7a790fe..af8b2f6 100644 --- a/src/api/__tests__/classes/classes.test.ts +++ b/src/api/__tests__/classes/classes.test.ts @@ -19,6 +19,7 @@ import { patchClassBlueprintByGrade, deleteClassBlueprintByGrade, postClassBlueprintApply, + getClassBlueprintStatus, } from "../../classes"; import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; @@ -185,4 +186,14 @@ describe("classes API", () => { expect(init?.method).toBe("POST"); expect(init?.body).toBeUndefined(); }); + + it("getClassBlueprintStatus GETs /classes/blueprints/:grade/status", async () => { + const mockStatus = { grade: "9/A", courses: ["co1"], matched: 3, sections: [] }; + mockFetchSuccess(mockStatus); + const result = await getClassBlueprintStatus("9/A"); + expect(result).toEqual(mockStatus); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/classes/blueprints/9%2FA/status"); + expect(init?.method).toBe("GET"); + }); }); diff --git a/src/api/__tests__/course-notes/course-notes.test.ts b/src/api/__tests__/course-notes/course-notes.test.ts index 2b287b7..40ce633 100644 --- a/src/api/__tests__/course-notes/course-notes.test.ts +++ b/src/api/__tests__/course-notes/course-notes.test.ts @@ -9,8 +9,9 @@ import { postCourseNoteFile } from "../../course-notes"; import { deleteCourseNoteFileById } from "../../course-notes"; import { getCourseNoteFileUrl } from "../../course-notes"; import { getCourseNoteFileBlob } from "../../course-notes"; +import { getCourseNoteRag } from "../../course-notes"; +import { deleteCourseNoteRagOutput } from "../../course-notes"; import { lastFetchCall, mockFetch204, mockFetchBlob, mockFetchSuccess } from "../helpers/mock-fetch"; - describe("course notes API", () => { afterEach(() => { vi.restoreAllMocks(); @@ -141,4 +142,26 @@ describe("course notes API", () => { expect(url).toBe("/api/course-notes/cn1/files/f1"); expect(init?.credentials).toBe("same-origin"); }); + + it("getCourseNoteRag calls /course-notes/:id/rag with pagination", async () => { + const mockPage = { items: [{ id: "r1", course_note: "cn1" }], total: 1 }; + mockFetchSuccess(mockPage); + + const result = await getCourseNoteRag("cn1", { limit: 10 }); + expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/course-notes/cn1/rag?limit=10"); + expect(init?.method).toBe("GET"); + }); + + it("deleteCourseNoteRagOutput calls /course-notes/:id/rag/:outputId", async () => { + mockFetch204(); + + await deleteCourseNoteRagOutput("cn1", "r1"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/course-notes/cn1/rag/r1"); + expect(init?.method).toBe("DELETE"); + }); }); diff --git a/src/api/__tests__/modules/modules.test.ts b/src/api/__tests__/modules/modules.test.ts new file mode 100644 index 0000000..4875d22 --- /dev/null +++ b/src/api/__tests__/modules/modules.test.ts @@ -0,0 +1,37 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { getModules } from "../../modules"; +import { getModulesCatalog } from "../../modules"; +import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; + +describe("modules API", () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("getModules calls /modules", async () => { + const mockModules = { enabled: ["courses", "meals"] }; + mockFetchSuccess(mockModules); + + const result = await getModules(); + expect(result).toEqual(mockModules); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/modules"); + expect(init?.method).toBe("GET"); + }); + + it("getModulesCatalog calls /modules/catalog", async () => { + const mockCatalog = { + modules: [{ module: "exams", package: "academics", requires: ["courses"] }], + packages: [{ package: "academics", modules: ["exams"] }], + }; + mockFetchSuccess(mockCatalog); + + const result = await getModulesCatalog(); + expect(result).toEqual(mockCatalog); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/modules/catalog"); + expect(init?.method).toBe("GET"); + }); +}); diff --git a/src/api/__tests__/terms/terms.test.ts b/src/api/__tests__/terms/terms.test.ts index 6c72f29..f3f9dbc 100644 --- a/src/api/__tests__/terms/terms.test.ts +++ b/src/api/__tests__/terms/terms.test.ts @@ -4,8 +4,9 @@ import { getTermById } from "../../terms"; import { postTerm } from "../../terms"; import { patchTermById } from "../../terms"; import { deleteTermById } from "../../terms"; +import { postTermArchive } from "../../terms"; +import { postTermUnarchive } from "../../terms"; import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; - describe("terms API", () => { afterEach(() => { vi.restoreAllMocks(); @@ -72,4 +73,28 @@ describe("terms API", () => { expect(url).toBe("/api/terms/t1"); expect(init?.method).toBe("DELETE"); }); + + it("postTermArchive calls /terms/:id/archive", async () => { + const mockTerm = { id: "t1", archived_at: 1756896000000 }; + mockFetchSuccess(mockTerm); + + const result = await postTermArchive("t1"); + expect(result).toEqual(mockTerm); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/terms/t1/archive"); + expect(init?.method).toBe("POST"); + }); + + it("postTermUnarchive calls /terms/:id/unarchive", async () => { + const mockTerm = { id: "t1", archived_at: null }; + mockFetchSuccess(mockTerm); + + const result = await postTermUnarchive("t1"); + expect(result).toEqual(mockTerm); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/terms/t1/unarchive"); + expect(init?.method).toBe("POST"); + }); }); diff --git a/src/api/classes/getClassBlueprintStatus.ts b/src/api/classes/getClassBlueprintStatus.ts new file mode 100644 index 0000000..d43d04f --- /dev/null +++ b/src/api/classes/getClassBlueprintStatus.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { BlueprintStatus } from "../client"; + +export function getClassBlueprintStatus(grade: string, signal?: AbortSignal): Promise { + return client(`/classes/blueprints/${encodeURIComponent(grade)}/status`, { signal }); +} diff --git a/src/api/classes/index.ts b/src/api/classes/index.ts index 6ed4cf3..f1e517e 100644 --- a/src/api/classes/index.ts +++ b/src/api/classes/index.ts @@ -17,3 +17,4 @@ export * from "./getClassBlueprintByGrade"; export * from "./patchClassBlueprintByGrade"; export * from "./deleteClassBlueprintByGrade"; export * from "./postClassBlueprintApply"; +export * from "./getClassBlueprintStatus"; diff --git a/src/api/client/client.ts b/src/api/client/client.ts index 9ad6713..d661db8 100644 --- a/src/api/client/client.ts +++ b/src/api/client/client.ts @@ -166,6 +166,18 @@ const API_ERROR_MESSAGES: Record> = { en: "Question bank templates still use this subject. Re-tag or delete them first.", tr: "Soru bankasındaki şablonlar hâlâ bu konuyu kullanıyor. Önce onları başka konuya taşı veya sil.", }, + "the term is archived — past years are read-only": { + en: "This term is archived. Past years are read-only.", + tr: "Bu dönem arşivli. Geçmiş dönemler salt okunur.", + }, + "this course's term is archived — past years are read-only": { + en: "This course's term is archived. Past years are read-only.", + tr: "Bu dersin dönemi arşivli. Geçmiş dönemler salt okunur.", + }, + "module disabled": { + en: "This feature is not enabled for your school.", + tr: "Bu özellik okulunuz için etkin değil.", + }, "course not found": { en: "Course not found.", tr: "Ders bulunamadı.", diff --git a/src/api/client/types.ts b/src/api/client/types.ts index b8292fc..ae6f331 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -113,6 +113,19 @@ export type CourseNote = { content: string; }; +/** One AI service output stored against a course note. `payload` is the + * service's own shape — stored and served unread, rendered as JSON. */ +export type RagOutput = { + id: string; + course_note: string; + course: string; + /** The note's file attachments the output was built from. */ + sources: string[]; + payload: unknown; + /** When the backend stored it, epoch milliseconds. */ + generated_at: number; +}; + export type NoteFile = { id: string; name: string; @@ -120,6 +133,29 @@ export type NoteFile = { size: number; }; +/** The caller's school entitlements: every switched-on module, sorted by name. */ +export type EnabledModules = { + enabled: string[]; +}; + +export type ModuleCatalogEntry = { + module: string; + package: string; + /** Modules that must be enabled alongside this one. */ + requires: string[]; +}; + +export type ModuleCatalogPackage = { + package: string; + modules: string[]; +}; + +/** The deployment's whole module catalog — identical for every school. */ +export type ModuleCatalog = { + modules: ModuleCatalogEntry[]; + packages: ModuleCatalogPackage[]; +}; + export type EventAudience = | { kind: "school" } | { kind: "role"; role: Role } @@ -219,6 +255,8 @@ export type Term = { name: string; starts_at: number; ends_at: number; + /** Archived at, UTC unix-millis; null while the term is open. */ + archived_at: number | null; }; export type Enrollment = { @@ -285,6 +323,23 @@ export type BlueprintResult = { blueprint: ClassBlueprint; skipped: BlueprintSki export type BlueprintApplyResult = { skipped: BlueprintSkip[] }; +/** One section measured against its grade's blueprint. */ +export type BlueprintSectionStatus = { + class: string; + class_name: string; + /** Template courses the section does not carry; empty when in sync. */ + missing: string[]; +}; + +/** Every section at a grade with the template courses it is missing. */ +export type BlueprintStatus = { + grade: string; + /** The template every section below is measured against. */ + courses: string[]; + matched: number; + sections: BlueprintSectionStatus[]; +}; + export type CourseSession = { id: string; course: string; diff --git a/src/api/course-notes/deleteCourseNoteRagOutput.ts b/src/api/course-notes/deleteCourseNoteRagOutput.ts new file mode 100644 index 0000000..dfad4e1 --- /dev/null +++ b/src/api/course-notes/deleteCourseNoteRagOutput.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteCourseNoteRagOutput(noteId: string, outputId: string): Promise { + return client(`/course-notes/${noteId}/rag/${outputId}`, { method: "DELETE" }); +} diff --git a/src/api/course-notes/getCourseNoteRag.ts b/src/api/course-notes/getCourseNoteRag.ts new file mode 100644 index 0000000..ef6a51b --- /dev/null +++ b/src/api/course-notes/getCourseNoteRag.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { RagOutput } from "../client"; + +export async function getCourseNoteRag( + noteId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client(`/course-notes/${noteId}/rag${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/course-notes/index.ts b/src/api/course-notes/index.ts index a417d40..908def6 100644 --- a/src/api/course-notes/index.ts +++ b/src/api/course-notes/index.ts @@ -8,3 +8,5 @@ export * from "./postCourseNoteFile"; export * from "./deleteCourseNoteFileById"; export * from "./getCourseNoteFileUrl"; export * from "./getCourseNoteFileBlob"; +export * from "./getCourseNoteRag"; +export * from "./deleteCourseNoteRagOutput"; diff --git a/src/api/modules/getModules.ts b/src/api/modules/getModules.ts new file mode 100644 index 0000000..ae1ef95 --- /dev/null +++ b/src/api/modules/getModules.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { EnabledModules } from "../client"; + +export function getModules(signal?: AbortSignal): Promise { + return client("/modules", { signal }); +} diff --git a/src/api/modules/getModulesCatalog.ts b/src/api/modules/getModulesCatalog.ts new file mode 100644 index 0000000..126cbff --- /dev/null +++ b/src/api/modules/getModulesCatalog.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { ModuleCatalog } from "../client"; + +export function getModulesCatalog(signal?: AbortSignal): Promise { + return client("/modules/catalog", { signal }); +} diff --git a/src/api/modules/index.ts b/src/api/modules/index.ts new file mode 100644 index 0000000..d9f18e9 --- /dev/null +++ b/src/api/modules/index.ts @@ -0,0 +1,2 @@ +export * from "./getModules"; +export * from "./getModulesCatalog"; diff --git a/src/api/terms/index.ts b/src/api/terms/index.ts index 9be7e09..5eafc13 100644 --- a/src/api/terms/index.ts +++ b/src/api/terms/index.ts @@ -3,3 +3,5 @@ export * from "./getTermById"; export * from "./postTerm"; export * from "./patchTermById"; export * from "./deleteTermById"; +export * from "./postTermArchive"; +export * from "./postTermUnarchive"; diff --git a/src/api/terms/postTermArchive.ts b/src/api/terms/postTermArchive.ts new file mode 100644 index 0000000..1050e2e --- /dev/null +++ b/src/api/terms/postTermArchive.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Term } from "../client"; + +export function postTermArchive(id: string): Promise { + return client(`/terms/${id}/archive`, { method: "POST" }); +} diff --git a/src/api/terms/postTermUnarchive.ts b/src/api/terms/postTermUnarchive.ts new file mode 100644 index 0000000..cc1b5f4 --- /dev/null +++ b/src/api/terms/postTermUnarchive.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Term } from "../client"; + +export function postTermUnarchive(id: string): Promise { + return client(`/terms/${id}/unarchive`, { method: "POST" }); +} diff --git a/src/components/classes/blueprints-tab.tsx b/src/components/classes/blueprints-tab.tsx index 1b19d55..39b2643 100644 --- a/src/components/classes/blueprints-tab.tsx +++ b/src/components/classes/blueprints-tab.tsx @@ -1,16 +1,17 @@ import { Show, createMemo, createResource, createSignal } from "solid-js"; import type { ColumnDef } from "@tanstack/solid-table"; -import { deleteClassBlueprintByGrade, getClassBlueprints } from "@/api/classes"; +import { deleteClassBlueprintByGrade, getClassBlueprints, getClassBlueprintStatus } from "@/api/classes"; import { getCourses } from "@/api/courses"; import { getLimits } from "@/api/limits"; -import { formatApiError, type BlueprintSkip, type ClassBlueprint } from "@/api/client"; +import { formatApiError, type BlueprintSectionStatus, type BlueprintSkip, type BlueprintStatus, type ClassBlueprint } from "@/api/client"; import { BlueprintPanel } from "@/components/classes/blueprint-panel"; import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report"; import { Alert } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; -import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; +import { IconClipboardCheck, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; +import { SidePanel } from "@/components/ui/side-panel"; import { TableRowActions } from "@/components/ui/table-row-actions"; import { createFlash } from "@/lib/flash"; import { personLabel } from "@/lib/person"; @@ -30,6 +31,7 @@ export function BlueprintsTab(props: { const [deleting, setDeleting] = createSignal(null); const [skipped, setSkipped] = createSignal([]); const [reportOpen, setReportOpen] = createSignal(false); + const [status, setStatus] = createSignal(null); const enabled = () => (props.active() && props.canManage() ? true : null); const [list, { refetch }] = createResource(enabled, async () => @@ -90,6 +92,11 @@ export function BlueprintsTab(props: { destructive: true, onSelect: () => setDeleting(cell.row.original), }, + { + label: t("classBlueprints.status"), + icon: , + onSelect: () => void checkStatus(cell.row.original.grade), + }, ]} /> ), @@ -120,6 +127,29 @@ export function BlueprintsTab(props: { setError(formatApiError(err)); } }; + const checkStatus = async (grade: string) => { + setError(""); + try { + setStatus(await getClassBlueprintStatus(grade)); + } catch (err) { + setError(formatApiError(err)); + } + }; + + const statusColumns = createMemo[]>(() => [ + { + id: "section", + accessorFn: (row) => row.class_name || row.class, + header: t("classBlueprints.statusSection"), + meta: { cellClass: "font-medium" }, + }, + { + id: "missing", + accessorFn: (row) => row.missing.map(courseTitle).join(", ") || "—", + header: t("classBlueprints.statusMissing"), + meta: { cellClass: "text-muted-foreground" }, + }, + ]); return (
@@ -186,6 +216,26 @@ export function BlueprintsTab(props: { courseTitle={courseTitle} /> + !open && setStatus(null)} + title={t("classBlueprints.statusTitle", { grade: status()?.grade ?? "" })} + size="wide" + > + + {(current) => ( + section.missing.length > 0)} + fallback={

{t("classBlueprints.statusEmpty")}

} + > + section.missing.length > 0)} + /> +
+ )} +
+
!open && setDeleting(null)} diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index a5cd5dc..9ab6a74 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -15,6 +15,7 @@ import { Button } from "@/components/ui/button"; import { IconChevronLeft, IconPanelLeft, IconSearch, IconSparkles } from "@/components/ui/icons"; import { Toaster } from "@/components/ui/toast"; import { useAuth } from "@/stores/auth-context"; +import { useModules } from "@/stores/modules-context"; import { ShellFeedProvider } from "@/stores/shell-feed-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { cn } from "@/lib/cn"; @@ -26,6 +27,7 @@ export function AppShell(props: ParentProps) { const auth = useAuth(); const prefs = usePreferences(); const t = useT(); + const modules = useModules(); const navigate = useNavigate(); const [mobileOpen, setMobileOpen] = createSignal(false); const [celebiOpen, setCelebiOpen] = createSignal(false); @@ -143,16 +145,18 @@ export function AppShell(props: ParentProps) {
- + + +
diff --git a/src/components/layout/command-palette.tsx b/src/components/layout/command-palette.tsx index 28a9aed..cc54dc9 100644 --- a/src/components/layout/command-palette.tsx +++ b/src/components/layout/command-palette.tsx @@ -20,6 +20,7 @@ import { import { HOME_ITEM, visibleNavGroups } from "@/components/layout/nav-items"; import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; +import { useModules } from "@/stores/modules-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { cn } from "@/lib/cn"; @@ -50,6 +51,7 @@ export function CommandPalette(props: CommandPaletteProps) { const prefs = usePreferences(); const t = useT(); const navigate = useNavigate(); + const modules = useModules(); const [query, setQuery] = createSignal(""); const [selectedIndex, setSelectedIndex] = createSignal(0); @@ -200,7 +202,7 @@ export function CommandPalette(props: CommandPaletteProps) { onSelect: () => void navigate({ to: HOME_ITEM.to }), }); - for (const group of visibleNavGroups(userRole)) { + for (const group of visibleNavGroups(userRole, modules.enabled())) { const groupName = t(group.labelKey); for (const item of group.items) { list.push({ diff --git a/src/components/layout/mobile-nav-sheet.tsx b/src/components/layout/mobile-nav-sheet.tsx index f91d1d7..3969d4f 100644 --- a/src/components/layout/mobile-nav-sheet.tsx +++ b/src/components/layout/mobile-nav-sheet.tsx @@ -5,6 +5,7 @@ import { SidebarAccount } from "@/components/layout/sidebar-account"; import { IconX } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; import { useAuth } from "@/stores/auth-context"; +import { useModules } from "@/stores/modules-context"; import { useShellFeed } from "@/stores/shell-feed-context"; import { useT } from "@/stores/preferences-context"; @@ -30,11 +31,12 @@ export function MobileNavSheet(props: { const auth = useAuth(); const t = useT(); const feed = useShellFeed(); + const modules = useModules(); const pathname = useRouterState({ select: (state) => state.location.pathname }); // The primary destinations are already one tap away in the tab bar, so the // sheet lists everything else. - const groups = () => sidebarNavGroups(auth.user()?.role); + const groups = () => sidebarNavGroups(auth.user()?.role, modules.enabled()); const current = () => routeNavItem(pathname(), auth.user()?.role); const badgeFor = (item: NavItem) => (item.id === "messages" ? feed.unreadMessages().total : 0); diff --git a/src/components/layout/mobile-tab-bar.tsx b/src/components/layout/mobile-tab-bar.tsx index 4d4533b..3c2e723 100644 --- a/src/components/layout/mobile-tab-bar.tsx +++ b/src/components/layout/mobile-tab-bar.tsx @@ -4,13 +4,15 @@ import { IconMenu } from "@/components/ui/icons"; import { primaryNavItems, primaryPathActive } from "@/components/layout/nav-items"; import { cn } from "@/lib/cn"; import { useAuth } from "@/stores/auth-context"; +import { useModules } from "@/stores/modules-context"; import { useT } from "@/stores/preferences-context"; export function MobileTabBar(props: { onMenu: () => void }) { const auth = useAuth(); const t = useT(); + const modules = useModules(); const pathname = useRouterState({ select: (state) => state.location.pathname }); - const items = () => primaryNavItems(auth.user()?.role); + const items = () => primaryNavItems(auth.user()?.role, modules.enabled()); return (
+ + + )} diff --git a/src/components/notes/rag-outputs-panel.tsx b/src/components/notes/rag-outputs-panel.tsx new file mode 100644 index 0000000..845fde7 --- /dev/null +++ b/src/components/notes/rag-outputs-panel.tsx @@ -0,0 +1,106 @@ +import { For, Show, Suspense, createResource, createSignal } from "solid-js"; +import { formatApiError } from "@/api/client"; +import type { RagOutput } from "@/api/client"; +import type { NoteFileSource } from "@/lib/note-source"; +import { Alert } from "@/components/ui/alert"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { PageSpinner } from "@/components/ui/page-spinner"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { createFlash } from "@/lib/flash"; +import { formatDateTime } from "@/lib/format"; +import { usePreferences, useT } from "@/stores/preferences-context"; +import { IconTrash } from "@/components/ui/icons"; + +const RAG_PAGE_SIZE = 10; + +export function RagOutputsPanel(props: { + noteId: string; + active: boolean; + source: NoteFileSource; + /** Delete control is teacher-only; readers see the list. Defaults to true. */ + canManage?: boolean; +}) { + const t = useT(); + const { locale } = usePreferences(); + const [error, setError] = createSignal(""); + const [flash, setFlash] = createFlash(); + const [deleteTarget, setDeleteTarget] = createSignal(null); + + const [list, { refetch }] = createResource( + () => (props.active && props.source.listRagOutputs ? props.noteId : null), + async (noteId) => props.source.listRagOutputs!(noteId, { limit: RAG_PAGE_SIZE }), + ); + + const outputs = () => list()?.items ?? []; + + const remove = async () => { + const target = deleteTarget(); + if (!target || !props.source.deleteRagOutput) return; + setError(""); + try { + await props.source.deleteRagOutput(props.noteId, target.id); + await refetch(); + setFlash(t("common.deleted")); + } catch (err) { + setError(formatApiError(err)); + } finally { + setDeleteTarget(null); + } + }; + + return ( +
+

{t("courseNotes.ragTitle")}

+ + {flash()} + + + {error()} + + }> + + {formatApiError(list.error)} + + 0} fallback={

{t("courseNotes.ragEmpty")}

}> +
    + + {(output) => ( +
  • +
    + + {formatDateTime(output.generated_at, locale())} + + + + , + destructive: true, + onSelect: () => setDeleteTarget(output), + }, + ]} + /> + + +
    +
    {JSON.stringify(output.payload, null, 2)}
    +
  • + )} +
    +
+
+
+ !open && setDeleteTarget(null)} + title={t("confirm.deleteTitle")} + variant="destructive" + summary={deleteTarget() ? formatDateTime(deleteTarget()?.generated_at ?? 0, locale()) : ""} + onConfirm={() => void remove()} + /> +
+ ); +} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index f2aaa9d..4d99884 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -84,6 +84,11 @@ export type MessageKey = | "classBlueprints.saved" | "classBlueprints.delete" | "classBlueprints.deleteConfirm" + | "classBlueprints.status" + | "classBlueprints.statusTitle" + | "classBlueprints.statusEmpty" + | "classBlueprints.statusSection" + | "classBlueprints.statusMissing" | "classBlueprints.deleted" | "classBlueprints.apply" | "classBlueprints.applyHint" @@ -540,6 +545,8 @@ export type MessageKey = | "courseNotes.add" | "courseNotes.empty" | "courseNotes.emptyManageHint" + | "courseNotes.ragTitle" + | "courseNotes.ragEmpty" | "notes.title" | "notes.subtitle" | "notes.new" @@ -1159,6 +1166,8 @@ export type MessageKey = | "settings.mealSlotNameInvalid" | "settings.aiPolicy" | "settings.aiPolicyHelp" + | "settings.modules" + | "settings.modulesHelp" | "settings.chatHistory" | "settings.chatThreads" | "settings.chatMessage" @@ -1365,6 +1374,9 @@ export type MessageKey = | "terms.term" | "terms.unassigned" | "terms.dateRequired" + | "terms.archive" + | "terms.unarchive" + | "terms.archived" | "sessions.title" | "sessions.item" | "sessions.subtitle" @@ -1619,6 +1631,11 @@ const en: Dict = { "classBlueprints.deleteConfirm": "Delete the blueprint for grade {grade}? The courses it attached are detached from every class at this grade. Hand-attached courses stay.", "classBlueprints.deleted": "Blueprint deleted.", + "classBlueprints.status": "Check sync", + "classBlueprints.statusTitle": "Sync status for grade {grade}", + "classBlueprints.statusEmpty": "Every section at this grade carries the full template.", + "classBlueprints.statusSection": "Section", + "classBlueprints.statusMissing": "Missing courses", "classBlueprints.apply": "Apply blueprint", "classBlueprints.applyHint": "Attaches this grade's blueprint courses to this class.", "classBlueprints.applyNoGrade": "Assign a grade to this class first.", @@ -2077,6 +2094,8 @@ const en: Dict = { "courseNotes.add": "Add note", "courseNotes.empty": "No notes on this course yet.", "courseNotes.emptyManageHint": "Write a note the whole class can read, and attach files to it.", + "courseNotes.ragTitle": "AI outputs", + "courseNotes.ragEmpty": "No AI outputs on this note yet.", "notes.title": "Notebook", "notes.subtitle": "Your private notebook for class ideas and reminders.", "notes.new": "New note", @@ -2786,6 +2805,8 @@ const en: Dict = { "settings.mealSlotNameInvalid": "A meal slot name can't contain / \\ ? # or %.", "settings.aiPolicy": "AI policy", "settings.aiPolicyHelp": "Limits for conversation context, threads, and message length.", + "settings.modules": "Modules", + "settings.modulesHelp": "Features your school has switched on, grouped by package. Switched-off features stay hidden in navigation.", "settings.chatHistory": "History turns", "settings.chatThreads": "Maximum threads", "settings.chatMessage": "Message length", @@ -2992,6 +3013,9 @@ const en: Dict = { "terms.term": "Term", "terms.unassigned": "Unassigned", "terms.dateRequired": "Start and end dates are required.", + "terms.archive": "Archive term", + "terms.unarchive": "Reopen term", + "terms.archived": "Archived", "sessions.title": "Lesson sessions", "sessions.item": "Session", "sessions.subtitle": "Schedule lesson sessions and record roll call for each class.", @@ -3162,6 +3186,11 @@ const tr: Dict = { "classBlueprints.deleteConfirm": "{grade} seviyesinin şablonu silinsin mi? Şablonun eklediği dersler bu seviyedeki her şubeden çıkarılır. Elle eklenen dersler kalır.", "classBlueprints.deleted": "Şablon silindi.", + "classBlueprints.status": "Eşitleme kontrolü", + "classBlueprints.statusTitle": "{grade} seviyesi eşitleme durumu", + "classBlueprints.statusEmpty": "Bu seviyedeki her şube şablonun tamamını taşıyor.", + "classBlueprints.statusSection": "Şube", + "classBlueprints.statusMissing": "Eksik dersler", "classBlueprints.apply": "Şablonu uygula", "classBlueprints.applyHint": "Bu seviyenin şablon derslerini bu şubeye ekler.", "classBlueprints.applyNoGrade": "Önce bu şubeye bir seviye ata.", @@ -3620,6 +3649,8 @@ const tr: Dict = { "courseNotes.add": "Not ekle", "courseNotes.empty": "Bu derse ait henüz not yok.", "courseNotes.emptyManageHint": "Tüm sınıfın okuyabileceği bir not yazın, dosya da ekleyebilirsiniz.", + "courseNotes.ragTitle": "YZ çıktıları", + "courseNotes.ragEmpty": "Bu notta henüz YZ çıktısı yok.", "notes.title": "Defter", "notes.subtitle": "Ders fikirleriniz ve hatırlatmalarınız için özel defteriniz.", "notes.new": "Yeni not", @@ -4329,6 +4360,8 @@ const tr: Dict = { "settings.mealSlotNameInvalid": "Öğün adı / \\ ? # veya % içeremez.", "settings.aiPolicy": "Yapay zekâ politikası", "settings.aiPolicyHelp": "Konuşma bağlamı, konu sayısı ve mesaj uzunluğu sınırları.", + "settings.modules": "Modüller", + "settings.modulesHelp": "Okulunuzda açık olan özellikler, pakete göre gruplu. Kapalı özellikler gezgin menüde gizlenir.", "settings.chatHistory": "Geçmiş turu", "settings.chatThreads": "En fazla konu", "settings.chatMessage": "Mesaj uzunluğu", @@ -4535,6 +4568,9 @@ const tr: Dict = { "terms.term": "Dönem", "terms.unassigned": "Atanmamış", "terms.dateRequired": "Başlangıç ve bitiş tarihi gerekli.", + "terms.archive": "Dönemi arşivle", + "terms.unarchive": "Dönemi yeniden aç", + "terms.archived": "Arşivli", "sessions.title": "Ders oturumları", "sessions.item": "Oturum", "sessions.subtitle": "Ders oturumlarını planlayın ve her ders için yoklama alın.", diff --git a/src/lib/note-source.ts b/src/lib/note-source.ts index b964b6f..8448aae 100644 --- a/src/lib/note-source.ts +++ b/src/lib/note-source.ts @@ -1,5 +1,5 @@ -import type { NoteFile, Page, PageParams } from "@/api/client"; -import { deleteCourseNoteFileById, getCourseNoteFileBlob, getCourseNoteFileUrl, getCourseNoteFiles, postCourseNoteFile } from "@/api/course-notes"; +import type { NoteFile, Page, PageParams, RagOutput } from "@/api/client"; +import { deleteCourseNoteFileById, deleteCourseNoteRagOutput, getCourseNoteFileBlob, getCourseNoteFileUrl, getCourseNoteFiles, getCourseNoteRag, postCourseNoteFile } from "@/api/course-notes"; import { deleteNoteFileById, getNoteFileBlob, getNoteFileUrl, getNoteFiles, postNoteFile } from "@/api/notes"; /** @@ -16,6 +16,9 @@ export type NoteFileSource = { deleteFile: (noteId: string, fileId: string) => Promise; fileUrl: (noteId: string, fileId: string) => string; fileBlob: (noteId: string, fileId: string, signal?: AbortSignal) => Promise; + /** AI outputs hanging off the note — only course notes have them. */ + listRagOutputs?: (noteId: string, params?: PageParams, signal?: AbortSignal) => Promise>; + deleteRagOutput?: (noteId: string, outputId: string) => Promise; }; export const personalNoteFiles: NoteFileSource = { @@ -34,4 +37,6 @@ export const courseNoteFiles: NoteFileSource = { deleteFile: deleteCourseNoteFileById, fileUrl: getCourseNoteFileUrl, fileBlob: getCourseNoteFileBlob, + listRagOutputs: getCourseNoteRag, + deleteRagOutput: deleteCourseNoteRagOutput, }; diff --git a/src/pages/settings-page.tsx b/src/pages/settings-page.tsx index 42e8300..0e2f9bc 100644 --- a/src/pages/settings-page.tsx +++ b/src/pages/settings-page.tsx @@ -1,7 +1,8 @@ -import { Index, Show, Suspense, createEffect, createResource, createSignal } from "solid-js"; +import { For, Index, Show, Suspense, createEffect, createResource, createSignal } from "solid-js"; import { getSettings } from "@/api/settings"; import { patchSettings } from "@/api/settings"; import { getLimits } from "@/api/limits"; +import { getModules, getModulesCatalog } from "@/api/modules"; import type { ExamKindSetting, GradeBand, MealSlot, SchoolSettings } from "@/api/client"; import { formatApiError } from "@/api/client"; import { RouteGuard } from "@/components/layout/route-guard"; @@ -49,6 +50,10 @@ export default function SettingsPage() { function SettingsContent() { const t = useT(); const [settings, { refetch, mutate }] = createResource(() => getSettings()); + const [modulesInfo, { refetch: refetchModules }] = createResource(async () => { + const [mine, catalog] = await Promise.all([getModules(), getModulesCatalog()]); + return { mine, catalog }; + }); const [examKinds, setExamKinds] = createSignal([]); const [attendanceStatuses, setAttendanceStatuses] = createSignal([]); const [gradeBands, setGradeBands] = createSignal([]); @@ -588,6 +593,39 @@ function SettingsContent() { +
+
+

{t("settings.modules")}

+

{t("settings.modulesHelp")}

+
+ }> + + void refetchModules()} /> + + + {(info) => ( +
+ + {(pkg) => ( +
+

{pkg.package}

+
+ + {(name) => ( + + {name} + + )} + +
+
+ )} +
+
+ )} +
+
+
diff --git a/src/pages/terms-page.tsx b/src/pages/terms-page.tsx index a99a532..2b689ae 100644 --- a/src/pages/terms-page.tsx +++ b/src/pages/terms-page.tsx @@ -4,18 +4,21 @@ import { deleteTermById } from "@/api/terms"; import { getTerms } from "@/api/terms"; import { patchTermById } from "@/api/terms"; import { postTerm } from "@/api/terms"; +import { postTermArchive } from "@/api/terms"; +import { postTermUnarchive } from "@/api/terms"; import { formatApiError } from "@/api/client"; import type { Term } from "@/api/client"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; import { Alert } from "@/components/ui/alert"; +import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; import { EmptyState } from "@/components/ui/empty-state"; import { DatePicker } from "@/components/ui/date-picker"; import { ErrorAlert } from "@/components/ui/error-alert"; -import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; +import { IconArchive, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { SidePanel } from "@/components/ui/side-panel"; @@ -82,6 +85,15 @@ function TermsContent() { header: t("events.ends"), cell: (cell) => {formatDateTime(cell.row.original.ends_at, locale())}, }, + { + accessorKey: "archived_at", + header: t("terms.archived"), + cell: (cell) => ( + —}> + {t("terms.archived")} + + ), + }, { id: "actions", header: t("common.actions"), @@ -95,6 +107,17 @@ function TermsContent() { icon: , onSelect: () => startEdit(cell.row.original), }, + cell.row.original.archived_at == null + ? { + label: t("terms.archive"), + icon: , + onSelect: () => void toggleArchive(cell.row.original, true), + } + : { + label: t("terms.unarchive"), + icon: , + onSelect: () => void toggleArchive(cell.row.original, false), + }, { label: t("common.delete"), icon: , @@ -128,6 +151,20 @@ function TermsContent() { setError(""); setPanelOpen(true); }; + const toggleArchive = async (term: Term, archive: boolean) => { + setError(""); + try { + if (archive) { + await postTermArchive(term.id); + } else { + await postTermUnarchive(term.id); + } + await refetch(); + setFlash(t("common.saved")); + } catch (err) { + setError(formatApiError(err)); + } + }; const save = async (e: SubmitEvent) => { e.preventDefault(); diff --git a/src/routes/router.tsx b/src/routes/router.tsx index 976a450..297b078 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -9,6 +9,7 @@ import { Suspense, createRenderEffect, createRoot, lazy, type Component } from " import { AppShell } from "@/components/layout/app-shell"; import { PageSpinner } from "@/components/ui/page-spinner"; import { AuthProvider } from "@/stores/auth-context"; +import { ModulesProvider } from "@/stores/modules-context"; import { PreferencesProvider } from "@/stores/preferences-context"; function lazyRoute(loader: () => Promise<{ default: Component }>): Component { @@ -70,9 +71,11 @@ function RootComponent() { return ( - - - + + + + + ); diff --git a/src/stores/modules-context.tsx b/src/stores/modules-context.tsx new file mode 100644 index 0000000..a4757ed --- /dev/null +++ b/src/stores/modules-context.tsx @@ -0,0 +1,61 @@ +import { + type Accessor, + type ParentProps, + createContext, + createMemo, + createResource, + useContext, +} from "solid-js"; +import { getModules } from "@/api/modules"; +import { useAuth } from "@/stores/auth-context"; + +type ModulesContextValue = { + /** + * The school's switched-on modules, sorted by name. Null while logged out, + * still loading, or failed — every consumer treats null as "unknown" and + * shows everything (fail open), so a modules outage never blanks the shell. + */ + enabled: Accessor; + /** Fail-open membership test over `enabled`. */ + isEnabled: (module: string) => boolean; + refresh: () => void; +}; + +const ModulesContext = createContext(); + +export function ModulesProvider(props: ParentProps) { + const auth = useAuth(); + // Keyed on the account id: switching account refetches. While logged out + // the source is null and the resource keeps its seeded null — the shell + // shows no nav without a role anyway, so nothing stale can render. + const userId = createMemo(() => auth.user()?.id ?? null); + const [modules, { refetch }] = createResource( + userId, + async (id) => { + if (id === null) return null; + try { + return (await getModules()).enabled; + } catch { + return null; + } + }, + { initialValue: null }, + ); + + const value: ModulesContextValue = { + enabled: () => modules(), + isEnabled: (module: string) => { + const enabled = modules(); + return enabled === null || enabled.includes(module); + }, + refresh: () => void refetch(), + }; + + return {props.children}; +} + +export function useModules(): ModulesContextValue { + const context = useContext(ModulesContext); + if (!context) throw new Error("useModules must be used inside ModulesProvider"); + return context; +}