Admin panel sync improvements, Baserow field handling (Single Select support), and UI emoji swap

This commit is contained in:
2026-04-16 17:01:12 +02:00
parent ec7b4d1f71
commit 247cca0803
4 changed files with 111 additions and 43 deletions
+21 -7
View File
@@ -14,13 +14,28 @@ function normalizeText(text) {
.trim();
}
/**
* Extract the string value from a Baserow Single Select field.
* Baserow returns { id: 6, value: "MC", color: "..." } for Single Select.
*/
function extractFieldValue(field, fallback) {
if (!field) return fallback || '';
if (typeof field === 'string') return field;
if (typeof field === 'object' && field.value !== undefined) return field.value;
return String(field);
}
function getTyp(question) {
return extractFieldValue(question['Typ'], 'MC').toLowerCase();
}
function checkFreitext(userAnswer, correctAnswer) {
return normalizeText(userAnswer) === normalizeText(correctAnswer);
}
function parseCorrectAnswers(question) {
const raw = (question['Richtige Antwort'] || '').trim();
const typ = (question['Typ'] || 'MC').toLowerCase();
const typ = getTyp(question);
if (typ === 'freitext') return [raw];
return raw
.split(',')
@@ -60,7 +75,7 @@ function calculateScore(question, selected, timeRemaining, totalTime, scoringMod
basis = 1000;
}
const typ = (question['Typ'] || 'MC').toLowerCase();
const typ = getTyp(question);
const correctAnswers = parseCorrectAnswers(question);
if (typ === 'freitext') {
@@ -93,14 +108,14 @@ function calculateScore(question, selected, timeRemaining, totalTime, scoringMod
* Strip the correct answer and shuffle options before sending to participants.
*/
function sanitizeQuestion(question) {
const typ = (question['Typ'] || 'MC').toLowerCase();
const typ = getTyp(question);
const sanitized = {
id: question.id,
frage: question['Frage'] || '',
typ: question['Typ'] || 'MC',
typ: extractFieldValue(question['Typ'], 'MC'),
bild: null,
antworten: [],
kategorie: question['Kategorie'] || '',
kategorie: extractFieldValue(question['Kategorie'], ''),
};
const bild = question['Bild'];
@@ -114,11 +129,10 @@ function sanitizeQuestion(question) {
const val = question[`Antwort ${k}`];
if (val) sanitized.antworten.push({ key: k, text: val });
}
// Shuffle answer order
sanitized.antworten = shuffleArray(sanitized.antworten);
}
return sanitized;
}
module.exports = { calculateScore, sanitizeQuestion, parseCorrectAnswers, normalizeText, shuffleArray };
module.exports = { calculateScore, sanitizeQuestion, parseCorrectAnswers, normalizeText, shuffleArray, extractFieldValue };