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:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user