Enhance VocabLessonView and VocabService for grammar exercise handling

- Added logic to initialize grammar exercises directly from lesson data or load them separately if not included.
- Introduced a new method to initialize answer arrays for gap fill exercises, improving user interaction and response tracking.
- Updated comments for clarity on the exercise loading process and initialization logic.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 15:33:15 +01:00
parent 4bb75de3f0
commit 4e5ddc8027
3 changed files with 79 additions and 13 deletions

View File

@@ -853,6 +853,19 @@ export default class VocabService {
{ {
model: VocabCourse, model: VocabCourse,
as: 'course' as: 'course'
},
{
model: VocabGrammarExercise,
as: 'grammarExercises',
include: [
{
model: VocabGrammarExerciseType,
as: 'exerciseType'
}
],
required: false,
separate: true,
order: [['exerciseNumber', 'ASC']]
} }
] ]
}); });

View File

@@ -132,22 +132,23 @@ export default {
try { try {
const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}`); const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}`);
this.lesson = res.data; this.lesson = res.data;
// Lade Grammatik-Übungen // Initialisiere Übungen aus der Lektion oder lade sie separat
if (this.lesson && this.lesson.id) { if (this.lesson && this.lesson.id) {
if (this.lesson.grammarExercises && this.lesson.grammarExercises.length > 0) {
// Übungen sind bereits in der Lektion enthalten
this.initializeExercises(this.lesson.grammarExercises);
} else {
// Lade Übungen separat (Fallback)
await this.loadGrammarExercises(); await this.loadGrammarExercises();
} }
}
} catch (e) { } catch (e) {
console.error('Konnte Lektion nicht laden:', e); console.error('Konnte Lektion nicht laden:', e);
} finally { } finally {
this.loading = false; this.loading = false;
} }
}, },
async loadGrammarExercises() { initializeExercises(exercises) {
try {
const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}/grammar-exercises`);
const exercises = res.data || [];
this.lesson.grammarExercises = exercises;
// Initialisiere Antwort-Arrays für Gap Fill Übungen // Initialisiere Antwort-Arrays für Gap Fill Übungen
exercises.forEach(exercise => { exercises.forEach(exercise => {
const exerciseType = this.getExerciseType(exercise); const exerciseType = this.getExerciseType(exercise);
@@ -157,7 +158,15 @@ export default {
} else { } else {
this.$set(this.exerciseAnswers, exercise.id, ''); this.$set(this.exerciseAnswers, exercise.id, '');
} }
this.$set(this.exerciseResults, exercise.id, null);
}); });
},
async loadGrammarExercises() {
try {
const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}/grammar-exercises`);
const exercises = res.data || [];
this.lesson.grammarExercises = exercises;
this.initializeExercises(exercises);
} catch (e) { } catch (e) {
console.error('Konnte Grammatik-Übungen nicht laden:', e); console.error('Konnte Grammatik-Übungen nicht laden:', e);
this.lesson.grammarExercises = []; this.lesson.grammarExercises = [];

44
run-bisaya-content-script.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
# Script zum Ausführen des Bisaya-Content-Scripts auf dem Server
# Verwendung: ./run-bisaya-content-script.sh [server_ip] [ssh_user]
set -euo pipefail
SERVER_IP="${1:-your-part.de}"
SSH_USER="${2:-root}"
echo "🚀 Führe Bisaya-Content-Script auf Server aus..."
echo "Server: $SERVER_IP"
echo "SSH User: $SSH_USER"
echo ""
ssh "$SSH_USER@$SERVER_IP" << 'EOF'
set -euo pipefail
cd /opt/yourpart/backend
echo "📋 Prüfe ob Script vorhanden ist..."
if [ ! -f "scripts/create-bisaya-course-content.js" ]; then
echo "❌ Script nicht gefunden: scripts/create-bisaya-course-content.js"
echo " Bitte zuerst Backend deployen!"
exit 1
fi
echo "✅ Script gefunden"
echo ""
echo "🔧 Führe Script aus..."
echo ""
# Führe Script als yourpart-Benutzer aus
sudo -u yourpart node scripts/create-bisaya-course-content.js
echo ""
echo "✅ Script erfolgreich ausgeführt!"
EOF
echo ""
echo "🎉 Fertig! Die Grammatik-Übungen wurden auf dem Server erstellt."
echo ""
echo "💡 Nächste Schritte:"
echo " 1. Frontend neu bauen und deployen (falls noch nicht geschehen)"
echo " 2. Browser-Cache leeren und Seite neu laden"