showing quesiton-keys instead of ids
This commit is contained in:
@ -16,7 +16,9 @@ export function testDataRowClassForUser(username) {
|
||||
return isDevTestUsername(username) ? ' row-test-data' : '';
|
||||
}
|
||||
|
||||
/** Local question key from full questionID (hash__q5 → q5). */
|
||||
const STABLE_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
||||
|
||||
/** Local question id from full questionID (hash__q5 → q5). */
|
||||
export function questionLocalKey(questionID, fallback = '') {
|
||||
const id = String(questionID ?? '');
|
||||
const sep = id.lastIndexOf('__');
|
||||
@ -24,6 +26,39 @@ export function questionLocalKey(questionID, fallback = '') {
|
||||
return fallback || id;
|
||||
}
|
||||
|
||||
function parseQuestionConfig(q) {
|
||||
if (!q || typeof q !== 'object') return {};
|
||||
let cfg = q.configJson;
|
||||
if (typeof cfg === 'string') {
|
||||
try {
|
||||
cfg = JSON.parse(cfg);
|
||||
} catch {
|
||||
cfg = {};
|
||||
}
|
||||
}
|
||||
return cfg && typeof cfg === 'object' ? cfg : {};
|
||||
}
|
||||
|
||||
/** Stable question key for table headers / CSV (matches server qdb_question_column_label). */
|
||||
export function questionDisplayKey(q) {
|
||||
if (!q) return '';
|
||||
if (q.questionKey) return String(q.questionKey);
|
||||
const cfg = parseQuestionConfig(q);
|
||||
const fromCfg = String(cfg.questionKey || '').trim();
|
||||
if (fromCfg && STABLE_KEY_RE.test(fromCfg)) return fromCfg;
|
||||
const dt = String(q.defaultText || '').trim();
|
||||
if (dt && STABLE_KEY_RE.test(dt)) return dt;
|
||||
return questionLocalKey(q.questionID, dt);
|
||||
}
|
||||
|
||||
/** German question text for header tooltips. */
|
||||
export function questionGermanLabel(q) {
|
||||
const dt = String(q?.defaultText || '').trim();
|
||||
const key = questionDisplayKey(q);
|
||||
if (dt && dt !== key) return dt;
|
||||
return '';
|
||||
}
|
||||
|
||||
/** header_order.json column id → question key (questionnaire_x-y → y). */
|
||||
export function headerColumnQuestionKey(headerId) {
|
||||
const id = String(headerId ?? '');
|
||||
|
||||
Reference in New Issue
Block a user