added prototype dev settings with test import and db wipe

This commit is contained in:
2026-05-26 16:38:37 +02:00
parent 2181d1731e
commit 9d783b60a9
13 changed files with 1253 additions and 33 deletions

View File

@ -257,6 +257,10 @@ function renderTableRows() {
const questionCells = questionsDef.map(q => {
const ans = c.answers && c.answers[q.questionID];
if (!ans) return '<td>—</td>';
if (q.type === 'glass_scale_question') {
const text = formatGlassAnswer(ans.freeTextValue);
return `<td>${esc(text || '—')}</td>`;
}
if (ans.answerOptionID && optionMap[ans.answerOptionID]) {
return `<td>${esc(optionMap[ans.answerOptionID])}</td>`;
}
@ -286,8 +290,12 @@ function getCellValue(client, key) {
if (key === 'completedAt') return client.completedAt;
if (key.startsWith('q_')) {
const qid = key.substring(2);
const q = questionsDef.find(qq => qq.questionID === qid);
const ans = client.answers && client.answers[qid];
if (!ans) return null;
if (q?.type === 'glass_scale_question') {
return formatGlassAnswer(ans.freeTextValue) || null;
}
if (ans.numericValue !== null && ans.numericValue !== undefined) return ans.numericValue;
if (ans.freeTextValue) return ans.freeTextValue;
return ans.answerOptionID || null;
@ -315,6 +323,9 @@ function exportCSV() {
const answerCols = questionsDef.map(q => {
const ans = c.answers && c.answers[q.questionID];
if (!ans) return '';
if (q.type === 'glass_scale_question') {
return formatGlassAnswer(ans.freeTextValue);
}
if (ans.answerOptionID && optionMap[ans.answerOptionID]) return optionMap[ans.answerOptionID];
if (ans.freeTextValue) return ans.freeTextValue;
if (ans.numericValue !== null && ans.numericValue !== undefined) return ans.numericValue;
@ -345,6 +356,22 @@ function csvEsc(val) {
return s;
}
function formatGlassAnswer(raw) {
if (!raw) return '';
try {
const o = JSON.parse(raw);
if (o && typeof o === 'object' && !Array.isArray(o)) {
return Object.entries(o)
.filter(([, v]) => v != null && String(v).trim() !== '')
.map(([k, v]) => `${k}: ${v}`)
.join('; ');
}
} catch {
/* plain text fallback */
}
return String(raw);
}
function esc(s) {
const d = document.createElement('div');
d.textContent = s ?? '';