Add Exercise Enrichment Admin API and Update Documentation
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m17s
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m17s
- Introduced the `exercise_enrichment_admin` API for batch exercise enrichment, allowing superadmins to filter candidates, preview, and apply skills. - Updated the access layer documentation to include the new endpoint and its exempt status. - Enhanced the frontend with a new admin page for exercise enrichment and updated navigation to include this feature. - Incremented version to 0.8.179 and updated changelog to reflect these additions and improvements.
This commit is contained in:
1 parent
d1d8539b42
commit
f4196c3580
12 files changed
+2263
-5
No files matched your search
@@ -56,6 +56,7 @@ const LegalPage = lazy(() => import('./pages/LegalPage'))
|
||||
const AdminLegalDocumentsPage = lazy(() => import('./pages/AdminLegalDocumentsPage'))
|
||||
const AdminAiSkillRetrievalPage = lazy(() => import('./pages/AdminAiSkillRetrievalPage'))
|
||||
const AdminAiPromptsPage = lazy(() => import('./pages/AdminAiPromptsPage'))
|
||||
const AdminExerciseEnrichmentPage = lazy(() => import('./pages/AdminExerciseEnrichmentPage'))
|
||||
const SettingsLegalPage = lazy(() => import('./pages/SettingsLegalPage'))
|
||||
|
||||
/** Shield „Admin“: nur Super-Admin (global). Vereinsorga: Vereine → Mitglieder. */
|
||||
@@ -318,6 +319,14 @@ const appRouter = createBrowserRouter([
|
||||
</PlatformAdminRoute>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/exercise-enrichment',
|
||||
element: (
|
||||
<PlatformAdminRoute>
|
||||
<AdminExerciseEnrichmentPage />
|
||||
</PlatformAdminRoute>
|
||||
),
|
||||
},
|
||||
{ path: 'trainer-contexts', element: <TrainerContextsPage /> },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import { TreePine, FolderTree, Download, Grid3x3, Users, Scale, Brain, Sparkles } from 'lucide-react'
|
||||
import { TreePine, FolderTree, Download, Grid3x3, Users, Scale, Brain, Sparkles, Wand2 } from 'lucide-react'
|
||||
|
||||
/**
|
||||
* Admin-Seiten-Navigation (horizontal) — nur für Super-Admins (globaler Portal-Mandant).
|
||||
@@ -13,6 +13,7 @@ export default function AdminPageNav() {
|
||||
{ to: '/admin/mediawiki-import', label: 'Wiki-Import', icon: Download },
|
||||
{ to: '/admin/legal-documents', label: 'Rechtstexte', icon: Scale },
|
||||
{ to: '/admin/ai-prompts', label: 'KI Prompts', icon: Sparkles },
|
||||
{ to: '/admin/exercise-enrichment', label: 'Übungs-Anreicherung', icon: Wand2 },
|
||||
]
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,881 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import api from '../utils/api'
|
||||
import AdminPageNav from '../components/AdminPageNav'
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: 'draft', label: 'Entwurf' },
|
||||
{ value: 'in_review', label: 'In Prüfung' },
|
||||
{ value: 'approved', label: 'Freigegeben' },
|
||||
{ value: 'archived', label: 'Archiviert' },
|
||||
]
|
||||
|
||||
const VISIBILITY_OPTIONS = [
|
||||
{ value: 'private', label: 'Privat (Standard)' },
|
||||
{ value: 'all', label: 'Alle Sichtbarkeiten' },
|
||||
{ value: 'official', label: 'Offiziell' },
|
||||
{ value: 'club', label: 'Verein' },
|
||||
]
|
||||
|
||||
const MERGE_OPTIONS = [
|
||||
{
|
||||
value: 'replace_all',
|
||||
label: 'Alle Skills ersetzen (empfohlen)',
|
||||
hint: 'Bestehende Zuordnungen werden entfernt. Alle neuen Skills erhalten ai_suggested=true — klar als KI erkennbar.',
|
||||
},
|
||||
{
|
||||
value: 'replace_ai_only',
|
||||
label: 'Nur bisherige KI-Skills ersetzen',
|
||||
hint: 'Manuelle Skills bleiben; nur ai_suggested=true wird neu gesetzt.',
|
||||
},
|
||||
{
|
||||
value: 'additive',
|
||||
label: 'Ergänzen (manuell behalten)',
|
||||
hint: 'Manuelle Skills bleiben unverändert; KI ergänzt neue. Intensität/Level nur bei KI-Skills.',
|
||||
},
|
||||
]
|
||||
|
||||
const INSTRUCTION_LABELS = {
|
||||
goal: 'Ziel',
|
||||
execution: 'Durchführung',
|
||||
preparation: 'Vorbereitung',
|
||||
trainer_notes: 'Trainer-Hinweise',
|
||||
}
|
||||
|
||||
const CHUNK_SIZE = 25
|
||||
|
||||
function skillLabel(sk) {
|
||||
if (!sk) return '—'
|
||||
const name = sk.skill_name || `Skill #${sk.skill_id}`
|
||||
const inten = sk.intensity ? ` · Int. ${sk.intensity}` : ''
|
||||
const from = sk.required_level || '?'
|
||||
const to = sk.target_level || from
|
||||
const lvl = ` · ${from}→${to}`
|
||||
const ai = sk.ai_suggested ? ' · KI' : ' · manuell'
|
||||
return `${name}${inten}${lvl}${ai}`
|
||||
}
|
||||
|
||||
function buildFilterParams(filters) {
|
||||
const params = { status: filters.status, visibility: filters.visibility || 'private' }
|
||||
if (filters.focusAreaId) params.focus_area_id = Number(filters.focusAreaId)
|
||||
if (filters.withoutSkills) params.without_skills = true
|
||||
if (filters.withAiSuggested) params.with_ai_suggested_skills = true
|
||||
if (filters.search.trim()) params.search = filters.search.trim()
|
||||
return params
|
||||
}
|
||||
|
||||
function DiffBlock({ diff }) {
|
||||
if (!diff) return null
|
||||
const hasAny =
|
||||
(diff.added?.length || 0) + (diff.changed?.length || 0) + (diff.removed?.length || 0) > 0
|
||||
if (!hasAny) {
|
||||
return (
|
||||
<p className="text-muted" style={{ margin: '8px 0 0', fontSize: '0.9rem' }}>
|
||||
Keine Skill-Änderungen.
|
||||
</p>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div style={{ fontSize: '0.88rem', marginTop: 8 }}>
|
||||
{diff.added?.length > 0 && (
|
||||
<div>
|
||||
<strong style={{ color: 'var(--accent)' }}>Neu:</strong>{' '}
|
||||
{diff.added.map((s) => skillLabel(s)).join('; ')}
|
||||
</div>
|
||||
)}
|
||||
{diff.changed?.length > 0 && (
|
||||
<div style={{ marginTop: 4 }}>
|
||||
<strong>Geändert:</strong>{' '}
|
||||
{diff.changed.map((c) => (
|
||||
<span key={c.skill_id}>
|
||||
{c.skill_name}: {skillLabel(c.before)} → {skillLabel(c.after)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{diff.removed?.length > 0 && (
|
||||
<div style={{ marginTop: 4 }}>
|
||||
<strong style={{ color: 'var(--danger)' }}>Entfernt:</strong>{' '}
|
||||
{diff.removed.map((s) => skillLabel(s)).join('; ')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function RunDialog({
|
||||
open,
|
||||
onClose,
|
||||
exerciseCount,
|
||||
analysis,
|
||||
modes,
|
||||
setModes,
|
||||
mergeMode,
|
||||
setMergeMode,
|
||||
setStatusAfterApply,
|
||||
statusAfterApply,
|
||||
costConfirmed,
|
||||
setCostConfirmed,
|
||||
onStartPreview,
|
||||
jobRunning,
|
||||
}) {
|
||||
if (!open) return null
|
||||
|
||||
const est = analysis?.estimated_llm_calls
|
||||
const totalCalls = est?.total ?? 0
|
||||
const mergeHint = MERGE_OPTIONS.find((o) => o.value === mergeMode)?.hint || ''
|
||||
|
||||
return (
|
||||
<div
|
||||
className="modal-overlay"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="enrichment-run-title"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget && !jobRunning) onClose()
|
||||
}}
|
||||
style={{
|
||||
position: 'fixed',
|
||||
inset: 0,
|
||||
background: 'rgba(0,0,0,0.45)',
|
||||
zIndex: 1000,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 16,
|
||||
}}
|
||||
>
|
||||
<div className="card" style={{ maxWidth: 520, width: '100%', padding: 20, maxHeight: '90vh', overflow: 'auto' }}>
|
||||
<h2 id="enrichment-run-title" style={{ margin: '0 0 12px', fontSize: '1.15rem' }}>
|
||||
Batch-Anreicherung konfigurieren
|
||||
</h2>
|
||||
|
||||
<div
|
||||
style={{
|
||||
background: 'var(--surface2)',
|
||||
borderRadius: 8,
|
||||
padding: 12,
|
||||
marginBottom: 16,
|
||||
fontSize: '0.92rem',
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong>{exerciseCount}</strong> Übung(en) ausgewählt
|
||||
</div>
|
||||
{est && (
|
||||
<div style={{ marginTop: 8, color: 'var(--text2)' }}>
|
||||
Geschätzte LLM-Aufrufe: <strong>{totalCalls}</strong>
|
||||
{modes.skills && est.skills > 0 && (
|
||||
<span> · Skills: {est.skills}</span>
|
||||
)}
|
||||
{modes.summary && est.summary > 0 && (
|
||||
<span> · Kurzfassung: {est.summary}</span>
|
||||
)}
|
||||
{modes.instructions && est.instructions > 0 && (
|
||||
<span> · Anleitung: {est.instructions}</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{exerciseCount >= 25 && (
|
||||
<p style={{ margin: '10px 0 0', color: 'var(--danger)', fontSize: '0.88rem' }}>
|
||||
Großer Batch — OpenRouter-Kosten und Laufzeit beachten. Der Lauf kann mehrere Minuten dauern.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<fieldset style={{ border: 'none', padding: 0, margin: '0 0 16px' }}>
|
||||
<legend style={{ fontWeight: 600, marginBottom: 8 }}>Inhalte per KI</legend>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
<label style={{ display: 'flex', gap: 8, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={modes.skills}
|
||||
onChange={(e) => setModes((m) => ({ ...m, skills: e.target.checked }))}
|
||||
/>
|
||||
Fähigkeiten (inkl. Intensität & Levelbereich)
|
||||
</label>
|
||||
<label style={{ display: 'flex', gap: 8, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={modes.summary}
|
||||
onChange={(e) => setModes((m) => ({ ...m, summary: e.target.checked }))}
|
||||
/>
|
||||
Kurzfassung (Summary)
|
||||
</label>
|
||||
<label style={{ display: 'flex', gap: 8, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={modes.instructions}
|
||||
onChange={(e) => setModes((m) => ({ ...m, instructions: e.target.checked }))}
|
||||
/>
|
||||
Anleitung (Ziel, Durchführung, Vorbereitung, Trainer-Hinweise)
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{modes.skills && (
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<label className="form-label">
|
||||
Skill-Merge-Modus
|
||||
<select className="form-input" value={mergeMode} onChange={(e) => setMergeMode(e.target.value)}>
|
||||
{MERGE_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{mergeHint && (
|
||||
<p style={{ margin: '6px 0 0', fontSize: '0.85rem', color: 'var(--text2)' }}>{mergeHint}</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<label className="form-label" style={{ marginBottom: 16 }}>
|
||||
Nach erfolgreichem Apply Status
|
||||
<select
|
||||
className="form-input"
|
||||
value={statusAfterApply}
|
||||
onChange={(e) => setStatusAfterApply(e.target.value)}
|
||||
>
|
||||
<option value="in_review">In Prüfung</option>
|
||||
<option value="draft">Entwurf (unverändert)</option>
|
||||
<option value="">Status nicht ändern</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 8,
|
||||
alignItems: 'flex-start',
|
||||
marginBottom: 16,
|
||||
cursor: 'pointer',
|
||||
fontSize: '0.9rem',
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={costConfirmed}
|
||||
onChange={(e) => setCostConfirmed(e.target.checked)}
|
||||
style={{ marginTop: 3 }}
|
||||
/>
|
||||
<span>
|
||||
Ich bestätige <strong>{exerciseCount}</strong> Übung(en) und ca.{' '}
|
||||
<strong>{totalCalls}</strong> LLM-Aufruf(e) — mir sind die Kosten bewusst.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end', flexWrap: 'wrap' }}>
|
||||
<button type="button" className="btn btn-secondary" disabled={jobRunning} onClick={onClose}>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
disabled={
|
||||
jobRunning ||
|
||||
!costConfirmed ||
|
||||
exerciseCount === 0 ||
|
||||
(!modes.skills && !modes.summary && !modes.instructions)
|
||||
}
|
||||
onClick={onStartPreview}
|
||||
>
|
||||
Vorschau starten
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Superadmin: Batch-Anreicherung von Übungen per KI.
|
||||
*/
|
||||
export default function AdminExerciseEnrichmentPage() {
|
||||
const { user } = useAuth()
|
||||
const isSuperadmin = user?.role === 'superadmin'
|
||||
|
||||
const [filters, setFilters] = useState({
|
||||
status: 'draft',
|
||||
visibility: 'private',
|
||||
focusAreaId: '',
|
||||
withoutSkills: true,
|
||||
withAiSuggested: false,
|
||||
search: '',
|
||||
})
|
||||
const [focusAreas, setFocusAreas] = useState([])
|
||||
const [items, setItems] = useState([])
|
||||
const [total, setTotal] = useState(0)
|
||||
const [offset, setOffset] = useState(0)
|
||||
const limit = 25
|
||||
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
const [selected, setSelected] = useState(() => new Set())
|
||||
|
||||
const [dialogOpen, setDialogOpen] = useState(false)
|
||||
const [analysis, setAnalysis] = useState(null)
|
||||
const [modes, setModes] = useState({ skills: true, summary: false, instructions: false })
|
||||
const [mergeMode, setMergeMode] = useState('replace_all')
|
||||
const [setStatusAfterApply, setSetStatusAfterApply] = useState('in_review')
|
||||
const [costConfirmed, setCostConfirmed] = useState(false)
|
||||
|
||||
const [previewRows, setPreviewRows] = useState([])
|
||||
const [previewErrors, setPreviewErrors] = useState([])
|
||||
const [previewMeta, setPreviewMeta] = useState(null)
|
||||
const [showPreview, setShowPreview] = useState(false)
|
||||
|
||||
const [jobRunning, setJobRunning] = useState(false)
|
||||
const [jobProgress, setJobProgress] = useState({ done: 0, total: 0, phase: '' })
|
||||
const abortRef = useRef(false)
|
||||
|
||||
const selectedIds = useMemo(() => Array.from(selected), [selected])
|
||||
const filterParams = useMemo(() => buildFilterParams(filters), [filters])
|
||||
|
||||
const loadCandidates = useCallback(async () => {
|
||||
const data = await api.listExerciseEnrichmentCandidates({ ...filterParams, limit, offset })
|
||||
setItems(Array.isArray(data.items) ? data.items : [])
|
||||
setTotal(Number(data.total) || 0)
|
||||
}, [filterParams, offset])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSuperadmin) return
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const faRaw = await api.listFocusAreas()
|
||||
if (!cancelled) {
|
||||
const fa = Array.isArray(faRaw) ? faRaw : []
|
||||
setFocusAreas(fa.filter((a) => !a.status || String(a.status).toLowerCase() === 'active'))
|
||||
}
|
||||
await loadCandidates()
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e.message || String(e))
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false)
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [isSuperadmin, loadCandidates])
|
||||
|
||||
useEffect(() => {
|
||||
if (!dialogOpen || selectedIds.length === 0) return
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
try {
|
||||
const data = await api.analyzeExerciseEnrichment({
|
||||
exercise_ids: selectedIds,
|
||||
modes,
|
||||
})
|
||||
if (!cancelled) {
|
||||
setAnalysis(data)
|
||||
setCostConfirmed(false)
|
||||
}
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e.message || String(e))
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [dialogOpen, modes, selectedIds])
|
||||
|
||||
if (!isSuperadmin) return <Navigate to="/" replace />
|
||||
|
||||
const pageIds = items.map((r) => r.id)
|
||||
const allPageSelected = pageIds.length > 0 && pageIds.every((id) => selected.has(id))
|
||||
|
||||
function toggleRow(id) {
|
||||
setSelected((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(id)) next.delete(id)
|
||||
else next.add(id)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
function togglePageAll() {
|
||||
setSelected((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (allPageSelected) pageIds.forEach((id) => next.delete(id))
|
||||
else pageIds.forEach((id) => next.add(id))
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
async function selectAllMatchingFilter() {
|
||||
setError('')
|
||||
try {
|
||||
const data = await api.listExerciseEnrichmentCandidateIds(filterParams)
|
||||
const ids = Array.isArray(data.ids) ? data.ids : []
|
||||
setSelected(new Set(ids))
|
||||
} catch (e) {
|
||||
setError(e.message || String(e))
|
||||
}
|
||||
}
|
||||
|
||||
async function openRunDialog() {
|
||||
if (selectedIds.length === 0) {
|
||||
setError('Bitte mindestens eine Übung auswählen.')
|
||||
return
|
||||
}
|
||||
setError('')
|
||||
setCostConfirmed(false)
|
||||
setModes({ skills: true, summary: false, instructions: false })
|
||||
setMergeMode('replace_all')
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
async function runPreviewFromDialog() {
|
||||
setDialogOpen(false)
|
||||
setError('')
|
||||
setJobRunning(true)
|
||||
abortRef.current = false
|
||||
const allResults = []
|
||||
const allErrors = []
|
||||
let estTotal = 0
|
||||
|
||||
setJobProgress({ done: 0, total: selectedIds.length, phase: 'Vorschau' })
|
||||
|
||||
try {
|
||||
for (let i = 0; i < selectedIds.length; i += CHUNK_SIZE) {
|
||||
if (abortRef.current) break
|
||||
const chunk = selectedIds.slice(i, i + CHUNK_SIZE)
|
||||
const resp = await api.previewExerciseEnrichment({
|
||||
exercise_ids: chunk,
|
||||
modes,
|
||||
merge_mode: mergeMode,
|
||||
})
|
||||
allResults.push(...(resp.results || []))
|
||||
allErrors.push(...(resp.errors || []))
|
||||
const est = resp.estimated_llm_calls
|
||||
estTotal += typeof est === 'object' ? est.total || 0 : est || 0
|
||||
setJobProgress({
|
||||
done: Math.min(i + chunk.length, selectedIds.length),
|
||||
total: selectedIds.length,
|
||||
phase: 'Vorschau',
|
||||
})
|
||||
}
|
||||
setPreviewRows(allResults)
|
||||
setPreviewErrors(allErrors)
|
||||
setPreviewMeta({
|
||||
estimated_llm_calls: estTotal,
|
||||
merge_mode: mergeMode,
|
||||
modes: { ...modes },
|
||||
})
|
||||
setShowPreview(true)
|
||||
} catch (e) {
|
||||
setError(e.message || String(e))
|
||||
} finally {
|
||||
setJobRunning(false)
|
||||
setJobProgress({ done: 0, total: 0, phase: '' })
|
||||
}
|
||||
}
|
||||
|
||||
function cancelJob() {
|
||||
abortRef.current = true
|
||||
}
|
||||
|
||||
async function runApply() {
|
||||
const applyItems = previewRows
|
||||
.filter((r) => r.ok)
|
||||
.map((r) => ({
|
||||
exercise_id: r.exercise_id,
|
||||
merged_skills: r.merged_skills || [],
|
||||
summary: r.suggested_summary || null,
|
||||
instruction_fields: r.suggested_instructions || null,
|
||||
}))
|
||||
if (applyItems.length === 0) {
|
||||
setError('Keine anwendbaren Vorschau-Ergebnisse.')
|
||||
return
|
||||
}
|
||||
|
||||
const statusLabel =
|
||||
setStatusAfterApply === 'in_review'
|
||||
? 'In Prüfung'
|
||||
: setStatusAfterApply || 'unverändert'
|
||||
if (
|
||||
!window.confirm(
|
||||
`${applyItems.length} Übung(en) speichern und Status „${statusLabel}“ setzen?`,
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
setError('')
|
||||
setJobRunning(true)
|
||||
abortRef.current = false
|
||||
const appliedAll = []
|
||||
const failedAll = []
|
||||
|
||||
setJobProgress({ done: 0, total: applyItems.length, phase: 'Anwenden' })
|
||||
|
||||
try {
|
||||
for (let i = 0; i < applyItems.length; i += CHUNK_SIZE) {
|
||||
if (abortRef.current) break
|
||||
const chunk = applyItems.slice(i, i + CHUNK_SIZE)
|
||||
const resp = await api.applyExerciseEnrichment({
|
||||
items: chunk,
|
||||
modes: previewMeta?.modes || modes,
|
||||
merge_mode: mergeMode,
|
||||
set_status: setStatusAfterApply || null,
|
||||
})
|
||||
appliedAll.push(...(resp.applied || []))
|
||||
failedAll.push(...(resp.failed || []))
|
||||
setJobProgress({
|
||||
done: Math.min(i + chunk.length, applyItems.length),
|
||||
total: applyItems.length,
|
||||
phase: 'Anwenden',
|
||||
})
|
||||
}
|
||||
setPreviewRows([])
|
||||
setShowPreview(false)
|
||||
setSelected(new Set())
|
||||
await loadCandidates()
|
||||
const msg = `${appliedAll.length} OK, ${failedAll.length} Fehler`
|
||||
if (failedAll.length) setError(msg)
|
||||
else setError('')
|
||||
window.alert(msg)
|
||||
} catch (e) {
|
||||
setError(e.message || String(e))
|
||||
} finally {
|
||||
setJobRunning(false)
|
||||
setJobProgress({ done: 0, total: 0, phase: '' })
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="page" style={{ paddingBottom: 80 }}>
|
||||
<AdminPageNav />
|
||||
<header style={{ marginBottom: 16 }}>
|
||||
<h1 style={{ margin: '0 0 4px', fontSize: '1.35rem' }}>Übungs-Anreicherung (KI)</h1>
|
||||
<p style={{ margin: 0, color: 'var(--text2)', fontSize: '0.95rem' }}>
|
||||
Batchweise Anreicherung nach Status — Vorschau ohne Speichern, danach kontrolliert in Prüfung
|
||||
überführen. Für große Bestände (300+) alle passenden Übungen auswählen und Kosten bestätigen.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
{error && (
|
||||
<div className="card" style={{ borderColor: 'var(--danger)', marginBottom: 12, padding: 12 }}>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card" style={{ marginBottom: 16, padding: 16 }}>
|
||||
<div className="form-row" style={{ flexWrap: 'wrap', gap: 12 }}>
|
||||
<label className="form-label" style={{ minWidth: 120 }}>
|
||||
Status
|
||||
<select
|
||||
className="form-input"
|
||||
value={filters.status}
|
||||
onChange={(e) => {
|
||||
setOffset(0)
|
||||
setFilters((f) => ({ ...f, status: e.target.value }))
|
||||
}}
|
||||
>
|
||||
{STATUS_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="form-label" style={{ minWidth: 160 }}>
|
||||
Sichtbarkeit
|
||||
<select
|
||||
className="form-input"
|
||||
value={filters.visibility}
|
||||
onChange={(e) => {
|
||||
setOffset(0)
|
||||
setFilters((f) => ({ ...f, visibility: e.target.value }))
|
||||
}}
|
||||
>
|
||||
{VISIBILITY_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="form-label" style={{ minWidth: 140 }}>
|
||||
Fokusbereich
|
||||
<select
|
||||
className="form-input"
|
||||
value={filters.focusAreaId}
|
||||
onChange={(e) => {
|
||||
setOffset(0)
|
||||
setFilters((f) => ({ ...f, focusAreaId: e.target.value }))
|
||||
}}
|
||||
>
|
||||
<option value="">—</option>
|
||||
{focusAreas.map((fa) => (
|
||||
<option key={fa.id} value={fa.id}>
|
||||
{fa.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="form-label" style={{ flex: '1 1 180px' }}>
|
||||
Suche
|
||||
<input
|
||||
className="form-input"
|
||||
value={filters.search}
|
||||
placeholder="Titel, Stichworte…"
|
||||
onChange={(e) => setFilters((f) => ({ ...f, search: e.target.value }))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
setOffset(0)
|
||||
loadCandidates().catch((err) => setError(err.message))
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 16, marginTop: 12, alignItems: 'center' }}>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={filters.withoutSkills}
|
||||
onChange={(e) => {
|
||||
setOffset(0)
|
||||
setFilters((f) => ({ ...f, withoutSkills: e.target.checked }))
|
||||
}}
|
||||
/>
|
||||
Ohne Skills
|
||||
</label>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={filters.withAiSuggested}
|
||||
onChange={(e) => {
|
||||
setOffset(0)
|
||||
setFilters((f) => ({ ...f, withAiSuggested: e.target.checked }))
|
||||
}}
|
||||
/>
|
||||
Mit KI-Skills
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={() => {
|
||||
setOffset(0)
|
||||
loadCandidates().catch((err) => setError(err.message))
|
||||
}}
|
||||
>
|
||||
Filtern
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ marginBottom: 16, padding: 16 }}>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' }}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={jobRunning || total === 0}
|
||||
onClick={selectAllMatchingFilter}
|
||||
>
|
||||
Alle {total} aus Filter auswählen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
disabled={jobRunning || selectedIds.length === 0}
|
||||
onClick={openRunDialog}
|
||||
>
|
||||
Anreicherung konfigurieren ({selectedIds.length})
|
||||
</button>
|
||||
{showPreview && previewRows.length > 0 && (
|
||||
<button type="button" className="btn btn-primary" disabled={jobRunning} onClick={runApply}>
|
||||
Anwenden & Status setzen
|
||||
</button>
|
||||
)}
|
||||
{jobRunning && (
|
||||
<button type="button" className="btn btn-secondary" onClick={cancelJob}>
|
||||
Abbrechen
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{jobRunning && jobProgress.total > 0 && (
|
||||
<p style={{ margin: '10px 0 0', fontSize: '0.9rem' }}>
|
||||
{jobProgress.phase}: {jobProgress.done}/{jobProgress.total}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<RunDialog
|
||||
open={dialogOpen}
|
||||
onClose={() => setDialogOpen(false)}
|
||||
exerciseCount={selectedIds.length}
|
||||
analysis={analysis}
|
||||
modes={modes}
|
||||
setModes={setModes}
|
||||
mergeMode={mergeMode}
|
||||
setMergeMode={setMergeMode}
|
||||
setStatusAfterApply={setStatusAfterApply}
|
||||
statusAfterApply={setStatusAfterApply}
|
||||
costConfirmed={costConfirmed}
|
||||
setCostConfirmed={setCostConfirmed}
|
||||
onStartPreview={runPreviewFromDialog}
|
||||
jobRunning={jobRunning}
|
||||
/>
|
||||
|
||||
{showPreview && (
|
||||
<div className="card" style={{ marginBottom: 16, padding: 16 }}>
|
||||
<h2 style={{ margin: '0 0 12px', fontSize: '1.1rem' }}>Vorschau</h2>
|
||||
{previewMeta && (
|
||||
<p style={{ margin: '0 0 12px', color: 'var(--text2)', fontSize: '0.9rem' }}>
|
||||
{previewRows.length} OK · {previewErrors.length} Fehler/übersprungen · ca.{' '}
|
||||
{previewMeta.estimated_llm_calls} LLM-Call(s)
|
||||
</p>
|
||||
)}
|
||||
{previewRows.map((row) => (
|
||||
<div
|
||||
key={row.exercise_id}
|
||||
style={{ borderTop: '1px solid var(--border)', paddingTop: 12, marginTop: 12 }}
|
||||
>
|
||||
<strong>{row.title || `#${row.exercise_id}`}</strong>
|
||||
<span style={{ color: 'var(--text2)', marginLeft: 8, fontSize: '0.85rem' }}>
|
||||
{row.status} · {row.visibility} · {row.primary_focus_name || '—'}
|
||||
</span>
|
||||
{(previewMeta?.modes?.skills || modes.skills) && (
|
||||
<div style={{ marginTop: 6, fontSize: '0.88rem' }}>
|
||||
<div>
|
||||
<span style={{ color: 'var(--text2)' }}>Vorhanden:</span>{' '}
|
||||
{(row.existing_skills || []).map((s) => skillLabel(s)).join('; ') || '—'}
|
||||
</div>
|
||||
<div style={{ marginTop: 4 }}>
|
||||
<span style={{ color: 'var(--text2)' }}>Vorgeschlagen:</span>{' '}
|
||||
{(row.suggested_skills || []).map((s) => skillLabel(s)).join('; ') || '—'}
|
||||
</div>
|
||||
<DiffBlock diff={row.diff} />
|
||||
</div>
|
||||
)}
|
||||
{(previewMeta?.modes?.summary || modes.summary) && row.suggested_summary && (
|
||||
<div style={{ marginTop: 8, fontSize: '0.88rem' }}>
|
||||
<span style={{ color: 'var(--text2)' }}>Kurzfassung:</span>{' '}
|
||||
{row.existing_summary ? `"${row.existing_summary}" → ` : ''}
|
||||
"{row.suggested_summary}"
|
||||
</div>
|
||||
)}
|
||||
{(previewMeta?.modes?.instructions || modes.instructions) &&
|
||||
row.suggested_instructions &&
|
||||
Object.keys(row.suggested_instructions).length > 0 && (
|
||||
<div style={{ marginTop: 8, fontSize: '0.88rem' }}>
|
||||
<span style={{ color: 'var(--text2)' }}>Anleitung geändert:</span>{' '}
|
||||
{Object.keys(row.suggested_instructions)
|
||||
.map((k) => INSTRUCTION_LABELS[k] || k)
|
||||
.join(', ')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{previewErrors.map((err) => (
|
||||
<div
|
||||
key={`err-${err.exercise_id}`}
|
||||
style={{ color: 'var(--danger)', marginTop: 8, fontSize: '0.88rem' }}
|
||||
>
|
||||
#{err.exercise_id}: {err.error || 'Fehler'}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card" style={{ padding: 0, overflow: 'hidden' }}>
|
||||
{loading ? (
|
||||
<p style={{ padding: 16 }}>Lade…</p>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ overflowX: 'auto' }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: '0.92rem' }}>
|
||||
<thead>
|
||||
<tr style={{ background: 'var(--surface2)', textAlign: 'left' }}>
|
||||
<th style={{ padding: '10px 12px', width: 40 }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={allPageSelected}
|
||||
onChange={togglePageAll}
|
||||
aria-label="Alle auf Seite"
|
||||
/>
|
||||
</th>
|
||||
<th style={{ padding: '10px 12px' }}>Titel</th>
|
||||
<th style={{ padding: '10px 12px' }}>Status</th>
|
||||
<th style={{ padding: '10px 12px' }}>Sichtbarkeit</th>
|
||||
<th style={{ padding: '10px 12px' }}>Fokus</th>
|
||||
<th style={{ padding: '10px 12px' }}>Skills</th>
|
||||
<th style={{ padding: '10px 12px' }}>KI-Skills</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={7} style={{ padding: 16, color: 'var(--text2)' }}>
|
||||
Keine Kandidaten für die Filter.
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
items.map((row) => (
|
||||
<tr key={row.id} style={{ borderTop: '1px solid var(--border)' }}>
|
||||
<td style={{ padding: '10px 12px' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected.has(row.id)}
|
||||
onChange={() => toggleRow(row.id)}
|
||||
aria-label={`Auswahl ${row.title}`}
|
||||
/>
|
||||
</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.title}</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.status}</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.visibility}</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.primary_focus_name || '—'}</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.skill_count ?? 0}</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.ai_suggested_skill_count ?? 0}</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
padding: '12px 16px',
|
||||
borderTop: '1px solid var(--border)',
|
||||
}}
|
||||
>
|
||||
<span style={{ color: 'var(--text2)', fontSize: '0.88rem' }}>
|
||||
{total} gesamt · {selectedIds.length} ausgewählt
|
||||
</span>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={offset <= 0}
|
||||
onClick={() => setOffset((o) => Math.max(0, o - limit))}
|
||||
>
|
||||
Zurück
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={offset + limit >= total}
|
||||
onClick={() => setOffset((o) => o + limit)}
|
||||
>
|
||||
Weiter
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -388,6 +388,50 @@ export async function deleteAiSkillRetrievalProfile(profileId) {
|
||||
return request(`/api/admin/ai-skill-retrieval-profiles/${profileId}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
/** Superadmin: Übungs-Anreicherung per KI (Batch Skills) */
|
||||
export async function listExerciseEnrichmentCandidates(params = {}) {
|
||||
const q = new URLSearchParams()
|
||||
Object.entries(params).forEach(([k, v]) => {
|
||||
if (v === undefined || v === null || v === '') return
|
||||
if (typeof v === 'boolean') q.set(k, v ? 'true' : 'false')
|
||||
else q.set(k, String(v))
|
||||
})
|
||||
const qs = q.toString()
|
||||
return request(`/api/admin/exercise-enrichment/candidates${qs ? `?${qs}` : ''}`)
|
||||
}
|
||||
|
||||
export async function previewExerciseEnrichment(body) {
|
||||
return request('/api/admin/exercise-enrichment/preview', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
}
|
||||
|
||||
export async function applyExerciseEnrichment(body) {
|
||||
return request('/api/admin/exercise-enrichment/apply', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
}
|
||||
|
||||
export async function listExerciseEnrichmentCandidateIds(params = {}) {
|
||||
const q = new URLSearchParams()
|
||||
Object.entries(params).forEach(([k, v]) => {
|
||||
if (v === undefined || v === null || v === '') return
|
||||
if (typeof v === 'boolean') q.set(k, v ? 'true' : 'false')
|
||||
else q.set(k, String(v))
|
||||
})
|
||||
const qs = q.toString()
|
||||
return request(`/api/admin/exercise-enrichment/candidate-ids${qs ? `?${qs}` : ''}`)
|
||||
}
|
||||
|
||||
export async function analyzeExerciseEnrichment(body) {
|
||||
return request('/api/admin/exercise-enrichment/analyze', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
}
|
||||
|
||||
/** Superadmin: KI Prompt-Templates (ai_prompts) */
|
||||
export async function listAdminAiPrompts() {
|
||||
return request('/api/admin/ai-prompts')
|
||||
@@ -844,6 +888,11 @@ export const api = {
|
||||
createAiSkillRetrievalProfile,
|
||||
updateAiSkillRetrievalProfile,
|
||||
deleteAiSkillRetrievalProfile,
|
||||
listExerciseEnrichmentCandidates,
|
||||
previewExerciseEnrichment,
|
||||
applyExerciseEnrichment,
|
||||
listExerciseEnrichmentCandidateIds,
|
||||
analyzeExerciseEnrichment,
|
||||
listAdminAiPrompts,
|
||||
getAdminAiPrompt,
|
||||
updateAdminAiPrompt,
|
||||
|
||||
Reference in new issue
Block a user