feat: füge Unterstützung für temporäre gap_fill-Übungen aus chapterLexemeTraining hinzu
All checks were successful
Deploy to production / deploy (push) Successful in 2m0s

This commit is contained in:
Torsten Schulz (local)
2026-05-26 16:04:36 +02:00
parent 1232edd570
commit 52ee406165
2 changed files with 41 additions and 0 deletions

View File

@@ -2881,6 +2881,23 @@ export default class VocabService {
}); });
const plainLesson = lesson.get({ plain: true }); const plainLesson = lesson.get({ plain: true });
// Normalize exercise types: if question text contains clear gap placeholders,
// ensure the questionData.type is 'gap_fill' so the frontend renders the gap UI.
(plainLesson.grammarExercises || []).forEach((ex) => {
try {
const qData = typeof ex.questionData === 'string' ? JSON.parse(ex.questionData || '{}') : (ex.questionData || {});
const text = String(qData.text || qData.question || '').trim();
const hasUnderscoreGap = /_{3,}/.test(text);
const hasBraceGap = /\{\s*gap\s*\}/i.test(text);
const hasParenPlaceholders = /\(\s*_{0,}\s*\)/.test(text);
if ((hasUnderscoreGap || hasBraceGap || hasParenPlaceholders) && qData.type !== 'gap_fill') {
qData.type = 'gap_fill';
ex.questionData = qData;
}
} catch (err) {
// ignore parse errors
}
});
// Lade Vokabeln aus vorherigen Lektionen (für Wiederholung UND für gemischten Vokabeltrainer) // Lade Vokabeln aus vorherigen Lektionen (für Wiederholung UND für gemischten Vokabeltrainer)
if (plainLesson.lessonNumber > 1) { if (plainLesson.lessonNumber > 1) {

View File

@@ -2816,6 +2816,30 @@ export default {
} }
await this.$nextTick(); await this.$nextTick();
let exercises = this.effectiveExercises; let exercises = this.effectiveExercises;
// Wenn das Backend eine chapterLexemeTraining-Liste liefert, wandle sie
// in temporäre gap_fill-Übungen um und mische sie in die grammarExercises
try {
if (this.lesson && Array.isArray(this.lesson.chapterLexemeTraining) && this.lesson.chapterLexemeTraining.length) {
const temps = this.lesson.chapterLexemeTraining.map((item, idx) => {
const id = `cht-${this.lesson.id}-${String(item.id)}`;
return {
id,
lessonId: this.lesson.id,
exerciseTypeId: 1,
title: `Kapitel-Vokabel: ${item.learning}`,
instruction: this.$t('socialnetwork.vocab.courses.fillTheBlank') || 'Lückentext',
questionData: { type: 'gap_fill', text: `{gap} (${item.learning})` },
answerData: { type: 'gap_fill', answers: [item.reference] }
};
});
this.lesson.grammarExercises = Array.isArray(this.lesson.grammarExercises)
? [...this.lesson.grammarExercises, ...temps]
: temps;
exercises = this.effectiveExercises;
}
} catch (err) {
console.warn('[VocabLessonView] Fehler beim Einfügen von chapterLexemeTraining:', err);
}
if (!exercises || exercises.length === 0) { if (!exercises || exercises.length === 0) {
debugLog('[VocabLessonView] Lade Übungen separat...'); debugLog('[VocabLessonView] Lade Übungen separat...');
await this.loadGrammarExercises(); await this.loadGrammarExercises();