[split-required] Split 500-850 LOC files (batch 2)

backend-lehrer (10 files):
- game/database.py (785 → 5), correction_api.py (683 → 4)
- classroom_engine/antizipation.py (676 → 5)
- llm_gateway schools/edu_search already done in prior batch

klausur-service (12 files):
- orientation_crop_api.py (694 → 5), pdf_export.py (677 → 4)
- zeugnis_crawler.py (676 → 5), grid_editor_api.py (671 → 5)
- eh_templates.py (658 → 5), mail/api.py (651 → 5)
- qdrant_service.py (638 → 5), training_api.py (625 → 4)

website (6 pages):
- middleware (696 → 8), mail (733 → 6), consent (628 → 8)
- compliance/risks (622 → 5), export (502 → 5), brandbook (629 → 7)

studio-v2 (3 components):
- B2BMigrationWizard (848 → 3), CleanupPanel (765 → 2)
- dashboard-experimental (739 → 2)

admin-lehrer (4 files):
- uebersetzungen (769 → 4), manager (670 → 2)
- ChunkBrowserQA (675 → 6), dsfa/page (674 → 5)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-04-25 08:24:01 +02:00
parent 34da9f4cda
commit b4613e26f3
118 changed files with 15258 additions and 14680 deletions

View File

@@ -0,0 +1,51 @@
'use client'
import type { Export } from './types'
import { formatFileSize } from './types'
interface ExportHistoryProps {
exports: Export[]
downloadExport: (id: string) => void
}
export default function ExportHistory({ exports, downloadExport }: ExportHistoryProps) {
return (
<div className="bg-white rounded-xl shadow-sm border p-6">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Letzte Exports</h3>
{exports.length === 0 ? (
<p className="text-slate-500 text-sm">Noch keine Exports vorhanden</p>
) : (
<div className="space-y-3">
{exports.slice(0, 10).map((exp) => (
<div key={exp.id} className="p-3 bg-slate-50 rounded-lg">
<div className="flex items-center justify-between mb-1">
<span className={`px-2 py-0.5 text-xs rounded-full ${
exp.status === 'completed' ? 'bg-green-100 text-green-700' :
exp.status === 'failed' ? 'bg-red-100 text-red-700' :
'bg-yellow-100 text-yellow-700'
}`}>
{exp.status}
</span>
<span className="text-xs text-slate-500">
{new Date(exp.requested_at).toLocaleDateString('de-DE')}
</span>
</div>
<p className="text-sm font-medium text-slate-900">{exp.export_name}</p>
<p className="text-xs text-slate-500">{exp.export_type} - {formatFileSize(exp.file_size_bytes)}</p>
{exp.status === 'completed' && (
<button
onClick={() => downloadExport(exp.id)}
className="mt-2 text-xs text-primary-600 hover:text-primary-700 font-medium"
>
Download
</button>
)}
</div>
))}
</div>
)}
</div>
)
}

View File

@@ -0,0 +1,287 @@
'use client'
import type { Export, Regulation } from './types'
import { EXPORT_TYPES, DOMAIN_OPTIONS, formatFileSize } from './types'
interface ExportWizardProps {
wizardStep: number
setWizardStep: (step: number) => void
exportType: string
setExportType: (type: string) => void
regulations: Regulation[]
selectedRegulations: string[]
toggleRegulation: (code: string) => void
selectedDomains: string[]
toggleDomain: (domain: string) => void
generating: boolean
startExport: () => void
currentExport: Export | null
resetWizard: () => void
downloadExport: (id: string) => void
}
export default function ExportWizard(props: ExportWizardProps) {
return (
<div className="lg:col-span-2 bg-white rounded-xl shadow-sm border p-6">
<WizardSteps current={props.wizardStep} />
{props.wizardStep === 1 && <Step1 exportType={props.exportType} setExportType={props.setExportType} next={() => props.setWizardStep(2)} />}
{props.wizardStep === 2 && <Step2 {...props} />}
{props.wizardStep === 3 && <Step3 {...props} />}
{props.wizardStep === 4 && <Step4 currentExport={props.currentExport} resetWizard={props.resetWizard} downloadExport={props.downloadExport} />}
</div>
)
}
function WizardSteps({ current }: { current: number }) {
const steps = [
{ num: 1, label: 'Typ' },
{ num: 2, label: 'Scope' },
{ num: 3, label: 'Bestaetigen' },
{ num: 4, label: 'Download' },
]
return (
<div className="flex items-center justify-center mb-8">
{steps.map((step, idx) => (
<div key={step.num} className="flex items-center">
<div className={`flex items-center justify-center w-10 h-10 rounded-full font-medium ${
current >= step.num ? 'bg-primary-600 text-white' : 'bg-slate-200 text-slate-500'
}`}>
{current > step.num ? (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
) : (
step.num
)}
</div>
<span className={`ml-2 text-sm ${current >= step.num ? 'text-slate-900' : 'text-slate-500'}`}>
{step.label}
</span>
{idx < 3 && (
<div className={`w-16 h-0.5 mx-4 ${current > step.num ? 'bg-primary-600' : 'bg-slate-200'}`} />
)}
</div>
))}
</div>
)
}
function Step1({ exportType, setExportType, next }: { exportType: string; setExportType: (t: string) => void; next: () => void }) {
return (
<div className="space-y-4">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Export-Typ waehlen</h3>
<div className="grid gap-4">
{EXPORT_TYPES.map((type) => (
<button
key={type.value}
onClick={() => setExportType(type.value)}
className={`p-4 rounded-lg border-2 text-left transition-colors ${
exportType === type.value ? 'border-primary-600 bg-primary-50' : 'border-slate-200 hover:border-slate-300'
}`}
>
<div className="flex items-center gap-3">
<div className={`w-5 h-5 rounded-full border-2 flex items-center justify-center ${
exportType === type.value ? 'border-primary-600' : 'border-slate-300'
}`}>
{exportType === type.value && <div className="w-3 h-3 rounded-full bg-primary-600" />}
</div>
<div>
<p className="font-medium text-slate-900">{type.label}</p>
<p className="text-sm text-slate-500">{type.description}</p>
</div>
</div>
</button>
))}
</div>
<div className="flex justify-end pt-4">
<button onClick={next} className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700">
Weiter
</button>
</div>
</div>
)
}
function Step2(props: ExportWizardProps) {
return (
<div className="space-y-6">
<h3 className="text-lg font-semibold text-slate-900">Scope definieren (optional)</h3>
<div>
<h4 className="text-sm font-medium text-slate-700 mb-3">Verordnungen filtern</h4>
<p className="text-sm text-slate-500 mb-3">Leer lassen fuer alle Verordnungen</p>
<div className="grid grid-cols-2 md:grid-cols-4 gap-2">
{props.regulations.map((reg) => (
<button
key={reg.code}
onClick={() => props.toggleRegulation(reg.code)}
className={`px-3 py-2 text-sm rounded-lg border transition-colors ${
props.selectedRegulations.includes(reg.code)
? 'border-primary-600 bg-primary-50 text-primary-700'
: 'border-slate-200 text-slate-600 hover:border-slate-300'
}`}
>
{reg.code}
</button>
))}
</div>
</div>
<div>
<h4 className="text-sm font-medium text-slate-700 mb-3">Domains filtern</h4>
<p className="text-sm text-slate-500 mb-3">Leer lassen fuer alle Domains</p>
<div className="grid grid-cols-2 md:grid-cols-3 gap-2">
{DOMAIN_OPTIONS.map((domain) => (
<button
key={domain.value}
onClick={() => props.toggleDomain(domain.value)}
className={`px-3 py-2 text-sm rounded-lg border transition-colors ${
props.selectedDomains.includes(domain.value)
? 'border-primary-600 bg-primary-50 text-primary-700'
: 'border-slate-200 text-slate-600 hover:border-slate-300'
}`}
>
{domain.label}
</button>
))}
</div>
</div>
<div className="flex justify-between pt-4">
<button onClick={() => props.setWizardStep(1)} className="px-6 py-2 text-slate-600 hover:text-slate-800">
Zurueck
</button>
<button onClick={() => props.setWizardStep(3)} className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700">
Weiter
</button>
</div>
</div>
)
}
function Step3(props: ExportWizardProps) {
return (
<div className="space-y-6">
<h3 className="text-lg font-semibold text-slate-900">Export bestaetigen</h3>
<div className="bg-slate-50 rounded-lg p-6 space-y-4">
<div className="flex justify-between">
<span className="text-slate-600">Export-Typ:</span>
<span className="font-medium text-slate-900">
{EXPORT_TYPES.find((t) => t.value === props.exportType)?.label}
</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Verordnungen:</span>
<span className="font-medium text-slate-900">
{props.selectedRegulations.length > 0 ? props.selectedRegulations.join(', ') : 'Alle'}
</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Domains:</span>
<span className="font-medium text-slate-900">
{props.selectedDomains.length > 0
? props.selectedDomains.map((d) => DOMAIN_OPTIONS.find((o) => o.value === d)?.label).join(', ')
: 'Alle'}
</span>
</div>
</div>
<div className="p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
<p className="text-sm text-yellow-800">
Der Export kann je nach Datenmenge einige Sekunden dauern.
Nach Abschluss koennen Sie die ZIP-Datei herunterladen.
</p>
</div>
<div className="flex justify-between pt-4">
<button onClick={() => props.setWizardStep(2)} className="px-6 py-2 text-slate-600 hover:text-slate-800">
Zurueck
</button>
<button
onClick={props.startExport}
disabled={props.generating}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 disabled:opacity-50 flex items-center gap-2"
>
{props.generating && (
<svg className="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
</svg>
)}
{props.generating ? 'Generiere...' : 'Export starten'}
</button>
</div>
</div>
)
}
function Step4({ currentExport, resetWizard, downloadExport }: { currentExport: Export | null; resetWizard: () => void; downloadExport: (id: string) => void }) {
if (currentExport?.status === 'completed') {
return (
<div className="space-y-6 text-center">
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto">
<svg className="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
</div>
<h3 className="text-lg font-semibold text-slate-900">Export erfolgreich!</h3>
<div className="bg-slate-50 rounded-lg p-6 text-left space-y-3">
<div className="flex justify-between">
<span className="text-slate-600">Compliance Score:</span>
<span className="font-medium text-slate-900">{currentExport.compliance_score?.toFixed(1)}%</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Controls:</span>
<span className="font-medium text-slate-900">{currentExport.total_controls}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Nachweise:</span>
<span className="font-medium text-slate-900">{currentExport.total_evidence}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Dateigroesse:</span>
<span className="font-medium text-slate-900">{formatFileSize(currentExport.file_size_bytes)}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">SHA-256:</span>
<span className="font-mono text-xs text-slate-500 truncate max-w-xs">{currentExport.file_hash}</span>
</div>
</div>
<div className="flex justify-center gap-4 pt-4">
<button onClick={resetWizard} className="px-6 py-2 text-slate-600 hover:text-slate-800">
Neuer Export
</button>
<button
onClick={() => downloadExport(currentExport.id)}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 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-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
ZIP herunterladen
</button>
</div>
</div>
)
}
return (
<div className="space-y-6 text-center">
<div className="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto">
<svg className="w-8 h-8 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</div>
<h3 className="text-lg font-semibold text-slate-900">Export fehlgeschlagen</h3>
<p className="text-slate-500">{currentExport?.error_message || 'Unbekannter Fehler'}</p>
<button onClick={resetWizard} className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700">
Erneut versuchen
</button>
</div>
)
}

