Add Stundenplan frontend scaffolding in studio-v2
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 31s
CI / test-go-edu-search (push) Successful in 29s
CI / test-python-klausur (push) Failing after 2m36s
CI / test-python-agent-core (push) Successful in 20s
CI / test-nodejs-website (push) Successful in 22s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 31s
CI / test-go-edu-search (push) Successful in 29s
CI / test-python-klausur (push) Failing after 2m36s
CI / test-python-agent-core (push) Successful in 20s
CI / test-nodejs-website (push) Successful in 22s
Phase 3 — initial UI for the timetable scheduler:
- app/stundenplan/page.tsx with tab navigation (Klassen / Lehrer /
Faecher / Raeume / Zeitraster / Stundentafel / Lehrauftraege /
Regeln) and a dev-mode JWT entry to authenticate against
school-service until full auth is wired up.
- app/stundenplan/_components/KlassenManager.tsx as the working
prototype for one entity (list / create / delete). Pattern can be
copied for the other 6 stammdaten + 15 constraint editors.
- lib/stundenplan/api.ts exposing typed clients for all 22 endpoints
(7 stammdaten + 15 constraint tables). Constraints use a factory
to keep the file tight.
- app/api/school/[...path]/route.ts proxies the browser through
Next.js to school-service so HTTPS studio-v2 can reach the plain
HTTP backend.
- Sidebar.tsx gains a Stundenplan entry with 26-language labels.
- docker-compose.yml exposes SCHOOL_SERVICE_URL to studio-v2 and
declares the school-service dependency.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,8 +109,10 @@ services:
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
BACKEND_URL: http://backend-lehrer:8001
|
||||
SCHOOL_SERVICE_URL: http://school-service:8084
|
||||
depends_on:
|
||||
- backend-lehrer
|
||||
- school-service
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- breakpilot-network
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
/**
|
||||
* Proxy for the school-service (Go/Gin, port 8084). The browser cannot call
|
||||
* the backend directly because studio-v2 is served over HTTPS and the backend
|
||||
* is plain HTTP; this Next.js route bridges them server-side.
|
||||
*/
|
||||
|
||||
const BACKEND_URL = process.env.SCHOOL_SERVICE_URL || 'http://school-service:8084'
|
||||
|
||||
async function proxyRequest(
|
||||
request: NextRequest,
|
||||
params: { path: string[] }
|
||||
): Promise<NextResponse> {
|
||||
const path = params.path.join('/')
|
||||
const url = `${BACKEND_URL}/api/v1/school/${path}`
|
||||
|
||||
try {
|
||||
const headers: HeadersInit = { 'Content-Type': 'application/json' }
|
||||
const authHeader = request.headers.get('authorization')
|
||||
if (authHeader) headers['Authorization'] = authHeader
|
||||
|
||||
const fetchOptions: RequestInit = {
|
||||
method: request.method,
|
||||
headers,
|
||||
}
|
||||
|
||||
if (['POST', 'PUT', 'PATCH'].includes(request.method)) {
|
||||
fetchOptions.body = await request.text()
|
||||
}
|
||||
|
||||
const response = await fetch(url, fetchOptions)
|
||||
const contentType = response.headers.get('content-type')
|
||||
const data = contentType?.includes('application/json')
|
||||
? await response.text()
|
||||
: await response.arrayBuffer()
|
||||
|
||||
return new NextResponse(data, {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': contentType || 'application/json' },
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed to proxy ${request.method} ${url}:`, error)
|
||||
return NextResponse.json(
|
||||
{ error: 'school-service nicht erreichbar', details: error instanceof Error ? error.message : 'Unknown error' },
|
||||
{ status: 502 },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest, context: { params: Promise<{ path: string[] }> }) {
|
||||
return proxyRequest(request, await context.params)
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest, context: { params: Promise<{ path: string[] }> }) {
|
||||
return proxyRequest(request, await context.params)
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest, context: { params: Promise<{ path: string[] }> }) {
|
||||
return proxyRequest(request, await context.params)
|
||||
}
|
||||
|
||||
export async function DELETE(request: NextRequest, context: { params: Promise<{ path: string[] }> }) {
|
||||
return proxyRequest(request, await context.params)
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useTheme } from '@/lib/ThemeContext'
|
||||
import { classesApi } from '@/lib/stundenplan/api'
|
||||
import type { TimetableClass, CreateTimetableClass } from '@/app/stundenplan/types'
|
||||
|
||||
export function KlassenManager() {
|
||||
const { isDark } = useTheme()
|
||||
const [classes, setClasses] = useState<TimetableClass[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const [form, setForm] = useState<CreateTimetableClass>({
|
||||
name: '',
|
||||
grade_level: 5,
|
||||
student_count: 0,
|
||||
notes: '',
|
||||
})
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const data = await classesApi.list()
|
||||
setClasses(data || [])
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Laden fehlgeschlagen')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => { load() }, [load])
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setSubmitting(true)
|
||||
setError(null)
|
||||
try {
|
||||
await classesApi.create(form)
|
||||
setForm({ name: '', grade_level: 5, student_count: 0, notes: '' })
|
||||
setShowForm(false)
|
||||
await load()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Anlegen fehlgeschlagen')
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (!confirm('Klasse wirklich loeschen?')) return
|
||||
try {
|
||||
await classesApi.remove(id)
|
||||
await load()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Loeschen fehlgeschlagen')
|
||||
}
|
||||
}
|
||||
|
||||
const cardClass = isDark
|
||||
? 'bg-white/10 border-white/20 text-white'
|
||||
: 'bg-white/80 border-black/10 text-slate-900'
|
||||
const inputClass = isDark
|
||||
? 'bg-white/10 border-white/20 text-white placeholder-white/40'
|
||||
: 'bg-white border-slate-300 text-slate-900 placeholder-slate-400'
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className={`text-xl font-semibold ${isDark ? 'text-white' : 'text-slate-900'}`}>
|
||||
Klassen ({classes.length})
|
||||
</h2>
|
||||
<button
|
||||
onClick={() => setShowForm(s => !s)}
|
||||
className={`px-4 py-2 rounded-xl font-medium transition-colors ${
|
||||
isDark
|
||||
? 'bg-indigo-500 hover:bg-indigo-600 text-white'
|
||||
: 'bg-indigo-600 hover:bg-indigo-700 text-white'
|
||||
}`}
|
||||
>
|
||||
{showForm ? 'Abbrechen' : '+ Neue Klasse'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="p-3 rounded-xl bg-red-500/20 border border-red-500/40 text-red-300">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showForm && (
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className={`p-4 rounded-2xl border backdrop-blur-xl ${cardClass}`}
|
||||
>
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Name</label>
|
||||
<input
|
||||
required
|
||||
value={form.name}
|
||||
onChange={e => setForm({ ...form, name: e.target.value })}
|
||||
placeholder="z.B. 5a"
|
||||
className={`w-full px-3 py-2 rounded-lg border ${inputClass}`}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Klassenstufe</label>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={13}
|
||||
required
|
||||
value={form.grade_level}
|
||||
onChange={e => setForm({ ...form, grade_level: parseInt(e.target.value) || 0 })}
|
||||
className={`w-full px-3 py-2 rounded-lg border ${inputClass}`}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Schueleranzahl</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={form.student_count}
|
||||
onChange={e => setForm({ ...form, student_count: parseInt(e.target.value) || 0 })}
|
||||
className={`w-full px-3 py-2 rounded-lg border ${inputClass}`}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={submitting}
|
||||
className="w-full px-4 py-2 rounded-lg bg-emerald-500 hover:bg-emerald-600 text-white font-medium disabled:opacity-50"
|
||||
>
|
||||
{submitting ? 'Speichert...' : 'Anlegen'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<label className="block text-sm mb-1 opacity-70">Notizen (optional)</label>
|
||||
<input
|
||||
value={form.notes || ''}
|
||||
onChange={e => setForm({ ...form, notes: e.target.value })}
|
||||
className={`w-full px-3 py-2 rounded-lg border ${inputClass}`}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<div className={`text-center py-8 opacity-60 ${isDark ? 'text-white' : 'text-slate-700'}`}>
|
||||
Laedt…
|
||||
</div>
|
||||
) : classes.length === 0 ? (
|
||||
<div className={`text-center py-8 opacity-60 ${isDark ? 'text-white' : 'text-slate-700'}`}>
|
||||
Noch keine Klassen angelegt.
|
||||
</div>
|
||||
) : (
|
||||
<div className={`rounded-2xl border backdrop-blur-xl overflow-hidden ${cardClass}`}>
|
||||
<table className="w-full">
|
||||
<thead className={isDark ? 'bg-white/5' : 'bg-slate-100'}>
|
||||
<tr>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Name</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Stufe</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Schueler</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Notizen</th>
|
||||
<th className="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{classes.map(c => (
|
||||
<tr key={c.id} className={isDark ? 'border-t border-white/10' : 'border-t border-slate-200'}>
|
||||
<td className="px-4 py-3 font-medium">{c.name}</td>
|
||||
<td className="px-4 py-3">{c.grade_level}</td>
|
||||
<td className="px-4 py-3">{c.student_count}</td>
|
||||
<td className="px-4 py-3 text-sm opacity-70">{c.notes || '—'}</td>
|
||||
<td className="px-4 py-3 text-right">
|
||||
<button
|
||||
onClick={() => handleDelete(c.id)}
|
||||
className="text-red-400 hover:text-red-300 text-sm"
|
||||
>
|
||||
Loeschen
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
'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 { setStundenplanToken, getStundenplanToken } from '@/lib/stundenplan/api'
|
||||
|
||||
type Tab = 'klassen' | 'lehrer' | 'faecher' | 'raeume' | 'periods' | 'curriculum' | 'assignments' | 'regeln'
|
||||
|
||||
const TABS: { id: Tab; label: string }[] = [
|
||||
{ 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>('klassen')
|
||||
const [token, setToken] = useState(getStundenplanToken())
|
||||
|
||||
const handleSaveToken = () => {
|
||||
setStundenplanToken(token)
|
||||
alert('Token gespeichert. Seite neu laden um die Aenderung zu uebernehmen.')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`flex min-h-screen p-4 gap-4 ${isDark ? 'bg-slate-900' : 'bg-slate-50'}`}>
|
||||
<Sidebar selectedTab="stundenplan" />
|
||||
|
||||
<main className="flex-1 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 und Regeln fuer den Solver
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<ThemeToggle />
|
||||
<LanguageDropdown />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div
|
||||
className={`mb-4 p-3 rounded-xl border backdrop-blur-xl ${
|
||||
isDark ? 'bg-amber-500/10 border-amber-500/30 text-amber-200' : 'bg-amber-50 border-amber-200 text-amber-900'
|
||||
}`}
|
||||
>
|
||||
<details>
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Dev: JWT-Token setzen (Anmeldung noch nicht integriert)
|
||||
</summary>
|
||||
<div className="mt-2 flex gap-2">
|
||||
<input
|
||||
type="password"
|
||||
value={token}
|
||||
onChange={e => setToken(e.target.value)}
|
||||
placeholder="Bearer-Token"
|
||||
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-amber-500 hover:bg-amber-600 text-white text-sm font-medium"
|
||||
>
|
||||
Speichern
|
||||
</button>
|
||||
</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'
|
||||
: 'bg-indigo-100 text-indigo-900'
|
||||
: isDark
|
||||
? 'bg-white/5 text-white/70 hover:bg-white/10'
|
||||
: 'bg-white text-slate-700 hover:bg-slate-100 border border-slate-200'
|
||||
}`}
|
||||
>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<section>
|
||||
{tab === 'klassen' && <KlassenManager />}
|
||||
{tab !== 'klassen' && (
|
||||
<div
|
||||
className={`rounded-2xl border backdrop-blur-xl p-8 text-center ${
|
||||
isDark ? 'bg-white/5 border-white/10 text-white/60' : 'bg-white/80 border-black/10 text-slate-500'
|
||||
}`}
|
||||
>
|
||||
<p className="text-lg">Noch nicht implementiert: {TABS.find(t => t.id === tab)?.label}</p>
|
||||
<p className="text-sm mt-2">
|
||||
Das Klassen-Modul ist der Prototyp. Die anderen Stammdaten und alle 15 Constraints folgen dem gleichen Muster.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
// Mirror of school-service/internal/models/timetable*.go.
|
||||
// Field names in JSON come from the Go struct json:"…" tags.
|
||||
|
||||
// ---------- Stammdaten (7) ----------
|
||||
|
||||
export interface TimetableClass {
|
||||
id: string
|
||||
created_by_user_id: string
|
||||
name: string
|
||||
grade_level: number
|
||||
student_count: number
|
||||
notes?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface TimetablePeriod {
|
||||
id: string
|
||||
created_by_user_id: string
|
||||
day_of_week: number
|
||||
period_index: number
|
||||
start_time: string
|
||||
end_time: string
|
||||
is_break: boolean
|
||||
label?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface TimetableRoom {
|
||||
id: string
|
||||
created_by_user_id: string
|
||||
name: string
|
||||
room_type?: string
|
||||
capacity: number
|
||||
floor_level: number
|
||||
has_elevator: boolean
|
||||
notes?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface TimetableSubject {
|
||||
id: string
|
||||
created_by_user_id: string
|
||||
name: string
|
||||
short_code: string
|
||||
color?: string
|
||||
is_main_subject: boolean
|
||||
required_room_type?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface TimetableTeacher {
|
||||
id: string
|
||||
created_by_user_id: string
|
||||
first_name: string
|
||||
last_name: string
|
||||
short_code: string
|
||||
employment_percentage: number
|
||||
max_hours_week: number
|
||||
notes?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface TimetableCurriculum {
|
||||
id: string
|
||||
class_id: string
|
||||
subject_id: string
|
||||
weekly_hours: number
|
||||
created_at: string
|
||||
subject_name?: string
|
||||
class_name?: string
|
||||
}
|
||||
|
||||
export interface TimetableAssignment {
|
||||
id: string
|
||||
teacher_id: string
|
||||
class_id: string
|
||||
subject_id: string
|
||||
created_at: string
|
||||
teacher_name?: string
|
||||
class_name?: string
|
||||
subject_name?: string
|
||||
}
|
||||
|
||||
// Create-request DTOs
|
||||
|
||||
export interface CreateTimetableClass {
|
||||
name: string
|
||||
grade_level: number
|
||||
student_count?: number
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface CreateTimetablePeriod {
|
||||
day_of_week: number
|
||||
period_index: number
|
||||
start_time: string
|
||||
end_time: string
|
||||
is_break?: boolean
|
||||
label?: string
|
||||
}
|
||||
|
||||
export interface CreateTimetableRoom {
|
||||
name: string
|
||||
room_type?: string
|
||||
capacity?: number
|
||||
floor_level?: number
|
||||
has_elevator?: boolean
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface CreateTimetableSubject {
|
||||
name: string
|
||||
short_code: string
|
||||
color?: string
|
||||
is_main_subject?: boolean
|
||||
required_room_type?: string
|
||||
}
|
||||
|
||||
export interface CreateTimetableTeacher {
|
||||
first_name: string
|
||||
last_name: string
|
||||
short_code: string
|
||||
employment_percentage?: number
|
||||
max_hours_week?: number
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export interface CreateTimetableCurriculum {
|
||||
class_id: string
|
||||
subject_id: string
|
||||
weekly_hours: number
|
||||
}
|
||||
|
||||
export interface CreateTimetableAssignment {
|
||||
teacher_id: string
|
||||
class_id: string
|
||||
subject_id: string
|
||||
}
|
||||
|
||||
// ---------- Constraints (15) ----------
|
||||
|
||||
interface ConstraintBase {
|
||||
id: string
|
||||
created_by_user_id: string
|
||||
is_hard: boolean
|
||||
weight: number
|
||||
active: boolean
|
||||
note?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface TeacherUnavailableDay extends ConstraintBase {
|
||||
teacher_id: string
|
||||
day_of_week: number
|
||||
}
|
||||
|
||||
export interface TeacherUnavailableWindow extends ConstraintBase {
|
||||
teacher_id: string
|
||||
day_of_week: number
|
||||
start_time: string
|
||||
end_time: string
|
||||
}
|
||||
|
||||
export interface TeacherMaxHoursDay extends ConstraintBase {
|
||||
teacher_id: string
|
||||
max_hours: number
|
||||
}
|
||||
|
||||
export interface TeacherMaxHoursWeek extends ConstraintBase {
|
||||
teacher_id: string
|
||||
max_hours: number
|
||||
}
|
||||
|
||||
export interface TeacherExcludedSubject extends ConstraintBase {
|
||||
teacher_id: string
|
||||
subject_id: string
|
||||
}
|
||||
|
||||
export interface TeacherExcludedRoom extends ConstraintBase {
|
||||
teacher_id: string
|
||||
room_id: string
|
||||
}
|
||||
|
||||
export interface SubjectMinDayGap extends ConstraintBase {
|
||||
subject_id: string
|
||||
min_gap_days: number
|
||||
}
|
||||
|
||||
export interface SubjectMaxConsecutive extends ConstraintBase {
|
||||
subject_id: string
|
||||
max_consecutive: number
|
||||
}
|
||||
|
||||
export interface SubjectContiguousWhenRepeated extends ConstraintBase {
|
||||
subject_id: string
|
||||
}
|
||||
|
||||
export interface SubjectPreferredPeriod extends ConstraintBase {
|
||||
subject_id: string
|
||||
period_from: number
|
||||
period_to: number
|
||||
}
|
||||
|
||||
export interface SubjectDoubleLesson extends ConstraintBase {
|
||||
subject_id: string
|
||||
}
|
||||
|
||||
export interface ClassMaxHoursDay extends ConstraintBase {
|
||||
class_id: string
|
||||
max_hours: number
|
||||
}
|
||||
|
||||
export interface ClassNoGaps extends ConstraintBase {
|
||||
class_id: string
|
||||
}
|
||||
|
||||
export interface RoomRequiresType extends ConstraintBase {
|
||||
subject_id: string
|
||||
room_type: string
|
||||
}
|
||||
|
||||
export interface RoomUnavailable extends ConstraintBase {
|
||||
room_id: string
|
||||
day_of_week: number
|
||||
period_index: number
|
||||
}
|
||||
@@ -17,6 +17,7 @@ const NAV_LABELS: Record<string, Record<string, string>> = {
|
||||
nav_eltern: { de: 'Eltern', en: 'Parents', tr: 'Ebeveyn', ar: '\u0627\u0644\u0648\u0627\u0644\u062f\u064a\u0646', uk: '\u0411\u0430\u0442\u044c\u043a\u0438', ru: '\u0420\u043e\u0434\u0438\u0442\u0435\u043b\u0438', pl: 'Rodzice', fr: 'Parents', es: 'Padres', it: 'Genitori', pt: 'Pais', nl: 'Ouders', ro: 'Parinti', el: '\u0393\u03bf\u03bd\u03b5\u03af\u03c2', bg: '\u0420\u043e\u0434\u0438\u0442\u0435\u043b\u0438', hr: 'Roditelji', cs: 'Rodice', hu: 'Szulok', sv: 'Foraldrar', da: 'Foraeldre', fi: 'Vanhemmat', sk: 'Rodicia', sl: 'Starsi', lt: 'Tevai', lv: 'Vecaki', et: 'Vanemad' },
|
||||
nav_woerterbuch: { de: 'Woerterbuch', en: 'Dictionary', tr: 'Sozluk', ar: '\u0627\u0644\u0642\u0627\u0645\u0648\u0633', uk: '\u0421\u043b\u043e\u0432\u043d\u0438\u043a', ru: '\u0421\u043b\u043e\u0432\u0430\u0440\u044c', pl: 'Slownik', fr: 'Dictionnaire', es: 'Diccionario', it: 'Dizionario', pt: 'Dicionario', nl: 'Woordenboek', ro: 'Dictionar', el: '\u039b\u03b5\u03be\u03b9\u03ba\u03cc', bg: '\u0420\u0435\u0447\u043d\u0438\u043a', hr: 'Rjecnik', cs: 'Slovnik', hu: 'Szotar', sv: 'Ordbok', da: 'Ordbog', fi: 'Sanakirja', sk: 'Slovnik', sl: 'Slovar', lt: 'Zodynas', lv: 'Vardnica', et: 'Sonaraamat' },
|
||||
nav_meet: { de: 'Videokonferenz', en: 'Video Call', tr: 'Gorusme', ar: '\u0645\u0643\u0627\u0644\u0645\u0629', uk: '\u0412\u0456\u0434\u0435\u043e\u0434\u0437\u0432\u0456\u043d\u043e\u043a', ru: '\u0412\u0438\u0434\u0435\u043e\u0437\u0432\u043e\u043d\u043e\u043a', pl: 'Wideorozmowa', fr: 'Visioconference', es: 'Videollamada', it: 'Videochiamata', pt: 'Videochamada', nl: 'Videogesprek', ro: 'Videoconferinta', el: '\u0392\u03b9\u03bd\u03c4\u03b5\u03bf\u03ba\u03bb\u03ae\u03c3\u03b7', bg: '\u0412\u0438\u0434\u0435\u043e\u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440', hr: 'Videopoziv', cs: 'Videohovor', hu: 'Videohivas', sv: 'Videosamtal', da: 'Videoopkald', fi: 'Videopuhelu', sk: 'Videohovor', sl: 'Videoklic', lt: 'Vaizdo skambutis', lv: 'Videozvans', et: 'Videokoone' },
|
||||
nav_stundenplan: { de: 'Stundenplan', en: 'Timetable', tr: 'Ders Programi', ar: 'جدول حصص', uk: 'Розклад', ru: 'Расписание', pl: 'Plan lekcji', fr: 'Emploi du temps', es: 'Horario', it: 'Orario', pt: 'Horario', nl: 'Rooster', ro: 'Orar', el: 'Πρόγραμμα', bg: 'Разписание', hr: 'Raspored', cs: 'Rozvrh', hu: 'Orarend', sv: 'Schema', da: 'Skema', fi: 'Lukujarjestys', sk: 'Rozvrh', sl: 'Urnik', lt: 'Tvarkarastis', lv: 'Stundu saraksts', et: 'Tunniplaan' },
|
||||
nav_companion: { de: 'KI-Assistent', en: 'AI Assistant', tr: 'Yapay Zeka', ar: '\u0645\u0633\u0627\u0639\u062f \u0630\u0643\u064a', uk: '\u0428\u0406-\u0430\u0441\u0438\u0441\u0442\u0435\u043d\u0442', ru: '\u0418\u0418-\u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442', pl: 'Asystent AI', fr: 'Assistant IA', es: 'Asistente IA', it: 'Assistente IA', pt: 'Assistente IA', nl: 'AI-assistent', ro: 'Asistent AI', el: 'AI \u0392\u03bf\u03b7\u03b8\u03cc\u03c2', bg: 'AI \u0430\u0441\u0438\u0441\u0442\u0435\u043d\u0442', hr: 'AI pomoenik', cs: 'AI asistent', hu: 'AI asszisztens', sv: 'AI-assistent', da: 'AI-assistent', fi: 'Tekoalyavustaja', sk: 'AI asistent', sl: 'AI pomoenik', lt: 'DI asistentas', lv: 'MI paligs', et: 'Tehisabiabi' },
|
||||
}
|
||||
|
||||
@@ -105,6 +106,11 @@ export function Sidebar({ selectedTab = 'dashboard', onTabChange }: SidebarProps
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
)},
|
||||
{ id: 'stundenplan', labelKey: 'nav_stundenplan', href: '/stundenplan', icon: (
|
||||
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
||||
</svg>
|
||||
)},
|
||||
{ id: 'companion', labelKey: 'nav_companion', href: '/companion', icon: (
|
||||
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<circle cx="12" cy="12" r="9" strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} />
|
||||
@@ -151,6 +157,7 @@ export function Sidebar({ selectedTab = 'dashboard', onTabChange }: SidebarProps
|
||||
if (pathname === '/alerts-b2b') return 'alerts-b2b'
|
||||
if (pathname === '/messages') return 'messages'
|
||||
if (pathname?.startsWith('/korrektur')) return 'korrektur'
|
||||
if (pathname?.startsWith('/stundenplan')) return 'stundenplan'
|
||||
return selectedTab
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Stundenplan API client. All requests go through /api/school/* which proxies
|
||||
* to the school-service Gin server (port 8084). Auth token, if available, is
|
||||
* passed via Authorization: Bearer; for now no token = upstream 401.
|
||||
*/
|
||||
|
||||
import type {
|
||||
TimetableClass, TimetablePeriod, TimetableRoom, TimetableSubject,
|
||||
TimetableTeacher, TimetableCurriculum, TimetableAssignment,
|
||||
CreateTimetableClass, CreateTimetablePeriod, CreateTimetableRoom,
|
||||
CreateTimetableSubject, CreateTimetableTeacher,
|
||||
CreateTimetableCurriculum, CreateTimetableAssignment,
|
||||
TeacherUnavailableDay, TeacherUnavailableWindow, TeacherMaxHoursDay,
|
||||
TeacherMaxHoursWeek, TeacherExcludedSubject, TeacherExcludedRoom,
|
||||
SubjectMinDayGap, SubjectMaxConsecutive, SubjectContiguousWhenRepeated,
|
||||
SubjectPreferredPeriod, SubjectDoubleLesson,
|
||||
ClassMaxHoursDay, ClassNoGaps,
|
||||
RoomRequiresType, RoomUnavailable,
|
||||
} from '@/app/stundenplan/types'
|
||||
|
||||
const TOKEN_KEY = 'bp_stundenplan_jwt'
|
||||
|
||||
export function setStundenplanToken(token: string): void {
|
||||
if (typeof window !== 'undefined') localStorage.setItem(TOKEN_KEY, token)
|
||||
}
|
||||
|
||||
export function getStundenplanToken(): string {
|
||||
if (typeof window === 'undefined') return ''
|
||||
return localStorage.getItem(TOKEN_KEY) || ''
|
||||
}
|
||||
|
||||
async function apiFetch<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers as Record<string, string> | undefined),
|
||||
}
|
||||
const token = getStundenplanToken()
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`
|
||||
|
||||
const res = await fetch(`/api/school${endpoint}`, { ...options, headers })
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({ error: 'Unknown error' }))
|
||||
throw new Error(errData.error || errData.detail || `HTTP ${res.status}`)
|
||||
}
|
||||
if (res.status === 204) return undefined as T
|
||||
return res.json()
|
||||
}
|
||||
|
||||
// ---------- Stammdaten ----------
|
||||
|
||||
export const classesApi = {
|
||||
list: () => apiFetch<TimetableClass[]>('/timetable/classes'),
|
||||
create: (data: CreateTimetableClass) =>
|
||||
apiFetch<TimetableClass>('/timetable/classes', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/classes/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
export const periodsApi = {
|
||||
list: () => apiFetch<TimetablePeriod[]>('/timetable/periods'),
|
||||
create: (data: CreateTimetablePeriod) =>
|
||||
apiFetch<TimetablePeriod>('/timetable/periods', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/periods/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
export const roomsApi = {
|
||||
list: () => apiFetch<TimetableRoom[]>('/timetable/rooms'),
|
||||
create: (data: CreateTimetableRoom) =>
|
||||
apiFetch<TimetableRoom>('/timetable/rooms', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/rooms/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
export const subjectsApi = {
|
||||
list: () => apiFetch<TimetableSubject[]>('/timetable/subjects'),
|
||||
create: (data: CreateTimetableSubject) =>
|
||||
apiFetch<TimetableSubject>('/timetable/subjects', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/subjects/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
export const teachersApi = {
|
||||
list: () => apiFetch<TimetableTeacher[]>('/timetable/teachers'),
|
||||
create: (data: CreateTimetableTeacher) =>
|
||||
apiFetch<TimetableTeacher>('/timetable/teachers', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/teachers/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
export const curriculumApi = {
|
||||
list: () => apiFetch<TimetableCurriculum[]>('/timetable/curriculum'),
|
||||
create: (data: CreateTimetableCurriculum) =>
|
||||
apiFetch<TimetableCurriculum>('/timetable/curriculum', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/curriculum/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
export const assignmentsApi = {
|
||||
list: () => apiFetch<TimetableAssignment[]>('/timetable/assignments'),
|
||||
create: (data: CreateTimetableAssignment) =>
|
||||
apiFetch<TimetableAssignment>('/timetable/assignments', { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/assignments/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
|
||||
// ---------- Constraints ----------
|
||||
|
||||
/**
|
||||
* Factory that builds a list/create/remove triple for a constraint endpoint.
|
||||
* The 15 constraint tables share the same CRUD shape; only TItem differs.
|
||||
*/
|
||||
function constraintApi<TItem, TCreate>(path: string) {
|
||||
return {
|
||||
list: () => apiFetch<TItem[]>(`/timetable/constraints/${path}`),
|
||||
create: (data: TCreate) =>
|
||||
apiFetch<TItem>(`/timetable/constraints/${path}`, { method: 'POST', body: JSON.stringify(data) }),
|
||||
remove: (id: string) =>
|
||||
apiFetch<void>(`/timetable/constraints/${path}/${id}`, { method: 'DELETE' }),
|
||||
}
|
||||
}
|
||||
|
||||
export const teacherUnavailableDayApi = constraintApi<TeacherUnavailableDay, Omit<TeacherUnavailableDay, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/unavailable-day')
|
||||
export const teacherUnavailableWindowApi = constraintApi<TeacherUnavailableWindow, Omit<TeacherUnavailableWindow, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/unavailable-window')
|
||||
export const teacherMaxHoursDayApi = constraintApi<TeacherMaxHoursDay, Omit<TeacherMaxHoursDay, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/max-hours-day')
|
||||
export const teacherMaxHoursWeekApi = constraintApi<TeacherMaxHoursWeek, Omit<TeacherMaxHoursWeek, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/max-hours-week')
|
||||
export const teacherExcludedSubjectApi = constraintApi<TeacherExcludedSubject, Omit<TeacherExcludedSubject, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/excluded-subject')
|
||||
export const teacherExcludedRoomApi = constraintApi<TeacherExcludedRoom, Omit<TeacherExcludedRoom, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/excluded-room')
|
||||
|
||||
export const subjectMinDayGapApi = constraintApi<SubjectMinDayGap, Omit<SubjectMinDayGap, 'id' | 'created_by_user_id' | 'created_at'>>('subject/min-day-gap')
|
||||
export const subjectMaxConsecutiveApi = constraintApi<SubjectMaxConsecutive, Omit<SubjectMaxConsecutive, 'id' | 'created_by_user_id' | 'created_at'>>('subject/max-consecutive')
|
||||
export const subjectContiguousWhenRepeatedApi = constraintApi<SubjectContiguousWhenRepeated, Omit<SubjectContiguousWhenRepeated, 'id' | 'created_by_user_id' | 'created_at'>>('subject/contiguous-when-repeated')
|
||||
export const subjectPreferredPeriodApi = constraintApi<SubjectPreferredPeriod, Omit<SubjectPreferredPeriod, 'id' | 'created_by_user_id' | 'created_at'>>('subject/preferred-period')
|
||||
export const subjectDoubleLessonApi = constraintApi<SubjectDoubleLesson, Omit<SubjectDoubleLesson, 'id' | 'created_by_user_id' | 'created_at'>>('subject/double-lesson')
|
||||
|
||||
export const classMaxHoursDayApi = constraintApi<ClassMaxHoursDay, Omit<ClassMaxHoursDay, 'id' | 'created_by_user_id' | 'created_at'>>('class/max-hours-day')
|
||||
export const classNoGapsApi = constraintApi<ClassNoGaps, Omit<ClassNoGaps, 'id' | 'created_by_user_id' | 'created_at'>>('class/no-gaps')
|
||||
|
||||
export const roomRequiresTypeApi = constraintApi<RoomRequiresType, Omit<RoomRequiresType, 'id' | 'created_by_user_id' | 'created_at'>>('room/requires-type')
|
||||
export const roomUnavailableApi = constraintApi<RoomUnavailable, Omit<RoomUnavailable, 'id' | 'created_by_user_id' | 'created_at'>>('room/unavailable')
|
||||
Reference in New Issue
Block a user