feat: 完成 P1 全部功能 + 修复 proxy 导出 + 切换 MySQL 端口至 14013
## P1 功能(20 项) - 站内消息系统、家长仪表盘、学生考勤管理 - Excel 导入导出、用户批量导入、成绩导出 - 排课规则+自动排课+课表调整 - 成绩趋势+对比分析、密码安全策略、速率限制 - 数据变更日志、文件预览+存储策略、全文检索 - 依赖审计集成 CI、数据库定时备份、E2E 测试完善 - 通知偏好管理 ## 基础设施修复 - src/proxy.ts: 将 middleware 导出重命名为 proxy(Next.js 16 要求) - .env: MySQL 端口从 13002 切换至 14013 - scripts/create-db.ts: 新增数据库初始化脚本 ## 架构文档同步 - 004_architecture_impact_map.md 和 005_architecture_data.json 完整记录所有新增表、模块、路由、权限、依赖关系
This commit is contained in:
36
src/app/(dashboard)/admin/announcements/[id]/page.tsx
Normal file
36
src/app/(dashboard)/admin/announcements/[id]/page.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { getAnnouncementById } from "@/modules/announcements/data-access"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
import { AnnouncementForm } from "@/modules/announcements/components/announcement-form"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function EditAnnouncementPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const { id } = await params
|
||||
|
||||
const [announcement, grades] = await Promise.all([
|
||||
getAnnouncementById(id),
|
||||
getGrades(),
|
||||
])
|
||||
|
||||
if (!announcement) notFound()
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Edit Announcement</h2>
|
||||
<p className="text-muted-foreground">Update the announcement details below.</p>
|
||||
</div>
|
||||
<AnnouncementForm
|
||||
mode="edit"
|
||||
announcement={announcement}
|
||||
grades={grades.map((g) => ({ id: g.id, name: g.name }))}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
39
src/app/(dashboard)/admin/announcements/page.tsx
Normal file
39
src/app/(dashboard)/admin/announcements/page.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import { getAnnouncements } from "@/modules/announcements/data-access"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
import { AdminAnnouncementsView } from "@/modules/announcements/components/admin-announcements-view"
|
||||
import type { AnnouncementStatus } from "@/modules/announcements/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
const isValidStatus = (v?: string): v is AnnouncementStatus =>
|
||||
v === "draft" || v === "published" || v === "archived"
|
||||
|
||||
export default async function AdminAnnouncementsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
const statusParam = getParam(sp, "status")
|
||||
const status = isValidStatus(statusParam) ? statusParam : undefined
|
||||
|
||||
const [announcements, grades] = await Promise.all([
|
||||
getAnnouncements({ status }),
|
||||
getGrades(),
|
||||
])
|
||||
|
||||
return (
|
||||
<AdminAnnouncementsView
|
||||
announcements={announcements}
|
||||
grades={grades.map((g) => ({ id: g.id, name: g.name }))}
|
||||
initialStatus={status}
|
||||
/>
|
||||
)
|
||||
}
|
||||
71
src/app/(dashboard)/admin/attendance/page.tsx
Normal file
71
src/app/(dashboard)/admin/attendance/page.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import Link from "next/link"
|
||||
import { BarChart3, ClipboardList } from "lucide-react"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getAdminClasses } from "@/modules/classes/data-access"
|
||||
import { getAttendanceRecords } from "@/modules/attendance/data-access"
|
||||
import { AttendanceFilters } from "@/modules/attendance/components/attendance-filters"
|
||||
import { AttendanceRecordList } from "@/modules/attendance/components/attendance-record-list"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function AdminAttendancePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const status = getParam(sp, "status")
|
||||
const date = getParam(sp, "date")
|
||||
|
||||
const classes = await getAdminClasses()
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
|
||||
const result = await getAttendanceRecords({
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
classId: classId && classId !== "all" ? classId : undefined,
|
||||
status: status && status !== "all" ? (status as "present" | "absent" | "late" | "early_leave" | "excused") : undefined,
|
||||
date: date && date.length > 0 ? date : undefined,
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Attendance Overview</h2>
|
||||
<p className="text-muted-foreground">View all attendance records across the school.</p>
|
||||
</div>
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/teacher/attendance/stats">
|
||||
<BarChart3 className="mr-2 h-4 w-4" />
|
||||
Statistics
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<AttendanceFilters classes={classOptions} />
|
||||
|
||||
{result.items.length === 0 && !classId && !status && !date ? (
|
||||
<EmptyState
|
||||
title="No attendance records"
|
||||
description="There are no attendance records yet."
|
||||
icon={ClipboardList}
|
||||
/>
|
||||
) : (
|
||||
<AttendanceRecordList records={result.items} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
69
src/app/(dashboard)/admin/audit-logs/data-changes/page.tsx
Normal file
69
src/app/(dashboard)/admin/audit-logs/data-changes/page.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import {
|
||||
getDataChangeLogs,
|
||||
getDataChangeStats,
|
||||
getDataChangeTableOptions,
|
||||
} from "@/modules/audit/data-access"
|
||||
import { DataChangeLogTable } from "@/modules/audit/components/data-change-log-table"
|
||||
import { AuditLogExportButton } from "@/modules/audit/components/audit-log-export-button"
|
||||
import type { DataChangeAction } from "@/modules/audit/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function DataChangeLogsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
await requirePermission(Permissions.AUDIT_LOG_READ)
|
||||
|
||||
const params = await searchParams
|
||||
const page = Number(getParam(params, "page") ?? "1") || 1
|
||||
const tableName = getParam(params, "tableName") ?? undefined
|
||||
const action = (getParam(params, "action") as DataChangeAction | undefined) ?? undefined
|
||||
const startDate = getParam(params, "startDate") ?? undefined
|
||||
const endDate = getParam(params, "endDate") ?? undefined
|
||||
|
||||
const [result, tableOptions, stats] = await Promise.all([
|
||||
getDataChangeLogs({ page, tableName, action, startDate, endDate }),
|
||||
getDataChangeTableOptions(),
|
||||
getDataChangeStats(),
|
||||
])
|
||||
|
||||
const exportParams: Record<string, string> = {}
|
||||
if (tableName) exportParams.tableName = tableName
|
||||
if (action) exportParams.action = action
|
||||
if (startDate) exportParams.startDate = startDate
|
||||
if (endDate) exportParams.endDate = endDate
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Data Change Logs</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Track all data mutations (create/update/delete) across system tables for compliance.
|
||||
</p>
|
||||
</div>
|
||||
<AuditLogExportButton exportType="dataChange" params={exportParams} />
|
||||
</div>
|
||||
<DataChangeLogTable
|
||||
items={result.items}
|
||||
page={result.page}
|
||||
pageSize={result.pageSize}
|
||||
total={result.total}
|
||||
totalPages={result.totalPages}
|
||||
tableOptions={tableOptions}
|
||||
stats={stats}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
59
src/app/(dashboard)/admin/audit-logs/login-logs/page.tsx
Normal file
59
src/app/(dashboard)/admin/audit-logs/login-logs/page.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getLoginLogs } from "@/modules/audit/data-access"
|
||||
import { LoginLogView } from "@/modules/audit/components/login-log-view"
|
||||
import { AuditLogExportButton } from "@/modules/audit/components/audit-log-export-button"
|
||||
import type { LoginLogAction, LoginLogStatus } from "@/modules/audit/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function LoginLogsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
await requirePermission(Permissions.AUDIT_LOG_READ)
|
||||
|
||||
const params = await searchParams
|
||||
const page = Number(getParam(params, "page") ?? "1") || 1
|
||||
const action = (getParam(params, "action") as LoginLogAction | undefined) ?? undefined
|
||||
const status = (getParam(params, "status") as LoginLogStatus | undefined) ?? undefined
|
||||
const startDate = getParam(params, "startDate") ?? undefined
|
||||
const endDate = getParam(params, "endDate") ?? undefined
|
||||
|
||||
const result = await getLoginLogs({ page, action, status, startDate, endDate })
|
||||
|
||||
const exportParams: Record<string, string> = {}
|
||||
if (action) exportParams.action = action
|
||||
if (status) exportParams.status = status
|
||||
if (startDate) exportParams.startDate = startDate
|
||||
if (endDate) exportParams.endDate = endDate
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Login Logs</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Monitor all authentication events including sign in, sign out, and sign up.
|
||||
</p>
|
||||
</div>
|
||||
<AuditLogExportButton exportType="login" params={exportParams} />
|
||||
</div>
|
||||
<LoginLogView
|
||||
items={result.items}
|
||||
page={result.page}
|
||||
pageSize={result.pageSize}
|
||||
total={result.total}
|
||||
totalPages={result.totalPages}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
65
src/app/(dashboard)/admin/audit-logs/page.tsx
Normal file
65
src/app/(dashboard)/admin/audit-logs/page.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getAuditLogs, getAuditModuleOptions } from "@/modules/audit/data-access"
|
||||
import { AuditLogView } from "@/modules/audit/components/audit-log-view"
|
||||
import { AuditLogExportButton } from "@/modules/audit/components/audit-log-export-button"
|
||||
import type { AuditLogStatus } from "@/modules/audit/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function AuditLogsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
await requirePermission(Permissions.AUDIT_LOG_READ)
|
||||
|
||||
const params = await searchParams
|
||||
const page = Number(getParam(params, "page") ?? "1") || 1
|
||||
const moduleFilter = getParam(params, "module") ?? undefined
|
||||
const action = getParam(params, "action") ?? undefined
|
||||
const status = (getParam(params, "status") as AuditLogStatus | undefined) ?? undefined
|
||||
const startDate = getParam(params, "startDate") ?? undefined
|
||||
const endDate = getParam(params, "endDate") ?? undefined
|
||||
|
||||
const [result, moduleOptions] = await Promise.all([
|
||||
getAuditLogs({ page, module: moduleFilter, action, status, startDate, endDate }),
|
||||
getAuditModuleOptions(),
|
||||
])
|
||||
|
||||
const exportParams: Record<string, string> = {}
|
||||
if (moduleFilter) exportParams.module = moduleFilter
|
||||
if (action) exportParams.action = action
|
||||
if (status) exportParams.status = status
|
||||
if (startDate) exportParams.startDate = startDate
|
||||
if (endDate) exportParams.endDate = endDate
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Audit Logs</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Track all user operations across the system for security and compliance.
|
||||
</p>
|
||||
</div>
|
||||
<AuditLogExportButton exportType="audit" params={exportParams} />
|
||||
</div>
|
||||
<AuditLogView
|
||||
items={result.items}
|
||||
page={result.page}
|
||||
pageSize={result.pageSize}
|
||||
total={result.total}
|
||||
totalPages={result.totalPages}
|
||||
moduleOptions={moduleOptions}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
45
src/app/(dashboard)/admin/course-plans/[id]/edit/page.tsx
Normal file
45
src/app/(dashboard)/admin/course-plans/[id]/edit/page.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { getCoursePlanById } from "@/modules/course-plans/data-access"
|
||||
import { getSubjectOptions } from "@/modules/course-plans/data-access"
|
||||
import { getAdminClasses } from "@/modules/classes/data-access"
|
||||
import { getAcademicYears, getStaffOptions } from "@/modules/school/data-access"
|
||||
import { CoursePlanForm } from "@/modules/course-plans/components/course-plan-form"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function EditCoursePlanPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const { id } = await params
|
||||
|
||||
const [plan, classes, subjects, teachers, academicYears] = await Promise.all([
|
||||
getCoursePlanById(id),
|
||||
getAdminClasses(),
|
||||
getSubjectOptions(),
|
||||
getStaffOptions(),
|
||||
getAcademicYears(),
|
||||
])
|
||||
|
||||
if (!plan) notFound()
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Edit Course Plan</h2>
|
||||
<p className="text-muted-foreground">Update the course plan details below.</p>
|
||||
</div>
|
||||
<CoursePlanForm
|
||||
mode="edit"
|
||||
plan={plan}
|
||||
classes={classes.map((c) => ({ id: c.id, name: c.name }))}
|
||||
subjects={subjects}
|
||||
teachers={teachers.map((t) => ({ id: t.id, name: t.name }))}
|
||||
academicYears={academicYears.map((y) => ({ id: y.id, name: y.name }))}
|
||||
backHref={`/admin/course-plans/${plan.id}`}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
27
src/app/(dashboard)/admin/course-plans/[id]/page.tsx
Normal file
27
src/app/(dashboard)/admin/course-plans/[id]/page.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { getCoursePlanById } from "@/modules/course-plans/data-access"
|
||||
import { CoursePlanDetail } from "@/modules/course-plans/components/course-plan-detail"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function CoursePlanDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const { id } = await params
|
||||
const plan = await getCoursePlanById(id)
|
||||
|
||||
if (!plan) notFound()
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-6 p-8">
|
||||
<CoursePlanDetail
|
||||
plan={plan}
|
||||
editHref={`/admin/course-plans/${plan.id}/edit`}
|
||||
backHref="/admin/course-plans"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
32
src/app/(dashboard)/admin/course-plans/create/page.tsx
Normal file
32
src/app/(dashboard)/admin/course-plans/create/page.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { getAdminClasses } from "@/modules/classes/data-access"
|
||||
import { getAcademicYears, getStaffOptions } from "@/modules/school/data-access"
|
||||
import { getSubjectOptions } from "@/modules/course-plans/data-access"
|
||||
import { CoursePlanForm } from "@/modules/course-plans/components/course-plan-form"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function CreateCoursePlanPage() {
|
||||
const [classes, subjects, teachers, academicYears] = await Promise.all([
|
||||
getAdminClasses(),
|
||||
getSubjectOptions(),
|
||||
getStaffOptions(),
|
||||
getAcademicYears(),
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">New Course Plan</h2>
|
||||
<p className="text-muted-foreground">Create a new course teaching plan.</p>
|
||||
</div>
|
||||
<CoursePlanForm
|
||||
mode="create"
|
||||
classes={classes.map((c) => ({ id: c.id, name: c.name }))}
|
||||
subjects={subjects}
|
||||
teachers={teachers.map((t) => ({ id: t.id, name: t.name }))}
|
||||
academicYears={academicYears.map((y) => ({ id: y.id, name: y.name }))}
|
||||
backHref="/admin/course-plans"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
45
src/app/(dashboard)/admin/course-plans/page.tsx
Normal file
45
src/app/(dashboard)/admin/course-plans/page.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { getCoursePlans } from "@/modules/course-plans/data-access"
|
||||
import { CoursePlanList } from "@/modules/course-plans/components/course-plan-list"
|
||||
import type { CoursePlanStatus } from "@/modules/course-plans/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
const isValidStatus = (v?: string): v is CoursePlanStatus =>
|
||||
v === "planning" || v === "active" || v === "completed" || v === "paused"
|
||||
|
||||
export default async function AdminCoursePlansPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
const statusParam = getParam(sp, "status")
|
||||
const status = isValidStatus(statusParam) ? statusParam : undefined
|
||||
|
||||
const plans = await getCoursePlans({ status })
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Course Plans</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Manage course teaching plans and weekly schedules.
|
||||
</p>
|
||||
</div>
|
||||
<CoursePlanList
|
||||
plans={plans}
|
||||
canManage
|
||||
createHref="/admin/course-plans/create"
|
||||
detailHrefBuilder={(id) => `/admin/course-plans/${id}`}
|
||||
initialStatus={status}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
19
src/app/(dashboard)/admin/files/page.tsx
Normal file
19
src/app/(dashboard)/admin/files/page.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import {
|
||||
getFileAttachmentsWithFilters,
|
||||
getFileStats,
|
||||
} from "@/modules/files/data-access"
|
||||
import { AdminFilesView } from "@/modules/files/components/admin-files-view"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminFilesPage() {
|
||||
await requirePermission(Permissions.FILE_READ)
|
||||
const [files, stats] = await Promise.all([
|
||||
getFileAttachmentsWithFilters({ limit: 200 }),
|
||||
getFileStats(),
|
||||
])
|
||||
|
||||
return <AdminFilesView files={files} stats={stats} />
|
||||
}
|
||||
51
src/app/(dashboard)/admin/scheduling/auto/page.tsx
Normal file
51
src/app/(dashboard)/admin/scheduling/auto/page.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import Link from "next/link"
|
||||
import { CalendarClock, ClipboardList, Settings2 } from "lucide-react"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAdminClassesForScheduling } from "@/modules/scheduling/actions"
|
||||
import { AutoSchedulePanel } from "@/modules/scheduling/components/auto-schedule-panel"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminSchedulingAutoPage() {
|
||||
const classes = await getAdminClassesForScheduling()
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name, grade: c.grade }))
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Auto Schedule</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Generate a weekly schedule automatically based on configured rules and subject
|
||||
assignments.
|
||||
</p>
|
||||
</div>
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/admin/scheduling/rules">
|
||||
<Settings2 className="mr-2 h-4 w-4" />
|
||||
Configure Rules
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{classOptions.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={ClipboardList}
|
||||
title="No classes available"
|
||||
description="Please create classes before running auto scheduling."
|
||||
/>
|
||||
) : (
|
||||
<AutoSchedulePanel classes={classOptions} />
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<CalendarClock className="h-4 w-4" />
|
||||
<span>
|
||||
Applying a new schedule will replace the existing schedule for the selected class.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
91
src/app/(dashboard)/admin/scheduling/changes/page.tsx
Normal file
91
src/app/(dashboard)/admin/scheduling/changes/page.tsx
Normal file
@@ -0,0 +1,91 @@
|
||||
import Link from "next/link"
|
||||
import { PlusCircle, ClipboardList } from "lucide-react"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import {
|
||||
getAdminClassesForScheduling,
|
||||
getScheduleChanges,
|
||||
} from "@/modules/scheduling/actions"
|
||||
import { ScheduleChangeList } from "@/modules/scheduling/components/schedule-change-list"
|
||||
import { ScheduleConflictsView } from "@/modules/scheduling/components/schedule-conflicts-view"
|
||||
import type { ScheduleChangeStatus } from "@/modules/scheduling/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
const isValidStatus = (v?: string): v is ScheduleChangeStatus =>
|
||||
v === "pending" || v === "approved" || v === "rejected" || v === "completed"
|
||||
|
||||
export default async function AdminSchedulingChangesPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
const statusParam = getParam(sp, "status")
|
||||
const status = isValidStatus(statusParam) ? statusParam : undefined
|
||||
const classIdParam = getParam(sp, "classId")
|
||||
const classId = classIdParam && classIdParam !== "all" ? classIdParam : undefined
|
||||
|
||||
const [classes, items] = await Promise.all([
|
||||
getAdminClassesForScheduling(),
|
||||
getScheduleChanges({ status, classId }),
|
||||
])
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name, grade: c.grade }))
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Schedule Change Requests</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Review, approve, or reject schedule change and substitute teacher requests.
|
||||
</p>
|
||||
</div>
|
||||
<Button asChild>
|
||||
<Link href="/teacher/schedule-changes">
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
New Request
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{items.length === 0 && !status && !classId ? (
|
||||
<EmptyState
|
||||
icon={ClipboardList}
|
||||
title="No schedule change requests"
|
||||
description="There are no schedule change requests yet."
|
||||
action={{
|
||||
label: "New Request",
|
||||
href: "/teacher/schedule-changes",
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<ScheduleChangeList items={items} canApprove />
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-lg font-semibold">Conflict Detection</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Detect time overlaps in an existing class schedule.
|
||||
</p>
|
||||
{classOptions.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={ClipboardList}
|
||||
title="No classes available"
|
||||
description="Please create classes before checking conflicts."
|
||||
/>
|
||||
) : (
|
||||
<ScheduleConflictsView classes={classOptions} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
47
src/app/(dashboard)/admin/scheduling/rules/page.tsx
Normal file
47
src/app/(dashboard)/admin/scheduling/rules/page.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { CalendarCog, ClipboardList } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import {
|
||||
getAdminClassesForScheduling,
|
||||
getSchedulingRules,
|
||||
} from "@/modules/scheduling/actions"
|
||||
import { SchedulingRulesForm } from "@/modules/scheduling/components/scheduling-rules-form"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminSchedulingRulesPage() {
|
||||
const [classes, existingRules] = await Promise.all([
|
||||
getAdminClassesForScheduling(),
|
||||
getSchedulingRules(),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name, grade: c.grade }))
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Scheduling Rules</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Configure daily hour limits, break windows, and balancing preferences for each class.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{classOptions.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={ClipboardList}
|
||||
title="No classes available"
|
||||
description="Please create classes before configuring scheduling rules."
|
||||
/>
|
||||
) : (
|
||||
<SchedulingRulesForm classes={classOptions} existingRules={existingRules} />
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<CalendarCog className="h-4 w-4" />
|
||||
<span>
|
||||
Tip: rules saved without selecting a specific class become the global default.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
134
src/app/(dashboard)/admin/users/import/page.tsx
Normal file
134
src/app/(dashboard)/admin/users/import/page.tsx
Normal file
@@ -0,0 +1,134 @@
|
||||
import { Metadata } from "next"
|
||||
import Link from "next/link"
|
||||
import { ArrowLeft, Users, FileSpreadsheet, Info } from "lucide-react"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { UserImportDialog } from "@/modules/users/components/user-import-dialog"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "批量导入用户 - Next_Edu",
|
||||
description: "通过 Excel 批量导入用户",
|
||||
}
|
||||
|
||||
export default function UserImportPage() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-6 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button asChild variant="ghost" size="sm">
|
||||
<Link href="/admin/dashboard">
|
||||
<ArrowLeft className="mr-1 h-4 w-4" />
|
||||
返回
|
||||
</Link>
|
||||
</Button>
|
||||
<h2 className="text-2xl font-bold tracking-tight">批量导入用户</h2>
|
||||
</div>
|
||||
<p className="text-muted-foreground mt-1">
|
||||
通过 Excel 文件批量创建用户账号,支持学生自动加入班级。
|
||||
</p>
|
||||
</div>
|
||||
<UserImportDialog />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<FileSpreadsheet className="h-5 w-5 text-primary" />
|
||||
<CardTitle className="text-base">导入说明</CardTitle>
|
||||
</div>
|
||||
<CardDescription>使用 Excel 批量导入用户的步骤</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3 text-sm">
|
||||
<div className="flex gap-3">
|
||||
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">1</span>
|
||||
<p>点击「批量导入用户」按钮,下载导入模板。</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">2</span>
|
||||
<p>按模板格式填写用户信息(姓名、邮箱、角色、手机、班级邀请码)。</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">3</span>
|
||||
<p>上传填写好的 Excel 文件,系统将解析并预览数据。</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-xs font-medium text-primary">4</span>
|
||||
<p>确认预览数据无误后,点击「确认导入」完成批量创建。</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Info className="h-5 w-5 text-amber-500" />
|
||||
<CardTitle className="text-base">注意事项</CardTitle>
|
||||
</div>
|
||||
<CardDescription>导入前请仔细阅读</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2 text-sm text-muted-foreground">
|
||||
<p>• 默认密码为 <code className="rounded bg-muted px-1 py-0.5 text-xs">123456</code>,请提示用户首次登录后修改。</p>
|
||||
<p>• 邮箱必须唯一,重复邮箱将被跳过并记录在错误报告中。</p>
|
||||
<p>• 角色可选:admin / teacher / student / parent / grade_head / teaching_head。</p>
|
||||
<p>• 班级邀请码仅对 student 角色有效,填写后学生将自动加入对应班级。</p>
|
||||
<p>• 单次最多导入 10MB 的文件,建议单次不超过 500 条记录。</p>
|
||||
<p>• 导入完成后将显示成功数、失败数及详细错误信息。</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Users className="h-5 w-5 text-primary" />
|
||||
<CardTitle className="text-base">模板字段说明</CardTitle>
|
||||
</div>
|
||||
<CardDescription>Excel 模板各列含义与要求</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b">
|
||||
<th className="py-2 pr-4 text-left font-medium">列名</th>
|
||||
<th className="py-2 pr-4 text-left font-medium">是否必填</th>
|
||||
<th className="py-2 pr-4 text-left font-medium">说明</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
<tr>
|
||||
<td className="py-2 pr-4 font-medium">姓名</td>
|
||||
<td className="py-2 pr-4">必填</td>
|
||||
<td className="py-2 pr-4 text-muted-foreground">用户姓名</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="py-2 pr-4 font-medium">邮箱</td>
|
||||
<td className="py-2 pr-4">必填</td>
|
||||
<td className="py-2 pr-4 text-muted-foreground">登录账号,需符合邮箱格式且唯一</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="py-2 pr-4 font-medium">角色</td>
|
||||
<td className="py-2 pr-4">必填</td>
|
||||
<td className="py-2 pr-4 text-muted-foreground">admin / teacher / student / parent / grade_head / teaching_head</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="py-2 pr-4 font-medium">手机</td>
|
||||
<td className="py-2 pr-4">选填</td>
|
||||
<td className="py-2 pr-4 text-muted-foreground">联系电话</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="py-2 pr-4 font-medium">班级邀请码</td>
|
||||
<td className="py-2 pr-4">选填</td>
|
||||
<td className="py-2 pr-4 text-muted-foreground">仅 student 角色有效,6 位邀请码</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
20
src/app/(dashboard)/announcements/page.tsx
Normal file
20
src/app/(dashboard)/announcements/page.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { getAnnouncements } from "@/modules/announcements/data-access"
|
||||
import { AnnouncementList } from "@/modules/announcements/components/announcement-list"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AnnouncementsPage() {
|
||||
const announcements = await getAnnouncements({ status: "published" })
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Announcements</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Stay up to date with the latest school announcements.
|
||||
</p>
|
||||
</div>
|
||||
<AnnouncementList announcements={announcements} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
30
src/app/(dashboard)/messages/[id]/page.tsx
Normal file
30
src/app/(dashboard)/messages/[id]/page.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getMessageById, markMessageAsRead } from "@/modules/messaging/data-access"
|
||||
import { MessageDetail } from "@/modules/messaging/components/message-detail"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function MessageDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
const { id } = await params
|
||||
|
||||
const message = await getMessageById(id, ctx.userId)
|
||||
if (!message) notFound()
|
||||
|
||||
// Auto-mark as read when viewed by the receiver
|
||||
if (!message.isRead && message.receiverId === ctx.userId) {
|
||||
await markMessageAsRead(id, ctx.userId)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col p-8">
|
||||
<MessageDetail message={message} currentUserId={ctx.userId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
34
src/app/(dashboard)/messages/compose/page.tsx
Normal file
34
src/app/(dashboard)/messages/compose/page.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getRecipients } from "@/modules/messaging/data-access"
|
||||
import { MessageCompose } from "@/modules/messaging/components/message-compose"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function ComposeMessagePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ parentId?: string; receiverId?: string; subject?: string }>
|
||||
}) {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_SEND)
|
||||
const sp = await searchParams
|
||||
|
||||
const recipients = await getRecipients(ctx.userId, ctx.dataScope)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col p-8">
|
||||
<div className="mx-auto w-full max-w-3xl space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Compose Message</h2>
|
||||
<p className="text-muted-foreground">Send a message to another user.</p>
|
||||
</div>
|
||||
<MessageCompose
|
||||
recipients={recipients}
|
||||
parentMessageId={sp.parentId}
|
||||
defaultReceiverId={sp.receiverId}
|
||||
defaultSubject={sp.subject}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
31
src/app/(dashboard)/messages/page.tsx
Normal file
31
src/app/(dashboard)/messages/page.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getMessages, getNotifications } from "@/modules/messaging/data-access"
|
||||
import { MessageList } from "@/modules/messaging/components/message-list"
|
||||
import { NotificationList } from "@/modules/messaging/components/notification-list"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function MessagesPage() {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
|
||||
const [messagesResult, notificationsResult] = await Promise.all([
|
||||
getMessages({ userId: ctx.userId, type: "all", page: 1, pageSize: 50 }),
|
||||
getNotifications(ctx.userId, { page: 1, pageSize: 20 }),
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Messages</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your inbox and stay updated with notifications.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<MessageList messages={messagesResult.items} currentUserId={ctx.userId} />
|
||||
|
||||
<NotificationList notifications={notificationsResult.items} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
61
src/app/(dashboard)/parent/attendance/page.tsx
Normal file
61
src/app/(dashboard)/parent/attendance/page.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getStudentAttendanceSummary } from "@/modules/attendance/data-access-stats"
|
||||
import { StudentAttendanceView } from "@/modules/attendance/components/student-attendance-view"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { CalendarCheck } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function ParentAttendancePage() {
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Children Attendance</h2>
|
||||
<p className="text-muted-foreground">View your children's attendance records.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No children linked"
|
||||
description="Your account is not linked to any student accounts yet. Please contact the school administrator."
|
||||
icon={CalendarCheck}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const summaries = await Promise.all(
|
||||
ctx.dataScope.childrenIds.map((id) => getStudentAttendanceSummary(id))
|
||||
)
|
||||
|
||||
const validSummaries = summaries.filter((s): s is NonNullable<typeof s> => s !== null)
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Children Attendance</h2>
|
||||
<p className="text-muted-foreground">View your children's attendance records.</p>
|
||||
</div>
|
||||
|
||||
{validSummaries.length === 0 ? (
|
||||
<EmptyState
|
||||
title="No attendance records"
|
||||
description="Your children don't have any attendance records yet."
|
||||
icon={CalendarCheck}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-8">
|
||||
{validSummaries.map((summary) => (
|
||||
<div key={summary.studentId} className="space-y-4">
|
||||
<h3 className="text-lg font-semibold border-b pb-2">{summary.studentName}</h3>
|
||||
<StudentAttendanceView summary={summary} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
71
src/app/(dashboard)/parent/children/[studentId]/page.tsx
Normal file
71
src/app/(dashboard)/parent/children/[studentId]/page.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { eq } from "drizzle-orm"
|
||||
|
||||
import { requireAuth } from "@/shared/lib/auth-guard"
|
||||
import { db } from "@/shared/db"
|
||||
import { parentStudentRelations } from "@/shared/db/schema"
|
||||
import { getChildDashboardData } from "@/modules/parent/data-access"
|
||||
import { ChildDetailHeader } from "@/modules/parent/components/child-detail-header"
|
||||
import { ChildDetailPanel } from "@/modules/parent/components/child-detail-panel"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { ShieldAlert } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function ChildDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ studentId: string }>
|
||||
}) {
|
||||
const { studentId } = await params
|
||||
const ctx = await requireAuth()
|
||||
|
||||
// Verify the student is linked to the current parent
|
||||
const [relation] = await db
|
||||
.select({
|
||||
id: parentStudentRelations.id,
|
||||
relation: parentStudentRelations.relation,
|
||||
})
|
||||
.from(parentStudentRelations)
|
||||
.where(eq(parentStudentRelations.studentId, studentId))
|
||||
.limit(1)
|
||||
|
||||
if (!relation) {
|
||||
return (
|
||||
<div className="p-6 md:p-8">
|
||||
<EmptyState
|
||||
icon={ShieldAlert}
|
||||
title="Access denied"
|
||||
description="This student is not linked to your account. Please contact the school administrator if you believe this is an error."
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Double-check the parent owns this relation
|
||||
if (ctx.dataScope.type === "children" && !ctx.dataScope.childrenIds.includes(studentId)) {
|
||||
return (
|
||||
<div className="p-6 md:p-8">
|
||||
<EmptyState
|
||||
icon={ShieldAlert}
|
||||
title="Access denied"
|
||||
description="You do not have permission to view this student's data."
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const child = await getChildDashboardData(studentId, relation.relation)
|
||||
if (!child) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 md:p-8 space-y-6">
|
||||
<ChildDetailHeader child={child} />
|
||||
<ChildDetailPanel child={child} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,16 @@
|
||||
export default function ParentDashboardPage() {
|
||||
import { requireAuth } from "@/shared/lib/auth-guard"
|
||||
import { getParentDashboardData } from "@/modules/parent/data-access"
|
||||
import { ParentDashboard } from "@/modules/parent/components/parent-dashboard"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function ParentDashboardPage() {
|
||||
const ctx = await requireAuth()
|
||||
const data = await getParentDashboardData(ctx.userId)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold">Parent Dashboard</h1>
|
||||
<p className="text-muted-foreground">Welcome, Parent!</p>
|
||||
<div className="p-6 md:p-8">
|
||||
<ParentDashboard data={data} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
61
src/app/(dashboard)/parent/grades/page.tsx
Normal file
61
src/app/(dashboard)/parent/grades/page.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getStudentGradeSummary } from "@/modules/grades/data-access"
|
||||
import { StudentGradeSummary } from "@/modules/grades/components/student-grade-summary"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { GraduationCap } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function ParentGradesPage() {
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Children Grades</h2>
|
||||
<p className="text-muted-foreground">View your children's grade records.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No children linked"
|
||||
description="Your account is not linked to any student accounts yet. Please contact the school administrator."
|
||||
icon={GraduationCap}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const summaries = await Promise.all(
|
||||
ctx.dataScope.childrenIds.map((id) => getStudentGradeSummary(id))
|
||||
)
|
||||
|
||||
const validSummaries = summaries.filter((s): s is NonNullable<typeof s> => s !== null)
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Children Grades</h2>
|
||||
<p className="text-muted-foreground">View your children's grade records.</p>
|
||||
</div>
|
||||
|
||||
{validSummaries.length === 0 ? (
|
||||
<EmptyState
|
||||
title="No grade records"
|
||||
description="Your children don't have any grade records yet."
|
||||
icon={GraduationCap}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-8">
|
||||
{validSummaries.map((summary) => (
|
||||
<div key={summary.studentId} className="space-y-4">
|
||||
<h3 className="text-lg font-semibold border-b pb-2">{summary.studentName}</h3>
|
||||
<StudentGradeSummary summary={summary} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { AdminSettingsView } from "@/modules/settings/components/admin-settings-
|
||||
import { StudentSettingsView } from "@/modules/settings/components/student-settings-view"
|
||||
import { TeacherSettingsView } from "@/modules/settings/components/teacher-settings-view"
|
||||
import { getUserProfile } from "@/modules/users/data-access"
|
||||
import { getNotificationPreferences } from "@/modules/messaging/notification-preferences"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -19,8 +20,13 @@ export default async function SettingsPage() {
|
||||
if (!userProfile) redirect("/login")
|
||||
|
||||
const permissions = session.user.permissions ?? []
|
||||
const notificationPrefs = await getNotificationPreferences(userId)
|
||||
|
||||
if (permissions.includes(Permissions.SETTINGS_ADMIN)) return <AdminSettingsView user={userProfile} />
|
||||
if (permissions.includes(Permissions.HOMEWORK_SUBMIT) && !permissions.includes(Permissions.EXAM_CREATE)) return <StudentSettingsView user={userProfile} />
|
||||
return <TeacherSettingsView user={userProfile} />
|
||||
if (permissions.includes(Permissions.SETTINGS_ADMIN)) {
|
||||
return <AdminSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
}
|
||||
if (permissions.includes(Permissions.HOMEWORK_SUBMIT) && !permissions.includes(Permissions.EXAM_CREATE)) {
|
||||
return <StudentSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
}
|
||||
return <TeacherSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
}
|
||||
|
||||
50
src/app/(dashboard)/settings/security/page.tsx
Normal file
50
src/app/(dashboard)/settings/security/page.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { redirect } from "next/navigation"
|
||||
import { Lock } from "lucide-react"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { PasswordChangeForm } from "@/modules/settings/components/password-change-form"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
title: "Security Settings",
|
||||
}
|
||||
|
||||
export default async function SecuritySettingsPage() {
|
||||
const session = await auth()
|
||||
if (!session?.user) redirect("/login")
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-8 p-8">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<Lock className="h-7 w-7 text-muted-foreground" />
|
||||
<h1 className="text-3xl font-bold tracking-tight">Security</h1>
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Manage your password and account security settings.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="max-w-2xl space-y-6">
|
||||
<PasswordChangeForm />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Security Tips</CardTitle>
|
||||
<CardDescription>Best practices to keep your account safe.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ul className="space-y-2 text-sm text-muted-foreground">
|
||||
<li>Use a unique password that you don't reuse across other sites.</li>
|
||||
<li>Avoid common words, names, or sequential patterns.</li>
|
||||
<li>Change your password periodically.</li>
|
||||
<li>Your account will be temporarily locked after multiple failed login attempts.</li>
|
||||
</ul>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
40
src/app/(dashboard)/student/attendance/page.tsx
Normal file
40
src/app/(dashboard)/student/attendance/page.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getStudentAttendanceSummary } from "@/modules/attendance/data-access-stats"
|
||||
import { StudentAttendanceView } from "@/modules/attendance/components/student-attendance-view"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { CalendarCheck } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function StudentAttendancePage() {
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
const summary = await getStudentAttendanceSummary(ctx.userId)
|
||||
|
||||
if (!summary) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">My Attendance</h2>
|
||||
<p className="text-muted-foreground">View your attendance records.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No user found"
|
||||
description="Unable to load your student profile."
|
||||
icon={CalendarCheck}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">My Attendance</h2>
|
||||
<p className="text-muted-foreground">View your attendance records and statistics.</p>
|
||||
</div>
|
||||
<StudentAttendanceView summary={summary} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
40
src/app/(dashboard)/student/grades/page.tsx
Normal file
40
src/app/(dashboard)/student/grades/page.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getStudentGradeSummary } from "@/modules/grades/data-access"
|
||||
import { StudentGradeSummary } from "@/modules/grades/components/student-grade-summary"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { GraduationCap } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function StudentGradesPage() {
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
const summary = await getStudentGradeSummary(ctx.userId)
|
||||
|
||||
if (!summary) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">My Grades</h2>
|
||||
<p className="text-muted-foreground">View your grade records.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No user found"
|
||||
description="Unable to load your student profile."
|
||||
icon={GraduationCap}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">My Grades</h2>
|
||||
<p className="text-muted-foreground">View your grade records.</p>
|
||||
</div>
|
||||
<StudentGradeSummary summary={summary} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
83
src/app/(dashboard)/teacher/attendance/page.tsx
Normal file
83
src/app/(dashboard)/teacher/attendance/page.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import Link from "next/link"
|
||||
import { PlusCircle, BarChart3, ClipboardList } from "lucide-react"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getAttendanceRecords } from "@/modules/attendance/data-access"
|
||||
import { AttendanceFilters } from "@/modules/attendance/components/attendance-filters"
|
||||
import { AttendanceRecordList } from "@/modules/attendance/components/attendance-record-list"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function TeacherAttendancePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const status = getParam(sp, "status")
|
||||
const date = getParam(sp, "date")
|
||||
|
||||
const classes = await getTeacherClasses()
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
|
||||
const result = await getAttendanceRecords({
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
classId: classId && classId !== "all" ? classId : undefined,
|
||||
status: status && status !== "all" ? (status as "present" | "absent" | "late" | "early_leave" | "excused") : undefined,
|
||||
date: date && date.length > 0 ? date : undefined,
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Attendance</h2>
|
||||
<p className="text-muted-foreground">Manage student attendance records.</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/teacher/attendance/stats">
|
||||
<BarChart3 className="mr-2 h-4 w-4" />
|
||||
Statistics
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild>
|
||||
<Link href="/teacher/attendance/sheet">
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
Take Attendance
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AttendanceFilters classes={classOptions} />
|
||||
|
||||
{result.items.length === 0 && !classId && !status && !date ? (
|
||||
<EmptyState
|
||||
title="No attendance records"
|
||||
description="Start by taking attendance for your classes."
|
||||
icon={ClipboardList}
|
||||
action={{
|
||||
label: "Take Attendance",
|
||||
href: "/teacher/attendance/sheet",
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<AttendanceRecordList records={result.items} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
49
src/app/(dashboard)/teacher/attendance/sheet/page.tsx
Normal file
49
src/app/(dashboard)/teacher/attendance/sheet/page.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassStudentsForAttendance } from "@/modules/attendance/data-access"
|
||||
import { AttendanceSheet } from "@/modules/attendance/components/attendance-sheet"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function AttendanceSheetPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
|
||||
const defaultClassId = getParam(sp, "classId")
|
||||
const defaultDate = getParam(sp, "date")
|
||||
|
||||
const classes = await getTeacherClasses()
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
|
||||
let students: Array<{ id: string; name: string; email: string }> = []
|
||||
if (defaultClassId) {
|
||||
students = await getClassStudentsForAttendance(defaultClassId)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Take Attendance</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Select a class and date, then mark attendance for each student.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<AttendanceSheet
|
||||
classes={classOptions}
|
||||
students={students}
|
||||
defaultClassId={defaultClassId}
|
||||
defaultDate={defaultDate}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
120
src/app/(dashboard)/teacher/attendance/stats/page.tsx
Normal file
120
src/app/(dashboard)/teacher/attendance/stats/page.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassAttendanceStats } from "@/modules/attendance/data-access-stats"
|
||||
import { AttendanceStatsCard } from "@/modules/attendance/components/attendance-stats-card"
|
||||
import { AttendanceRecordList } from "@/modules/attendance/components/attendance-record-list"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function AttendanceStatsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const startDate = getParam(sp, "startDate")
|
||||
const endDate = getParam(sp, "endDate")
|
||||
|
||||
const classes = await getTeacherClasses()
|
||||
|
||||
if (classes.length === 0) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Attendance Statistics</h2>
|
||||
<p className="text-muted-foreground">View class attendance statistics.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No classes"
|
||||
description="You don't have any classes yet."
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const targetClassId = classId ?? classes[0].id
|
||||
|
||||
const summary = await getClassAttendanceStats(
|
||||
targetClassId,
|
||||
startDate,
|
||||
endDate
|
||||
)
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Attendance Statistics</h2>
|
||||
<p className="text-muted-foreground">View class attendance statistics and trends.</p>
|
||||
</div>
|
||||
|
||||
<StatsClassSelector
|
||||
classes={classOptions}
|
||||
currentClassId={targetClassId}
|
||||
startDate={startDate ?? ""}
|
||||
endDate={endDate ?? ""}
|
||||
/>
|
||||
|
||||
{summary ? (
|
||||
<>
|
||||
<AttendanceStatsCard stats={summary.stats} />
|
||||
<div>
|
||||
<h3 className="mb-4 text-lg font-semibold">Student Records</h3>
|
||||
<AttendanceRecordList records={summary.studentRecords} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<EmptyState
|
||||
title="No data"
|
||||
description="No attendance data available for this class."
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StatsClassSelector({
|
||||
classes,
|
||||
currentClassId,
|
||||
startDate,
|
||||
endDate,
|
||||
}: {
|
||||
classes: Array<{ id: string; name: string }>
|
||||
currentClassId: string
|
||||
startDate: string
|
||||
endDate: string
|
||||
}) {
|
||||
const dateParams = `${startDate ? `&startDate=${startDate}` : ""}${endDate ? `&endDate=${endDate}` : ""}`
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{classes.map((c) => (
|
||||
<a
|
||||
key={c.id}
|
||||
href={`/teacher/attendance/stats?classId=${c.id}${dateParams}`}
|
||||
className={`rounded-md border px-3 py-1.5 text-sm transition-colors ${
|
||||
c.id === currentClassId
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-card hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{c.name}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
26
src/app/(dashboard)/teacher/course-plans/[id]/page.tsx
Normal file
26
src/app/(dashboard)/teacher/course-plans/[id]/page.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { getCoursePlanById } from "@/modules/course-plans/data-access"
|
||||
import { CoursePlanDetail } from "@/modules/course-plans/components/course-plan-detail"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function TeacherCoursePlanDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const { id } = await params
|
||||
const plan = await getCoursePlanById(id)
|
||||
|
||||
if (!plan) notFound()
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-6 p-8">
|
||||
<CoursePlanDetail
|
||||
plan={plan}
|
||||
backHref="/teacher/course-plans"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
49
src/app/(dashboard)/teacher/course-plans/page.tsx
Normal file
49
src/app/(dashboard)/teacher/course-plans/page.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { auth } from "@/auth"
|
||||
import { getCoursePlans } from "@/modules/course-plans/data-access"
|
||||
import { CoursePlanList } from "@/modules/course-plans/components/course-plan-list"
|
||||
import type { CoursePlanStatus } from "@/modules/course-plans/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
const isValidStatus = (v?: string): v is CoursePlanStatus =>
|
||||
v === "planning" || v === "active" || v === "completed" || v === "paused"
|
||||
|
||||
export default async function TeacherCoursePlansPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const session = await auth()
|
||||
const teacherId = String(session?.user?.id ?? "")
|
||||
|
||||
const sp = await searchParams
|
||||
const statusParam = getParam(sp, "status")
|
||||
const status = isValidStatus(statusParam) ? statusParam : undefined
|
||||
|
||||
const plans = teacherId
|
||||
? await getCoursePlans({ teacherId, status })
|
||||
: []
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">My Course Plans</h2>
|
||||
<p className="text-muted-foreground">
|
||||
View your course teaching plans and weekly schedules.
|
||||
</p>
|
||||
</div>
|
||||
<CoursePlanList
|
||||
plans={plans}
|
||||
detailHrefBuilder={(id) => `/teacher/course-plans/${id}`}
|
||||
initialStatus={status}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
259
src/app/(dashboard)/teacher/grades/analytics/page.tsx
Normal file
259
src/app/(dashboard)/teacher/grades/analytics/page.tsx
Normal file
@@ -0,0 +1,259 @@
|
||||
import Link from "next/link"
|
||||
import { BarChart3, ArrowLeft } from "lucide-react"
|
||||
import { asc } from "drizzle-orm"
|
||||
|
||||
import { db } from "@/shared/db"
|
||||
import { subjects } from "@/shared/db/schema"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
|
||||
import {
|
||||
getClassComparison,
|
||||
getGradeDistribution,
|
||||
getGradeTrend,
|
||||
getSubjectComparison,
|
||||
} from "@/modules/grades/data-access-analytics"
|
||||
import { GradeTrendChart } from "@/modules/grades/components/grade-trend-chart"
|
||||
import { ClassComparisonChart } from "@/modules/grades/components/class-comparison-chart"
|
||||
import { SubjectComparisonChart } from "@/modules/grades/components/subject-comparison-chart"
|
||||
import { GradeDistributionChart } from "@/modules/grades/components/grade-distribution-chart"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function GradeAnalyticsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}) {
|
||||
const sp = await searchParams
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const subjectId = getParam(sp, "subjectId")
|
||||
const gradeId = getParam(sp, "gradeId")
|
||||
|
||||
const [classes, allGrades, allSubjects] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
getGrades(),
|
||||
db.query.subjects.findMany({
|
||||
orderBy: [asc(subjects.order), asc(subjects.name)],
|
||||
}),
|
||||
])
|
||||
|
||||
if (classes.length === 0) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Grade Analytics</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Trend analysis, class comparisons, and score distributions.
|
||||
</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No classes"
|
||||
description="You don't have any classes yet."
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const targetClassId = classId ?? classes[0].id
|
||||
const targetSubjectId =
|
||||
subjectId && subjectId !== "all" ? subjectId : undefined
|
||||
const targetGradeId = gradeId ?? allGrades[0]?.id
|
||||
|
||||
// Run analytics queries in parallel
|
||||
const [trend, distribution, subjectComparison, classComparison] =
|
||||
await Promise.all([
|
||||
getGradeTrend({
|
||||
classId: targetClassId,
|
||||
subjectId: targetSubjectId,
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
}),
|
||||
getGradeDistribution({
|
||||
classId: targetClassId,
|
||||
subjectId: targetSubjectId,
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
}),
|
||||
getSubjectComparison({
|
||||
classId: targetClassId,
|
||||
scope: ctx.dataScope,
|
||||
}),
|
||||
targetGradeId
|
||||
? getClassComparison({
|
||||
gradeId: targetGradeId,
|
||||
subjectId: targetSubjectId ?? allSubjects[0]?.id ?? "",
|
||||
scope: ctx.dataScope,
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-6 p-8 md:flex">
|
||||
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Grade Analytics</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Trend analysis, class comparisons, and score distributions.
|
||||
</p>
|
||||
</div>
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/teacher/grades">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Back to Grades
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<AnalyticsFilters
|
||||
classes={classes.map((c) => ({ id: c.id, name: c.name }))}
|
||||
grades={allGrades.map((g) => ({ id: g.id, name: g.name }))}
|
||||
subjects={allSubjects.map((s) => ({ id: s.id, name: s.name ?? "Unknown" }))}
|
||||
currentClassId={targetClassId}
|
||||
currentSubjectId={subjectId ?? "all"}
|
||||
currentGradeId={targetGradeId ?? ""}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<GradeTrendChart data={trend} />
|
||||
<GradeDistributionChart data={distribution} />
|
||||
<SubjectComparisonChart data={subjectComparison} />
|
||||
<ClassComparisonChart data={classComparison} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface AnalyticsFiltersProps {
|
||||
classes: Array<{ id: string; name: string }>
|
||||
grades: Array<{ id: string; name: string }>
|
||||
subjects: Array<{ id: string; name: string }>
|
||||
currentClassId: string
|
||||
currentSubjectId: string
|
||||
currentGradeId: string
|
||||
}
|
||||
|
||||
function AnalyticsFilters({
|
||||
classes,
|
||||
grades,
|
||||
subjects,
|
||||
currentClassId,
|
||||
currentSubjectId,
|
||||
currentGradeId,
|
||||
}: AnalyticsFiltersProps) {
|
||||
const buildHref = (overrides: {
|
||||
classId?: string
|
||||
subjectId?: string
|
||||
gradeId?: string
|
||||
}) => {
|
||||
const params = new URLSearchParams()
|
||||
params.set(
|
||||
"classId",
|
||||
overrides.classId !== undefined ? overrides.classId : currentClassId
|
||||
)
|
||||
params.set(
|
||||
"subjectId",
|
||||
overrides.subjectId !== undefined ? overrides.subjectId : currentSubjectId
|
||||
)
|
||||
if (
|
||||
overrides.gradeId !== undefined
|
||||
? overrides.gradeId
|
||||
: currentGradeId
|
||||
) {
|
||||
params.set(
|
||||
"gradeId",
|
||||
overrides.gradeId !== undefined ? overrides.gradeId : currentGradeId
|
||||
)
|
||||
}
|
||||
return `/teacher/grades/analytics?${params.toString()}`
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border bg-card p-4">
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div className="space-y-2">
|
||||
<div className="text-xs font-medium text-muted-foreground">Class</div>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{classes.map((c) => (
|
||||
<a
|
||||
key={c.id}
|
||||
href={buildHref({ classId: c.id })}
|
||||
className={`rounded-md border px-2.5 py-1 text-xs transition-colors ${
|
||||
c.id === currentClassId
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-background hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{c.name}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-xs font-medium text-muted-foreground">Subject</div>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
<a
|
||||
href={buildHref({ subjectId: "all" })}
|
||||
className={`rounded-md border px-2.5 py-1 text-xs transition-colors ${
|
||||
currentSubjectId === "all"
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-background hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
All
|
||||
</a>
|
||||
{subjects.map((s) => (
|
||||
<a
|
||||
key={s.id}
|
||||
href={buildHref({ subjectId: s.id })}
|
||||
className={`rounded-md border px-2.5 py-1 text-xs transition-colors ${
|
||||
s.id === currentSubjectId
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-background hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{s.name}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-xs font-medium text-muted-foreground">
|
||||
Grade (for class comparison)
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{grades.map((g) => (
|
||||
<a
|
||||
key={g.id}
|
||||
href={buildHref({ gradeId: g.id })}
|
||||
className={`rounded-md border px-2.5 py-1 text-xs transition-colors ${
|
||||
g.id === currentGradeId
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-background hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{g.name}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
52
src/app/(dashboard)/teacher/grades/entry/page.tsx
Normal file
52
src/app/(dashboard)/teacher/grades/entry/page.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import { db } from "@/shared/db"
|
||||
import { subjects } from "@/shared/db/schema"
|
||||
import { asc } from "drizzle-orm"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassStudentsForEntry } from "@/modules/grades/data-access"
|
||||
import { BatchGradeEntry } from "@/modules/grades/components/batch-grade-entry"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function BatchEntryPage({ searchParams }: { searchParams: Promise<SearchParams> }) {
|
||||
const sp = await searchParams
|
||||
|
||||
const defaultClassId = getParam(sp, "classId")
|
||||
const defaultSubjectId = getParam(sp, "subjectId")
|
||||
|
||||
const [classes, allSubjects] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
db.query.subjects.findMany({ orderBy: [asc(subjects.order), asc(subjects.name)] }),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
const subjectOptions = allSubjects.map((s) => ({ id: s.id, name: s.name }))
|
||||
|
||||
let students: Array<{ id: string; name: string; email: string }> = []
|
||||
if (defaultClassId) {
|
||||
students = await getClassStudentsForEntry(defaultClassId)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Batch Grade Entry</h2>
|
||||
<p className="text-muted-foreground">Enter grades for all students in a class at once.</p>
|
||||
</div>
|
||||
|
||||
<BatchGradeEntry
|
||||
classes={classOptions}
|
||||
subjects={subjectOptions}
|
||||
students={students}
|
||||
defaultClassId={defaultClassId}
|
||||
defaultSubjectId={defaultSubjectId}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
101
src/app/(dashboard)/teacher/grades/page.tsx
Normal file
101
src/app/(dashboard)/teacher/grades/page.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
import Link from "next/link"
|
||||
import { PlusCircle, BarChart3, ClipboardList } from "lucide-react"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { db } from "@/shared/db"
|
||||
import { subjects } from "@/shared/db/schema"
|
||||
import { asc } from "drizzle-orm"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getGradeRecords } from "@/modules/grades/data-access"
|
||||
import { GradeQueryFilters } from "@/modules/grades/components/grade-query-filters"
|
||||
import { GradeRecordList } from "@/modules/grades/components/grade-record-list"
|
||||
import { ExportButton } from "@/modules/grades/components/export-button"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function TeacherGradesPage({ searchParams }: { searchParams: Promise<SearchParams> }) {
|
||||
const sp = await searchParams
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const subjectId = getParam(sp, "subjectId")
|
||||
const type = getParam(sp, "type")
|
||||
const semester = getParam(sp, "semester")
|
||||
|
||||
const [classes, allSubjects] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
db.query.subjects.findMany({ orderBy: [asc(subjects.order), asc(subjects.name)] }),
|
||||
])
|
||||
|
||||
const records = await getGradeRecords({
|
||||
scope: ctx.dataScope,
|
||||
currentUserId: ctx.userId,
|
||||
classId: classId && classId !== "all" ? classId : undefined,
|
||||
subjectId: subjectId && subjectId !== "all" ? subjectId : undefined,
|
||||
type: type && type !== "all" ? (type as "exam" | "quiz" | "homework" | "other") : undefined,
|
||||
semester: semester && semester !== "all" ? (semester as "1" | "2") : undefined,
|
||||
})
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
const subjectOptions = allSubjects.map((s) => ({ id: s.id, name: s.name }))
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Grades</h2>
|
||||
<p className="text-muted-foreground">Manage student grade records.</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/teacher/grades/stats">
|
||||
<BarChart3 className="mr-2 h-4 w-4" />
|
||||
Statistics
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/teacher/grades/entry">
|
||||
<ClipboardList className="mr-2 h-4 w-4" />
|
||||
Batch Entry
|
||||
</Link>
|
||||
</Button>
|
||||
<ExportButton
|
||||
classId={classId && classId !== "all" ? classId : ""}
|
||||
subjectId={subjectId && subjectId !== "all" ? subjectId : undefined}
|
||||
variant="outline"
|
||||
/>
|
||||
<Button asChild>
|
||||
<Link href="/teacher/grades/entry">
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
Record Grades
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<GradeQueryFilters classes={classOptions} subjects={subjectOptions} />
|
||||
|
||||
{records.length === 0 && !classId && !subjectId ? (
|
||||
<EmptyState
|
||||
title="No grade records"
|
||||
description="Start by recording grades for your classes."
|
||||
icon={ClipboardList}
|
||||
action={{
|
||||
label: "Record Grades",
|
||||
href: "/teacher/grades/entry",
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<GradeRecordList records={records} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
139
src/app/(dashboard)/teacher/grades/stats/page.tsx
Normal file
139
src/app/(dashboard)/teacher/grades/stats/page.tsx
Normal file
@@ -0,0 +1,139 @@
|
||||
import { db } from "@/shared/db"
|
||||
import { subjects } from "@/shared/db/schema"
|
||||
import { asc } from "drizzle-orm"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassGradeStatsWithMeta, getClassRanking } from "@/modules/grades/data-access"
|
||||
import { ClassGradeReport } from "@/modules/grades/components/class-grade-report"
|
||||
import { ExportButton } from "@/modules/grades/components/export-button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
type SearchParams = { [key: string]: string | string[] | undefined }
|
||||
|
||||
const getParam = (params: SearchParams, key: string) => {
|
||||
const v = params[key]
|
||||
return Array.isArray(v) ? v[0] : v
|
||||
}
|
||||
|
||||
export default async function StatsPage({ searchParams }: { searchParams: Promise<SearchParams> }) {
|
||||
const sp = await searchParams
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const subjectId = getParam(sp, "subjectId")
|
||||
|
||||
const [classes, allSubjects] = await Promise.all([
|
||||
getTeacherClasses(),
|
||||
db.query.subjects.findMany({ orderBy: [asc(subjects.order), asc(subjects.name)] }),
|
||||
])
|
||||
|
||||
if (classes.length === 0) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Grade Statistics</h2>
|
||||
<p className="text-muted-foreground">View class grade statistics and rankings.</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title="No classes"
|
||||
description="You don't have any classes yet."
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const targetClassId = classId ?? classes[0].id
|
||||
const targetSubjectId = subjectId && subjectId !== "all" ? subjectId : undefined
|
||||
|
||||
const [stats, ranking] = await Promise.all([
|
||||
getClassGradeStatsWithMeta(targetClassId, targetSubjectId),
|
||||
getClassRanking(targetClassId, targetSubjectId),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
const subjectOptions = allSubjects.map((s) => ({ id: s.id, name: s.name }))
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Grade Statistics</h2>
|
||||
<p className="text-muted-foreground">View class grade statistics and rankings.</p>
|
||||
</div>
|
||||
<ExportButton
|
||||
classId={targetClassId}
|
||||
subjectId={targetSubjectId}
|
||||
variant="outline"
|
||||
label="导出成绩"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<StatsClassSelector
|
||||
classes={classOptions}
|
||||
subjects={subjectOptions}
|
||||
currentClassId={targetClassId}
|
||||
currentSubjectId={subjectId ?? "all"}
|
||||
/>
|
||||
|
||||
<ClassGradeReport stats={stats} ranking={ranking} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StatsClassSelector({
|
||||
classes,
|
||||
subjects,
|
||||
currentClassId,
|
||||
currentSubjectId,
|
||||
}: {
|
||||
classes: Array<{ id: string; name: string }>
|
||||
subjects: Array<{ id: string; name: string }>
|
||||
currentClassId: string
|
||||
currentSubjectId: string
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{classes.map((c) => (
|
||||
<a
|
||||
key={c.id}
|
||||
href={`/teacher/grades/stats?classId=${c.id}${currentSubjectId !== "all" ? `&subjectId=${currentSubjectId}` : ""}`}
|
||||
className={`rounded-md border px-3 py-1.5 text-sm transition-colors ${
|
||||
c.id === currentClassId
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-card hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{c.name}
|
||||
</a>
|
||||
))}
|
||||
<div className="ml-auto flex flex-wrap gap-2">
|
||||
<a
|
||||
href={`/teacher/grades/stats?classId=${currentClassId}`}
|
||||
className={`rounded-md border px-3 py-1.5 text-sm transition-colors ${
|
||||
currentSubjectId === "all"
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-card hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
All Subjects
|
||||
</a>
|
||||
{subjects.map((s) => (
|
||||
<a
|
||||
key={s.id}
|
||||
href={`/teacher/grades/stats?classId=${currentClassId}&subjectId=${s.id}`}
|
||||
className={`rounded-md border px-3 py-1.5 text-sm transition-colors ${
|
||||
s.id === currentSubjectId
|
||||
? "border-primary bg-primary text-primary-foreground"
|
||||
: "bg-card hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{s.name}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
69
src/app/(dashboard)/teacher/schedule-changes/page.tsx
Normal file
69
src/app/(dashboard)/teacher/schedule-changes/page.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
import { ClipboardList } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import {
|
||||
getAdminClassesForScheduling,
|
||||
getScheduleChanges,
|
||||
getTeachersForScheduling,
|
||||
} from "@/modules/scheduling/actions"
|
||||
import { ScheduleChangeForm } from "@/modules/scheduling/components/schedule-change-form"
|
||||
import { ScheduleChangeList } from "@/modules/scheduling/components/schedule-change-list"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function TeacherScheduleChangesPage() {
|
||||
const ctx = await getAuthContext()
|
||||
|
||||
// Teachers see only their own requests; admins landing here see all.
|
||||
const requesterId = ctx.roles.includes("admin") ? undefined : ctx.userId
|
||||
|
||||
const [classes, teachers, items] = await Promise.all([
|
||||
getAdminClassesForScheduling(),
|
||||
getTeachersForScheduling(),
|
||||
getScheduleChanges({ requesterId }),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name, grade: c.grade }))
|
||||
const teacherOptions = teachers.map((t) => ({
|
||||
id: t.id,
|
||||
name: t.name ?? "Unknown",
|
||||
email: t.email ?? "",
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-2xl font-bold tracking-tight">Schedule Change Requests</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Submit a schedule change or substitute teacher request, and track its status.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{classOptions.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={ClipboardList}
|
||||
title="No classes available"
|
||||
description="There are no classes available to request schedule changes for."
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-8">
|
||||
<ScheduleChangeForm classes={classOptions} teachers={teacherOptions} />
|
||||
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-lg font-semibold">My Requests</h3>
|
||||
{items.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={ClipboardList}
|
||||
title="No requests yet"
|
||||
description="Your submitted schedule change requests will appear here."
|
||||
/>
|
||||
) : (
|
||||
<ScheduleChangeList items={items} canApprove={false} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user