7c96d89927
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>
82 lines
4.0 KiB
TypeScript
82 lines
4.0 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import { subjectMaxConsecutiveApi, subjectsApi } from '@/lib/stundenplan/api'
|
|
import type { SubjectMaxConsecutive, TimetableSubject } from '@/app/stundenplan/types'
|
|
import { useConstraintCrud, ConstraintShell, useShellStyles } from './_shell'
|
|
|
|
type FormState = Omit<SubjectMaxConsecutive, 'id' | 'created_by_user_id' | 'created_at'>
|
|
|
|
const initialForm: FormState = {
|
|
subject_id: '', max_consecutive: 2, is_hard: true, weight: 100, active: true, note: '',
|
|
}
|
|
|
|
export function SubjectMaxConsecutiveEditor() {
|
|
const styles = useShellStyles()
|
|
const crud = useConstraintCrud<SubjectMaxConsecutive, FormState>(subjectMaxConsecutiveApi, initialForm)
|
|
const [subjects, setSubjects] = useState<TimetableSubject[]>([])
|
|
|
|
useEffect(() => { subjectsApi.list().then(setSubjects).catch(() => setSubjects([])) }, [])
|
|
|
|
const sLabel = (id: string): string => {
|
|
const s = subjects.find(x => x.id === id)
|
|
return s ? `${s.name} (${s.short_code})` : id.slice(0, 8) + '…'
|
|
}
|
|
|
|
return (
|
|
<ConstraintShell
|
|
testId="subject-max-consecutive-editor"
|
|
title="Fach: Max. Stunden am Stueck"
|
|
description="Beispiel: „Mathe nicht mehr als 2 Stunden am Stueck" (keine Dreifach-Stunde)."
|
|
newLabel="+ Neue Regel"
|
|
newDisabled={subjects.length === 0}
|
|
prereqWarning={subjects.length === 0 ? 'Zuerst Faecher anlegen.' : null}
|
|
emptyText="Keine Regeln vorhanden."
|
|
tableHeaders={['Fach', 'Max. Stunden', 'Hart', 'Weight']}
|
|
state={crud}
|
|
formBody={
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-3">
|
|
<div>
|
|
<label className="block text-sm mb-1 opacity-70">Fach</label>
|
|
<select required value={crud.form.subject_id} onChange={e => crud.setForm({ ...crud.form, subject_id: e.target.value })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`}>
|
|
<option value="">— bitte waehlen —</option>
|
|
{subjects.map(s => <option key={s.id} value={s.id}>{s.name}</option>)}
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm mb-1 opacity-70">Max. Stunden (1-5)</label>
|
|
<input type="number" min={1} max={5} required value={crud.form.max_consecutive} onChange={e => crud.setForm({ ...crud.form, max_consecutive: parseInt(e.target.value) || 1 })} 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_mc" 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_mc" 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={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={crud.submitting} className={styles.submitBtn}>
|
|
{crud.submitting ? 'Speichert...' : 'Anlegen'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
renderRow={(item) => {
|
|
const c = item as SubjectMaxConsecutive
|
|
return (
|
|
<tr key={c.id} className={styles.rowClass}>
|
|
<td className="px-4 py-3 font-medium">{sLabel(c.subject_id)}</td>
|
|
<td className="px-4 py-3">{c.max_consecutive}</td>
|
|
<td className="px-4 py-3">{c.is_hard ? '✓' : '—'}</td>
|
|
<td className="px-4 py-3">{c.weight}</td>
|
|
<td className="px-4 py-3 text-right">
|
|
<button onClick={() => crud.remove(c.id)} className={styles.deleteBtn}>Loeschen</button>
|
|
</td>
|
|
</tr>
|
|
)
|
|
}}
|
|
/>
|
|
)
|
|
}
|