Stundenplan Phase 3d: all 15 constraint editors via shared shell
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 29s
CI / test-python-klausur (push) Failing after 2m38s
CI / test-python-agent-core (push) Successful in 18s
CI / test-nodejs-website (push) Successful in 20s
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 29s
CI / test-python-klausur (push) Failing after 2m38s
CI / test-python-agent-core (push) Successful in 18s
CI / test-nodejs-website (push) Successful in 20s
Backend was already complete in Phase 2; this finishes the UI.
- regeln/_shell.tsx introduces useConstraintCrud (handles list/create/
delete state + reload), ConstraintShell (header, prereq banner,
form toggle, error display, empty/loading/table render), and
useShellStyles for the recurring theme tokens. Each editor now
only carries its schema-specific bits.
- Existing 4 editors (TeacherUnavailableDay/Window, SubjectMax
Consecutive/PreferredPeriod) refactored onto the shell — every
Playwright selector preserved.
- 11 new editors covering the remaining constraint tables:
TeacherMaxHours{Day,Week}, TeacherExcluded{Subject,Room},
Subject{MinDayGap,ContiguousWhenRepeated,DoubleLesson},
Class{MaxHoursDay,NoGaps},
Room{RequiresType,Unavailable}.
- RegelnHub now references all 15 editors directly — no more 'soon'
placeholders. The two duplicate 'Max. Stunden / Tag' entries
(teacher + class) are intentional and disambiguated by group.
Tests:
- e2e/stundenplan.spec.ts: mock routes added for all 11 new constraint
endpoints. RegelnHub suite gains a single test that switches
through 13 uniquely-labelled editors, plus a dedicated test for
the two duplicate 'Max. Stunden / Tag' labels.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,183 +1,99 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useTheme } from '@/lib/ThemeContext'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { teacherUnavailableWindowApi, teachersApi } from '@/lib/stundenplan/api'
|
||||
import type { TeacherUnavailableWindow, TimetableTeacher } from '@/app/stundenplan/types'
|
||||
|
||||
const DAYS = [
|
||||
{ v: 1, label: 'Montag' }, { v: 2, label: 'Dienstag' }, { v: 3, label: 'Mittwoch' },
|
||||
{ v: 4, label: 'Donnerstag' }, { v: 5, label: 'Freitag' }, { v: 6, label: 'Samstag' }, { v: 7, label: 'Sonntag' },
|
||||
]
|
||||
import { useConstraintCrud, ConstraintShell, useShellStyles, DAYS, dayLabel } from './_shell'
|
||||
|
||||
type FormState = Omit<TeacherUnavailableWindow, 'id' | 'created_by_user_id' | 'created_at'>
|
||||
|
||||
const initialForm: FormState = {
|
||||
teacher_id: '',
|
||||
day_of_week: 2,
|
||||
start_time: '13:00',
|
||||
end_time: '17:00',
|
||||
is_hard: true,
|
||||
weight: 100,
|
||||
active: true,
|
||||
note: '',
|
||||
teacher_id: '', day_of_week: 2, start_time: '13:00', end_time: '17:00',
|
||||
is_hard: true, weight: 100, active: true, note: '',
|
||||
}
|
||||
|
||||
export function TeacherUnavailableWindowEditor() {
|
||||
const { isDark } = useTheme()
|
||||
const [items, setItems] = useState<TeacherUnavailableWindow[]>([])
|
||||
const styles = useShellStyles()
|
||||
const crud = useConstraintCrud<TeacherUnavailableWindow, FormState>(teacherUnavailableWindowApi, initialForm)
|
||||
const [teachers, setTeachers] = useState<TimetableTeacher[]>([])
|
||||
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<FormState>(initialForm)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true); setError(null)
|
||||
try {
|
||||
const [rules, t] = await Promise.all([teacherUnavailableWindowApi.list(), teachersApi.list()])
|
||||
setItems(rules || [])
|
||||
setTeachers(t || [])
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Laden fehlgeschlagen')
|
||||
} finally { setLoading(false) }
|
||||
}, [])
|
||||
useEffect(() => { teachersApi.list().then(setTeachers).catch(() => setTeachers([])) }, [])
|
||||
|
||||
useEffect(() => { load() }, [load])
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setSubmitting(true); setError(null)
|
||||
try {
|
||||
await teacherUnavailableWindowApi.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('Regel wirklich loeschen?')) return
|
||||
try { await teacherUnavailableWindowApi.remove(id); await load() }
|
||||
catch (err) { setError(err instanceof Error ? err.message : 'Loeschen fehlgeschlagen') }
|
||||
}
|
||||
|
||||
const tLabel = (id: string): string => {
|
||||
const teacherLabel = (id: string): string => {
|
||||
const t = teachers.find(x => x.id === id)
|
||||
return t ? `${t.last_name}, ${t.first_name}` : id.slice(0, 8) + '…'
|
||||
}
|
||||
|
||||
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' : 'bg-white border-slate-300 text-slate-900'
|
||||
|
||||
return (
|
||||
<div className="space-y-4" data-testid="teacher-unavailable-window-editor">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className={`text-lg font-semibold ${isDark ? 'text-white' : 'text-slate-900'}`}>
|
||||
Lehrer: Zeitfenster nicht verfuegbar
|
||||
</h3>
|
||||
<p className={`text-sm ${isDark ? 'text-white/60' : 'text-slate-500'}`}>
|
||||
Beispiel: „Lehrer Z Dienstags 13:00–17:00 nicht".
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShowForm(s => !s)}
|
||||
disabled={teachers.length === 0}
|
||||
className={`px-4 py-2 rounded-xl font-medium transition-colors disabled:opacity-50 ${isDark ? 'bg-indigo-500 hover:bg-indigo-600 text-white' : 'bg-indigo-600 hover:bg-indigo-700 text-white'}`}
|
||||
>
|
||||
{showForm ? 'Abbrechen' : '+ Neue Regel'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{teachers.length === 0 && !loading && (
|
||||
<div className={`p-3 rounded-xl text-sm ${isDark ? 'bg-amber-500/10 border border-amber-500/30 text-amber-200' : 'bg-amber-50 border border-amber-200 text-amber-900'}`}>
|
||||
Zuerst Lehrer anlegen.
|
||||
</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}`}>
|
||||
<ConstraintShell
|
||||
testId="teacher-unavailable-window-editor"
|
||||
title="Lehrer: Zeitfenster nicht verfuegbar"
|
||||
description="Beispiel: „Lehrer Z Dienstags 13:00–17:00 nicht"."
|
||||
newLabel="+ Neue Regel"
|
||||
newDisabled={teachers.length === 0}
|
||||
prereqWarning={teachers.length === 0 ? 'Zuerst Lehrer anlegen.' : null}
|
||||
emptyText="Keine Regeln vorhanden."
|
||||
tableHeaders={['Lehrer', 'Tag', 'Zeitfenster', 'Hart', 'Notiz']}
|
||||
state={crud}
|
||||
formBody={
|
||||
<>
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Lehrer</label>
|
||||
<select required value={form.teacher_id} onChange={e => setForm({ ...form, teacher_id: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`}>
|
||||
<select required value={crud.form.teacher_id} onChange={e => crud.setForm({ ...crud.form, teacher_id: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`}>
|
||||
<option value="">— bitte waehlen —</option>
|
||||
{teachers.map(t => <option key={t.id} value={t.id}>{t.last_name}, {t.first_name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Wochentag</label>
|
||||
<select value={form.day_of_week} onChange={e => setForm({ ...form, day_of_week: parseInt(e.target.value) })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`}>
|
||||
<select value={crud.form.day_of_week} onChange={e => crud.setForm({ ...crud.form, day_of_week: parseInt(e.target.value) })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`}>
|
||||
{DAYS.map(d => <option key={d.v} value={d.v}>{d.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Von</label>
|
||||
<input type="time" required value={form.start_time} onChange={e => setForm({ ...form, start_time: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
||||
<input type="time" required value={crud.form.start_time} onChange={e => crud.setForm({ ...crud.form, start_time: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`} />
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Bis</label>
|
||||
<input type="time" required value={form.end_time} onChange={e => setForm({ ...form, end_time: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
||||
<input type="time" required value={crud.form.end_time} onChange={e => crud.setForm({ ...crud.form, end_time: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`} />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input type="checkbox" id="is_hard_w" checked={form.is_hard} onChange={e => setForm({ ...form, is_hard: e.target.checked })} className="w-5 h-5" />
|
||||
<input type="checkbox" id="is_hard_w" checked={crud.form.is_hard} onChange={e => crud.setForm({ ...crud.form, is_hard: e.target.checked })} className="w-5 h-5" />
|
||||
<label htmlFor="is_hard_w" className="text-sm">Harte Regel</label>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm mb-1 opacity-70">Weight (0-100)</label>
|
||||
<input type="number" min={0} max={100} value={form.weight} onChange={e => setForm({ ...form, weight: parseInt(e.target.value) || 0 })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
||||
<input type="number" min={0} max={100} value={crud.form.weight} onChange={e => crud.setForm({ ...crud.form, weight: parseInt(e.target.value) || 0 })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`} />
|
||||
</div>
|
||||
<div className="md:col-span-2 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 type="submit" disabled={crud.submitting} className={styles.submitBtn}>
|
||||
{crud.submitting ? 'Speichert...' : 'Anlegen'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<label className="block text-sm mb-1 opacity-70">Begruendung (optional)</label>
|
||||
<input value={form.note || ''} onChange={e => setForm({ ...form, note: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${inputClass}`} />
|
||||
<input value={crud.form.note || ''} onChange={e => crud.setForm({ ...crud.form, note: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`} />
|
||||
</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'}`}>Keine Regeln vorhanden.</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">Lehrer</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Tag</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Zeitfenster</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Hart</th>
|
||||
<th className="text-left px-4 py-3 text-sm font-medium opacity-70">Notiz</th>
|
||||
<th className="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.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">{tLabel(c.teacher_id)}</td>
|
||||
<td className="px-4 py-3">{DAYS.find(d => d.v === c.day_of_week)?.label || c.day_of_week}</td>
|
||||
<td className="px-4 py-3">{c.start_time}–{c.end_time}</td>
|
||||
<td className="px-4 py-3">{c.is_hard ? '✓' : '—'}</td>
|
||||
<td className="px-4 py-3 text-sm opacity-70">{c.note || '—'}</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>
|
||||
</>
|
||||
}
|
||||
renderRow={(item) => {
|
||||
const c = item as TeacherUnavailableWindow
|
||||
return (
|
||||
<tr key={c.id} className={styles.rowClass}>
|
||||
<td className="px-4 py-3 font-medium">{teacherLabel(c.teacher_id)}</td>
|
||||
<td className="px-4 py-3">{dayLabel(c.day_of_week)}</td>
|
||||
<td className="px-4 py-3">{c.start_time}–{c.end_time}</td>
|
||||
<td className="px-4 py-3">{c.is_hard ? '✓' : '—'}</td>
|
||||
<td className="px-4 py-3 text-sm opacity-70">{c.note || '—'}</td>
|
||||
<td className="px-4 py-3 text-right">
|
||||
<button onClick={() => crud.remove(c.id)} className={styles.deleteBtn}>Loeschen</button>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user