73636f76a2
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 30s
CI / test-go-edu-search (push) Successful in 30s
CI / test-python-klausur (push) Failing after 3m6s
CI / test-python-agent-core (push) Successful in 20s
CI / test-nodejs-website (push) Successful in 21s
Frontend additions in studio-v2:
- LehrerManager / FaecherManager / RaeumeManager — same CRUD pattern as
Klassen, with entity-specific form fields and table columns.
- regeln/TeacherUnavailableDayEditor — first constraint editor, joins
against teachersApi to render a readable name in the dropdown and
list. Falls back to a guidance banner when no teachers exist yet.
- page.tsx wires up the new tabs; data-testid attributes added across
managers so the Playwright suite can target them deterministically.
Tests:
- school-service: timetable_constraints_more_test.go fills the
remaining 9 constraint DTOs (TeacherMaxHoursDay/Week,
TeacherExcludedSubject/Room, SubjectMinDayGap,
SubjectContiguousWhenRepeated, SubjectDoubleLesson, ClassNoGaps,
RoomRequiresType). 66 subtests total, all green.
- studio-v2: e2e/stundenplan.spec.ts covers the page shell, tab
navigation, Klassen CRUD with mocked backend, constraint editor's
empty-teacher fallback, sidebar entry. All school-service calls
intercepted via page.route() so the suite is hermetic.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
144 lines
6.7 KiB
TypeScript
144 lines
6.7 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
import { useTheme } from '@/lib/ThemeContext'
|
|
import { roomsApi } from '@/lib/stundenplan/api'
|
|
import type { TimetableRoom, CreateTimetableRoom } from '@/app/stundenplan/types'
|
|
|
|
const initialForm: CreateTimetableRoom = {
|
|
name: '',
|
|
room_type: '',
|
|
capacity: 30,
|
|
floor_level: 0,
|
|
has_elevator: true,
|
|
notes: '',
|
|
}
|
|
|
|
export function RaeumeManager() {
|
|
const { isDark } = useTheme()
|
|
const [items, setItems] = useState<TimetableRoom[]>([])
|
|
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<CreateTimetableRoom>(initialForm)
|
|
|
|
const load = useCallback(async () => {
|
|
setLoading(true); setError(null)
|
|
try {
|
|
const data = await roomsApi.list()
|
|
setItems(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 roomsApi.create(form)
|
|
setForm(initialForm)
|
|
setShowForm(false)
|
|
await load()
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : 'Anlegen fehlgeschlagen')
|
|
} finally { setSubmitting(false) }
|
|
}
|
|
|
|
const handleDelete = async (id: string) => {
|
|
if (!confirm('Raum wirklich loeschen?')) return
|
|
try {
|
|
await roomsApi.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" data-testid="raeume-manager">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className={`text-xl font-semibold ${isDark ? 'text-white' : 'text-slate-900'}`}>Raeume ({items.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' : '+ Neuer Raum'}
|
|
</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-3 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. A101" className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm mb-1 opacity-70">Typ</label>
|
|
<input value={form.room_type || ''} onChange={e => setForm({ ...form, room_type: e.target.value })} placeholder="z.B. Sporthalle, Chemie" className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm mb-1 opacity-70">Kapazitaet</label>
|
|
<input type="number" min={0} value={form.capacity ?? 30} onChange={e => setForm({ ...form, capacity: 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">Stockwerk</label>
|
|
<input type="number" value={form.floor_level ?? 0} onChange={e => setForm({ ...form, floor_level: parseInt(e.target.value) || 0 })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<input type="checkbox" id="has_elevator" checked={!!form.has_elevator} onChange={e => setForm({ ...form, has_elevator: e.target.checked })} className="w-5 h-5" />
|
|
<label htmlFor="has_elevator" className="text-sm">Aufzug erreichbar</label>
|
|
</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>
|
|
</form>
|
|
)}
|
|
|
|
{loading ? (
|
|
<div className={`text-center py-8 opacity-60 ${isDark ? 'text-white' : 'text-slate-700'}`}>Laedt…</div>
|
|
) : items.length === 0 ? (
|
|
<div className={`text-center py-8 opacity-60 ${isDark ? 'text-white' : 'text-slate-700'}`}>Noch keine Raeume 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">Typ</th>
|
|
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Kapazitaet</th>
|
|
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Stockwerk</th>
|
|
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Aufzug</th>
|
|
<th className="px-4 py-3"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{items.map(r => (
|
|
<tr key={r.id} className={isDark ? 'border-t border-white/10' : 'border-t border-slate-200'}>
|
|
<td className="px-4 py-3 font-medium">{r.name}</td>
|
|
<td className="px-4 py-3">{r.room_type || '—'}</td>
|
|
<td className="px-4 py-3">{r.capacity}</td>
|
|
<td className="px-4 py-3">{r.floor_level}</td>
|
|
<td className="px-4 py-3">{r.has_elevator ? 'Ja' : 'Nein'}</td>
|
|
<td className="px-4 py-3 text-right">
|
|
<button onClick={() => handleDelete(r.id)} className="text-red-400 hover:text-red-300 text-sm">Loeschen</button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|