Files
breakpilot-lehrer/studio-v2/app/stundenplan/page.tsx
T
Benjamin Admin 306886a42b Phase 8: CSV + ICS export, print view, MkDocs docs, SBOM + dev-mode auth
Auth (Test-Mode):
  - middleware.AuthMiddleware now takes a devMode flag. In dev,
    requests without Authorization fall back to a deterministic dev
    UUID (00000000-...-001) and role=teacher. ENVIRONMENT=production
    re-enables the strict 401 path.
  - main.go wires devMode = cfg.Environment != "production".
  - page.tsx replaces the red 'Anmeldung noch nicht integriert' banner
    with a softer Testumgebung notice; the manual-token form moves
    behind a nested details block.

Export endpoints (school-service):
  - LoadExportLessons joins tt_lesson with tt_period for wall-clock
    times; one query feeds both CSV and ICS.
  - WriteCSV streams 10 columns including pinned flag.
  - WriteICS emits one VEVENT per lesson anchored to a Monday — caller
    overridable via ?start=YYYY-MM-DD. RFC 5545 escapes for ',', ';',
    '\n' in icsEscape().
  - NextMonday helper for the default anchor.
  - GET /timetable/solutions/:id/export.{csv,ics} handlers attach
    Content-Disposition: attachment so browsers download instead of
    rendering.

Frontend:
  - lib/stundenplan/api.ts downloadSolutionExport() fetches as blob,
    triggers a synthetic <a download> click, and forwards the JWT when
    present.
  - PlanView gains CSV / ICS / Drucken buttons next to the perspective
    selector. The toolbar carries class 'no-print' so window.print()
    yields only the grid.
  - globals.css @media print rule hides chrome, forces white
    background, gives the table proper borders for A4.

Docs:
  - docs-src/services/stundenplan/{index,architecture,constraints,
    solver-tuning,export}.md with nav entry in mkdocs.yml under
    Services → Stundenplaner.
  - sbom/stundenplan/README.md lists manually-verified key dependencies
    and the policy reference. scripts/stundenplan-sbom.sh generates
    full machine-readable inventories via go-licenses + pip-licenses
    + license-checker when those tools are available.

Tests:
  - internal/services/timetable_exports_test.go: 4 unit tests covering
    CSV column layout + quoting, ICS structure + DTSTART formatting,
    icsEscape special chars, NextMonday weekday math.
  - studio-v2/e2e/stundenplan-export.spec.ts split out of the main spec
    file (LOC budget) — 3 tests for button render, CSV download,
    ICS download.
  - mockSchoolApi extended with export.csv + export.ics routes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 08:57:07 +02:00

160 lines
7.2 KiB
TypeScript

