From e9609a3e3af5eb4e3047d197b8dc78ba166b57ab Mon Sep 17 00:00:00 2001 From: jamulix Date: Tue, 21 Oct 2025 18:22:44 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20F=C3=BCge=20Lektionsauswahl=20mit=20Tit?= =?UTF-8?q?eln=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (deepseek/deepseek-reasoner) --- app.py | 36 ++++++++++++++++++++++++++++++++++++ static/js/script.js | 30 ++++++++++++++++++++++++++++++ templates/index.html | 5 ++--- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index e8b18fe..011d53e 100644 --- a/app.py +++ b/app.py @@ -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""" diff --git a/static/js/script.js b/static/js/script.js index dd0a128..d9257c3 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -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', { diff --git a/templates/index.html b/templates/index.html index 6f9e3de..b95e52f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -99,9 +99,8 @@ {% for lesson in lessons %}
{% endfor %}