import type { Metadata } from 'next'; import Link from 'next/link'; import { erfordereBenutzer } from '@/lib/auth/rechte'; import { ausbildungenVonAusbilder } from '@/lib/repos/ausbildung'; import { inhalte } from '@/lib/inhalte'; import { ergebnisVon, staendeVon } from '@/lib/repos/kontrollen'; import { gesamtpunkte, zustandVon, type Zustand } from '@/lib/kontrollen/sicht'; import { verlauf } from '@/lib/kontrollen/bewertung'; import { alsZeitpunktText } from '@/lib/zeit'; import { kontrolleFreigeben, freigabeZurueck } from './aktionen'; export const metadata: Metadata = { title: 'Lernzielkontrollen' }; export const dynamic = 'force-dynamic'; const zustandsmarke: Record = { gesperrt: { text: 'nicht freigegeben', ton: 'neutral', zeichen: '○' }, freigegeben: { text: 'freigegeben', ton: 'warnung', zeichen: '▶' }, abgegeben: { text: 'abgegeben', ton: 'warnung', zeichen: '▲' }, korrigiert: { text: 'korrigiert', ton: 'gut', zeichen: '✓' }, }; export default async function KontrollenSeite() { const benutzer = await erfordereBenutzer(); const alle = inhalte(); if (benutzer.rolle === 'azubi') { const staende = staendeVon(benutzer.id); const zeilen = alle.kontrollen.map((inhalt) => { const stand = staende.get(inhalt.id); const zustand = zustandVon({ azubiId: benutzer.id, freigegebenAm: stand?.freigegebenAm ?? null, abgegebenAm: stand?.abgegebenAm ?? null, korrigiertAm: stand?.korrigiertAm ?? null, }); const ergebnis = stand && stand.korrigiertAm ? ergebnisVon(stand.id, inhalt) : null; return { inhalt, zustand, ergebnis, stand }; }); const korrigierte = zeilen .filter((z) => z.ergebnis) .map((z) => ({ titel: z.inhalt.titel, prozent: z.ergebnis!.prozent, note: z.ergebnis!.note })); const stand = verlauf(korrigierte); return (

Lernzielkontrollen

{alle.kontrollen.length} Kontrollen · {korrigierte.length} korrigiert {stand.anzahl > 0 ? ` · Schnitt ${stand.schnittProzent} %, Note ${zahl(stand.schnittNote)}` : ''}

Eine Kontrolle wird von deinem Ausbilder freigegeben. Vorher sind die Fragen nicht einsehbar – die Musterlösungen erst nach dem Absenden.

); } // --- Ausbilder --- const meine = ausbildungenVonAusbilder(benutzer.id); return (

Lernzielkontrollen

Freigeben, korrigieren, Ergebnisse ansehen.

{meine.length === 0 ? (

Noch kein Azubikonto. Jetzt eines anlegen.

) : ( meine.map(({ azubi }) => { const staende = staendeVon(azubi.id); return (

{azubi.name}

    {alle.kontrollen.map((inhalt) => { const stand = staende.get(inhalt.id); const zustand = zustandVon({ azubiId: azubi.id, freigegebenAm: stand?.freigegebenAm ?? null, abgegebenAm: stand?.abgegebenAm ?? null, korrigiertAm: stand?.korrigiertAm ?? null, }); const marke = zustandsmarke[zustand]; const ergebnis = stand && stand.abgegebenAm ? ergebnisVon(stand.id, inhalt) : null; return (
  • Woche {inhalt.woche} {inhalt.titel} {inhalt.fragen.length} Fragen · {gesamtpunkte(inhalt)} Punkte {stand?.abgegebenAm ? ` · abgegeben ${alsZeitpunktText(stand.abgegebenAm)}` : ''}
    {ergebnis && stand?.korrigiertAm ? ( {ergebnis.prozent} % · Note {ergebnis.note} ) : null} {marke.zeichen} {marke.text} {zustand === 'gesperrt' ? (
    ) : null} {zustand === 'freigegeben' ? (
    ) : null}
  • ); })}
); }) )}
); } function Zeileninhalt({ inhalt, marke, ergebnis, }: { inhalt: { id: string; woche: number; titel: string; fragen: { punkte: number }[] }; marke: { text: string; ton: string; zeichen: string }; ergebnis: { prozent: number; note: number } | null; }) { return ( <> Woche {inhalt.woche} {inhalt.titel} {inhalt.fragen.length} Fragen · {inhalt.fragen.reduce((s, f) => s + f.punkte, 0)} Punkte {ergebnis ? ( {ergebnis.prozent} % · Note {ergebnis.note} ) : null} {marke.zeichen} {marke.text} ); } function zahl(wert: number): string { return wert.toString().replace('.', ','); }