From 4e5ddc80277ff775336f1aebf62612392a512928 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 19 Jan 2026 15:33:15 +0100 Subject: [PATCH] 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. --- backend/services/vocabService.js | 13 ++++++ frontend/src/views/social/VocabLessonView.vue | 35 +++++++++------ run-bisaya-content-script.sh | 44 +++++++++++++++++++ 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100755 run-bisaya-content-script.sh diff --git a/backend/services/vocabService.js b/backend/services/vocabService.js index 10e7fa5..2fed776 100644 --- a/backend/services/vocabService.js +++ b/backend/services/vocabService.js @@ -853,6 +853,19 @@ export default class VocabService { { model: VocabCourse, as: 'course' + }, + { + model: VocabGrammarExercise, + as: 'grammarExercises', + include: [ + { + model: VocabGrammarExerciseType, + as: 'exerciseType' + } + ], + required: false, + separate: true, + order: [['exerciseNumber', 'ASC']] } ] }); diff --git a/frontend/src/views/social/VocabLessonView.vue b/frontend/src/views/social/VocabLessonView.vue index 8f4aef2..4cb352b 100644 --- a/frontend/src/views/social/VocabLessonView.vue +++ b/frontend/src/views/social/VocabLessonView.vue @@ -132,9 +132,15 @@ export default { try { const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}`); this.lesson = res.data; - // Lade Grammatik-Übungen + // Initialisiere Übungen aus der Lektion oder lade sie separat if (this.lesson && this.lesson.id) { - await this.loadGrammarExercises(); + 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(); + } } } catch (e) { console.error('Konnte Lektion nicht laden:', e); @@ -142,22 +148,25 @@ export default { this.loading = false; } }, + initializeExercises(exercises) { + // Initialisiere Antwort-Arrays für Gap Fill Übungen + exercises.forEach(exercise => { + const exerciseType = this.getExerciseType(exercise); + if (exerciseType === 'gap_fill') { + const gapCount = this.getGapCount(exercise); + this.$set(this.exerciseAnswers, exercise.id, new Array(gapCount).fill('')); + } else { + 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; - - // Initialisiere Antwort-Arrays für Gap Fill Übungen - exercises.forEach(exercise => { - const exerciseType = this.getExerciseType(exercise); - if (exerciseType === 'gap_fill') { - const gapCount = this.getGapCount(exercise); - this.$set(this.exerciseAnswers, exercise.id, new Array(gapCount).fill('')); - } else { - this.$set(this.exerciseAnswers, exercise.id, ''); - } - }); + this.initializeExercises(exercises); } catch (e) { console.error('Konnte Grammatik-Übungen nicht laden:', e); this.lesson.grammarExercises = []; diff --git a/run-bisaya-content-script.sh b/run-bisaya-content-script.sh new file mode 100755 index 0000000..6f62a9f --- /dev/null +++ b/run-bisaya-content-script.sh @@ -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"