View File

@@ -0,0 +1,46 @@
export interface Export {
id: string
export_type: string
export_name: string
status: string
requested_by: string
requested_at: string
completed_at: string | null
file_path: string | null
file_hash: string | null
file_size_bytes: number | null
total_controls: number | null
total_evidence: number | null
compliance_score: number | null
error_message: string | null
}
export interface Regulation {
code: string
name: string
}
export const EXPORT_TYPES = [
{ value: 'full', label: 'Vollstaendiger Export', description: 'Alle Daten inkl. Regulations, Controls, Evidence, Risks' },
{ value: 'controls_only', label: 'Nur Controls', description: 'Control Catalogue mit Mappings' },
{ value: 'evidence_only', label: 'Nur Nachweise', description: 'Evidence-Dateien und Metadaten' },
]
export const DOMAIN_OPTIONS = [
{ value: 'gov', label: 'Governance' },
{ value: 'priv', label: 'Datenschutz' },
{ value: 'iam', label: 'Identity & Access' },
{ value: 'crypto', label: 'Kryptografie' },
{ value: 'sdlc', label: 'Secure Dev' },
{ value: 'ops', label: 'Operations' },
{ value: 'ai', label: 'KI-spezifisch' },
{ value: 'cra', label: 'Supply Chain' },
{ value: 'aud', label: 'Audit' },
]
export function formatFileSize(bytes: number | null): string {
if (!bytes) return '-'
if (bytes < 1024) return `${bytes} B`
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
}

View File

