feat: Füge Lektionsauswahl mit Titeln hinzu

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
jamulix 2025-10-21 18:22:44 +02:00
commit e9609a3e3a
3 changed files with 68 additions and 3 deletions

36
app.py
View file

@ -416,6 +416,42 @@ def next_text():
print(f"Fehler in next_text: {e}")
return jsonify({'error': 'Interner Serverfehler'}), 500
@app.route('/set_lesson', methods=['POST'])
def set_lesson():
"""Setzt die aktuelle Lektion auf die ausgewählte"""
try:
data = request.get_json()
lesson_index = data.get('lesson_index')
if lesson_index is None or not isinstance(lesson_index, int):
return jsonify({'error': 'Ungültiger Lektionsindex'}), 400
if lesson_index < 0 or lesson_index >= len(lessons):
return jsonify({'error': 'Lektionsindex außerhalb des gültigen Bereichs'}), 400
progress = Progress.query.first()
if not progress:
return jsonify({'error': 'Progress nicht gefunden'}), 400
progress.current_text_index = lesson_index
progress.current_position = 0
progress.last_text = lessons[lesson_index]['text']
db.session.commit()
# Bestimme den Titel der neuen Lektion
new_lesson = lessons[lesson_index]
lesson_title = new_lesson.get('description', f"Lektion {lesson_index + 1}")
return jsonify({
'text': new_lesson['text'],
'title': lesson_title
})
except Exception as e:
print(f"Fehler in set_lesson: {e}")
return jsonify({'error': 'Interner Serverfehler'}), 500
@app.route('/end_session', methods=['POST'])
def end_session():
"""Beendet eine Tipp-Session und speichert Statistiken"""

View file

@ -48,6 +48,36 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
// Event-Listener für Lektions-Buttons
document.querySelectorAll('.lesson-btn').forEach(button => {
button.addEventListener('click', function() {
const lessonIndex = parseInt(this.getAttribute('data-lesson-index'));
fetch('/set_lesson', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
lesson_index: lessonIndex
})
})
.then(response => response.json())
.then(data => {
if (data.error) {
alert('Fehler: ' + data.error);
} else {
currentText = data.text;
document.getElementById('target-text').textContent = currentText;
document.getElementById('lesson-title').textContent = data.title;
userInput.value = '';
userInput.focus();
updateStatistics('', currentText);
}
})
.catch(error => console.error('Fehler:', error));
});
});
// Nächste Zeile Button
nextBtn.addEventListener('click', function() {
fetch('/next_text', {

View file

@ -99,9 +99,8 @@
{% for lesson in lessons %}
<div class="col-md-3 mb-2">
<button class="btn btn-outline-primary w-100 lesson-btn"
data-lesson="{{ lesson.lesson }}"
data-text="{{ lesson.text }}">
Lektion {{ lesson.lesson }}
data-lesson-index="{{ loop.index0 }}">
{{ lesson.get('description', 'Lektion ' ~ (loop.index0 + 1)) }}
</button>
</div>
{% endfor %}