'use client'
import { useState } from 'react'
import { useTheme } from '@/lib/ThemeContext'
import { Sidebar } from '@/components/Sidebar'
import { ThemeToggle } from '@/components/ThemeToggle'
import { LanguageDropdown } from '@/components/LanguageDropdown'
import { KlassenManager } from './_components/KlassenManager'
import { LehrerManager } from './_components/LehrerManager'
import { FaecherManager } from './_components/FaecherManager'
import { RaeumeManager } from './_components/RaeumeManager'
import { PeriodsManager } from './_components/PeriodsManager'
import { CurriculumManager } from './_components/CurriculumManager'
import { AssignmentsManager } from './_components/AssignmentsManager'
import { RegelnHub } from './_components/regeln/RegelnHub'
import { PlanHub } from './_components/plan/PlanHub'
import { HelpPanel } from './_components/HelpPanel'
import { setStundenplanToken, getStundenplanToken } from '@/lib/stundenplan/api'
type Tab = 'plan' | 'klassen' | 'lehrer' | 'faecher' | 'raeume' | 'periods' | 'curriculum' | 'assignments' | 'regeln'
const TABS: { id: Tab; label: string }[] = [
{ id: 'plan', label: 'Plan' },
{ id: 'klassen', label: 'Klassen' },
{ id: 'lehrer', label: 'Lehrer' },
{ id: 'faecher', label: 'Faecher' },
{ id: 'raeume', label: 'Raeume' },
{ id: 'periods', label: 'Zeitraster' },
{ id: 'curriculum', label: 'Stundentafel' },
{ id: 'assignments', label: 'Lehrauftraege' },
{ id: 'regeln', label: 'Regeln (Constraints)' },
]
export default function StundenplanPage() {
const { isDark } = useTheme()
const [tab, setTab] = useState<Tab>('plan')
const [token, setToken] = useState(getStundenplanToken())
const [tokenSaved, setTokenSaved] = useState(false)
const handleSaveToken = () => {
setStundenplanToken(token)
setTokenSaved(true)
setTimeout(() => setTokenSaved(false), 2500)
}
return (
<div className={`min-h-screen flex relative overflow-hidden ${
isDark ? 'bg-gradient-to-br from-indigo-900 via-purple-900 to-pink-800'
: 'bg-gradient-to-br from-slate-100 via-blue-50 to-indigo-100'
}`}>
{/* Background blobs — same effect as /korrektur to keep the visual
language consistent across studio-v2 pages. */}
<div className={`absolute -top-40 -right-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob ${isDark ? 'bg-purple-500 opacity-30' : 'bg-purple-300 opacity-40'}`} />
<div className={`absolute top-1/2 -left-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-2000 ${isDark ? 'bg-pink-500 opacity-30' : 'bg-pink-300 opacity-40'}`} />
<div className={`absolute -bottom-40 right-1/3 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-4000 ${isDark ? 'bg-blue-500 opacity-30' : 'bg-blue-300 opacity-40'}`} />
<div className="relative z-10 p-4"><Sidebar selectedTab="stundenplan" /></div>
<main className="flex-1 relative z-10 p-6 overflow-y-auto">
<div className="max-w-7xl mx-auto">
<header className="flex items-center justify-between mb-6">
<div>
<h1 className={`text-3xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>
Stundenplan
</h1>
<p className={`text-sm mt-1 ${isDark ? 'text-white/60' : 'text-slate-500'}`}>
Stammdaten, Regeln und Plan-Generierung fuer den Schul-Stundenplan
</p>
</div>
<div className="flex items-center gap-3">
<ThemeToggle />
<LanguageDropdown />
</div>
</header>
<HelpPanel />
<div
className={`mb-4 p-3 rounded-xl border backdrop-blur-xl text-sm ${
isDark ? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-200' : 'bg-emerald-50 border-emerald-200 text-emerald-900'
}`}
>
<details>
<summary className="cursor-pointer font-medium">
Testumgebung Anmeldung deaktiviert
</summary>
<div className="mt-2 space-y-2">
<p>
Der school-service laeuft im Development-Mode und akzeptiert Requests
ohne JWT. Alle Aktionen werden einem festen Dev-User
zugeordnet (<code className={`px-1 rounded ${isDark ? 'bg-white/10' : 'bg-emerald-100'}`}>00000000-0000-0000-0000-000000000001</code>).
</p>
<p>
Fuer Production muss <code className={`px-1 rounded ${isDark ? 'bg-white/10' : 'bg-emerald-100'}`}>ENVIRONMENT=production</code> gesetzt werden dann ist ein gueltiger
JWT in jedem Request Pflicht.
</p>
<details className="opacity-70">
<summary className="cursor-pointer text-xs">Manueller Token (falls noetig)</summary>
<div className="mt-2 flex gap-2">
<input
type="password"
value={token}
onChange={e => setToken(e.target.value)}
placeholder="Bearer-Token (optional)"
className={`flex-1 px-3 py-1.5 rounded-lg text-sm ${
isDark ? 'bg-white/10 border border-white/20 text-white' : 'bg-white border border-slate-300 text-slate-900'
}`}
/>
<button
onClick={handleSaveToken}
className="px-3 py-1.5 rounded-lg bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium"
>
Speichern
</button>
</div>
{tokenSaved && (
<p className="mt-1 text-xs opacity-90">Token gespeichert. Seite neu laden.</p>
)}
</details>
</div>
</details>
</div>
<nav className="flex flex-wrap gap-2 mb-6">
{TABS.map(t => (
<button
key={t.id}
onClick={() => setTab(t.id)}
className={`px-4 py-2 rounded-xl text-sm font-medium transition-colors ${
tab === t.id
? isDark
? 'bg-white/20 text-white shadow-lg'
: 'bg-indigo-600 text-white shadow-lg'
: isDark
? 'bg-white/5 text-white/70 hover:bg-white/15'
: 'bg-white/70 text-slate-700 hover:bg-white border border-slate-200'
}`}
>
{t.label}
</button>
))}
</nav>
<section>
{tab === 'plan' && <PlanHub />}
{tab === 'klassen' && <KlassenManager />}
{tab === 'lehrer' && <LehrerManager />}
{tab === 'faecher' && <FaecherManager />}
{tab === 'raeume' && <RaeumeManager />}
{tab === 'periods' && <PeriodsManager />}
{tab === 'curriculum' && <CurriculumManager />}
{tab === 'assignments' && <AssignmentsManager />}
{tab === 'regeln' && <RegelnHub />}
</section>
</div>
</main>
</div>
)
}