Compare commits
7 Commits
759c725793
...
8acf1d2e12
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8acf1d2e12 | ||
|
|
1698912a27 | ||
|
|
94006be778 | ||
|
|
77a8170a6e | ||
|
|
20bc51b86c | ||
|
|
3ffba9ef4f | ||
|
|
c78a7b687e |
@@ -18,6 +18,7 @@ import {
|
|||||||
fetchEnrollments,
|
fetchEnrollments,
|
||||||
deleteCourse,
|
deleteCourse,
|
||||||
submitQuiz,
|
submitQuiz,
|
||||||
|
updateLesson,
|
||||||
generateVideos,
|
generateVideos,
|
||||||
getVideoStatus
|
getVideoStatus
|
||||||
} from '@/lib/sdk/academy/api'
|
} from '@/lib/sdk/academy/api'
|
||||||
@@ -39,6 +40,11 @@ export default function CourseDetailPage() {
|
|||||||
const [isSubmittingQuiz, setIsSubmittingQuiz] = useState(false)
|
const [isSubmittingQuiz, setIsSubmittingQuiz] = useState(false)
|
||||||
const [videoStatus, setVideoStatus] = useState<any>(null)
|
const [videoStatus, setVideoStatus] = useState<any>(null)
|
||||||
const [isGeneratingVideos, setIsGeneratingVideos] = useState(false)
|
const [isGeneratingVideos, setIsGeneratingVideos] = useState(false)
|
||||||
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
|
const [editContent, setEditContent] = useState('')
|
||||||
|
const [editTitle, setEditTitle] = useState('')
|
||||||
|
const [isSaving, setIsSaving] = useState(false)
|
||||||
|
const [saveMessage, setSaveMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
@@ -89,6 +95,65 @@ export default function CourseDetailPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleStartEdit = () => {
|
||||||
|
if (!selectedLesson) return
|
||||||
|
setEditContent(selectedLesson.contentMarkdown || '')
|
||||||
|
setEditTitle(selectedLesson.title || '')
|
||||||
|
setIsEditing(true)
|
||||||
|
setSaveMessage(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCancelEdit = () => {
|
||||||
|
setIsEditing(false)
|
||||||
|
setSaveMessage(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveLesson = async () => {
|
||||||
|
if (!selectedLesson) return
|
||||||
|
setIsSaving(true)
|
||||||
|
setSaveMessage(null)
|
||||||
|
try {
|
||||||
|
await updateLesson(selectedLesson.id, {
|
||||||
|
title: editTitle,
|
||||||
|
content_url: editContent,
|
||||||
|
})
|
||||||
|
const updatedLesson = { ...selectedLesson, title: editTitle, contentMarkdown: editContent }
|
||||||
|
setSelectedLesson(updatedLesson)
|
||||||
|
if (course) {
|
||||||
|
const updatedLessons = course.lessons.map(l => l.id === updatedLesson.id ? updatedLesson : l)
|
||||||
|
setCourse({ ...course, lessons: updatedLessons })
|
||||||
|
}
|
||||||
|
setIsEditing(false)
|
||||||
|
setSaveMessage({ type: 'success', text: 'Lektion gespeichert.' })
|
||||||
|
} catch (error: any) {
|
||||||
|
setSaveMessage({ type: 'error', text: error.message || 'Fehler beim Speichern.' })
|
||||||
|
} finally {
|
||||||
|
setIsSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleApproveLesson = async () => {
|
||||||
|
if (!selectedLesson) return
|
||||||
|
if (!confirm('Lektion fuer Video-Verarbeitung freigeben? Der Text wird als final markiert.')) return
|
||||||
|
setIsSaving(true)
|
||||||
|
setSaveMessage(null)
|
||||||
|
try {
|
||||||
|
await updateLesson(selectedLesson.id, {
|
||||||
|
description: 'approved_for_video',
|
||||||
|
})
|
||||||
|
const updatedLesson = { ...selectedLesson }
|
||||||
|
if (course) {
|
||||||
|
const updatedLessons = course.lessons.map(l => l.id === updatedLesson.id ? updatedLesson : l)
|
||||||
|
setCourse({ ...course, lessons: updatedLessons })
|
||||||
|
}
|
||||||
|
setSaveMessage({ type: 'success', text: 'Lektion fuer Video-Verarbeitung freigegeben.' })
|
||||||
|
} catch (error: any) {
|
||||||
|
setSaveMessage({ type: 'error', text: error.message || 'Fehler bei der Freigabe.' })
|
||||||
|
} finally {
|
||||||
|
setIsSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleGenerateVideos = async () => {
|
const handleGenerateVideos = async () => {
|
||||||
setIsGeneratingVideos(true)
|
setIsGeneratingVideos(true)
|
||||||
try {
|
try {
|
||||||
@@ -285,7 +350,17 @@ export default function CourseDetailPage() {
|
|||||||
{selectedLesson ? (
|
{selectedLesson ? (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
|
{isEditing ? (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={editTitle}
|
||||||
|
onChange={e => setEditTitle(e.target.value)}
|
||||||
|
className="text-xl font-semibold text-gray-900 border border-gray-300 rounded-lg px-3 py-1 flex-1 mr-3"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
<h2 className="text-xl font-semibold text-gray-900">{selectedLesson.title}</h2>
|
<h2 className="text-xl font-semibold text-gray-900">{selectedLesson.title}</h2>
|
||||||
|
)}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
<span className={`px-3 py-1 text-xs rounded-full ${
|
<span className={`px-3 py-1 text-xs rounded-full ${
|
||||||
selectedLesson.type === 'quiz' ? 'bg-yellow-100 text-yellow-700' :
|
selectedLesson.type === 'quiz' ? 'bg-yellow-100 text-yellow-700' :
|
||||||
selectedLesson.type === 'video' ? 'bg-blue-100 text-blue-700' :
|
selectedLesson.type === 'video' ? 'bg-blue-100 text-blue-700' :
|
||||||
@@ -293,7 +368,51 @@ export default function CourseDetailPage() {
|
|||||||
}`}>
|
}`}>
|
||||||
{selectedLesson.type === 'quiz' ? 'Quiz' : selectedLesson.type === 'video' ? 'Video' : 'Text'}
|
{selectedLesson.type === 'quiz' ? 'Quiz' : selectedLesson.type === 'video' ? 'Video' : 'Text'}
|
||||||
</span>
|
</span>
|
||||||
|
{selectedLesson.type !== 'quiz' && !isEditing && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={handleStartEdit}
|
||||||
|
className="px-3 py-1 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
Bearbeiten
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleApproveLesson}
|
||||||
|
disabled={isSaving}
|
||||||
|
className="px-3 py-1 text-sm bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors disabled:opacity-50"
|
||||||
|
>
|
||||||
|
Freigeben
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{isEditing && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={handleCancelEdit}
|
||||||
|
className="px-3 py-1 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
Abbrechen
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleSaveLesson}
|
||||||
|
disabled={isSaving}
|
||||||
|
className="px-3 py-1 text-sm bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{isSaving ? 'Speichert...' : 'Speichern'}
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Save/Approve Message */}
|
||||||
|
{saveMessage && (
|
||||||
|
<div className={`p-3 rounded-lg text-sm ${
|
||||||
|
saveMessage.type === 'success' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-red-50 text-red-700 border border-red-200'
|
||||||
|
}`}>
|
||||||
|
{saveMessage.text}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Video Player */}
|
{/* Video Player */}
|
||||||
{selectedLesson.type === 'video' && selectedLesson.videoUrl && (
|
{selectedLesson.type === 'video' && selectedLesson.videoUrl && (
|
||||||
@@ -306,8 +425,23 @@ export default function CourseDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Text Content */}
|
{/* Text Content - Edit Mode */}
|
||||||
{(selectedLesson.type === 'text' || selectedLesson.type === 'video') && selectedLesson.contentMarkdown && (
|
{isEditing && (selectedLesson.type === 'text' || selectedLesson.type === 'video') && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<label className="text-sm text-gray-500">Inhalt (Markdown)</label>
|
||||||
|
<textarea
|
||||||
|
value={editContent}
|
||||||
|
onChange={e => setEditContent(e.target.value)}
|
||||||
|
rows={20}
|
||||||
|
className="w-full border border-gray-300 rounded-xl p-4 text-sm font-mono text-gray-800 leading-relaxed resize-y focus:ring-2 focus:ring-purple-500 focus:border-transparent"
|
||||||
|
placeholder="Markdown-Inhalt der Lektion..."
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-gray-400">Unterstuetzt: # Ueberschrift, ## Unterueberschrift, - Aufzaehlung, **fett**</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Text Content - View Mode */}
|
||||||
|
{!isEditing && (selectedLesson.type === 'text' || selectedLesson.type === 'video') && selectedLesson.contentMarkdown && (
|
||||||
<div className="prose prose-sm max-w-none">
|
<div className="prose prose-sm max-w-none">
|
||||||
<div className="whitespace-pre-wrap text-gray-700 leading-relaxed">
|
<div className="whitespace-pre-wrap text-gray-700 leading-relaxed">
|
||||||
{selectedLesson.contentMarkdown.split('\n').map((line, i) => {
|
{selectedLesson.contentMarkdown.split('\n').map((line, i) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useState } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useSDK } from '@/lib/sdk'
|
import { useSDK } from '@/lib/sdk'
|
||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
GenerateCourseRequest
|
GenerateCourseRequest
|
||||||
} from '@/lib/sdk/academy/types'
|
} from '@/lib/sdk/academy/types'
|
||||||
import { createCourse, generateCourse } from '@/lib/sdk/academy/api'
|
import { createCourse, generateCourse } from '@/lib/sdk/academy/api'
|
||||||
|
import { getModules } from '@/lib/sdk/training/api'
|
||||||
|
import type { TrainingModule } from '@/lib/sdk/training/types'
|
||||||
|
|
||||||
type CreationMode = 'manual' | 'ai'
|
type CreationMode = 'manual' | 'ai'
|
||||||
|
|
||||||
@@ -27,10 +29,26 @@ export default function NewCoursePage() {
|
|||||||
const [duration, setDuration] = useState(60)
|
const [duration, setDuration] = useState(60)
|
||||||
const [passingScore, setPassingScore] = useState(70)
|
const [passingScore, setPassingScore] = useState(70)
|
||||||
|
|
||||||
// AI generation state
|
// AI generation state - module selection
|
||||||
const [topic, setTopic] = useState('')
|
const [trainingModules, setTrainingModules] = useState<TrainingModule[]>([])
|
||||||
const [targetGroup, setTargetGroup] = useState('Alle Mitarbeiter')
|
const [selectedModuleId, setSelectedModuleId] = useState('')
|
||||||
const [useRag, setUseRag] = useState(true)
|
const [modulesLoading, setModulesLoading] = useState(true)
|
||||||
|
|
||||||
|
// Load training modules on mount
|
||||||
|
useEffect(() => {
|
||||||
|
async function loadModules() {
|
||||||
|
setModulesLoading(true)
|
||||||
|
try {
|
||||||
|
const res = await getModules()
|
||||||
|
setTrainingModules(res.modules || [])
|
||||||
|
} catch {
|
||||||
|
setError('Training-Module konnten nicht geladen werden.')
|
||||||
|
} finally {
|
||||||
|
setModulesLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadModules()
|
||||||
|
}, [])
|
||||||
|
|
||||||
const handleManualCreate = async () => {
|
const handleManualCreate = async () => {
|
||||||
if (!title.trim()) {
|
if (!title.trim()) {
|
||||||
@@ -69,25 +87,16 @@ export default function NewCoursePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleAIGenerate = async () => {
|
const handleAIGenerate = async () => {
|
||||||
if (!topic.trim()) {
|
if (!selectedModuleId) {
|
||||||
setError('Bitte geben Sie ein Thema fuer den Kurs ein.')
|
setError('Bitte waehlen Sie ein Training-Modul aus.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setError(null)
|
setError(null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tenantId = typeof window !== 'undefined'
|
|
||||||
? localStorage.getItem('bp_tenant_id') || 'default-tenant'
|
|
||||||
: 'default-tenant'
|
|
||||||
|
|
||||||
const result = await generateCourse({
|
const result = await generateCourse({
|
||||||
tenantId,
|
moduleId: selectedModuleId,
|
||||||
topic: topic.trim(),
|
|
||||||
category,
|
|
||||||
targetGroup: targetGroup.trim(),
|
|
||||||
language: 'de',
|
|
||||||
useRag
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result && result.course && result.course.id) {
|
if (result && result.course && result.course.id) {
|
||||||
@@ -174,82 +183,69 @@ export default function NewCoursePage() {
|
|||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
|
||||||
</svg>
|
</svg>
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-medium text-purple-800">KI-generierter Kurs</h3>
|
<h3 className="font-medium text-purple-800">Kurs aus Training-Modul generieren</h3>
|
||||||
<p className="text-sm text-purple-600 mt-1">
|
<p className="text-sm text-purple-600 mt-1">
|
||||||
Die KI erstellt automatisch Lektionen, Inhalte und Quizfragen basierend auf dem gewaehlten Thema.
|
Waehlen Sie ein bestehendes Training-Modul aus. Der Academy-Kurs wird automatisch mit den generierten Inhalten und Quizfragen erstellt.
|
||||||
Optionaler RAG-Kontext aus relevanten Gesetzestexten wird einbezogen.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Topic */}
|
{/* Module Selection */}
|
||||||
<div>
|
{modulesLoading ? (
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Schulungsthema *</label>
|
<div className="flex items-center gap-3 py-8 justify-center text-gray-500">
|
||||||
<input
|
<svg className="animate-spin w-5 h-5" fill="none" viewBox="0 0 24 24">
|
||||||
type="text"
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||||
value={topic}
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||||
onChange={(e) => setTopic(e.target.value)}
|
</svg>
|
||||||
placeholder="z.B. DSGVO-Grundlagen fuer neue Mitarbeiter"
|
Training-Module werden geladen...
|
||||||
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 focus:border-purple-500 text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
) : trainingModules.length === 0 ? (
|
||||||
{/* Category */}
|
<div className="text-center py-8">
|
||||||
|
<p className="text-gray-500">Keine Training-Module gefunden.</p>
|
||||||
|
<p className="text-sm text-gray-400 mt-1">Bitte erstellen Sie zuerst Module unter Schulung > Module.</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Kategorie *</label>
|
<label className="block text-sm font-medium text-gray-700 mb-2">Training-Modul auswaehlen *</label>
|
||||||
<div className="grid grid-cols-2 md:grid-cols-3 gap-3">
|
<p className="text-xs text-gray-400 mb-3">Module mit bestehendem Kurs werden beim Generieren uebersprungen oder neu verknuepft.</p>
|
||||||
{Object.entries(COURSE_CATEGORY_INFO).map(([cat, info]) => (
|
<div className="grid gap-3 max-h-[400px] overflow-y-auto pr-2">
|
||||||
|
{trainingModules.map((mod) => (
|
||||||
<button
|
<button
|
||||||
key={cat}
|
key={mod.id}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setCategory(cat as CourseCategory)}
|
onClick={() => setSelectedModuleId(mod.id)}
|
||||||
className={`p-4 rounded-xl border-2 text-left transition-all ${
|
className={`p-4 rounded-xl border-2 text-left transition-all ${
|
||||||
category === cat
|
selectedModuleId === mod.id
|
||||||
? 'border-purple-500 bg-purple-50'
|
? 'border-purple-500 bg-purple-50'
|
||||||
: 'border-gray-200 hover:border-gray-300'
|
: 'border-gray-200 hover:border-gray-300'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className={`text-sm font-medium ${category === cat ? 'text-purple-700' : 'text-gray-700'}`}>
|
<div className="flex items-center justify-between">
|
||||||
{info.label}
|
<div className={`text-sm font-medium ${selectedModuleId === mod.id ? 'text-purple-700' : 'text-gray-700'}`}>
|
||||||
|
{mod.title}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{mod.academy_course_id && (
|
||||||
|
<span className="text-xs px-2 py-0.5 rounded-full bg-green-100 text-green-700">Kurs vorhanden</span>
|
||||||
|
)}
|
||||||
|
<span className="text-xs px-2 py-1 rounded-full bg-gray-100 text-gray-600">
|
||||||
|
{mod.regulation_area}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{mod.description && (
|
||||||
|
<div className="text-xs text-gray-500 mt-1 line-clamp-2">{mod.description}</div>
|
||||||
|
)}
|
||||||
|
<div className="flex gap-3 mt-2 text-xs text-gray-400">
|
||||||
|
<span>{mod.duration_minutes} Min.</span>
|
||||||
|
<span>{mod.frequency_type}</span>
|
||||||
|
<span>{mod.module_code}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xs text-gray-500 mt-1 line-clamp-2">{info.description}</div>
|
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{/* Target Group */}
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Zielgruppe</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={targetGroup}
|
|
||||||
onChange={(e) => setTargetGroup(e.target.value)}
|
|
||||||
placeholder="z.B. Alle Mitarbeiter, IT-Abteilung, Fuehrungskraefte"
|
|
||||||
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 focus:border-purple-500"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* RAG Toggle */}
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setUseRag(!useRag)}
|
|
||||||
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${
|
|
||||||
useRag ? 'bg-purple-600' : 'bg-gray-300'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${
|
|
||||||
useRag ? 'translate-x-6' : 'translate-x-1'
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
<div>
|
|
||||||
<span className="text-sm font-medium text-gray-700">RAG-Kontext verwenden</span>
|
|
||||||
<p className="text-xs text-gray-500">Relevante Gesetzestexte (DSGVO, AI Act, NIS2) einbeziehen</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Submit */}
|
{/* Submit */}
|
||||||
<div className="flex justify-end gap-3 pt-4 border-t border-gray-200">
|
<div className="flex justify-end gap-3 pt-4 border-t border-gray-200">
|
||||||
@@ -261,7 +257,7 @@ export default function NewCoursePage() {
|
|||||||
</Link>
|
</Link>
|
||||||
<button
|
<button
|
||||||
onClick={handleAIGenerate}
|
onClick={handleAIGenerate}
|
||||||
disabled={isLoading || !topic.trim()}
|
disabled={isLoading || !selectedModuleId}
|
||||||
className="px-6 py-2.5 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
className="px-6 py-2.5 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
@@ -270,7 +266,7 @@ export default function NewCoursePage() {
|
|||||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
<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 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||||
</svg>
|
</svg>
|
||||||
KI generiert Kurs...
|
Kurs wird generiert...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ function StatCard({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CourseCard({ course, enrollmentCount }: { course: Course; enrollmentCount: number }) {
|
function CourseCard({ course, enrollmentCount }: { course: Course; enrollmentCount: number }) {
|
||||||
const categoryInfo = COURSE_CATEGORY_INFO[course.category]
|
const categoryInfo = COURSE_CATEGORY_INFO[course.category] || COURSE_CATEGORY_INFO['custom']
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={`/sdk/academy/${course.id}`}>
|
<Link href={`/sdk/academy/${course.id}`}>
|
||||||
@@ -589,7 +589,7 @@ export default function AcademyPage() {
|
|||||||
/>
|
/>
|
||||||
<StatCard
|
<StatCard
|
||||||
label="Aktive Teilnehmer"
|
label="Aktive Teilnehmer"
|
||||||
value={statistics.byStatus.in_progress + statistics.byStatus.not_started}
|
value={(statistics.byStatus?.in_progress || 0) + (statistics.byStatus?.not_started || 0)}
|
||||||
color="blue"
|
color="blue"
|
||||||
/>
|
/>
|
||||||
<StatCard
|
<StatCard
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ async function proxyRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Forward identity headers for RBAC context
|
// Forward identity headers for RBAC context
|
||||||
|
// Only use client-provided values if they look like UUIDs
|
||||||
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
||||||
const userHeader = request.headers.get('x-user-id')
|
const userHeader = request.headers.get('x-user-id')
|
||||||
headers['X-User-ID'] = userHeader || '00000000-0000-0000-0000-000000000001'
|
headers['X-User-ID'] = (userHeader && uuidRegex.test(userHeader)) ? userHeader : '00000000-0000-0000-0000-000000000001'
|
||||||
|
|
||||||
const tenantHeader = request.headers.get('x-tenant-id')
|
const tenantHeader = request.headers.get('x-tenant-id')
|
||||||
headers['X-Tenant-ID'] = tenantHeader || (process.env.DEFAULT_TENANT_ID || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e')
|
headers['X-Tenant-ID'] = (tenantHeader && uuidRegex.test(tenantHeader)) ? tenantHeader : (process.env.DEFAULT_TENANT_ID || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e')
|
||||||
|
|
||||||
const fetchOptions: RequestInit = {
|
const fetchOptions: RequestInit = {
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -33,8 +33,12 @@ async function proxyRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Forward identity headers with defaults for RBAC context
|
// Forward identity headers with defaults for RBAC context
|
||||||
headers['X-User-ID'] = request.headers.get('x-user-id') || '00000000-0000-0000-0000-000000000001'
|
// Only use client-provided values if they look like UUIDs
|
||||||
headers['X-Tenant-ID'] = request.headers.get('x-tenant-id') || (process.env.DEFAULT_TENANT_ID || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e')
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
||||||
|
const clientUserId = request.headers.get('x-user-id')
|
||||||
|
const clientTenantId = request.headers.get('x-tenant-id')
|
||||||
|
headers['X-User-ID'] = (clientUserId && uuidRegex.test(clientUserId)) ? clientUserId : '00000000-0000-0000-0000-000000000001'
|
||||||
|
headers['X-Tenant-ID'] = (clientTenantId && uuidRegex.test(clientTenantId)) ? clientTenantId : (process.env.DEFAULT_TENANT_ID || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e')
|
||||||
|
|
||||||
const fetchOptions: RequestInit = {
|
const fetchOptions: RequestInit = {
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -142,6 +142,14 @@ interface BackendCourse {
|
|||||||
updated_at: string
|
updated_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BackendQuizQuestion {
|
||||||
|
id: string
|
||||||
|
question: string
|
||||||
|
options: string[]
|
||||||
|
correct_index: number
|
||||||
|
explanation: string
|
||||||
|
}
|
||||||
|
|
||||||
interface BackendLesson {
|
interface BackendLesson {
|
||||||
id: string
|
id: string
|
||||||
course_id: string
|
course_id: string
|
||||||
@@ -151,7 +159,7 @@ interface BackendLesson {
|
|||||||
content_url?: string
|
content_url?: string
|
||||||
duration_minutes: number
|
duration_minutes: number
|
||||||
order_index: number
|
order_index: number
|
||||||
quiz_questions?: Array<{ question: string; options: string[]; correct_index: number; explanation: string }>
|
quiz_questions?: BackendQuizQuestion[]
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapCourseFromBackend(bc: BackendCourse): Course {
|
function mapCourseFromBackend(bc: BackendCourse): Course {
|
||||||
@@ -170,6 +178,14 @@ function mapCourseFromBackend(bc: BackendCourse): Course {
|
|||||||
contentMarkdown: l.content_url || '',
|
contentMarkdown: l.content_url || '',
|
||||||
durationMinutes: l.duration_minutes || 0,
|
durationMinutes: l.duration_minutes || 0,
|
||||||
order: l.order_index,
|
order: l.order_index,
|
||||||
|
quizQuestions: (l.quiz_questions || []).map(q => ({
|
||||||
|
id: q.id || `q-${Math.random().toString(36).slice(2)}`,
|
||||||
|
lessonId: l.id,
|
||||||
|
question: q.question,
|
||||||
|
options: q.options,
|
||||||
|
correctOptionIndex: q.correct_index,
|
||||||
|
explanation: q.explanation,
|
||||||
|
})),
|
||||||
})),
|
})),
|
||||||
createdAt: bc.created_at,
|
createdAt: bc.created_at,
|
||||||
updatedAt: bc.updated_at,
|
updatedAt: bc.updated_at,
|
||||||
@@ -305,11 +321,11 @@ export async function generateCertificate(enrollmentId: string): Promise<Certifi
|
|||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quiz-Antworten einreichen und auswerten
|
* Quiz-Antworten einreichen und auswerten (ohne Enrollment)
|
||||||
*/
|
*/
|
||||||
export async function submitQuiz(lessonId: string, answers: SubmitQuizRequest): Promise<SubmitQuizResponse> {
|
export async function submitQuiz(lessonId: string, answers: SubmitQuizRequest): Promise<SubmitQuizResponse> {
|
||||||
return fetchWithTimeout<SubmitQuizResponse>(
|
return fetchWithTimeout<SubmitQuizResponse>(
|
||||||
`${ACADEMY_API_BASE}/lessons/${lessonId}/quiz`,
|
`${ACADEMY_API_BASE}/lessons/${lessonId}/quiz-test`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(answers)
|
body: JSON.stringify(answers)
|
||||||
@@ -317,6 +333,25 @@ export async function submitQuiz(lessonId: string, answers: SubmitQuizRequest):
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lektion aktualisieren (Content, Titel, Quiz-Fragen)
|
||||||
|
*/
|
||||||
|
export async function updateLesson(lessonId: string, update: {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
content_url?: string
|
||||||
|
duration_minutes?: number
|
||||||
|
quiz_questions?: Array<{ question: string; options: string[]; correct_index: number; explanation: string }>
|
||||||
|
}): Promise<{ lesson: any }> {
|
||||||
|
return fetchWithTimeout(
|
||||||
|
`${ACADEMY_API_BASE}/lessons/${lessonId}`,
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(update)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// STATISTICS
|
// STATISTICS
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ export interface Lesson {
|
|||||||
videoUrl?: string
|
videoUrl?: string
|
||||||
order: number
|
order: number
|
||||||
durationMinutes: number
|
durationMinutes: number
|
||||||
|
quizQuestions?: QuizQuestion[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface QuizQuestion {
|
export interface QuizQuestion {
|
||||||
|
|||||||
@@ -481,6 +481,10 @@ func main() {
|
|||||||
// Quiz
|
// Quiz
|
||||||
academyRoutes.POST("/courses/:id/quiz", academyHandlers.SubmitQuiz)
|
academyRoutes.POST("/courses/:id/quiz", academyHandlers.SubmitQuiz)
|
||||||
|
|
||||||
|
// Lessons
|
||||||
|
academyRoutes.PUT("/lessons/:id", academyHandlers.UpdateLesson)
|
||||||
|
academyRoutes.POST("/lessons/:id/quiz-test", academyHandlers.TestQuiz)
|
||||||
|
|
||||||
// Statistics
|
// Statistics
|
||||||
academyRoutes.GET("/stats", academyHandlers.GetStatistics)
|
academyRoutes.GET("/stats", academyHandlers.GetStatistics)
|
||||||
|
|
||||||
|
|||||||
@@ -331,6 +331,23 @@ func (s *Store) GetLesson(ctx context.Context, id uuid.UUID) (*Lesson, error) {
|
|||||||
return &lesson, nil
|
return &lesson, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateLesson updates a lesson's content, title, and quiz questions
|
||||||
|
func (s *Store) UpdateLesson(ctx context.Context, lesson *Lesson) error {
|
||||||
|
quizQuestions, _ := json.Marshal(lesson.QuizQuestions)
|
||||||
|
|
||||||
|
_, err := s.pool.Exec(ctx, `
|
||||||
|
UPDATE academy_lessons SET
|
||||||
|
title = $2, description = $3, content_url = $4,
|
||||||
|
duration_minutes = $5, quiz_questions = $6
|
||||||
|
WHERE id = $1
|
||||||
|
`,
|
||||||
|
lesson.ID, lesson.Title, lesson.Description,
|
||||||
|
lesson.ContentURL, lesson.DurationMinutes, quizQuestions,
|
||||||
|
)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Enrollment Operations
|
// Enrollment Operations
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
@@ -572,6 +572,131 @@ func (h *AcademyHandlers) SubmitQuiz(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Lesson Update
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// UpdateLesson updates a lesson's content, title, or quiz questions
|
||||||
|
// PUT /sdk/v1/academy/lessons/:id
|
||||||
|
func (h *AcademyHandlers) UpdateLesson(c *gin.Context) {
|
||||||
|
lessonID, err := uuid.Parse(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid lesson ID"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lesson, err := h.store.GetLesson(c.Request.Context(), lessonID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if lesson == nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "lesson not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req struct {
|
||||||
|
Title *string `json:"title"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
ContentURL *string `json:"content_url"`
|
||||||
|
DurationMinutes *int `json:"duration_minutes"`
|
||||||
|
QuizQuestions *[]academy.QuizQuestion `json:"quiz_questions"`
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Title != nil {
|
||||||
|
lesson.Title = *req.Title
|
||||||
|
}
|
||||||
|
if req.Description != nil {
|
||||||
|
lesson.Description = *req.Description
|
||||||
|
}
|
||||||
|
if req.ContentURL != nil {
|
||||||
|
lesson.ContentURL = *req.ContentURL
|
||||||
|
}
|
||||||
|
if req.DurationMinutes != nil {
|
||||||
|
lesson.DurationMinutes = *req.DurationMinutes
|
||||||
|
}
|
||||||
|
if req.QuizQuestions != nil {
|
||||||
|
lesson.QuizQuestions = *req.QuizQuestions
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.store.UpdateLesson(c.Request.Context(), lesson); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"lesson": lesson})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestQuiz evaluates quiz answers without requiring an enrollment
|
||||||
|
// POST /sdk/v1/academy/lessons/:id/quiz-test
|
||||||
|
func (h *AcademyHandlers) TestQuiz(c *gin.Context) {
|
||||||
|
lessonID, err := uuid.Parse(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid lesson ID"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lesson, err := h.store.GetLesson(c.Request.Context(), lessonID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if lesson == nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "lesson not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(lesson.QuizQuestions) == 0 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "lesson has no quiz questions"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req struct {
|
||||||
|
Answers []int `json:"answers"`
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.Answers) != len(lesson.QuizQuestions) {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "number of answers must match number of questions"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
correctCount := 0
|
||||||
|
var results []academy.QuizResult
|
||||||
|
for i, question := range lesson.QuizQuestions {
|
||||||
|
correct := req.Answers[i] == question.CorrectIndex
|
||||||
|
if correct {
|
||||||
|
correctCount++
|
||||||
|
}
|
||||||
|
results = append(results, academy.QuizResult{
|
||||||
|
Question: question.Question,
|
||||||
|
Correct: correct,
|
||||||
|
Explanation: question.Explanation,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
totalQuestions := len(lesson.QuizQuestions)
|
||||||
|
score := 0
|
||||||
|
if totalQuestions > 0 {
|
||||||
|
score = (correctCount * 100) / totalQuestions
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, academy.SubmitQuizResponse{
|
||||||
|
Score: score,
|
||||||
|
Passed: score >= 70,
|
||||||
|
CorrectAnswers: correctCount,
|
||||||
|
TotalQuestions: totalQuestions,
|
||||||
|
Results: results,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Statistics
|
// Statistics
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user