@@ -0,0 +1,110 @@
'use client'
import { useState, useEffect } from 'react'
import type { Export, Regulation } from './types'
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'
export function useExport() {
const [exports, setExports] = useState<Export[]>([])
const [regulations, setRegulations] = useState<Regulation[]>([])
const [loading, setLoading] = useState(true)
const [generating, setGenerating] = useState(false)
const [wizardStep, setWizardStep] = useState(1)
const [exportType, setExportType] = useState('full')
const [selectedRegulations, setSelectedRegulations] = useState<string[]>([])
const [selectedDomains, setSelectedDomains] = useState<string[]>([])
const [currentExport, setCurrentExport] = useState<Export | null>(null)
useEffect(() => {
loadData()
}, [])
const loadData = async () => {
setLoading(true)
try {
const [exportsRes, regulationsRes] = await Promise.all([
fetch(`${BACKEND_URL}/api/v1/compliance/exports`),
fetch(`${BACKEND_URL}/api/v1/compliance/regulations`),
])
if (exportsRes.ok) {
const data = await exportsRes.json()
setExports(data.exports || [])
}
if (regulationsRes.ok) {
const data = await regulationsRes.json()
setRegulations(data.regulations || [])
}
} catch (error) {
console.error('Failed to load data:', error)
} finally {
setLoading(false)
}
}
const startExport = async () => {
setGenerating(true)
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/export`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
export_type: exportType,
included_regulations: selectedRegulations.length > 0 ? selectedRegulations : null,
included_domains: selectedDomains.length > 0 ? selectedDomains : null,
}),
})
if (res.ok) {
const exportData = await res.json()
setCurrentExport(exportData)
setWizardStep(4)
loadData()
} else {
const error = await res.text()
alert(`Export fehlgeschlagen: ${error}`)
}
} catch (error) {
console.error('Export failed:', error)
alert('Export fehlgeschlagen')
} finally {
setGenerating(false)
}
}
const downloadExport = (exportId: string) => {
window.open(`${BACKEND_URL}/api/v1/compliance/export/${exportId}/download`, '_blank')
}
const resetWizard = () => {
setWizardStep(1)
setExportType('full')
setSelectedRegulations([])
setSelectedDomains([])
setCurrentExport(null)
}
const toggleRegulation = (code: string) => {
setSelectedRegulations((prev) =>
prev.includes(code) ? prev.filter((r) => r !== code) : [...prev, code]
)
}
const toggleDomain = (domain: string) => {
setSelectedDomains((prev) =>
prev.includes(domain) ? prev.filter((d) => d !== domain) : [...prev, domain]
)
}
return {
exports, regulations, loading, generating,
wizardStep, setWizardStep,
exportType, setExportType,
selectedRegulations, selectedDomains,
currentExport,
startExport, downloadExport, resetWizard,
toggleRegulation, toggleDomain,
}
}

View File

@@ -11,420 +11,14 @@
* - Export history
*/
import { useState, useEffect } from 'react'
import Link from 'next/link'
import AdminLayout from '@/components/admin/AdminLayout'
interface Export {
id: string
export_type: string
export_name: string
status: string
requested_by: string
requested_at: string
completed_at: string | null
file_path: string | null
file_hash: string | null
file_size_bytes: number | null
total_controls: number | null
total_evidence: number | null
compliance_score: number | null
error_message: string | null
}
interface Regulation {
code: string
name: string
}
const EXPORT_TYPES = [
{ value: 'full', label: 'Vollstaendiger Export', description: 'Alle Daten inkl. Regulations, Controls, Evidence, Risks' },
{ value: 'controls_only', label: 'Nur Controls', description: 'Control Catalogue mit Mappings' },
{ value: 'evidence_only', label: 'Nur Nachweise', description: 'Evidence-Dateien und Metadaten' },
]
const DOMAIN_OPTIONS = [
{ value: 'gov', label: 'Governance' },
{ value: 'priv', label: 'Datenschutz' },
{ value: 'iam', label: 'Identity & Access' },
{ value: 'crypto', label: 'Kryptografie' },
{ value: 'sdlc', label: 'Secure Dev' },
{ value: 'ops', label: 'Operations' },
{ value: 'ai', label: 'KI-spezifisch' },
{ value: 'cra', label: 'Supply Chain' },
{ value: 'aud', label: 'Audit' },
]
import { useExport } from './_components/useExport'
import ExportWizard from './_components/ExportWizard'
import ExportHistory from './_components/ExportHistory'
export default function ExportPage() {
const [exports, setExports] = useState<Export[]>([])
const [regulations, setRegulations] = useState<Regulation[]>([])
const [loading, setLoading] = useState(true)
const [generating, setGenerating] = useState(false)
const [wizardStep, setWizardStep] = useState(1)
const [exportType, setExportType] = useState('full')
const [selectedRegulations, setSelectedRegulations] = useState<string[]>([])
const [selectedDomains, setSelectedDomains] = useState<string[]>([])
const [currentExport, setCurrentExport] = useState<Export | null>(null)
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'
useEffect(() => {
loadData()
}, [])
const loadData = async () => {
setLoading(true)
try {
const [exportsRes, regulationsRes] = await Promise.all([
fetch(`${BACKEND_URL}/api/v1/compliance/exports`),
fetch(`${BACKEND_URL}/api/v1/compliance/regulations`),
])
if (exportsRes.ok) {
const data = await exportsRes.json()
setExports(data.exports || [])
}
if (regulationsRes.ok) {
const data = await regulationsRes.json()
setRegulations(data.regulations || [])
}
} catch (error) {
console.error('Failed to load data:', error)
} finally {
setLoading(false)
}
}
const startExport = async () => {
setGenerating(true)
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/export`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
export_type: exportType,
included_regulations: selectedRegulations.length > 0 ? selectedRegulations : null,
included_domains: selectedDomains.length > 0 ? selectedDomains : null,
}),
})
if (res.ok) {
const exportData = await res.json()
setCurrentExport(exportData)
setWizardStep(4)
loadData()
} else {
const error = await res.text()
alert(`Export fehlgeschlagen: ${error}`)
}
} catch (error) {
console.error('Export failed:', error)
alert('Export fehlgeschlagen')
} finally {
setGenerating(false)
}
}
const downloadExport = (exportId: string) => {
window.open(`${BACKEND_URL}/api/v1/compliance/export/${exportId}/download`, '_blank')
}
const resetWizard = () => {
setWizardStep(1)
setExportType('full')
setSelectedRegulations([])
setSelectedDomains([])
setCurrentExport(null)
}
const toggleRegulation = (code: string) => {
setSelectedRegulations((prev) =>
prev.includes(code) ? prev.filter((r) => r !== code) : [...prev, code]
)
}
const toggleDomain = (domain: string) => {
setSelectedDomains((prev) =>
prev.includes(domain) ? prev.filter((d) => d !== domain) : [...prev, domain]
)
}
const formatFileSize = (bytes: number | null) => {
if (!bytes) return '-'
if (bytes < 1024) return `${bytes} B`
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
}
const renderWizardSteps = () => (
<div className="flex items-center justify-center mb-8">
{[
{ num: 1, label: 'Typ' },
{ num: 2, label: 'Scope' },
{ num: 3, label: 'Bestaetigen' },
{ num: 4, label: 'Download' },
].map((step, idx) => (
<div key={step.num} className="flex items-center">
<div className={`flex items-center justify-center w-10 h-10 rounded-full font-medium ${
wizardStep >= step.num
? 'bg-primary-600 text-white'
: 'bg-slate-200 text-slate-500'
}`}>
{wizardStep > step.num ? (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
) : (
step.num
)}
</div>
<span className={`ml-2 text-sm ${wizardStep >= step.num ? 'text-slate-900' : 'text-slate-500'}`}>
{step.label}
</span>
{idx < 3 && (
<div className={`w-16 h-0.5 mx-4 ${wizardStep > step.num ? 'bg-primary-600' : 'bg-slate-200'}`} />
)}
</div>
))}
</div>
)
const renderStep1 = () => (
<div className="space-y-4">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Export-Typ waehlen</h3>
<div className="grid gap-4">
{EXPORT_TYPES.map((type) => (
<button
key={type.value}
onClick={() => setExportType(type.value)}
className={`p-4 rounded-lg border-2 text-left transition-colors ${
exportType === type.value
? 'border-primary-600 bg-primary-50'
: 'border-slate-200 hover:border-slate-300'
}`}
>
<div className="flex items-center gap-3">
<div className={`w-5 h-5 rounded-full border-2 flex items-center justify-center ${
exportType === type.value ? 'border-primary-600' : 'border-slate-300'
}`}>
{exportType === type.value && (
<div className="w-3 h-3 rounded-full bg-primary-600" />
)}
</div>
<div>
<p className="font-medium text-slate-900">{type.label}</p>
<p className="text-sm text-slate-500">{type.description}</p>
</div>
</div>
</button>
))}
</div>
<div className="flex justify-end pt-4">
<button
onClick={() => setWizardStep(2)}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Weiter
</button>
</div>
</div>
)
const renderStep2 = () => (
<div className="space-y-6">
<h3 className="text-lg font-semibold text-slate-900">Scope definieren (optional)</h3>
{/* Regulations Filter */}
<div>
<h4 className="text-sm font-medium text-slate-700 mb-3">Verordnungen filtern</h4>
<p className="text-sm text-slate-500 mb-3">Leer lassen fuer alle Verordnungen</p>
<div className="grid grid-cols-2 md:grid-cols-4 gap-2">
{regulations.map((reg) => (
<button
key={reg.code}
onClick={() => toggleRegulation(reg.code)}
className={`px-3 py-2 text-sm rounded-lg border transition-colors ${
selectedRegulations.includes(reg.code)
? 'border-primary-600 bg-primary-50 text-primary-700'
: 'border-slate-200 text-slate-600 hover:border-slate-300'
}`}
>
{reg.code}
</button>
))}
</div>
</div>
{/* Domains Filter */}
<div>
<h4 className="text-sm font-medium text-slate-700 mb-3">Domains filtern</h4>
<p className="text-sm text-slate-500 mb-3">Leer lassen fuer alle Domains</p>
<div className="grid grid-cols-2 md:grid-cols-3 gap-2">
{DOMAIN_OPTIONS.map((domain) => (
<button
key={domain.value}
onClick={() => toggleDomain(domain.value)}
className={`px-3 py-2 text-sm rounded-lg border transition-colors ${
selectedDomains.includes(domain.value)
? 'border-primary-600 bg-primary-50 text-primary-700'
: 'border-slate-200 text-slate-600 hover:border-slate-300'
}`}
>
{domain.label}
</button>
))}
</div>
</div>
<div className="flex justify-between pt-4">
<button
onClick={() => setWizardStep(1)}
className="px-6 py-2 text-slate-600 hover:text-slate-800"
>
Zurueck
</button>
<button
onClick={() => setWizardStep(3)}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Weiter
</button>
</div>
</div>
)
const renderStep3 = () => (
<div className="space-y-6">
<h3 className="text-lg font-semibold text-slate-900">Export bestaetigen</h3>
<div className="bg-slate-50 rounded-lg p-6 space-y-4">
<div className="flex justify-between">
<span className="text-slate-600">Export-Typ:</span>
<span className="font-medium text-slate-900">
{EXPORT_TYPES.find((t) => t.value === exportType)?.label}
</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Verordnungen:</span>
<span className="font-medium text-slate-900">
{selectedRegulations.length > 0 ? selectedRegulations.join(', ') : 'Alle'}
</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Domains:</span>
<span className="font-medium text-slate-900">
{selectedDomains.length > 0
? selectedDomains.map((d) => DOMAIN_OPTIONS.find((o) => o.value === d)?.label).join(', ')
: 'Alle'}
</span>
</div>
</div>
<div className="p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
<p className="text-sm text-yellow-800">
Der Export kann je nach Datenmenge einige Sekunden dauern.
Nach Abschluss koennen Sie die ZIP-Datei herunterladen.
</p>
</div>
<div className="flex justify-between pt-4">
<button
onClick={() => setWizardStep(2)}
className="px-6 py-2 text-slate-600 hover:text-slate-800"
>
Zurueck
</button>
<button
onClick={startExport}
disabled={generating}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 disabled:opacity-50 flex items-center gap-2"
>
{generating && (
<svg className="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
</svg>
)}
{generating ? 'Generiere...' : 'Export starten'}
</button>
</div>
</div>
)
const renderStep4 = () => (
<div className="space-y-6 text-center">
{currentExport?.status === 'completed' ? (
<>
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto">
<svg className="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
</div>
<h3 className="text-lg font-semibold text-slate-900">Export erfolgreich!</h3>
<div className="bg-slate-50 rounded-lg p-6 text-left space-y-3">
<div className="flex justify-between">
<span className="text-slate-600">Compliance Score:</span>
<span className="font-medium text-slate-900">{currentExport.compliance_score?.toFixed(1)}%</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Controls:</span>
<span className="font-medium text-slate-900">{currentExport.total_controls}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Nachweise:</span>
<span className="font-medium text-slate-900">{currentExport.total_evidence}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">Dateigroesse:</span>
<span className="font-medium text-slate-900">{formatFileSize(currentExport.file_size_bytes)}</span>
</div>
<div className="flex justify-between">
<span className="text-slate-600">SHA-256:</span>
<span className="font-mono text-xs text-slate-500 truncate max-w-xs">{currentExport.file_hash}</span>
</div>
</div>
<div className="flex justify-center gap-4 pt-4">
<button
onClick={resetWizard}
className="px-6 py-2 text-slate-600 hover:text-slate-800"
>
Neuer Export
</button>
<button
onClick={() => downloadExport(currentExport.id)}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 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-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
ZIP herunterladen
</button>
</div>
</>
) : (
<>
<div className="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto">
<svg className="w-8 h-8 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</div>
<h3 className="text-lg font-semibold text-slate-900">Export fehlgeschlagen</h3>
<p className="text-slate-500">{currentExport?.error_message || 'Unbekannter Fehler'}</p>
<button
onClick={resetWizard}
className="px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Erneut versuchen
</button>
</>
)}
</div>
)
const exp = useExport()
return (
<AdminLayout title="Audit Export" description="Export fuer externe Pruefer">
@@ -441,60 +35,32 @@ export default function ExportPage() {
</Link>
</div>
{loading ? (
{exp.loading ? (
<div className="flex items-center justify-center h-64">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary-600" />
</div>
) : (
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Wizard */}
<div className="lg:col-span-2 bg-white rounded-xl shadow-sm border p-6">
{renderWizardSteps()}
{wizardStep === 1 && renderStep1()}
{wizardStep === 2 && renderStep2()}
{wizardStep === 3 && renderStep3()}
{wizardStep === 4 && renderStep4()}
</div>
{/* Export History */}
<div className="bg-white rounded-xl shadow-sm border p-6">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Letzte Exports</h3>
{exports.length === 0 ? (
<p className="text-slate-500 text-sm">Noch keine Exports vorhanden</p>
) : (
<div className="space-y-3">
{exports.slice(0, 10).map((exp) => (
<div key={exp.id} className="p-3 bg-slate-50 rounded-lg">
<div className="flex items-center justify-between mb-1">
<span className={`px-2 py-0.5 text-xs rounded-full ${
exp.status === 'completed' ? 'bg-green-100 text-green-700' :
exp.status === 'failed' ? 'bg-red-100 text-red-700' :
'bg-yellow-100 text-yellow-700'
}`}>
{exp.status}
</span>
<span className="text-xs text-slate-500">
{new Date(exp.requested_at).toLocaleDateString('de-DE')}
</span>
</div>
<p className="text-sm font-medium text-slate-900">{exp.export_name}</p>
<p className="text-xs text-slate-500">{exp.export_type} - {formatFileSize(exp.file_size_bytes)}</p>
{exp.status === 'completed' && (
<button
onClick={() => downloadExport(exp.id)}
className="mt-2 text-xs text-primary-600 hover:text-primary-700 font-medium"
>
Download
</button>
)}
</div>
))}
</div>
)}
</div>
<ExportWizard
wizardStep={exp.wizardStep}
setWizardStep={exp.setWizardStep}
exportType={exp.exportType}
setExportType={exp.setExportType}
regulations={exp.regulations}
selectedRegulations={exp.selectedRegulations}
toggleRegulation={exp.toggleRegulation}
selectedDomains={exp.selectedDomains}
toggleDomain={exp.toggleDomain}
generating={exp.generating}
startExport={exp.startExport}
currentExport={exp.currentExport}
resetWizard={exp.resetWizard}
downloadExport={exp.downloadExport}
/>
<ExportHistory
exports={exp.exports}
downloadExport={exp.downloadExport}
/>
</div>
)}
</AdminLayout>

View File

@@ -0,0 +1,141 @@
'use client'
import type { RiskFormData } from './types'
import { RISK_COLORS, CATEGORY_OPTIONS, STATUS_OPTIONS, calculateRiskLevel } from './types'
interface RiskFormProps {
formData: RiskFormData
setFormData: (data: RiskFormData) => void
isCreate: boolean
}
export default function RiskForm({ formData, setFormData, isCreate }: RiskFormProps) {
return (
<div className="space-y-4">
{isCreate && (
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Risk ID</label>
<input
type="text"
value={formData.risk_id}
onChange={(e) => setFormData({ ...formData, risk_id: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
)}
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Titel *</label>
<input
type="text"
value={formData.title}
onChange={(e) => setFormData({ ...formData, title: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Beschreibung</label>
<textarea
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
rows={2}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Kategorie</label>
<select
value={formData.category}
onChange={(e) => setFormData({ ...formData, category: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
>
{CATEGORY_OPTIONS.map((c) => (
<option key={c.value} value={c.value}>{c.label}</option>
))}
</select>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Status</label>
<select
value={formData.status}
onChange={(e) => setFormData({ ...formData, status: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
>
{STATUS_OPTIONS.map((s) => (
<option key={s} value={s}>{s}</option>
))}
</select>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Likelihood (1-5)</label>
<input
type="range"
min="1"
max="5"
value={formData.likelihood}
onChange={(e) => setFormData({ ...formData, likelihood: parseInt(e.target.value) })}
className="w-full"
/>
<div className="flex justify-between text-xs text-slate-500">
<span>1</span>
<span className="font-medium">{formData.likelihood}</span>
<span>5</span>
</div>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Impact (1-5)</label>
<input
type="range"
min="1"
max="5"
value={formData.impact}
onChange={(e) => setFormData({ ...formData, impact: parseInt(e.target.value) })}
className="w-full"
/>
<div className="flex justify-between text-xs text-slate-500">
<span>1</span>
<span className="font-medium">{formData.impact}</span>
<span>5</span>
</div>
</div>
</div>
<div className="p-3 bg-slate-50 rounded-lg">
<p className="text-sm text-slate-600">
Berechnetes Risiko:{' '}
<span className={`font-medium px-2 py-0.5 rounded text-white ${RISK_COLORS[calculateRiskLevel(formData.likelihood, formData.impact)]}`}>
{calculateRiskLevel(formData.likelihood, formData.impact).toUpperCase()} ({formData.likelihood * formData.impact})
</span>
</p>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Verantwortlich</label>
<input
type="text"
value={formData.owner}
onChange={(e) => setFormData({ ...formData, owner: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Behandlungsplan</label>
<textarea
value={formData.treatment_plan}
onChange={(e) => setFormData({ ...formData, treatment_plan: e.target.value })}
rows={2}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
</div>
)
}

View File

@@ -0,0 +1,76 @@
'use client'
import type { Risk } from './types'
import { RISK_COLORS, CATEGORY_OPTIONS } from './types'
interface RiskListProps {
risks: Risk[]
onEditRisk: (risk: Risk) => void
}
export default function RiskList({ risks, onEditRisk }: RiskListProps) {
return (
<div className="bg-white rounded-xl shadow-sm border overflow-hidden">
<table className="w-full">
<thead className="bg-slate-50">
<tr>
<th className="px-4 py-3 text-left text-xs font-medium text-slate-500 uppercase">ID</th>
<th className="px-4 py-3 text-left text-xs font-medium text-slate-500 uppercase">Titel</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">Kategorie</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">L x I</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">Risiko</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">Status</th>
<th className="px-4 py-3 text-right text-xs font-medium text-slate-500 uppercase">Aktionen</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-200">
{risks.map((risk) => (
<tr key={risk.id} className="hover:bg-slate-50">
<td className="px-4 py-3">
<span className="font-mono font-medium text-primary-600">{risk.risk_id}</span>
</td>
<td className="px-4 py-3">
<div>
<p className="font-medium text-slate-900">{risk.title}</p>
{risk.description && (
<p className="text-sm text-slate-500 truncate max-w-md">{risk.description}</p>
)}
</div>
</td>
<td className="px-4 py-3 text-center">
<span className="text-sm text-slate-600">
{CATEGORY_OPTIONS.find((c) => c.value === risk.category)?.label || risk.category}
</span>
</td>
<td className="px-4 py-3 text-center">
<span className="font-mono">{risk.likelihood} x {risk.impact}</span>
</td>
<td className="px-4 py-3 text-center">
<span className={`px-2 py-1 text-xs font-medium rounded-full text-white ${RISK_COLORS[risk.inherent_risk] || 'bg-slate-500'}`}>
{risk.inherent_risk}
</span>
</td>
<td className="px-4 py-3 text-center">
<span className={`px-2 py-1 text-xs rounded-full ${
risk.status === 'mitigated' ? 'bg-green-100 text-green-700' :
risk.status === 'accepted' ? 'bg-blue-100 text-blue-700' :
'bg-slate-100 text-slate-700'
}`}>
{risk.status}
</span>
</td>
<td className="px-4 py-3 text-right">
<button
onClick={() => onEditRisk(risk)}
className="text-sm text-primary-600 hover:text-primary-700 font-medium"
>
Bearbeiten
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)
}

View File

@@ -0,0 +1,98 @@
'use client'
import type { Risk } from './types'
import { RISK_COLORS, RISK_BG_COLORS, calculateRiskLevel } from './types'
interface RiskMatrixProps {
risks: Risk[]
onEditRisk: (risk: Risk) => void
}
export default function RiskMatrix({ risks, onEditRisk }: RiskMatrixProps) {
const matrix: Record<number, Record<number, Risk[]>> = {}
for (let l = 1; l <= 5; l++) {
matrix[l] = {}
for (let i = 1; i <= 5; i++) {
matrix[l][i] = []
}
}
risks.forEach((risk) => {
if (matrix[risk.likelihood] && matrix[risk.likelihood][risk.impact]) {
matrix[risk.likelihood][risk.impact].push(risk)
}
})
return (
<div className="bg-white rounded-xl shadow-sm border p-6">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Risk Matrix (Likelihood x Impact)</h3>
<div className="overflow-x-auto">
<div className="inline-block">
{/* Column headers (Impact) */}
<div className="flex ml-16">
{[1, 2, 3, 4, 5].map((i) => (
<div key={i} className="w-24 text-center text-sm font-medium text-slate-500 pb-2">
Impact {i}
</div>
))}
</div>
{/* Matrix rows */}
{[5, 4, 3, 2, 1].map((likelihood) => (
<div key={likelihood} className="flex items-center">
<div className="w-16 text-sm font-medium text-slate-500 text-right pr-2">
L{likelihood}
</div>
{[1, 2, 3, 4, 5].map((impact) => {
const level = calculateRiskLevel(likelihood, impact)
const cellRisks = matrix[likelihood][impact]
return (
<div
key={impact}
className={`w-24 h-20 border m-0.5 rounded flex flex-col items-center justify-center ${RISK_BG_COLORS[level]}`}
>
{cellRisks.length > 0 && (
<div className="flex flex-wrap gap-1 justify-center">
{cellRisks.map((r) => (
<button
key={r.id}
onClick={() => onEditRisk(r)}
className={`px-2 py-0.5 text-xs font-medium rounded text-white ${RISK_COLORS[r.inherent_risk] || 'bg-slate-500'} hover:opacity-80`}
title={r.title}
>
{r.risk_id}
</button>
))}
</div>
)}
</div>
)
})}
</div>
))}
</div>
</div>
{/* Legend */}
<div className="flex gap-4 mt-6 pt-4 border-t">
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-green-500 rounded" />
<span className="text-sm text-slate-600">Low (1-5)</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-yellow-500 rounded" />
<span className="text-sm text-slate-600">Medium (6-11)</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-orange-500 rounded" />
<span className="text-sm text-slate-600">High (12-19)</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-red-500 rounded" />
<span className="text-sm text-slate-600">Critical (20-25)</span>
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,65 @@
export interface Risk {
id: string
risk_id: string
title: string
description: string
category: string
likelihood: number
impact: number
inherent_risk: string
mitigating_controls: string[] | null
residual_likelihood: number | null
residual_impact: number | null
residual_risk: string | null
owner: string
status: string
treatment_plan: string
}
export const RISK_COLORS: Record<string, string> = {
low: 'bg-green-500',
medium: 'bg-yellow-500',
high: 'bg-orange-500',
critical: 'bg-red-500',
}
export const RISK_BG_COLORS: Record<string, string> = {
low: 'bg-green-100 border-green-300',
medium: 'bg-yellow-100 border-yellow-300',
high: 'bg-orange-100 border-orange-300',
critical: 'bg-red-100 border-red-300',
}
export const STATUS_OPTIONS = ['open', 'mitigated', 'accepted', 'transferred']
export const CATEGORY_OPTIONS = [
{ value: 'data_breach', label: 'Datenschutzverletzung' },
{ value: 'compliance_gap', label: 'Compliance-Luecke' },
{ value: 'vendor_risk', label: 'Lieferantenrisiko' },
{ value: 'operational', label: 'Betriebsrisiko' },
{ value: 'technical', label: 'Technisches Risiko' },
{ value: 'legal', label: 'Rechtliches Risiko' },
]
export const calculateRiskLevel = (likelihood: number, impact: number): string => {
const score = likelihood * impact
if (score >= 20) return 'critical'
if (score >= 12) return 'high'
if (score >= 6) return 'medium'
return 'low'
}
export interface RiskFormData {
risk_id: string
title: string
description: string
category: string
likelihood: number
impact: number
owner: string
treatment_plan: string
status: string
mitigating_controls: string[]
residual_likelihood: number | null
residual_impact: number | null
}

View File

@@ -0,0 +1,163 @@
'use client'
import { useState, useEffect } from 'react'
import type { Risk, RiskFormData } from './types'
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'
export function useRisks() {
const [risks, setRisks] = useState<Risk[]>([])
const [loading, setLoading] = useState(true)
const [viewMode, setViewMode] = useState<'matrix' | 'list'>('matrix')
const [selectedRisk, setSelectedRisk] = useState<Risk | null>(null)
const [editModalOpen, setEditModalOpen] = useState(false)
const [createModalOpen, setCreateModalOpen] = useState(false)
const [formData, setFormData] = useState<RiskFormData>({
risk_id: '',
title: '',
description: '',
category: 'compliance_gap',
likelihood: 3,
impact: 3,
owner: '',
treatment_plan: '',
status: 'open',
mitigating_controls: [],
residual_likelihood: null,
residual_impact: null,
})
useEffect(() => {
loadRisks()
}, [])
const loadRisks = async () => {
setLoading(true)
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/risks`)
if (res.ok) {
const data = await res.json()
setRisks(data.risks || [])
}
} catch (error) {
console.error('Failed to load risks:', error)
} finally {
setLoading(false)
}
}
const openCreateModal = () => {
setFormData({
risk_id: `RISK-${String(risks.length + 1).padStart(3, '0')}`,
title: '',
description: '',
category: 'compliance_gap',
likelihood: 3,
impact: 3,
owner: '',
treatment_plan: '',
status: 'open',
mitigating_controls: [],
residual_likelihood: null,
residual_impact: null,
})
setCreateModalOpen(true)
}
const openEditModal = (risk: Risk) => {
setSelectedRisk(risk)
setFormData({
risk_id: risk.risk_id,
title: risk.title,
description: risk.description || '',
category: risk.category,
likelihood: risk.likelihood,
impact: risk.impact,
owner: risk.owner || '',
treatment_plan: risk.treatment_plan || '',
status: risk.status,
mitigating_controls: risk.mitigating_controls || [],
residual_likelihood: risk.residual_likelihood,
residual_impact: risk.residual_impact,
})
setEditModalOpen(true)
}
const handleCreate = async () => {
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/risks`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
risk_id: formData.risk_id,
title: formData.title,
description: formData.description,
category: formData.category,
likelihood: formData.likelihood,
impact: formData.impact,
owner: formData.owner,
treatment_plan: formData.treatment_plan,
mitigating_controls: formData.mitigating_controls,
}),
})
if (res.ok) {
setCreateModalOpen(false)
loadRisks()
} else {
const error = await res.text()
alert(`Fehler: ${error}`)
}
} catch (error) {
console.error('Create failed:', error)
alert('Fehler beim Erstellen')
}
}
const handleUpdate = async () => {
if (!selectedRisk) return
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/risks/${selectedRisk.risk_id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: formData.title,
description: formData.description,
category: formData.category,
likelihood: formData.likelihood,
impact: formData.impact,
owner: formData.owner,
treatment_plan: formData.treatment_plan,
status: formData.status,
mitigating_controls: formData.mitigating_controls,
residual_likelihood: formData.residual_likelihood,
residual_impact: formData.residual_impact,
}),
})
if (res.ok) {
setEditModalOpen(false)
loadRisks()
} else {
const error = await res.text()
alert(`Fehler: ${error}`)
}
} catch (error) {
console.error('Update failed:', error)
alert('Fehler beim Aktualisieren')
}
}
return {
risks, loading,
viewMode, setViewMode,
selectedRisk,
editModalOpen, setEditModalOpen,
createModalOpen, setCreateModalOpen,
formData, setFormData,
openCreateModal, openEditModal,
handleCreate, handleUpdate,
}
}

View File

@@ -9,496 +9,15 @@
* - Risk assessment / update
*/
import { useState, useEffect } from 'react'
import Link from 'next/link'
import AdminLayout from '@/components/admin/AdminLayout'
interface Risk {
id: string
risk_id: string
title: string
description: string
category: string
likelihood: number
impact: number
inherent_risk: string
mitigating_controls: string[] | null
residual_likelihood: number | null
residual_impact: number | null
residual_risk: string | null
owner: string
status: string
treatment_plan: string
}
const RISK_COLORS: Record<string, string> = {
low: 'bg-green-500',
medium: 'bg-yellow-500',
high: 'bg-orange-500',
critical: 'bg-red-500',
}
const RISK_BG_COLORS: Record<string, string> = {
low: 'bg-green-100 border-green-300',
medium: 'bg-yellow-100 border-yellow-300',
high: 'bg-orange-100 border-orange-300',
critical: 'bg-red-100 border-red-300',
}
const STATUS_OPTIONS = ['open', 'mitigated', 'accepted', 'transferred']
const CATEGORY_OPTIONS = [
{ value: 'data_breach', label: 'Datenschutzverletzung' },
{ value: 'compliance_gap', label: 'Compliance-Luecke' },
{ value: 'vendor_risk', label: 'Lieferantenrisiko' },
{ value: 'operational', label: 'Betriebsrisiko' },
{ value: 'technical', label: 'Technisches Risiko' },
{ value: 'legal', label: 'Rechtliches Risiko' },
]
const calculateRiskLevel = (likelihood: number, impact: number): string => {
const score = likelihood * impact
if (score >= 20) return 'critical'
if (score >= 12) return 'high'
if (score >= 6) return 'medium'
return 'low'
}
import { useRisks } from './_components/useRisks'
import RiskMatrix from './_components/RiskMatrix'
import RiskList from './_components/RiskList'
import RiskForm from './_components/RiskForm'
export default function RisksPage() {
const [risks, setRisks] = useState<Risk[]>([])
const [loading, setLoading] = useState(true)
const [viewMode, setViewMode] = useState<'matrix' | 'list'>('matrix')
const [selectedRisk, setSelectedRisk] = useState<Risk | null>(null)
const [editModalOpen, setEditModalOpen] = useState(false)
const [createModalOpen, setCreateModalOpen] = useState(false)
const [formData, setFormData] = useState({
risk_id: '',
title: '',
description: '',
category: 'compliance_gap',
likelihood: 3,
impact: 3,
owner: '',
treatment_plan: '',
status: 'open',
mitigating_controls: [] as string[],
residual_likelihood: null as number | null,
residual_impact: null as number | null,
})
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'
useEffect(() => {
loadRisks()
}, [])
const loadRisks = async () => {
setLoading(true)
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/risks`)
if (res.ok) {
const data = await res.json()
setRisks(data.risks || [])
}
} catch (error) {
console.error('Failed to load risks:', error)
} finally {
setLoading(false)
}
}
const openCreateModal = () => {
setFormData({
risk_id: `RISK-${String(risks.length + 1).padStart(3, '0')}`,
title: '',
description: '',
category: 'compliance_gap',
likelihood: 3,
impact: 3,
owner: '',
treatment_plan: '',
status: 'open',
mitigating_controls: [],
residual_likelihood: null,
residual_impact: null,
})
setCreateModalOpen(true)
}
const openEditModal = (risk: Risk) => {
setSelectedRisk(risk)
setFormData({
risk_id: risk.risk_id,
title: risk.title,
description: risk.description || '',
category: risk.category,
likelihood: risk.likelihood,
impact: risk.impact,
owner: risk.owner || '',
treatment_plan: risk.treatment_plan || '',
status: risk.status,
mitigating_controls: risk.mitigating_controls || [],
residual_likelihood: risk.residual_likelihood,
residual_impact: risk.residual_impact,
})
setEditModalOpen(true)
}
const handleCreate = async () => {
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/risks`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
risk_id: formData.risk_id,
title: formData.title,
description: formData.description,
category: formData.category,
likelihood: formData.likelihood,
impact: formData.impact,
owner: formData.owner,
treatment_plan: formData.treatment_plan,
mitigating_controls: formData.mitigating_controls,
}),
})
if (res.ok) {
setCreateModalOpen(false)
loadRisks()
} else {
const error = await res.text()
alert(`Fehler: ${error}`)
}
} catch (error) {
console.error('Create failed:', error)
alert('Fehler beim Erstellen')
}
}
const handleUpdate = async () => {
if (!selectedRisk) return
try {
const res = await fetch(`${BACKEND_URL}/api/v1/compliance/risks/${selectedRisk.risk_id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: formData.title,
description: formData.description,
category: formData.category,
likelihood: formData.likelihood,
impact: formData.impact,
owner: formData.owner,
treatment_plan: formData.treatment_plan,
status: formData.status,
mitigating_controls: formData.mitigating_controls,
residual_likelihood: formData.residual_likelihood,
residual_impact: formData.residual_impact,
}),
})
if (res.ok) {
setEditModalOpen(false)
loadRisks()
} else {
const error = await res.text()
alert(`Fehler: ${error}`)
}
} catch (error) {
console.error('Update failed:', error)
alert('Fehler beim Aktualisieren')
}
}
// Build matrix data structure
const buildMatrix = () => {
const matrix: Record<number, Record<number, Risk[]>> = {}
for (let l = 1; l <= 5; l++) {
matrix[l] = {}
for (let i = 1; i <= 5; i++) {
matrix[l][i] = []
}
}
risks.forEach((risk) => {
if (matrix[risk.likelihood] && matrix[risk.likelihood][risk.impact]) {
matrix[risk.likelihood][risk.impact].push(risk)
}
})
return matrix
}
const renderMatrix = () => {
const matrix = buildMatrix()
return (
<div className="bg-white rounded-xl shadow-sm border p-6">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Risk Matrix (Likelihood x Impact)</h3>
<div className="overflow-x-auto">
<div className="inline-block">
{/* Column headers (Impact) */}
<div className="flex ml-16">
{[1, 2, 3, 4, 5].map((i) => (
<div key={i} className="w-24 text-center text-sm font-medium text-slate-500 pb-2">
Impact {i}
</div>
))}
</div>
{/* Matrix rows */}
{[5, 4, 3, 2, 1].map((likelihood) => (
<div key={likelihood} className="flex items-center">
<div className="w-16 text-sm font-medium text-slate-500 text-right pr-2">
L{likelihood}
</div>
{[1, 2, 3, 4, 5].map((impact) => {
const level = calculateRiskLevel(likelihood, impact)
const cellRisks = matrix[likelihood][impact]
return (
<div
key={impact}
className={`w-24 h-20 border m-0.5 rounded flex flex-col items-center justify-center ${RISK_BG_COLORS[level]}`}
>
{cellRisks.length > 0 && (
<div className="flex flex-wrap gap-1 justify-center">
{cellRisks.map((r) => (
<button
key={r.id}
onClick={() => openEditModal(r)}
className={`px-2 py-0.5 text-xs font-medium rounded text-white ${RISK_COLORS[r.inherent_risk] || 'bg-slate-500'} hover:opacity-80`}
title={r.title}
>
{r.risk_id}
</button>
))}
</div>
)}
</div>
)
})}
</div>
))}
</div>
</div>
{/* Legend */}
<div className="flex gap-4 mt-6 pt-4 border-t">
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-green-500 rounded" />
<span className="text-sm text-slate-600">Low (1-5)</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-yellow-500 rounded" />
<span className="text-sm text-slate-600">Medium (6-11)</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-orange-500 rounded" />
<span className="text-sm text-slate-600">High (12-19)</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 bg-red-500 rounded" />
<span className="text-sm text-slate-600">Critical (20-25)</span>
</div>
</div>
</div>
)
}
const renderList = () => (
<div className="bg-white rounded-xl shadow-sm border overflow-hidden">
<table className="w-full">
<thead className="bg-slate-50">
<tr>
<th className="px-4 py-3 text-left text-xs font-medium text-slate-500 uppercase">ID</th>
<th className="px-4 py-3 text-left text-xs font-medium text-slate-500 uppercase">Titel</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">Kategorie</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">L x I</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">Risiko</th>
<th className="px-4 py-3 text-center text-xs font-medium text-slate-500 uppercase">Status</th>
<th className="px-4 py-3 text-right text-xs font-medium text-slate-500 uppercase">Aktionen</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-200">
{risks.map((risk) => (
<tr key={risk.id} className="hover:bg-slate-50">
<td className="px-4 py-3">
<span className="font-mono font-medium text-primary-600">{risk.risk_id}</span>
</td>
<td className="px-4 py-3">
<div>
<p className="font-medium text-slate-900">{risk.title}</p>
{risk.description && (
<p className="text-sm text-slate-500 truncate max-w-md">{risk.description}</p>
)}
</div>
</td>
<td className="px-4 py-3 text-center">
<span className="text-sm text-slate-600">
{CATEGORY_OPTIONS.find((c) => c.value === risk.category)?.label || risk.category}
</span>
</td>
<td className="px-4 py-3 text-center">
<span className="font-mono">{risk.likelihood} x {risk.impact}</span>
</td>
<td className="px-4 py-3 text-center">
<span className={`px-2 py-1 text-xs font-medium rounded-full text-white ${RISK_COLORS[risk.inherent_risk] || 'bg-slate-500'}`}>
{risk.inherent_risk}
</span>
</td>
<td className="px-4 py-3 text-center">
<span className={`px-2 py-1 text-xs rounded-full ${
risk.status === 'mitigated' ? 'bg-green-100 text-green-700' :
risk.status === 'accepted' ? 'bg-blue-100 text-blue-700' :
'bg-slate-100 text-slate-700'
}`}>
{risk.status}
</span>
</td>
<td className="px-4 py-3 text-right">
<button
onClick={() => openEditModal(risk)}
className="text-sm text-primary-600 hover:text-primary-700 font-medium"
>
Bearbeiten
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)
const renderForm = (isCreate: boolean) => (
<div className="space-y-4">
{isCreate && (
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Risk ID</label>
<input
type="text"
value={formData.risk_id}
onChange={(e) => setFormData({ ...formData, risk_id: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
)}
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Titel *</label>
<input
type="text"
value={formData.title}
onChange={(e) => setFormData({ ...formData, title: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Beschreibung</label>
<textarea
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
rows={2}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Kategorie</label>
<select
value={formData.category}
onChange={(e) => setFormData({ ...formData, category: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
>
{CATEGORY_OPTIONS.map((c) => (
<option key={c.value} value={c.value}>{c.label}</option>
))}
</select>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Status</label>
<select
value={formData.status}
onChange={(e) => setFormData({ ...formData, status: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
>
{STATUS_OPTIONS.map((s) => (
<option key={s} value={s}>{s}</option>
))}
</select>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Likelihood (1-5)</label>
<input
type="range"
min="1"
max="5"
value={formData.likelihood}
onChange={(e) => setFormData({ ...formData, likelihood: parseInt(e.target.value) })}
className="w-full"
/>
<div className="flex justify-between text-xs text-slate-500">
<span>1</span>
<span className="font-medium">{formData.likelihood}</span>
<span>5</span>
</div>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Impact (1-5)</label>
<input
type="range"
min="1"
max="5"
value={formData.impact}
onChange={(e) => setFormData({ ...formData, impact: parseInt(e.target.value) })}
className="w-full"
/>
<div className="flex justify-between text-xs text-slate-500">
<span>1</span>
<span className="font-medium">{formData.impact}</span>
<span>5</span>
</div>
</div>
</div>
<div className="p-3 bg-slate-50 rounded-lg">
<p className="text-sm text-slate-600">
Berechnetes Risiko:{' '}
<span className={`font-medium px-2 py-0.5 rounded text-white ${RISK_COLORS[calculateRiskLevel(formData.likelihood, formData.impact)]}`}>
{calculateRiskLevel(formData.likelihood, formData.impact).toUpperCase()} ({formData.likelihood * formData.impact})
</span>
</p>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Verantwortlich</label>
<input
type="text"
value={formData.owner}
onChange={(e) => setFormData({ ...formData, owner: e.target.value })}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1">Behandlungsplan</label>
<textarea
value={formData.treatment_plan}
onChange={(e) => setFormData({ ...formData, treatment_plan: e.target.value })}
rows={2}
className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500"
/>
</div>
</div>
)
const r = useRisks()
return (
<AdminLayout title="Risk Matrix" description="Risikobewertung & Management">
@@ -519,17 +38,17 @@ export default function RisksPage() {
{/* View Toggle */}
<div className="flex bg-slate-100 rounded-lg p-1">
<button
onClick={() => setViewMode('matrix')}
onClick={() => r.setViewMode('matrix')}
className={`px-3 py-1.5 text-sm rounded-md transition-colors ${
viewMode === 'matrix' ? 'bg-white shadow text-slate-900' : 'text-slate-600'
r.viewMode === 'matrix' ? 'bg-white shadow text-slate-900' : 'text-slate-600'
}`}
>
Matrix
</button>
<button
onClick={() => setViewMode('list')}
onClick={() => r.setViewMode('list')}
className={`px-3 py-1.5 text-sm rounded-md transition-colors ${
viewMode === 'list' ? 'bg-white shadow text-slate-900' : 'text-slate-600'
r.viewMode === 'list' ? 'bg-white shadow text-slate-900' : 'text-slate-600'
}`}
>
Liste
@@ -537,7 +56,7 @@ export default function RisksPage() {
</div>
<button
onClick={openCreateModal}
onClick={r.openCreateModal}
className="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Risiko hinzufuegen
@@ -545,44 +64,44 @@ export default function RisksPage() {
</div>
{/* Content */}
{loading ? (
{r.loading ? (
<div className="flex items-center justify-center h-64">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary-600" />
</div>
) : risks.length === 0 ? (
) : r.risks.length === 0 ? (
<div className="bg-white rounded-xl shadow-sm border p-12 text-center">
<svg className="w-16 h-16 text-slate-300 mx-auto mb-4" 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>
<p className="text-slate-500 mb-4">Keine Risiken erfasst</p>
<button
onClick={openCreateModal}
onClick={r.openCreateModal}
className="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Erstes Risiko hinzufuegen
</button>
</div>
) : viewMode === 'matrix' ? (
renderMatrix()
) : r.viewMode === 'matrix' ? (
<RiskMatrix risks={r.risks} onEditRisk={r.openEditModal} />
) : (
renderList()
<RiskList risks={r.risks} onEditRisk={r.openEditModal} />
)}
{/* Create Modal */}
{createModalOpen && (
{r.createModalOpen && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
<div className="bg-white rounded-xl shadow-xl w-full max-w-lg p-6 max-h-[90vh] overflow-y-auto">
<h3 className="text-lg font-semibold text-slate-900 mb-4">Neues Risiko</h3>
{renderForm(true)}
<RiskForm formData={r.formData} setFormData={r.setFormData} isCreate={true} />
<div className="flex justify-end gap-3 mt-6">
<button
onClick={() => setCreateModalOpen(false)}
onClick={() => r.setCreateModalOpen(false)}
className="px-4 py-2 text-slate-600 hover:text-slate-800"
>
Abbrechen
</button>
<button
onClick={handleCreate}
onClick={r.handleCreate}
className="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Erstellen
@@ -593,22 +112,22 @@ export default function RisksPage() {
)}
{/* Edit Modal */}
{editModalOpen && selectedRisk && (
{r.editModalOpen && r.selectedRisk && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
<div className="bg-white rounded-xl shadow-xl w-full max-w-lg p-6 max-h-[90vh] overflow-y-auto">
<h3 className="text-lg font-semibold text-slate-900 mb-4">
Risiko bearbeiten: {selectedRisk.risk_id}
Risiko bearbeiten: {r.selectedRisk.risk_id}
</h3>
{renderForm(false)}
<RiskForm formData={r.formData} setFormData={r.setFormData} isCreate={false} />
<div className="flex justify-end gap-3 mt-6">
<button
onClick={() => setEditModalOpen(false)}
onClick={() => r.setEditModalOpen(false)}
className="px-4 py-2 text-slate-600 hover:text-slate-800"
>
Abbrechen
</button>
<button
onClick={handleUpdate}
onClick={r.handleUpdate}
className="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700"
>
Speichern