👩‍🏫

Lehrkraft-Login

Mathe Warm-Up · NRW Hauptschule

← Zurück zum Mathe Warm-Up

`); w.document.close(); w.focus(); setTimeout(()=>w.print(), 400); } async function printClassQR(classIdOverride) { const filterSel = document.getElementById('studentClassFilter'); const classId = classIdOverride || (filterSel ? filterSel.value : ''); if(!classId) { alert('Bitte zuerst eine Klasse ausw\u00e4hlen.'); return; } try { const students = await api('GET', '/students?class_id=' + classId); if(!students.length) { alert('Keine Sch\u00fcler\u00b7innen in dieser Klasse.'); return; } const className = students[0].class_name; const rows = students.map(s => { const url = 'http://mathe-warmup.duckdns.org/quiz.html?pin=' + encodeURIComponent(s.class_pin||'') + '&sid=' + s.id; const qrImg = 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + encodeURIComponent(url); return `

${s.name}

${className}

${url}

`; }).join(''); const w = window.open('', '_blank'); w.document.write(`QR-Codes ${className}

📱 QR-Codes – ${className} – Mathe Warm-Up

${rows}
`); w.document.close(); w.focus(); setTimeout(()=>w.print(), 1400); } catch(e) { alert('Fehler: ' + e.message); } } function toggleCreateAufgabe(show) { const form = document.getElementById('createAufgabeForm'); const visible = show !== undefined ? show : form.classList.contains('hidden'); if (visible) { form.classList.remove('hidden'); document.getElementById('aufgabeFormTitle').textContent = 'Aufgabe hinzuf\u00fcgen'; document.getElementById('editAufgabeId').value = ''; ['newAufgabeGrade','newAufgabeTopic','newAufgabeLevel','newAufgabeText','newOptA','newOptB','newOptC','newOptD'].forEach(id => { const el = document.getElementById(id); if(el) el.value = ''; }); document.querySelectorAll('input[name="newCorrect"]').forEach(r => r.checked = false); } else { form.classList.add('hidden'); } } function toggleAufgabenSection(id) { const el = document.getElementById(id); const arrow = document.getElementById('arrow-' + id); if (!el) return; const hidden = el.classList.toggle('hidden'); if (arrow) arrow.textContent = hidden ? '\u25b6' : '\u25bc'; } const _lvlCls = l => l==='N1' ? 'bg-blue-900/40 text-blue-400 border-blue-700/30' : l==='N2' ? 'bg-yellow-900/40 text-yellow-400 border-yellow-700/30' : 'bg-purple-900/40 text-purple-400 border-purple-700/30'; const _labels = ['A','B','C','D']; function _renderQuestion(q) { return `
${q.level}

${q.question}

${[q.option_a, q.option_b, q.option_c, q.option_d].map((opt, i) => `
${_labels[i]}${opt}
`).join('')}
`; } async function loadAufgaben() { if (document.getElementById('tab-aufgaben').classList.contains('hidden')) return; try { const questions = await fetch('/api/questions', {headers: {Authorization: 'Bearer ' + token}}).then(r => r.json()); document.getElementById('aufgabeCount').textContent = questions.length + ' Aufgabe' + (questions.length !== 1 ? 'n' : '') + ' gesamt'; // Group: grade \u2192 topic \u2192 questions[] const byGrade = {}; for (const q of questions) { if (!byGrade[q.grade]) byGrade[q.grade] = {}; const t = q.topic || 'Allgemein'; if (!byGrade[q.grade][t]) byGrade[q.grade][t] = []; byGrade[q.grade][t].push(q); } const grades = Object.keys(byGrade).sort((a, b) => +a - +b); const list = document.getElementById('aufgabenList'); if (!grades.length) { list.innerHTML = '

Keine Aufgaben gefunden.

'; return; } list.innerHTML = grades.map(grade => { const topicsObj = byGrade[grade]; const total = Object.values(topicsObj).reduce((s, a) => s + a.length, 0); const gradeId = 'grade-sec-' + grade; const topicsHTML = Object.entries(topicsObj) .sort(([a], [b]) => a.localeCompare(b, 'de')) .map(([topic, qs]) => { const topicId = 'topic-sec-' + grade + '-' + topic.replace(/[^a-zA-Z0-9]/g, '_'); return `
`; }).join(''); return `
`; }).join(''); } catch(e) { console.error(e); } } async function saveAufgabe() { const id = document.getElementById('editAufgabeId').value; const grade = parseInt(document.getElementById('newAufgabeGrade').value); const level = document.getElementById('newAufgabeLevel').value; const topic = document.getElementById('newAufgabeTopic').value.trim() || null; const question = document.getElementById('newAufgabeText').value.trim(); const option_a = document.getElementById('newOptA').value.trim(); const option_b = document.getElementById('newOptB').value.trim(); const option_c = document.getElementById('newOptC').value.trim(); const option_d = document.getElementById('newOptD').value.trim(); const correctEl = document.querySelector('input[name="newCorrect"]:checked'); if(!grade || !level || !question || !option_a || !option_b || !option_c || !option_d || !correctEl) { alert('Bitte alle Felder ausf\u00fcllen und die richtige Antwort w\u00e4hlen.'); return; } const body = {grade, level, topic, question, option_a, option_b, option_c, option_d, correct_index: parseInt(correctEl.value)}; try { if(id) { await api('PUT', '/questions/' + id, body); } else { await api('POST', '/questions', body); } toggleCreateAufgabe(false); loadAufgaben(); } catch(e) { alert('Fehler: ' + e.message); } } async function editAufgabe(id) { try { const all = await fetch('/api/questions', {headers:{Authorization:'Bearer '+token}}).then(r=>r.json()); const q = all.find(x => x.id === id); if(!q) return; document.getElementById('aufgabeFormTitle').textContent = 'Aufgabe bearbeiten'; document.getElementById('editAufgabeId').value = q.id; document.getElementById('newAufgabeGrade').value = q.grade; document.getElementById('newAufgabeTopic').value = q.topic || ''; document.getElementById('newAufgabeLevel').value = q.level; document.getElementById('newAufgabeText').value = q.question; document.getElementById('newOptA').value = q.option_a; document.getElementById('newOptB').value = q.option_b; document.getElementById('newOptC').value = q.option_c; document.getElementById('newOptD').value = q.option_d; const radio = document.querySelector('input[name="newCorrect"][value="'+q.correct_index+'"]'); if(radio) radio.checked = true; document.getElementById('createAufgabeForm').classList.remove('hidden'); document.getElementById('createAufgabeForm').scrollIntoView({behavior:'smooth', block:'start'}); } catch(e) { alert('Fehler: ' + e.message); } } async function deleteAufgabe(id) { if(!confirm('Aufgabe l\u00f6schen?')) return; try { await api('DELETE', '/questions/' + id); loadAufgaben(); } catch(e) { alert('Fehler: ' + e.message); } }