fix: Restore all files lost during destructive rebase

A previous `git pull --rebase origin main` dropped 177 local commits,
losing 3400+ files across admin-v2, backend, studio-v2, website,
klausur-service, and many other services. The partial restore attempt
(660295e2) only recovered some files.

This commit restores all missing files from pre-rebase ref 98933f5e
while preserving post-rebase additions (night-scheduler, night-mode UI,
NightModeWidget dashboard integration).

Restored features include:
- AI Module Sidebar (FAB), OCR Labeling, OCR Compare
- GPU Dashboard, RAG Pipeline, Magic Help
- Klausur-Korrektur (8 files), Abitur-Archiv (5+ files)
- Companion, Zeugnisse-Crawler, Screen Flow
- Full backend, studio-v2, website, klausur-service
- All compliance SDKs, agent-core, voice-service
- CI/CD configs, documentation, scripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-02-09 09:51:32 +01:00
parent f7487ee240
commit 21a844cb8a
1986 changed files with 744143 additions and 1731 deletions

View File

@@ -0,0 +1,492 @@
'use client'
import { useState, useEffect, useCallback } from 'react'
import { useRouter, useParams } from 'next/navigation'
import { useTheme } from '@/lib/ThemeContext'
import { Sidebar } from '@/components/Sidebar'
import { ThemeToggle } from '@/components/ThemeToggle'
import { LanguageDropdown } from '@/components/LanguageDropdown'
import {
DocumentViewer,
AnnotationLayer,
AnnotationToolbar,
AnnotationLegend,
CriteriaPanel,
GutachtenEditor,
EHSuggestionPanel,
} from '@/components/korrektur'
import { korrekturApi } from '@/lib/korrektur/api'
import type {
Klausur,
StudentWork,
Annotation,
AnnotationType,
AnnotationPosition,
CriteriaScores,
EHSuggestion,
} from '../../types'
// =============================================================================
// GLASS CARD
// =============================================================================
interface GlassCardProps {
children: React.ReactNode
className?: string
}
function GlassCard({ children, className = '' }: GlassCardProps) {
return (
<div
className={`rounded-3xl p-4 ${className}`}
style={{
background: 'rgba(255, 255, 255, 0.08)',
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
border: '1px solid rgba(255, 255, 255, 0.1)',
boxShadow: '0 4px 24px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.05)',
}}
>
{children}
</div>
)
}
// =============================================================================
// MAIN PAGE
// =============================================================================
export default function StudentWorkspacePage() {
const { isDark } = useTheme()
const router = useRouter()
const params = useParams()
const klausurId = params.klausurId as string
const studentId = params.studentId as string
// State
const [klausur, setKlausur] = useState<Klausur | null>(null)
const [student, setStudent] = useState<StudentWork | null>(null)
const [students, setStudents] = useState<StudentWork[]>([])
const [annotations, setAnnotations] = useState<Annotation[]>([])
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
// Editor state
const [currentPage, setCurrentPage] = useState(1)
const [totalPages, setTotalPages] = useState(1)
const [selectedTool, setSelectedTool] = useState<AnnotationType | null>(null)
const [selectedAnnotation, setSelectedAnnotation] = useState<string | null>(null)
const [activeTab, setActiveTab] = useState<'kriterien' | 'gutachten' | 'eh'>('kriterien')
// Criteria and Gutachten state
const [criteriaScores, setCriteriaScores] = useState<CriteriaScores>({})
const [gutachten, setGutachten] = useState('')
const [isGeneratingGutachten, setIsGeneratingGutachten] = useState(false)
// EH Suggestions state
const [ehSuggestions, setEhSuggestions] = useState<EHSuggestion[]>([])
const [isLoadingEH, setIsLoadingEH] = useState(false)
// Saving state
const [isSaving, setIsSaving] = useState(false)
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false)
// Load data
const loadData = useCallback(async () => {
if (!klausurId || !studentId) return
setIsLoading(true)
setError(null)
try {
const [klausurData, studentData, studentsData, annotationsData] = await Promise.all([
korrekturApi.getKlausur(klausurId),
korrekturApi.getStudent(studentId),
korrekturApi.getStudents(klausurId),
korrekturApi.getAnnotations(studentId),
])
setKlausur(klausurData)
setStudent(studentData)
setStudents(studentsData)
setAnnotations(annotationsData)
// Initialize editor state from student data
setCriteriaScores(studentData.criteria_scores || {})
setGutachten(studentData.gutachten || '')
// Estimate total pages (for images, usually 1; for PDFs, would need backend info)
setTotalPages(studentData.file_type === 'pdf' ? 5 : 1)
} catch (err) {
console.error('Failed to load data:', err)
setError(err instanceof Error ? err.message : 'Laden fehlgeschlagen')
} finally {
setIsLoading(false)
}
}, [klausurId, studentId])
useEffect(() => {
loadData()
}, [loadData])
// Get current student index
const currentIndex = students.findIndex((s) => s.id === studentId)
const prevStudent = currentIndex > 0 ? students[currentIndex - 1] : null
const nextStudent = currentIndex < students.length - 1 ? students[currentIndex + 1] : null
// Navigation
const goToStudent = (id: string) => {
if (hasUnsavedChanges) {
if (!confirm('Sie haben ungespeicherte Aenderungen. Trotzdem wechseln?')) {
return
}
}
router.push(`/korrektur/${klausurId}/${id}`)
}
// Handle criteria change
const handleCriteriaChange = (criterion: string, value: number) => {
setCriteriaScores((prev) => ({
...prev,
[criterion]: value,
}))
setHasUnsavedChanges(true)
}
// Handle gutachten change
const handleGutachtenChange = (value: string) => {
setGutachten(value)
setHasUnsavedChanges(true)
}
// Generate gutachten
const handleGenerateGutachten = async () => {
setIsGeneratingGutachten(true)
try {
const result = await korrekturApi.generateGutachten(studentId)
setGutachten(result.gutachten)
setHasUnsavedChanges(true)
} catch (err) {
console.error('Failed to generate gutachten:', err)
setError('Gutachten-Generierung fehlgeschlagen')
} finally {
setIsGeneratingGutachten(false)
}
}
// Load EH suggestions
const handleLoadEHSuggestions = async (criterion?: string) => {
setIsLoadingEH(true)
try {
const suggestions = await korrekturApi.getEHSuggestions(studentId, criterion)
setEhSuggestions(suggestions)
} catch (err) {
console.error('Failed to load EH suggestions:', err)
setError('EH-Vorschlaege konnten nicht geladen werden')
} finally {
setIsLoadingEH(false)
}
}
// Create annotation
const handleAnnotationCreate = async (position: AnnotationPosition, type: AnnotationType) => {
try {
const newAnnotation = await korrekturApi.createAnnotation(studentId, {
page: currentPage,
position,
type,
text: '',
severity: 'minor',
})
setAnnotations((prev) => [...prev, newAnnotation])
setSelectedAnnotation(newAnnotation.id)
setSelectedTool(null)
} catch (err) {
console.error('Failed to create annotation:', err)
}
}
// Delete annotation
const handleAnnotationDelete = async (id: string) => {
try {
await korrekturApi.deleteAnnotation(id)
setAnnotations((prev) => prev.filter((a) => a.id !== id))
setSelectedAnnotation(null)
} catch (err) {
console.error('Failed to delete annotation:', err)
}
}
// Save all changes
const handleSave = async () => {
setIsSaving(true)
try {
await Promise.all([
korrekturApi.updateCriteria(studentId, criteriaScores),
korrekturApi.updateGutachten(studentId, gutachten),
])
setHasUnsavedChanges(false)
} catch (err) {
console.error('Failed to save:', err)
setError('Speichern fehlgeschlagen')
} finally {
setIsSaving(false)
}
}
// Insert EH suggestion into gutachten
const handleInsertSuggestion = (text: string) => {
setGutachten((prev) => prev + '\n\n' + text)
setHasUnsavedChanges(true)
setActiveTab('gutachten')
}
// Keyboard shortcuts
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
// Don't trigger shortcuts when typing in inputs
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
return
}
if (e.key === 'Escape') {
setSelectedTool(null)
setSelectedAnnotation(null)
} else if (e.key === 'r' || e.key === 'R') {
setSelectedTool('rechtschreibung')
} else if (e.key === 'g' || e.key === 'G') {
setSelectedTool('grammatik')
} else if (e.key === 'i' || e.key === 'I') {
setSelectedTool('inhalt')
} else if (e.key === 's' && e.metaKey) {
e.preventDefault()
handleSave()
}
}
window.addEventListener('keydown', handleKeyDown)
return () => window.removeEventListener('keydown', handleKeyDown)
}, [criteriaScores, gutachten])
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-900 via-purple-900/30 to-slate-900">
<div className="w-12 h-12 border-4 border-purple-500 border-t-transparent rounded-full animate-spin" />
</div>
)
}
return (
<div className="min-h-screen flex relative overflow-hidden bg-gradient-to-br from-slate-900 via-purple-900/30 to-slate-900">
{/* Animated Background Blobs */}
<div className="absolute -top-40 -right-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob bg-purple-500 opacity-30" />
<div className="absolute top-1/2 -left-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-2000 bg-blue-500 opacity-30" />
{/* Sidebar */}
<div className="relative z-10 p-4">
<Sidebar />
</div>
{/* Main Content */}
<div className="flex-1 flex flex-col relative z-10 p-4 overflow-hidden">
{/* Header */}
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-4">
<button
onClick={() => router.push(`/korrektur/${klausurId}`)}
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-colors"
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
</button>
<div>
<h1 className="text-xl font-bold text-white">
{student?.anonym_id || 'Student'}
</h1>
<p className="text-white/50 text-sm">{klausur?.title}</p>
</div>
</div>
{/* Navigation */}
<div className="flex items-center gap-2">
<button
onClick={() => prevStudent && goToStudent(prevStudent.id)}
disabled={!prevStudent}
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-colors disabled:opacity-30"
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 19l-7-7 7-7" />
</svg>
</button>
<span className="text-white/60 text-sm px-3">
{currentIndex + 1} / {students.length}
</span>
<button
onClick={() => nextStudent && goToStudent(nextStudent.id)}
disabled={!nextStudent}
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-colors disabled:opacity-30"
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
</button>
</div>
<div className="flex items-center gap-3">
{hasUnsavedChanges && (
<span className="text-amber-400 text-sm">Ungespeicherte Aenderungen</span>
)}
<button
onClick={handleSave}
disabled={isSaving || !hasUnsavedChanges}
className="px-4 py-2 rounded-xl bg-gradient-to-r from-green-500 to-emerald-500 text-white font-medium hover:shadow-lg hover:shadow-green-500/30 transition-all disabled:opacity-50 flex items-center gap-2"
>
{isSaving ? (
<>
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
Speichern...
</>
) : (
<>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
Speichern
</>
)}
</button>
<ThemeToggle />
<LanguageDropdown />
</div>
</div>
{/* Error Display */}
{error && (
<GlassCard className="mb-4">
<div className="flex items-center gap-3 text-red-400">
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span className="text-sm">{error}</span>
<button
onClick={() => setError(null)}
className="ml-auto text-white/60 hover:text-white"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</GlassCard>
)}
{/* Main Workspace - 2/3 - 1/3 Layout */}
<div className="flex-1 flex gap-4 overflow-hidden">
{/* Left: Document Viewer (2/3) */}
<div className="w-2/3 flex flex-col">
<GlassCard className="flex-1 flex flex-col overflow-hidden">
<DocumentViewer
fileUrl={korrekturApi.getStudentFileUrl(studentId)}
fileType={student?.file_type || 'image'}
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
>
<AnnotationLayer
annotations={annotations.filter((a) => a.page === currentPage)}
selectedAnnotation={selectedAnnotation}
currentTool={selectedTool}
onAnnotationCreate={handleAnnotationCreate}
onAnnotationSelect={setSelectedAnnotation}
onAnnotationDelete={handleAnnotationDelete}
/>
</DocumentViewer>
</GlassCard>
{/* Annotation Toolbar */}
<div className="mt-3 flex items-center justify-between">
<AnnotationToolbar
selectedTool={selectedTool}
onToolSelect={setSelectedTool}
/>
<AnnotationLegend className="hidden lg:flex" />
</div>
</div>
{/* Right: Criteria/Gutachten Panel (1/3) */}
<div className="w-1/3 flex flex-col">
<GlassCard className="flex-1 flex flex-col overflow-hidden">
{/* Tabs */}
<div className="flex border-b border-white/10 mb-4">
<button
onClick={() => setActiveTab('kriterien')}
className={`flex-1 py-2 text-sm font-medium transition-colors ${
activeTab === 'kriterien'
? 'text-white border-b-2 border-purple-500'
: 'text-white/50 hover:text-white'
}`}
>
Kriterien
</button>
<button
onClick={() => setActiveTab('gutachten')}
className={`flex-1 py-2 text-sm font-medium transition-colors ${
activeTab === 'gutachten'
? 'text-white border-b-2 border-purple-500'
: 'text-white/50 hover:text-white'
}`}
>
Gutachten
</button>
<button
onClick={() => setActiveTab('eh')}
className={`flex-1 py-2 text-sm font-medium transition-colors ${
activeTab === 'eh'
? 'text-white border-b-2 border-purple-500'
: 'text-white/50 hover:text-white'
}`}
>
EH
</button>
</div>
{/* Tab Content */}
<div className="flex-1 overflow-y-auto">
{activeTab === 'kriterien' && (
<CriteriaPanel
scores={criteriaScores}
annotations={annotations}
onScoreChange={handleCriteriaChange}
onLoadEHSuggestions={(criterion) => {
handleLoadEHSuggestions(criterion)
setActiveTab('eh')
}}
/>
)}
{activeTab === 'gutachten' && (
<GutachtenEditor
value={gutachten}
onChange={handleGutachtenChange}
onGenerate={handleGenerateGutachten}
isGenerating={isGeneratingGutachten}
/>
)}
{activeTab === 'eh' && (
<EHSuggestionPanel
suggestions={ehSuggestions}
isLoading={isLoadingEH}
onLoadSuggestions={handleLoadEHSuggestions}
onInsertSuggestion={handleInsertSuggestion}
/>
)}
</div>
</GlassCard>
</div>
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,569 @@
'use client'
import { useState, useEffect, useCallback, useMemo } from 'react'
import { useRouter, useParams } from 'next/navigation'
import { useTheme } from '@/lib/ThemeContext'
import { Sidebar } from '@/components/Sidebar'
import { ThemeToggle } from '@/components/ThemeToggle'
import { LanguageDropdown } from '@/components/LanguageDropdown'
import { korrekturApi } from '@/lib/korrektur/api'
import type { Klausur, StudentWork, FairnessAnalysis } from '../../types'
import { DEFAULT_CRITERIA, ANNOTATION_COLORS, getGradeLabel } from '../../types'
// =============================================================================
// GLASS CARD
// =============================================================================
interface GlassCardProps {
children: React.ReactNode
className?: string
delay?: number
isDark?: boolean
}
function GlassCard({ children, className = '', delay = 0, isDark = true }: GlassCardProps) {
const [isVisible, setIsVisible] = useState(false)
useEffect(() => {
const timer = setTimeout(() => setIsVisible(true), delay)
return () => clearTimeout(timer)
}, [delay])
return (
<div
className={`rounded-3xl p-5 ${className}`}
style={{
background: isDark ? 'rgba(255, 255, 255, 0.08)' : 'rgba(255, 255, 255, 0.7)',
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
border: isDark ? '1px solid rgba(255, 255, 255, 0.1)' : '1px solid rgba(0, 0, 0, 0.1)',
boxShadow: isDark
? '0 4px 24px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.05)'
: '0 4px 24px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.5)',
opacity: isVisible ? 1 : 0,
transform: isVisible ? 'translateY(0)' : 'translateY(20px)',
transition: 'all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)',
}}
>
{children}
</div>
)
}
// =============================================================================
// HISTOGRAM
// =============================================================================
interface HistogramProps {
students: StudentWork[]
className?: string
isDark?: boolean
}
function Histogram({ students, className = '', isDark = true }: HistogramProps) {
// Group students by grade points (0-15)
const distribution = useMemo(() => {
const counts: Record<number, number> = {}
for (let i = 0; i <= 15; i++) {
counts[i] = 0
}
for (const student of students) {
if (student.grade_points !== undefined) {
counts[student.grade_points] = (counts[student.grade_points] || 0) + 1
}
}
return counts
}, [students])
const maxCount = Math.max(...Object.values(distribution), 1)
return (
<div className={className}>
<h3 className={`font-semibold mb-4 ${isDark ? 'text-white' : 'text-slate-900'}`}>Notenverteilung</h3>
<div className="flex items-end gap-1 h-40">
{Array.from({ length: 16 }, (_, i) => 15 - i).map((grade) => {
const count = distribution[grade] || 0
const height = (count / maxCount) * 100
// Color based on grade
let color = '#22c55e' // Green for good grades
if (grade <= 4) color = '#ef4444' // Red for poor grades
else if (grade <= 9) color = '#f97316' // Orange for medium grades
return (
<div
key={grade}
className="flex-1 flex flex-col items-center gap-1"
>
<span className={`text-xs ${isDark ? 'text-white/40' : 'text-slate-400'}`}>{count || ''}</span>
<div
className="w-full rounded-t transition-all hover:opacity-80"
style={{
height: `${height}%`,
minHeight: count > 0 ? '8px' : '0',
backgroundColor: color,
}}
title={`${grade} Punkte (${getGradeLabel(grade)}): ${count} Schueler`}
/>
<span className={`text-xs ${isDark ? 'text-white/50' : 'text-slate-500'}`}>{grade}</span>
</div>
)
})}
</div>
<p className={`text-xs text-center mt-2 ${isDark ? 'text-white/40' : 'text-slate-400'}`}>Punkte</p>
</div>
)
}
// =============================================================================
// CRITERIA HEATMAP
// =============================================================================
interface CriteriaHeatmapProps {
students: StudentWork[]
className?: string
isDark?: boolean
}
function CriteriaHeatmap({ students, className = '', isDark = true }: CriteriaHeatmapProps) {
// Calculate average for each criterion
const criteriaAverages = useMemo(() => {
const sums: Record<string, { sum: number; count: number }> = {}
for (const criterion of Object.keys(DEFAULT_CRITERIA)) {
sums[criterion] = { sum: 0, count: 0 }
}
for (const student of students) {
if (student.criteria_scores) {
for (const [criterion, score] of Object.entries(student.criteria_scores)) {
if (score !== undefined && sums[criterion]) {
sums[criterion].sum += score
sums[criterion].count += 1
}
}
}
}
const averages: Record<string, number> = {}
for (const [criterion, data] of Object.entries(sums)) {
averages[criterion] = data.count > 0 ? Math.round(data.sum / data.count) : 0
}
return averages
}, [students])
return (
<div className={className}>
<h3 className={`font-semibold mb-4 ${isDark ? 'text-white' : 'text-slate-900'}`}>Kriterien-Durchschnitt</h3>
<div className="space-y-3">
{Object.entries(DEFAULT_CRITERIA).map(([criterion, config]) => {
const average = criteriaAverages[criterion] || 0
const color = ANNOTATION_COLORS[criterion as keyof typeof ANNOTATION_COLORS] || '#6b7280'
return (
<div key={criterion} className="space-y-1">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div
className="w-3 h-3 rounded-full"
style={{ backgroundColor: color }}
/>
<span className={`text-sm ${isDark ? 'text-white/70' : 'text-slate-600'}`}>{config.name}</span>
</div>
<span className={`text-sm font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>{average}%</span>
</div>
<div className={`h-2 rounded-full overflow-hidden ${isDark ? 'bg-white/10' : 'bg-slate-200'}`}>
<div
className="h-full rounded-full transition-all"
style={{
width: `${average}%`,
backgroundColor: color,
}}
/>
</div>
</div>
)
})}
</div>
</div>
)
}
// =============================================================================
// OUTLIER LIST
// =============================================================================
interface OutlierListProps {
fairness: FairnessAnalysis | null
onStudentClick: (studentId: string) => void
className?: string
isDark?: boolean
}
function OutlierList({ fairness, onStudentClick, className = '', isDark = true }: OutlierListProps) {
if (!fairness || fairness.outliers.length === 0) {
return (
<div className={`text-center py-8 ${className}`}>
<div className="w-12 h-12 rounded-full bg-green-500/20 flex items-center justify-center mx-auto mb-3">
<svg className="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
</div>
<p className={`text-sm ${isDark ? 'text-white/60' : 'text-slate-600'}`}>Keine Ausreisser erkannt</p>
<p className={`text-xs mt-1 ${isDark ? 'text-white/40' : 'text-slate-400'}`}>Alle Bewertungen sind konsistent</p>
</div>
)
}
return (
<div className={className}>
<h3 className={`font-semibold mb-4 ${isDark ? 'text-white' : 'text-slate-900'}`}>
Ausreisser ({fairness.outliers.length})
</h3>
<div className="space-y-2 max-h-64 overflow-y-auto">
{fairness.outliers.map((outlier) => (
<button
key={outlier.student_id}
onClick={() => onStudentClick(outlier.student_id)}
className={`w-full p-3 rounded-xl border transition-colors text-left ${isDark ? 'bg-white/5 border-white/10 hover:bg-white/10' : 'bg-slate-100 border-slate-200 hover:bg-slate-200'}`}
>
<div className="flex items-center justify-between mb-1">
<span className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>{outlier.anonym_id}</span>
<span
className={`px-2 py-0.5 rounded-full text-xs font-medium ${
outlier.deviation > 0
? 'bg-green-500/20 text-green-400'
: 'bg-red-500/20 text-red-400'
}`}
>
{outlier.deviation > 0 ? '+' : ''}{outlier.deviation.toFixed(1)} Punkte
</span>
</div>
<div className="flex items-center justify-between">
<span className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>
{outlier.grade_points} Punkte ({getGradeLabel(outlier.grade_points)})
</span>
<span className={`text-xs ${isDark ? 'text-white/40' : 'text-slate-400'}`}>{outlier.reason}</span>
</div>
</button>
))}
</div>
</div>
)
}
// =============================================================================
// FAIRNESS SCORE
// =============================================================================
interface FairnessScoreProps {
fairness: FairnessAnalysis | null
className?: string
isDark?: boolean
}
function FairnessScore({ fairness, className = '', isDark = true }: FairnessScoreProps) {
const score = fairness?.fairness_score || 0
const percentage = Math.round(score * 100)
let color = '#22c55e' // Green
let label = 'Ausgezeichnet'
if (percentage < 70) {
color = '#ef4444'
label = 'Ueberpruefung empfohlen'
} else if (percentage < 85) {
color = '#f97316'
label = 'Akzeptabel'
} else if (percentage < 95) {
color = '#22c55e'
label = 'Gut'
}
// SVG ring
const size = 120
const strokeWidth = 10
const radius = (size - strokeWidth) / 2
const circumference = radius * 2 * Math.PI
const offset = circumference - (percentage / 100) * circumference
return (
<div className={`text-center ${className}`}>
<div className="relative inline-block" style={{ width: size, height: size }}>
<svg className="transform -rotate-90" width={size} height={size}>
<circle
cx={size / 2}
cy={size / 2}
r={radius}
fill="none"
stroke={isDark ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)'}
strokeWidth={strokeWidth}
/>
<circle
cx={size / 2}
cy={size / 2}
r={radius}
fill="none"
stroke={color}
strokeWidth={strokeWidth}
strokeDasharray={circumference}
strokeDashoffset={offset}
strokeLinecap="round"
style={{ transition: 'stroke-dashoffset 1s ease-out' }}
/>
</svg>
<div className="absolute inset-0 flex flex-col items-center justify-center">
<span className={`text-3xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>{percentage}</span>
<span className={`text-xs ${isDark ? 'text-white/40' : 'text-slate-400'}`}>%</span>
</div>
</div>
<p className={`font-medium mt-3 ${isDark ? 'text-white' : 'text-slate-900'}`}>{label}</p>
<p className={`text-xs mt-1 ${isDark ? 'text-white/40' : 'text-slate-400'}`}>Fairness-Score</p>
</div>
)
}
// =============================================================================
// MAIN PAGE
// =============================================================================
export default function FairnessPage() {
const { isDark } = useTheme()
const router = useRouter()
const params = useParams()
const klausurId = params.klausurId as string
// State
const [klausur, setKlausur] = useState<Klausur | null>(null)
const [students, setStudents] = useState<StudentWork[]>([])
const [fairness, setFairness] = useState<FairnessAnalysis | null>(null)
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
// Load data
const loadData = useCallback(async () => {
if (!klausurId) return
setIsLoading(true)
setError(null)
try {
const [klausurData, studentsData, fairnessData] = await Promise.all([
korrekturApi.getKlausur(klausurId),
korrekturApi.getStudents(klausurId),
korrekturApi.getFairnessAnalysis(klausurId),
])
setKlausur(klausurData)
setStudents(studentsData)
setFairness(fairnessData)
} catch (err) {
console.error('Failed to load data:', err)
setError(err instanceof Error ? err.message : 'Laden fehlgeschlagen')
} finally {
setIsLoading(false)
}
}, [klausurId])
useEffect(() => {
loadData()
}, [loadData])
// Calculated stats
const stats = useMemo(() => {
if (!fairness) return null
return {
studentCount: fairness.student_count,
average: fairness.average_grade,
stdDev: fairness.std_deviation,
spread: fairness.spread,
outlierCount: fairness.outliers.length,
warningCount: fairness.warnings.length,
}
}, [fairness])
return (
<div className={`min-h-screen flex relative overflow-hidden ${
isDark
? 'bg-gradient-to-br from-indigo-900 via-purple-900 to-pink-800'
: 'bg-gradient-to-br from-slate-100 via-blue-50 to-indigo-100'
}`}>
{/* Animated Background Blobs */}
<div className={`absolute -top-40 -right-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob ${isDark ? 'bg-purple-500 opacity-30' : 'bg-purple-300 opacity-40'}`} />
<div className={`absolute top-1/2 -left-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-2000 ${isDark ? 'bg-pink-500 opacity-30' : 'bg-pink-300 opacity-40'}`} />
<div className={`absolute -bottom-40 right-1/3 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-4000 ${isDark ? 'bg-blue-500 opacity-30' : 'bg-blue-300 opacity-40'}`} />
{/* Sidebar */}
<div className="relative z-10 p-4">
<Sidebar />
</div>
{/* Main Content */}
<div className="flex-1 flex flex-col relative z-10 p-6 overflow-y-auto">
{/* Header */}
<div className="flex items-center justify-between mb-8">
<div className="flex items-center gap-4">
<button
onClick={() => router.push(`/korrektur/${klausurId}`)}
className={`p-2 rounded-xl transition-colors ${isDark ? 'bg-white/10 hover:bg-white/20 text-white' : 'bg-slate-200 hover:bg-slate-300 text-slate-700'}`}
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
</button>
<div>
<h1 className={`text-3xl font-bold mb-1 ${isDark ? 'text-white' : 'text-slate-900'}`}>Fairness-Analyse</h1>
<p className={isDark ? 'text-white/50' : 'text-slate-500'}>{klausur?.title}</p>
</div>
</div>
<div className="flex items-center gap-3">
<a
href={korrekturApi.getOverviewExportUrl(klausurId)}
target="_blank"
rel="noopener noreferrer"
className={`px-4 py-2 rounded-xl transition-colors flex items-center gap-2 ${isDark ? 'bg-white/10 text-white hover:bg-white/20' : 'bg-slate-200 text-slate-700 hover:bg-slate-300'}`}
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
PDF Export
</a>
<ThemeToggle />
<LanguageDropdown />
</div>
</div>
{/* Error Display */}
{error && (
<GlassCard className="mb-6" isDark={isDark}>
<div className="flex items-center gap-3 text-red-400">
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span>{error}</span>
<button
onClick={loadData}
className={`ml-auto px-3 py-1 rounded-lg transition-colors text-sm ${isDark ? 'bg-white/10 hover:bg-white/20' : 'bg-slate-200 hover:bg-slate-300'}`}
>
Erneut versuchen
</button>
</div>
</GlassCard>
)}
{/* Loading */}
{isLoading && (
<div className="flex-1 flex items-center justify-center">
<div className="w-12 h-12 border-4 border-purple-500 border-t-transparent rounded-full animate-spin" />
</div>
)}
{/* Content */}
{!isLoading && fairness && (
<>
{/* Stats Row */}
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4 mb-6">
<GlassCard delay={100} isDark={isDark}>
<p className={`text-xs mb-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Arbeiten</p>
<p className={`text-2xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>{stats?.studentCount}</p>
</GlassCard>
<GlassCard delay={150} isDark={isDark}>
<p className={`text-xs mb-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Durchschnitt</p>
<p className={`text-2xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>
{stats?.average.toFixed(1)} P
</p>
</GlassCard>
<GlassCard delay={200} isDark={isDark}>
<p className={`text-xs mb-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Standardabw.</p>
<p className={`text-2xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>
{stats?.stdDev.toFixed(2)}
</p>
</GlassCard>
<GlassCard delay={250} isDark={isDark}>
<p className={`text-xs mb-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Spannweite</p>
<p className={`text-2xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>{stats?.spread} P</p>
</GlassCard>
<GlassCard delay={300} isDark={isDark}>
<p className={`text-xs mb-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Ausreisser</p>
<p className={`text-2xl font-bold ${stats?.outlierCount ? 'text-amber-400' : 'text-green-400'}`}>
{stats?.outlierCount}
</p>
</GlassCard>
<GlassCard delay={350} isDark={isDark}>
<p className={`text-xs mb-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Warnungen</p>
<p className={`text-2xl font-bold ${stats?.warningCount ? 'text-red-400' : 'text-green-400'}`}>
{stats?.warningCount}
</p>
</GlassCard>
</div>
{/* Warnings */}
{fairness.warnings.length > 0 && (
<GlassCard className="mb-6" delay={400} isDark={isDark}>
<h3 className={`font-semibold mb-3 flex items-center gap-2 ${isDark ? 'text-white' : 'text-slate-900'}`}>
<svg className="w-5 h-5 text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
Warnungen
</h3>
<ul className="space-y-2">
{fairness.warnings.map((warning, index) => (
<li key={index} className={`text-sm flex items-start gap-2 ${isDark ? 'text-white/70' : 'text-slate-600'}`}>
<span className="text-amber-400 mt-1">-</span>
{warning}
</li>
))}
</ul>
</GlassCard>
)}
{/* Main Grid */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Fairness Score */}
<GlassCard delay={450} isDark={isDark}>
<FairnessScore fairness={fairness} isDark={isDark} />
</GlassCard>
{/* Histogram */}
<GlassCard className="lg:col-span-2" delay={500} isDark={isDark}>
<Histogram students={students} isDark={isDark} />
</GlassCard>
{/* Criteria Heatmap */}
<GlassCard delay={550} isDark={isDark}>
<CriteriaHeatmap students={students} isDark={isDark} />
</GlassCard>
{/* Outlier List */}
<GlassCard className="lg:col-span-2" delay={600} isDark={isDark}>
<OutlierList
fairness={fairness}
onStudentClick={(studentId) =>
router.push(`/korrektur/${klausurId}/${studentId}`)
}
isDark={isDark}
/>
</GlassCard>
</div>
</>
)}
{/* No Data */}
{!isLoading && !fairness && !error && (
<GlassCard className="text-center py-12" isDark={isDark}>
<div className={`w-16 h-16 rounded-2xl flex items-center justify-center mx-auto mb-4 ${isDark ? 'bg-white/10' : 'bg-slate-200'}`}>
<svg className={`w-8 h-8 ${isDark ? 'text-white/30' : 'text-slate-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
</div>
<h3 className={`text-xl font-semibold mb-2 ${isDark ? 'text-white' : 'text-slate-900'}`}>Keine Daten verfuegbar</h3>
<p className={isDark ? 'text-white/50' : 'text-slate-500'}>
Die Fairness-Analyse erfordert korrigierte Arbeiten.
</p>
</GlassCard>
)}
</div>
</div>
)
}

View File

@@ -0,0 +1,578 @@
'use client'
import { useState, useEffect, useCallback, useRef } from 'react'
import { useRouter, useParams } from 'next/navigation'
import { useTheme } from '@/lib/ThemeContext'
import { Sidebar } from '@/components/Sidebar'
import { ThemeToggle } from '@/components/ThemeToggle'
import { LanguageDropdown } from '@/components/LanguageDropdown'
import { QRCodeUpload, UploadedFile } from '@/components/QRCodeUpload'
import { korrekturApi } from '@/lib/korrektur/api'
import type { Klausur, StudentWork, StudentStatus } from '../types'
import { STATUS_COLORS, STATUS_LABELS, getGradeLabel } from '../types'
// LocalStorage Key for upload session
const SESSION_ID_KEY = 'bp_korrektur_student_session'
// =============================================================================
// GLASS CARD
// =============================================================================
interface GlassCardProps {
children: React.ReactNode
className?: string
onClick?: () => void
size?: 'sm' | 'md' | 'lg'
delay?: number
}
function GlassCard({ children, className = '', onClick, size = 'md', delay = 0, isDark = true }: GlassCardProps & { isDark?: boolean }) {
const [isVisible, setIsVisible] = useState(false)
const [isHovered, setIsHovered] = useState(false)
useEffect(() => {
const timer = setTimeout(() => setIsVisible(true), delay)
return () => clearTimeout(timer)
}, [delay])
const sizeClasses = {
sm: 'p-4',
md: 'p-5',
lg: 'p-6',
}
return (
<div
className={`
rounded-3xl
${sizeClasses[size]}
${onClick ? 'cursor-pointer' : ''}
${className}
`}
style={{
background: isDark
? (isHovered ? 'rgba(255, 255, 255, 0.12)' : 'rgba(255, 255, 255, 0.08)')
: (isHovered ? 'rgba(255, 255, 255, 0.9)' : 'rgba(255, 255, 255, 0.7)'),
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
border: isDark ? '1px solid rgba(255, 255, 255, 0.1)' : '1px solid rgba(0, 0, 0, 0.1)',
boxShadow: isDark
? '0 4px 24px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.05)'
: '0 4px 24px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.5)',
opacity: isVisible ? 1 : 0,
transform: isVisible
? `translateY(0) scale(${isHovered ? 1.01 : 1})`
: 'translateY(20px)',
transition: 'all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)',
}}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={onClick}
>
{children}
</div>
)
}
// =============================================================================
// STUDENT CARD
// =============================================================================
interface StudentCardProps {
student: StudentWork
index: number
onClick: () => void
delay?: number
isDark?: boolean
}
function StudentCard({ student, index, onClick, delay = 0, isDark = true }: StudentCardProps) {
const statusColor = STATUS_COLORS[student.status] || '#6b7280'
const statusLabel = STATUS_LABELS[student.status] || student.status
const hasGrade = student.status === 'COMPLETED' || student.status === 'FIRST_EXAMINER' || student.status === 'SECOND_EXAMINER'
return (
<GlassCard onClick={onClick} delay={delay} size="sm" isDark={isDark}>
<div className="flex items-center gap-4">
{/* Index/Number */}
<div className={`w-10 h-10 rounded-xl flex items-center justify-center font-medium ${isDark ? 'bg-white/10 text-white/60' : 'bg-slate-200 text-slate-600'}`}>
{index + 1}
</div>
{/* Info */}
<div className="flex-1 min-w-0">
<p className={`font-medium truncate ${isDark ? 'text-white' : 'text-slate-900'}`}>{student.anonym_id}</p>
<div className="flex items-center gap-2 mt-1">
<span
className="px-2 py-0.5 rounded-full text-xs font-medium"
style={{ backgroundColor: `${statusColor}20`, color: statusColor }}
>
{statusLabel}
</span>
{hasGrade && student.grade_points > 0 && (
<span className={`text-sm ${isDark ? 'text-white/60' : 'text-slate-500'}`}>
{student.grade_points} P ({getGradeLabel(student.grade_points)})
</span>
)}
</div>
</div>
{/* Arrow */}
<svg className={`w-5 h-5 ${isDark ? 'text-white/40' : 'text-slate-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
</div>
</GlassCard>
)
}
// =============================================================================
// UPLOAD MODAL
// =============================================================================
interface UploadModalProps {
isOpen: boolean
onClose: () => void
onUpload: (files: File[], anonymIds: string[]) => void
isUploading: boolean
}
function UploadModal({ isOpen, onClose, onUpload, isUploading }: UploadModalProps) {
const [files, setFiles] = useState<File[]>([])
const [anonymIds, setAnonymIds] = useState<string[]>([])
const fileInputRef = useRef<HTMLInputElement>(null)
if (!isOpen) return null
const handleFileSelect = (selectedFiles: FileList | null) => {
if (!selectedFiles) return
const newFiles = Array.from(selectedFiles)
setFiles((prev) => [...prev, ...newFiles])
// Generate default anonym IDs
setAnonymIds((prev) => [
...prev,
...newFiles.map((_, i) => `Arbeit-${prev.length + i + 1}`),
])
}
const handleDrop = (e: React.DragEvent) => {
e.preventDefault()
handleFileSelect(e.dataTransfer.files)
}
const removeFile = (index: number) => {
setFiles((prev) => prev.filter((_, i) => i !== index))
setAnonymIds((prev) => prev.filter((_, i) => i !== index))
}
const updateAnonymId = (index: number, value: string) => {
setAnonymIds((prev) => {
const updated = [...prev]
updated[index] = value
return updated
})
}
const handleSubmit = () => {
if (files.length > 0) {
onUpload(files, anonymIds)
}
}
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={onClose} />
<GlassCard className="relative w-full max-w-2xl max-h-[80vh] overflow-hidden" size="lg" delay={0}>
<div className="flex items-center justify-between mb-6">
<h2 className="text-xl font-bold text-white">Arbeiten hochladen</h2>
<button
onClick={onClose}
className="p-2 rounded-lg hover:bg-white/10 text-white/60 transition-colors"
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
{/* Drop Zone */}
<div
className="border-2 border-dashed border-white/20 rounded-2xl p-8 text-center cursor-pointer transition-all hover:border-purple-400/50 hover:bg-white/5 mb-6"
onDrop={handleDrop}
onDragOver={(e) => e.preventDefault()}
onClick={() => fileInputRef.current?.click()}
>
<input
ref={fileInputRef}
type="file"
accept="image/*,.pdf"
multiple
onChange={(e) => handleFileSelect(e.target.files)}
className="hidden"
/>
<svg className="w-12 h-12 mx-auto mb-3 text-white/30" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
<p className="text-white font-medium">Dateien hierher ziehen</p>
<p className="text-white/50 text-sm mt-1">oder klicken zum Auswaehlen</p>
</div>
{/* File List */}
{files.length > 0 && (
<div className="max-h-64 overflow-y-auto space-y-2 mb-6">
{files.map((file, index) => (
<div
key={index}
className="flex items-center gap-3 p-3 rounded-xl bg-white/5"
>
<span className="text-lg">
{file.type.startsWith('image/') ? '🖼️' : '📄'}
</span>
<div className="flex-1 min-w-0">
<p className="text-white text-sm truncate">{file.name}</p>
<input
type="text"
value={anonymIds[index] || ''}
onChange={(e) => updateAnonymId(index, e.target.value)}
placeholder="Anonym-ID"
className="mt-1 w-full px-2 py-1 rounded bg-white/10 border border-white/10 text-white text-sm placeholder-white/40 focus:outline-none focus:border-purple-500"
/>
</div>
<button
onClick={() => removeFile(index)}
className="p-2 rounded-lg hover:bg-red-500/20 text-red-400 transition-colors"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</div>
))}
</div>
)}
{/* Actions */}
<div className="flex gap-3">
<button
onClick={onClose}
className="flex-1 px-4 py-3 rounded-xl bg-white/10 text-white hover:bg-white/20 transition-colors"
>
Abbrechen
</button>
<button
onClick={handleSubmit}
disabled={isUploading || files.length === 0}
className="flex-1 px-4 py-3 rounded-xl bg-gradient-to-r from-purple-500 to-pink-500 text-white font-semibold hover:shadow-lg hover:shadow-purple-500/30 transition-all disabled:opacity-50 flex items-center justify-center gap-2"
>
{isUploading ? (
<>
<div className="w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin" />
Hochladen...
</>
) : (
<>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
</svg>
{files.length} Dateien hochladen
</>
)}
</button>
</div>
</GlassCard>
</div>
)
}
// =============================================================================
// MAIN PAGE
// =============================================================================
export default function KlausurDetailPage() {
const { isDark } = useTheme()
const router = useRouter()
const params = useParams()
const klausurId = params.klausurId as string
// State
const [klausur, setKlausur] = useState<Klausur | null>(null)
const [students, setStudents] = useState<StudentWork[]>([])
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
// Modal states
const [showUploadModal, setShowUploadModal] = useState(false)
const [showQRModal, setShowQRModal] = useState(false)
const [isUploading, setIsUploading] = useState(false)
const [uploadSessionId, setUploadSessionId] = useState('')
// Initialize session ID
useEffect(() => {
let storedSessionId = localStorage.getItem(SESSION_ID_KEY)
if (!storedSessionId) {
storedSessionId = `student-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
localStorage.setItem(SESSION_ID_KEY, storedSessionId)
}
setUploadSessionId(storedSessionId)
}, [])
// Load data
const loadData = useCallback(async () => {
if (!klausurId) return
setIsLoading(true)
setError(null)
try {
const [klausurData, studentsData] = await Promise.all([
korrekturApi.getKlausur(klausurId),
korrekturApi.getStudents(klausurId),
])
setKlausur(klausurData)
setStudents(studentsData)
} catch (err) {
console.error('Failed to load data:', err)
setError(err instanceof Error ? err.message : 'Laden fehlgeschlagen')
} finally {
setIsLoading(false)
}
}, [klausurId])
useEffect(() => {
loadData()
}, [loadData])
// Handle upload
const handleUpload = async (files: File[], anonymIds: string[]) => {
setIsUploading(true)
try {
for (let i = 0; i < files.length; i++) {
await korrekturApi.uploadStudentWork(klausurId, files[i], anonymIds[i])
}
setShowUploadModal(false)
loadData() // Refresh the list
} catch (err) {
console.error('Upload failed:', err)
setError(err instanceof Error ? err.message : 'Upload fehlgeschlagen')
} finally {
setIsUploading(false)
}
}
// Calculate progress
const completedCount = students.filter(s => s.status === 'COMPLETED').length
const progress = students.length > 0 ? Math.round((completedCount / students.length) * 100) : 0
return (
<div className={`min-h-screen flex relative overflow-hidden ${
isDark
? 'bg-gradient-to-br from-indigo-900 via-purple-900 to-pink-800'
: 'bg-gradient-to-br from-slate-100 via-blue-50 to-indigo-100'
}`}>
{/* Animated Background Blobs */}
<div className={`absolute -top-40 -right-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob ${isDark ? 'bg-purple-500 opacity-30' : 'bg-purple-300 opacity-40'}`} />
<div className={`absolute top-1/2 -left-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-2000 ${isDark ? 'bg-pink-500 opacity-30' : 'bg-pink-300 opacity-40'}`} />
<div className={`absolute -bottom-40 right-1/3 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-4000 ${isDark ? 'bg-blue-500 opacity-30' : 'bg-blue-300 opacity-40'}`} />
{/* Sidebar */}
<div className="relative z-10 p-4">
<Sidebar />
</div>
{/* Main Content */}
<div className="flex-1 flex flex-col relative z-10 p-6 overflow-y-auto">
{/* Header */}
<div className="flex items-center justify-between mb-8">
<div className="flex items-center gap-4">
<button
onClick={() => router.push('/korrektur')}
className={`p-2 rounded-xl transition-colors ${isDark ? 'bg-white/10 hover:bg-white/20 text-white' : 'bg-slate-200 hover:bg-slate-300 text-slate-700'}`}
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
</button>
<div>
<h1 className={`text-3xl font-bold mb-1 ${isDark ? 'text-white' : 'text-slate-900'}`}>
{klausur?.title || 'Klausur'}
</h1>
<p className={isDark ? 'text-white/50' : 'text-slate-500'}>
{klausur ? `${klausur.subject} ${klausur.semester} ${klausur.year}` : ''}
</p>
</div>
</div>
<div className="flex items-center gap-3">
<ThemeToggle />
<LanguageDropdown />
</div>
</div>
{/* Stats Row */}
{!isLoading && klausur && (
<div className="grid grid-cols-1 sm:grid-cols-4 gap-4 mb-8">
<GlassCard size="sm" delay={100} isDark={isDark}>
<div className="text-center">
<p className={`text-3xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>{students.length}</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Arbeiten</p>
</div>
</GlassCard>
<GlassCard size="sm" delay={150} isDark={isDark}>
<div className="text-center">
<p className="text-3xl font-bold text-green-400">{completedCount}</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Abgeschlossen</p>
</div>
</GlassCard>
<GlassCard size="sm" delay={200} isDark={isDark}>
<div className="text-center">
<p className="text-3xl font-bold text-orange-400">{students.length - completedCount}</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Offen</p>
</div>
</GlassCard>
<GlassCard size="sm" delay={250} isDark={isDark}>
<div className="text-center">
<p className="text-3xl font-bold text-purple-400">{progress}%</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Fortschritt</p>
</div>
</GlassCard>
</div>
)}
{/* Progress Bar */}
{!isLoading && students.length > 0 && (
<GlassCard size="sm" className="mb-6" delay={300} isDark={isDark}>
<div className="flex items-center justify-between text-sm mb-2">
<span className={isDark ? 'text-white/50' : 'text-slate-500'}>Gesamtfortschritt</span>
<span className={isDark ? 'text-white' : 'text-slate-900'}>{completedCount}/{students.length} korrigiert</span>
</div>
<div className={`h-3 rounded-full overflow-hidden ${isDark ? 'bg-white/10' : 'bg-slate-200'}`}>
<div
className="h-full rounded-full transition-all duration-500 bg-gradient-to-r from-green-500 to-emerald-400"
style={{ width: `${progress}%` }}
/>
</div>
</GlassCard>
)}
{/* Error Display */}
{error && (
<GlassCard className="mb-6" size="sm" isDark={isDark}>
<div className="flex items-center gap-3 text-red-400">
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span>{error}</span>
<button
onClick={loadData}
className={`ml-auto px-3 py-1 rounded-lg transition-colors text-sm ${isDark ? 'bg-white/10 hover:bg-white/20' : 'bg-slate-200 hover:bg-slate-300'}`}
>
Erneut versuchen
</button>
</div>
</GlassCard>
)}
{/* Loading */}
{isLoading && (
<div className="flex-1 flex items-center justify-center">
<div className="w-12 h-12 border-4 border-purple-500 border-t-transparent rounded-full animate-spin" />
</div>
)}
{/* Action Buttons */}
{!isLoading && (
<div className="flex gap-3 mb-6">
<button
onClick={() => setShowUploadModal(true)}
className="px-6 py-3 rounded-xl bg-gradient-to-r from-purple-500 to-pink-500 text-white font-semibold hover:shadow-lg hover:shadow-purple-500/30 transition-all flex items-center gap-2"
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
</svg>
Arbeiten hochladen
</button>
<button
onClick={() => setShowQRModal(true)}
className={`px-6 py-3 rounded-xl transition-colors flex items-center gap-2 ${isDark ? 'bg-white/10 text-white hover:bg-white/20' : 'bg-slate-200 text-slate-700 hover:bg-slate-300'}`}
>
<span className="text-xl">📱</span>
QR Upload
</button>
{students.length > 0 && (
<button
onClick={() => router.push(`/korrektur/${klausurId}/fairness`)}
className={`px-6 py-3 rounded-xl transition-colors flex items-center gap-2 ${isDark ? 'bg-white/10 text-white hover:bg-white/20' : 'bg-slate-200 text-slate-700 hover:bg-slate-300'}`}
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
Fairness-Analyse
</button>
)}
</div>
)}
{/* Students List */}
{!isLoading && students.length === 0 && (
<GlassCard className="text-center py-12" delay={350} isDark={isDark}>
<div className={`w-20 h-20 mx-auto mb-4 rounded-2xl flex items-center justify-center ${isDark ? 'bg-white/10' : 'bg-slate-200'}`}>
<svg className={`w-10 h-10 ${isDark ? 'text-white/30' : 'text-slate-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
</div>
<h3 className={`text-xl font-semibold mb-2 ${isDark ? 'text-white' : 'text-slate-900'}`}>Keine Arbeiten vorhanden</h3>
<p className={`mb-6 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Laden Sie Schuelerarbeiten hoch, um mit der Korrektur zu beginnen.</p>
<button
onClick={() => setShowUploadModal(true)}
className="px-6 py-3 rounded-xl bg-gradient-to-r from-purple-500 to-pink-500 text-white font-semibold hover:shadow-lg hover:shadow-purple-500/30 transition-all"
>
Arbeiten hochladen
</button>
</GlassCard>
)}
{!isLoading && students.length > 0 && (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{students.map((student, index) => (
<StudentCard
key={student.id}
student={student}
index={index}
onClick={() => router.push(`/korrektur/${klausurId}/${student.id}`)}
delay={350 + index * 30}
isDark={isDark}
/>
))}
</div>
)}
</div>
{/* Upload Modal */}
<UploadModal
isOpen={showUploadModal}
onClose={() => setShowUploadModal(false)}
onUpload={handleUpload}
isUploading={isUploading}
/>
{/* QR Code Modal */}
{showQRModal && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={() => setShowQRModal(false)} />
<div className={`relative w-full max-w-md rounded-3xl ${isDark ? 'bg-slate-900' : 'bg-white'}`}>
<QRCodeUpload
sessionId={uploadSessionId}
onClose={() => setShowQRModal(false)}
onFilesChanged={(files) => {
// Handle mobile uploaded files
if (files.length > 0) {
// Could auto-process the files here
}
}}
/>
</div>
</div>
)}
</div>
)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,914 @@
'use client'
import { useState, useEffect, useCallback } from 'react'
import { useRouter } from 'next/navigation'
import { useTheme } from '@/lib/ThemeContext'
import { useLanguage } from '@/lib/LanguageContext'
import { Sidebar } from '@/components/Sidebar'
import { ThemeToggle } from '@/components/ThemeToggle'
import { LanguageDropdown } from '@/components/LanguageDropdown'
import { QRCodeUpload, UploadedFile } from '@/components/QRCodeUpload'
import {
korrekturApi,
getKorrekturStats,
type KorrekturStats,
} from '@/lib/korrektur/api'
import type { Klausur, CreateKlausurData } from './types'
// LocalStorage Key for upload session
const SESSION_ID_KEY = 'bp_korrektur_session'
// =============================================================================
// GLASS CARD - Ultra Transparent (Apple Weather Style)
// =============================================================================
interface GlassCardProps {
children: React.ReactNode
className?: string
onClick?: () => void
size?: 'sm' | 'md' | 'lg'
delay?: number
}
function GlassCard({ children, className = '', onClick, size = 'md', delay = 0, isDark = true }: GlassCardProps & { isDark?: boolean }) {
const [isVisible, setIsVisible] = useState(false)
const [isHovered, setIsHovered] = useState(false)
useEffect(() => {
const timer = setTimeout(() => setIsVisible(true), delay)
return () => clearTimeout(timer)
}, [delay])
const sizeClasses = {
sm: 'p-4',
md: 'p-5',
lg: 'p-6',
}
return (
<div
className={`
rounded-3xl
${sizeClasses[size]}
${onClick ? 'cursor-pointer' : ''}
${className}
`}
style={{
background: isDark
? (isHovered ? 'rgba(255, 255, 255, 0.12)' : 'rgba(255, 255, 255, 0.08)')
: (isHovered ? 'rgba(255, 255, 255, 0.9)' : 'rgba(255, 255, 255, 0.7)'),
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
border: isDark ? '1px solid rgba(255, 255, 255, 0.1)' : '1px solid rgba(0, 0, 0, 0.1)',
boxShadow: isDark
? '0 4px 24px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.05)'
: '0 4px 24px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.5)',
opacity: isVisible ? 1 : 0,
transform: isVisible
? `translateY(0) scale(${isHovered ? 1.01 : 1})`
: 'translateY(20px)',
transition: 'all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1)',
}}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={onClick}
>
{children}
</div>
)
}
// =============================================================================
// STAT CARD
// =============================================================================
interface StatCardProps {
label: string
value: string | number
icon: React.ReactNode
color?: string
delay?: number
isDark?: boolean
}
function StatCard({ label, value, icon, color = '#a78bfa', delay = 0, isDark = true }: StatCardProps) {
return (
<GlassCard size="sm" delay={delay} isDark={isDark}>
<div className="flex items-center gap-4">
<div
className="w-12 h-12 rounded-2xl flex items-center justify-center"
style={{ backgroundColor: `${color}20` }}
>
<span style={{ color }}>{icon}</span>
</div>
<div>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>{label}</p>
<p className={`text-2xl font-bold ${isDark ? 'text-white' : 'text-slate-900'}`}>{value}</p>
</div>
</div>
</GlassCard>
)
}
// =============================================================================
// KLAUSUR CARD
// =============================================================================
interface KlausurCardProps {
klausur: Klausur
onClick: () => void
delay?: number
isDark?: boolean
}
function KlausurCard({ klausur, onClick, delay = 0, isDark = true }: KlausurCardProps) {
const progress = klausur.student_count
? Math.round(((klausur.completed_count || 0) / klausur.student_count) * 100)
: 0
const statusColor = klausur.status === 'completed'
? '#22c55e'
: klausur.status === 'in_progress'
? '#f97316'
: '#6b7280'
return (
<GlassCard onClick={onClick} delay={delay} className="min-h-[180px]" isDark={isDark}>
<div className="flex flex-col h-full">
<div className="flex items-start justify-between mb-3">
<h3 className={`text-lg font-semibold ${isDark ? 'text-white' : 'text-slate-900'}`}>{klausur.title}</h3>
<span
className="px-2 py-1 rounded-full text-xs font-medium"
style={{ backgroundColor: `${statusColor}20`, color: statusColor }}
>
{klausur.status === 'completed' ? 'Fertig' : klausur.status === 'in_progress' ? 'In Arbeit' : 'Entwurf'}
</span>
</div>
<p className={`text-sm mb-4 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>
{klausur.subject} {klausur.semester} {klausur.year}
</p>
<div className="mt-auto">
<div className="flex justify-between text-sm mb-2">
<span className={isDark ? 'text-white/50' : 'text-slate-500'}>{klausur.student_count || 0} Arbeiten</span>
<span className={isDark ? 'text-white' : 'text-slate-900'}>{progress}%</span>
</div>
<div className={`h-2 rounded-full overflow-hidden ${isDark ? 'bg-white/10' : 'bg-slate-200'}`}>
<div
className="h-full rounded-full transition-all duration-500"
style={{
width: `${progress}%`,
background: `linear-gradient(90deg, ${statusColor}, ${statusColor}80)`,
}}
/>
</div>
</div>
</div>
</GlassCard>
)
}
// =============================================================================
// CREATE KLAUSUR MODAL
// =============================================================================
interface CreateKlausurModalProps {
isOpen: boolean
onClose: () => void
onSubmit: (data: CreateKlausurData) => void
isLoading: boolean
isDark?: boolean
}
function CreateKlausurModal({ isOpen, onClose, onSubmit, isLoading, isDark = true }: CreateKlausurModalProps) {
const [title, setTitle] = useState('')
const [subject, setSubject] = useState('Deutsch')
const [year, setYear] = useState(new Date().getFullYear())
const [semester, setSemester] = useState('Abitur')
const [modus, setModus] = useState<'landes_abitur' | 'vorabitur'>('landes_abitur')
if (!isOpen) return null
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
onSubmit({ title, subject, year, semester, modus })
}
const inputClasses = isDark
? 'bg-white/10 border-white/20 text-white placeholder-white/40'
: 'bg-slate-100 border-slate-300 text-slate-900 placeholder-slate-400'
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={onClose} />
<GlassCard className="relative w-full max-w-md" size="lg" delay={0} isDark={isDark}>
<h2 className={`text-xl font-bold mb-6 ${isDark ? 'text-white' : 'text-slate-900'}`}>Neue Klausur erstellen</h2>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label htmlFor="klausur-titel" className={`block text-sm mb-2 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>Titel</label>
<input
id="klausur-titel"
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="z.B. Deutsch LK Q4"
className={`w-full p-3 rounded-xl border focus:ring-2 focus:ring-purple-500 focus:border-transparent ${inputClasses}`}
required
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label htmlFor="klausur-fach" className={`block text-sm mb-2 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>Fach</label>
<select
id="klausur-fach"
value={subject}
onChange={(e) => setSubject(e.target.value)}
className={`w-full p-3 rounded-xl border focus:ring-2 focus:ring-purple-500 ${inputClasses}`}
>
<option value="Deutsch">Deutsch</option>
<option value="Englisch">Englisch</option>
<option value="Mathematik">Mathematik</option>
</select>
</div>
<div>
<label htmlFor="klausur-jahr" className={`block text-sm mb-2 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>Jahr</label>
<input
id="klausur-jahr"
type="number"
value={year}
onChange={(e) => setYear(Number(e.target.value))}
className={`w-full p-3 rounded-xl border focus:ring-2 focus:ring-purple-500 ${inputClasses}`}
/>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label htmlFor="klausur-semester" className={`block text-sm mb-2 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>Semester</label>
<select
id="klausur-semester"
value={semester}
onChange={(e) => setSemester(e.target.value)}
className={`w-full p-3 rounded-xl border focus:ring-2 focus:ring-purple-500 ${inputClasses}`}
>
<option value="Abitur">Abitur</option>
<option value="Q1">Q1</option>
<option value="Q2">Q2</option>
<option value="Q3">Q3</option>
<option value="Q4">Q4</option>
</select>
</div>
<div>
<label htmlFor="klausur-modus" className={`block text-sm mb-2 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>Modus</label>
<select
id="klausur-modus"
value={modus}
onChange={(e) => setModus(e.target.value as 'landes_abitur' | 'vorabitur')}
className={`w-full p-3 rounded-xl border focus:ring-2 focus:ring-purple-500 ${inputClasses}`}
>
<option value="landes_abitur">Landes-Abitur (NiBiS EH)</option>
<option value="vorabitur">Vorabitur (Eigener EH)</option>
</select>
</div>
</div>
<div className="flex gap-3 pt-4">
<button
type="button"
onClick={onClose}
className={`flex-1 px-4 py-3 rounded-xl transition-colors ${isDark ? 'bg-white/10 text-white hover:bg-white/20' : 'bg-slate-200 text-slate-700 hover:bg-slate-300'}`}
>
Abbrechen
</button>
<button
type="submit"
disabled={isLoading || !title.trim()}
className="flex-1 px-4 py-3 rounded-xl bg-gradient-to-r from-purple-500 to-pink-500 text-white font-semibold hover:shadow-lg hover:shadow-purple-500/30 transition-all disabled:opacity-50"
>
{isLoading ? 'Erstelle...' : 'Erstellen'}
</button>
</div>
</form>
</GlassCard>
</div>
)
}
// =============================================================================
// MAIN PAGE
// =============================================================================
export default function KorrekturPage() {
const { isDark } = useTheme()
const { t } = useLanguage()
const router = useRouter()
// State
const [klausuren, setKlausuren] = useState<Klausur[]>([])
const [stats, setStats] = useState<KorrekturStats | null>(null)
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
// Modal states
const [showCreateModal, setShowCreateModal] = useState(false)
const [isCreating, setIsCreating] = useState(false)
const [showQRModal, setShowQRModal] = useState(false)
const [uploadSessionId, setUploadSessionId] = useState('')
const [showDirectUpload, setShowDirectUpload] = useState(false)
const [showEHUpload, setShowEHUpload] = useState(false)
const [isDragging, setIsDragging] = useState(false)
const [uploadedFiles, setUploadedFiles] = useState<File[]>([])
const [ehFile, setEhFile] = useState<File | null>(null)
const [isUploading, setIsUploading] = useState(false)
// Initialize session ID
useEffect(() => {
let storedSessionId = localStorage.getItem(SESSION_ID_KEY)
if (!storedSessionId) {
storedSessionId = `korrektur-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
localStorage.setItem(SESSION_ID_KEY, storedSessionId)
}
setUploadSessionId(storedSessionId)
}, [])
// Load data
const loadData = useCallback(async () => {
setIsLoading(true)
setError(null)
try {
const [klausurenData, statsData] = await Promise.all([
korrekturApi.getKlausuren(),
getKorrekturStats(),
])
setKlausuren(klausurenData)
setStats(statsData)
} catch (err) {
console.error('Failed to load data:', err)
setError(err instanceof Error ? err.message : 'Laden fehlgeschlagen')
} finally {
setIsLoading(false)
}
}, [])
useEffect(() => {
loadData()
}, [loadData])
// Create klausur
const handleCreateKlausur = async (data: CreateKlausurData) => {
setIsCreating(true)
try {
const newKlausur = await korrekturApi.createKlausur(data)
setKlausuren((prev) => [newKlausur, ...prev])
setShowCreateModal(false)
// Navigate to the new klausur
router.push(`/korrektur/${newKlausur.id}`)
} catch (err) {
console.error('Failed to create klausur:', err)
setError(err instanceof Error ? err.message : 'Erstellung fehlgeschlagen')
} finally {
setIsCreating(false)
}
}
// Handle QR uploaded files
const handleMobileFileSelect = async (uploadedFile: UploadedFile) => {
// For now, just close the modal - in production this would create a quick-start klausur
setShowQRModal(false)
// Could auto-create a klausur and navigate
}
// Handle direct file upload with drag & drop
const handleDragOver = (e: React.DragEvent) => {
e.preventDefault()
setIsDragging(true)
}
const handleDragLeave = (e: React.DragEvent) => {
e.preventDefault()
setIsDragging(false)
}
const handleDrop = (e: React.DragEvent, isEH = false) => {
e.preventDefault()
setIsDragging(false)
const files = Array.from(e.dataTransfer.files).filter(
f => f.type === 'application/pdf' || f.type.startsWith('image/')
)
if (isEH && files.length > 0) {
setEhFile(files[0])
} else {
setUploadedFiles(prev => [...prev, ...files])
}
}
const handleFileSelect = (e: React.ChangeEvent<HTMLInputElement>, isEH = false) => {
if (!e.target.files) return
const files = Array.from(e.target.files)
if (isEH && files.length > 0) {
setEhFile(files[0])
} else {
setUploadedFiles(prev => [...prev, ...files])
}
}
const handleDirectUpload = async () => {
if (uploadedFiles.length === 0) return
setIsUploading(true)
try {
// Create a quick-start klausur
const newKlausur = await korrekturApi.createKlausur({
title: `Schnellstart ${new Date().toLocaleDateString('de-DE')}`,
subject: 'Deutsch',
year: new Date().getFullYear(),
semester: 'Abitur',
modus: 'landes_abitur'
})
// Upload each file
for (let i = 0; i < uploadedFiles.length; i++) {
await korrekturApi.uploadStudentWork(newKlausur.id, uploadedFiles[i], `Arbeit-${i + 1}`)
}
setShowDirectUpload(false)
setUploadedFiles([])
router.push(`/korrektur/${newKlausur.id}`)
} catch (err) {
console.error('Upload failed:', err)
setError(err instanceof Error ? err.message : 'Upload fehlgeschlagen')
} finally {
setIsUploading(false)
}
}
const handleEHUpload = async () => {
if (!ehFile) return
setIsUploading(true)
try {
// Upload EH to backend
await korrekturApi.uploadEH(ehFile)
setShowEHUpload(false)
setEhFile(null)
loadData() // Refresh to show new EH
} catch (err) {
console.error('EH Upload failed:', err)
setError(err instanceof Error ? err.message : 'EH Upload fehlgeschlagen')
} finally {
setIsUploading(false)
}
}
return (
<div className={`min-h-screen flex relative overflow-hidden ${
isDark
? 'bg-gradient-to-br from-indigo-900 via-purple-900 to-pink-800'
: 'bg-gradient-to-br from-slate-100 via-blue-50 to-indigo-100'
}`}>
{/* Animated Background Blobs */}
<div className={`absolute -top-40 -right-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob ${isDark ? 'bg-purple-500 opacity-30' : 'bg-purple-300 opacity-40'}`} />
<div className={`absolute top-1/2 -left-40 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-2000 ${isDark ? 'bg-pink-500 opacity-30' : 'bg-pink-300 opacity-40'}`} />
<div className={`absolute -bottom-40 right-1/3 w-96 h-96 rounded-full mix-blend-multiply filter blur-3xl animate-blob animation-delay-4000 ${isDark ? 'bg-blue-500 opacity-30' : 'bg-blue-300 opacity-40'}`} />
{/* Sidebar */}
<div className="relative z-10 p-4">
<Sidebar />
</div>
{/* Main Content */}
<div className="flex-1 flex flex-col relative z-10 p-6 overflow-y-auto">
{/* Header */}
<div className="flex items-center justify-between mb-8">
<div>
<h1 className={`text-3xl font-bold mb-2 ${isDark ? 'text-white' : 'text-slate-900'}`}>Korrekturplattform</h1>
<p className={isDark ? 'text-white/50' : 'text-slate-500'}>KI-gestuetzte Abiturklausur-Korrektur</p>
</div>
<div className="flex items-center gap-3">
<ThemeToggle />
<LanguageDropdown />
</div>
</div>
{/* Stats Cards */}
{stats && (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
<StatCard
label="Offene Korrekturen"
value={stats.openCorrections}
icon={
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
</svg>
}
color="#f97316"
delay={100}
isDark={isDark}
/>
<StatCard
label="Erledigt (Woche)"
value={stats.completedThisWeek}
icon={
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
}
color="#22c55e"
delay={200}
isDark={isDark}
/>
<StatCard
label="Durchschnitt"
value={stats.averageGrade > 0 ? `${stats.averageGrade} P` : '-'}
icon={
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
}
color="#3b82f6"
delay={300}
isDark={isDark}
/>
<StatCard
label="Zeit gespart"
value={`${stats.timeSavedHours}h`}
icon={
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
}
color="#a78bfa"
delay={400}
isDark={isDark}
/>
</div>
)}
{/* Error Display */}
{error && (
<GlassCard className="mb-6" size="sm" isDark={isDark}>
<div className="flex items-center gap-3 text-red-400">
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span>{error}</span>
<button
onClick={loadData}
className={`ml-auto px-3 py-1 rounded-lg transition-colors text-sm ${isDark ? 'bg-white/10 hover:bg-white/20' : 'bg-slate-200 hover:bg-slate-300'}`}
>
Erneut versuchen
</button>
</div>
</GlassCard>
)}
{/* Loading */}
{isLoading && (
<div className="flex-1 flex items-center justify-center">
<div className="w-12 h-12 border-4 border-purple-500 border-t-transparent rounded-full animate-spin" />
</div>
)}
{/* Klausuren Grid */}
{!isLoading && (
<>
<div className="flex items-center justify-between mb-4">
<h2 className={`text-xl font-semibold ${isDark ? 'text-white' : 'text-slate-900'}`}>Klausuren</h2>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-8">
{klausuren.map((klausur, index) => (
<KlausurCard
key={klausur.id}
klausur={klausur}
onClick={() => router.push(`/korrektur/${klausur.id}`)}
delay={500 + index * 50}
isDark={isDark}
/>
))}
{/* New Klausur Card */}
<GlassCard
onClick={() => setShowCreateModal(true)}
delay={500 + klausuren.length * 50}
className={`min-h-[180px] border-2 border-dashed ${isDark ? 'border-white/20 hover:border-purple-400/50' : 'border-slate-300 hover:border-purple-400'}`}
isDark={isDark}
>
<div className="flex flex-col items-center justify-center h-full text-center">
<div className="w-16 h-16 rounded-2xl bg-purple-500/20 flex items-center justify-center mb-4">
<svg className="w-8 h-8 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
</svg>
</div>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>Neue Klausur</p>
<p className={`text-sm mt-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Klausur erstellen</p>
</div>
</GlassCard>
</div>
{/* Quick Actions */}
<h2 className={`text-xl font-semibold mb-4 ${isDark ? 'text-white' : 'text-slate-900'}`}>Schnellaktionen</h2>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<GlassCard
onClick={() => setShowQRModal(true)}
delay={700}
className="cursor-pointer"
isDark={isDark}
>
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-blue-500/20 flex items-center justify-center">
<span className="text-2xl">📱</span>
</div>
<div>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>QR Upload</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Mit Handy scannen</p>
</div>
</div>
</GlassCard>
<GlassCard
onClick={() => setShowDirectUpload(true)}
delay={750}
className="cursor-pointer"
isDark={isDark}
>
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-green-500/20 flex items-center justify-center">
<svg className="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
</div>
<div>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>Direkt hochladen</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Drag & Drop</p>
</div>
</div>
</GlassCard>
<GlassCard
onClick={() => setShowCreateModal(true)}
delay={800}
className="cursor-pointer"
isDark={isDark}
>
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-purple-500/20 flex items-center justify-center">
<svg className="w-6 h-6 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
</svg>
</div>
<div>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>Schnellstart</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Direkt loslegen</p>
</div>
</div>
</GlassCard>
<GlassCard
onClick={() => setShowEHUpload(true)}
delay={850}
className="cursor-pointer"
isDark={isDark}
>
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-orange-500/20 flex items-center justify-center">
<svg className="w-6 h-6 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
</svg>
</div>
<div>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>EH hochladen</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>Erwartungshorizont</p>
</div>
</div>
</GlassCard>
<GlassCard
onClick={() => router.push('/korrektur/archiv')}
delay={900}
className="cursor-pointer"
isDark={isDark}
>
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-indigo-500/20 flex items-center justify-center">
<svg className="w-6 h-6 text-indigo-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
</svg>
</div>
<div>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>Abitur-Archiv</p>
<p className={`text-sm ${isDark ? 'text-white/50' : 'text-slate-500'}`}>EH durchsuchen</p>
</div>
</div>
</GlassCard>
</div>
</>
)}
</div>
{/* Create Klausur Modal */}
<CreateKlausurModal
isOpen={showCreateModal}
onClose={() => setShowCreateModal(false)}
onSubmit={handleCreateKlausur}
isLoading={isCreating}
isDark={isDark}
/>
{/* QR Code Modal */}
{showQRModal && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={() => setShowQRModal(false)} />
<div className={`relative w-full max-w-md rounded-3xl ${isDark ? 'bg-slate-900' : 'bg-white'}`}>
<QRCodeUpload
sessionId={uploadSessionId}
onClose={() => setShowQRModal(false)}
onFileUploaded={handleMobileFileSelect}
/>
</div>
</div>
)}
{/* Direct Upload Modal */}
{showDirectUpload && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={() => setShowDirectUpload(false)} />
<GlassCard className="relative w-full max-w-lg" size="lg" delay={0} isDark={isDark}>
<h2 className={`text-xl font-bold mb-4 ${isDark ? 'text-white' : 'text-slate-900'}`}>Arbeiten hochladen</h2>
<p className={`mb-4 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>
Ziehen Sie eingescannte Klausuren hierher oder klicken Sie zum Auswaehlen.
</p>
{/* Error Display in Modal */}
{error && (
<div className="mb-4 p-3 rounded-lg bg-red-500/20 border border-red-500/30 text-red-300 text-sm">
{error}
</div>
)}
{/* Drag & Drop Zone */}
<div
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={(e) => handleDrop(e, false)}
className={`relative p-8 rounded-2xl border-2 border-dashed transition-colors ${
isDragging
? 'border-purple-400 bg-purple-500/10'
: isDark
? 'border-white/20 hover:border-white/40'
: 'border-slate-300 hover:border-slate-400'
}`}
>
<input
type="file"
accept=".pdf,image/*"
multiple
onChange={(e) => handleFileSelect(e, false)}
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
/>
<div className="text-center">
<svg className={`w-12 h-12 mx-auto mb-4 ${isDark ? 'text-white/40' : 'text-slate-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>
{isDragging ? 'Dateien hier ablegen' : 'Dateien hierher ziehen'}
</p>
<p className={`text-sm mt-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>
PDF oder Bilder (JPG, PNG)
</p>
</div>
</div>
{/* Uploaded Files List */}
{uploadedFiles.length > 0 && (
<div className="mt-4 space-y-2">
<p className={`text-sm font-medium ${isDark ? 'text-white/60' : 'text-slate-600'}`}>
{uploadedFiles.length} Datei(en) ausgewaehlt:
</p>
<div className="max-h-32 overflow-y-auto space-y-1">
{uploadedFiles.map((file, idx) => (
<div key={idx} className={`flex items-center justify-between p-2 rounded-lg ${isDark ? 'bg-white/5' : 'bg-slate-100'}`}>
<span className={`text-sm truncate ${isDark ? 'text-white/80' : 'text-slate-700'}`}>{file.name}</span>
<button
onClick={() => setUploadedFiles(prev => prev.filter((_, i) => i !== idx))}
className="text-red-400 hover:text-red-300"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
))}
</div>
</div>
)}
{/* Actions */}
<div className="flex gap-3 mt-6">
<button
onClick={() => { setShowDirectUpload(false); setUploadedFiles([]) }}
className={`flex-1 px-4 py-3 rounded-xl transition-colors ${isDark ? 'bg-white/10 text-white hover:bg-white/20' : 'bg-slate-200 text-slate-700 hover:bg-slate-300'}`}
>
Abbrechen
</button>
<button
onClick={handleDirectUpload}
disabled={uploadedFiles.length === 0 || isUploading}
className="flex-1 px-4 py-3 rounded-xl bg-gradient-to-r from-purple-500 to-pink-500 text-white font-semibold hover:shadow-lg hover:shadow-purple-500/30 transition-all disabled:opacity-50"
>
{isUploading ? 'Hochladen...' : `${uploadedFiles.length} Arbeiten hochladen`}
</button>
</div>
</GlassCard>
</div>
)}
{/* EH Upload Modal */}
{showEHUpload && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm" onClick={() => setShowEHUpload(false)} />
<GlassCard className="relative w-full max-w-lg" size="lg" delay={0} isDark={isDark}>
<h2 className={`text-xl font-bold mb-4 ${isDark ? 'text-white' : 'text-slate-900'}`}>Erwartungshorizont hochladen</h2>
<p className={`mb-6 ${isDark ? 'text-white/60' : 'text-slate-600'}`}>
Laden Sie einen eigenen Erwartungshorizont fuer Vorabitur-Klausuren hoch.
</p>
{/* Drag & Drop Zone */}
<div
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={(e) => handleDrop(e, true)}
className={`relative p-8 rounded-2xl border-2 border-dashed transition-colors ${
isDragging
? 'border-orange-400 bg-orange-500/10'
: isDark
? 'border-white/20 hover:border-white/40'
: 'border-slate-300 hover:border-slate-400'
}`}
>
<input
type="file"
accept=".pdf,.docx,.doc"
onChange={(e) => handleFileSelect(e, true)}
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
/>
<div className="text-center">
<svg className={`w-12 h-12 mx-auto mb-4 ${isDark ? 'text-white/40' : 'text-slate-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
<p className={`font-medium ${isDark ? 'text-white' : 'text-slate-900'}`}>
{ehFile ? ehFile.name : 'EH-Datei hierher ziehen'}
</p>
<p className={`text-sm mt-1 ${isDark ? 'text-white/50' : 'text-slate-500'}`}>
PDF oder Word-Dokument
</p>
</div>
</div>
{/* Selected File */}
{ehFile && (
<div className={`mt-4 flex items-center justify-between p-3 rounded-lg ${isDark ? 'bg-white/5' : 'bg-slate-100'}`}>
<div className="flex items-center gap-3">
<svg className="w-6 h-6 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
<span className={`text-sm truncate ${isDark ? 'text-white/80' : 'text-slate-700'}`}>{ehFile.name}</span>
</div>
<button
onClick={() => setEhFile(null)}
className="text-red-400 hover:text-red-300"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
)}
{/* Actions */}
<div className="flex gap-3 mt-6">
<button
onClick={() => { setShowEHUpload(false); setEhFile(null) }}
className={`flex-1 px-4 py-3 rounded-xl transition-colors ${isDark ? 'bg-white/10 text-white hover:bg-white/20' : 'bg-slate-200 text-slate-700 hover:bg-slate-300'}`}
>
Abbrechen
</button>
<button
onClick={handleEHUpload}
disabled={!ehFile || isUploading}
className="flex-1 px-4 py-3 rounded-xl bg-gradient-to-r from-orange-500 to-red-500 text-white font-semibold hover:shadow-lg hover:shadow-orange-500/30 transition-all disabled:opacity-50"
>
{isUploading ? 'Hochladen...' : 'EH hochladen'}
</button>
</div>
</GlassCard>
</div>
)}
</div>
)
}

View File

@@ -0,0 +1,257 @@
// TypeScript Interfaces fuer Korrekturplattform (Studio v2)
export interface Klausur {
id: string
title: string
subject: string
year: number
semester: string
modus: 'landes_abitur' | 'vorabitur'
eh_id?: string
created_at: string
student_count?: number
completed_count?: number
status?: 'draft' | 'in_progress' | 'completed'
}
export interface StudentWork {
id: string
klausur_id: string
anonym_id: string
file_path: string
file_type: 'pdf' | 'image'
ocr_text: string
criteria_scores: CriteriaScores
gutachten: string
status: StudentStatus
raw_points: number
grade_points: number
grade_label?: string
created_at: string
examiner_id?: string
second_examiner_id?: string
second_examiner_grade?: number
}
export type StudentStatus =
| 'UPLOADED'
| 'OCR_PROCESSING'
| 'OCR_COMPLETE'
| 'ANALYZING'
| 'FIRST_EXAMINER'
| 'SECOND_EXAMINER'
| 'COMPLETED'
| 'ERROR'
export interface CriteriaScores {
rechtschreibung?: number
grammatik?: number
inhalt?: number
struktur?: number
stil?: number
[key: string]: number | undefined
}
export interface Criterion {
id: string
name: string
weight: number
description?: string
}
export interface GradeInfo {
thresholds: Record<number, number>
labels: Record<number, string>
criteria: Record<string, Criterion>
}
export interface Annotation {
id: string
student_work_id: string
page: number
position: AnnotationPosition
type: AnnotationType
text: string
severity: 'minor' | 'major' | 'critical'
suggestion?: string
created_by: string
created_at: string
role: 'first_examiner' | 'second_examiner'
linked_criterion?: string
}
export interface AnnotationPosition {
x: number // Prozent (0-100)
y: number // Prozent (0-100)
width: number // Prozent (0-100)
height: number // Prozent (0-100)
}
export type AnnotationType =
| 'rechtschreibung'
| 'grammatik'
| 'inhalt'
| 'struktur'
| 'stil'
| 'comment'
| 'highlight'
export interface FairnessAnalysis {
klausur_id: string
student_count: number
average_grade: number
std_deviation: number
spread: number
outliers: OutlierInfo[]
criteria_analysis: Record<string, CriteriaStats>
fairness_score: number
warnings: string[]
}
export interface OutlierInfo {
student_id: string
anonym_id: string
grade_points: number
deviation: number
reason: string
}
export interface CriteriaStats {
min: number
max: number
average: number
std_deviation: number
}
export interface EHSuggestion {
criterion: string
excerpt: string
relevance_score: number
source_chunk_id: string
// Attribution fields (CTRL-SRC-002)
source_document?: string
source_url?: string
license?: string
license_url?: string
publisher?: string
}
// Default Attribution for NiBiS documents (CTRL-SRC-002)
export const NIBIS_ATTRIBUTION = {
publisher: 'Niedersaechsischer Bildungsserver (NiBiS)',
license: 'DL-DE-BY-2.0',
license_url: 'https://www.govdata.de/dl-de/by-2-0',
source_url: 'https://nibis.de',
}
export interface GutachtenSection {
title: string
content: string
evidence_links?: string[]
}
export interface Gutachten {
einleitung: string
hauptteil: string
fazit: string
staerken: string[]
schwaechen: string[]
generated_at?: string
}
// API Response Types
export interface KlausurenResponse {
klausuren: Klausur[]
total: number
}
export interface StudentsResponse {
students: StudentWork[]
total: number
}
export interface AnnotationsResponse {
annotations: Annotation[]
}
// Create/Update Types
export interface CreateKlausurData {
title: string
subject?: string
year?: number
semester?: string
modus?: 'landes_abitur' | 'vorabitur'
}
// Color mapping for annotation types
export const ANNOTATION_COLORS: Record<AnnotationType, string> = {
rechtschreibung: '#dc2626', // Red
grammatik: '#2563eb', // Blue
inhalt: '#16a34a', // Green
struktur: '#9333ea', // Purple
stil: '#ea580c', // Orange
comment: '#6b7280', // Gray
highlight: '#eab308', // Yellow
}
// Status colors
export const STATUS_COLORS: Record<StudentStatus, string> = {
UPLOADED: '#6b7280',
OCR_PROCESSING: '#eab308',
OCR_COMPLETE: '#3b82f6',
ANALYZING: '#8b5cf6',
FIRST_EXAMINER: '#f97316',
SECOND_EXAMINER: '#06b6d4',
COMPLETED: '#22c55e',
ERROR: '#ef4444',
}
export const STATUS_LABELS: Record<StudentStatus, string> = {
UPLOADED: 'Hochgeladen',
OCR_PROCESSING: 'OCR laeuft',
OCR_COMPLETE: 'OCR fertig',
ANALYZING: 'Analyse laeuft',
FIRST_EXAMINER: 'Erstkorrektur',
SECOND_EXAMINER: 'Zweitkorrektur',
COMPLETED: 'Abgeschlossen',
ERROR: 'Fehler',
}
// Default criteria with weights (NI standard)
export const DEFAULT_CRITERIA: Record<string, { name: string; weight: number }> = {
rechtschreibung: { name: 'Rechtschreibung', weight: 15 },
grammatik: { name: 'Grammatik', weight: 15 },
inhalt: { name: 'Inhalt', weight: 40 },
struktur: { name: 'Struktur', weight: 15 },
stil: { name: 'Stil', weight: 15 },
}
// Grade thresholds (15-point system)
export const GRADE_THRESHOLDS: Record<number, number> = {
15: 95, 14: 90, 13: 85, 12: 80, 11: 75,
10: 70, 9: 65, 8: 60, 7: 55, 6: 50,
5: 45, 4: 40, 3: 33, 2: 27, 1: 20, 0: 0
}
// Helper function to calculate grade from percentage
export function calculateGrade(percentage: number): number {
for (const [grade, threshold] of Object.entries(GRADE_THRESHOLDS).sort((a, b) => Number(b[0]) - Number(a[0]))) {
if (percentage >= threshold) {
return Number(grade)
}
}
return 0
}
// Helper function to get grade label
export function getGradeLabel(points: number): string {
const labels: Record<number, string> = {
15: '1+', 14: '1', 13: '1-',
12: '2+', 11: '2', 10: '2-',
9: '3+', 8: '3', 7: '3-',
6: '4+', 5: '4', 4: '4-',
3: '5+', 2: '5', 1: '5-',
0: '6'
}
return labels[points] || String(points)
}