From 764b4c554575dcaa401992c8cf15e50bce9bcc70 Mon Sep 17 00:00:00 2001 From: Tom Hempel Date: Fri, 17 Jul 2026 17:45:38 +0200 Subject: [PATCH] settings for future and past dates --- docs/android-questionnaire-api.md | 3 ++- handlers/app_questionnaires.php | 1 + lib/dev_fixture.php | 7 +++++-- website/js/pages/editor.js | 11 +++++++++++ website/js/questionnaire-preview.js | 7 ++++++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/android-questionnaire-api.md b/docs/android-questionnaire-api.md index fabd971..d7c5f04 100644 --- a/docs/android-questionnaire-api.md +++ b/docs/android-questionnaire-api.md @@ -231,7 +231,8 @@ Question fields: - `options[].key`: answer option key. Send this back as `answerOptionKey` during upload. - `options[].nextQuestionId`: optional conditional navigation target. - `pointsMap`: optional map from answer option key to point value. -- `textKey`, `textKey1`, `textKey2`, `hint`, `hint1`, `hint2`, `symptoms`, `range`, `constraints`, `minSelection`: optional layout-specific config fields. +- `textKey`, `textKey1`, `textKey2`, `hint`, `hint1`, `hint2`, `symptoms`, `range`, `constraints`, `precision`, `dateRange`, `minSelection`: optional layout-specific config fields. + - `dateRange` (date_spinner): `"past"` (default) or `"future"` — which years/dates the app offers. Important ID rule: the fetch response returns short question IDs such as `q1`. The server resolves these back to full database IDs during upload, so the Android app should upload the same short IDs it received. diff --git a/handlers/app_questionnaires.php b/handlers/app_questionnaires.php index 13a076c..0dc6ee6 100644 --- a/handlers/app_questionnaires.php +++ b/handlers/app_questionnaires.php @@ -581,6 +581,7 @@ if ($qnID) { if (isset($config['unitLabel'])) $q['unitLabel'] = $config['unitLabel']; if (isset($config['constraints'])) $q['constraints'] = $config['constraints']; if (isset($config['precision'])) $q['precision'] = $config['precision']; + if (isset($config['dateRange'])) $q['dateRange'] = $config['dateRange']; if (isset($config['minSelection'])) $q['minSelection'] = $config['minSelection']; if (isset($config['maxLength'])) $q['maxLength'] = (int)$config['maxLength']; if (isset($config['nextQuestionId'])) $q['nextQuestionId'] = $config['nextQuestionId']; diff --git a/lib/dev_fixture.php b/lib/dev_fixture.php index a693ff7..3e8e117 100644 --- a/lib/dev_fixture.php +++ b/lib/dev_fixture.php @@ -490,10 +490,13 @@ function qdb_dev_build_answers_for_questionnaire(PDO $pdo, string $qnID, int $va break; case 'date_spinner': - $year = 2018 + ($v % 6); + $precision = $config['precision'] ?? 'full'; + $dateRange = ($config['dateRange'] ?? 'past') === 'future' ? 'future' : 'past'; + $year = $dateRange === 'future' + ? ((int)date('Y') + ($v % 5)) + : (2018 + ($v % 6)); $month = 1 + ($v % 12); $day = 1 + ($v % 28); - $precision = $config['precision'] ?? 'full'; $dateValue = match ($precision) { 'year' => sprintf('%04d', $year), 'year_month' => sprintf('%04d-%02d', $year, $month), diff --git a/website/js/pages/editor.js b/website/js/pages/editor.js index 0d01394..a49b4e4 100644 --- a/website/js/pages/editor.js +++ b/website/js/pages/editor.js @@ -602,6 +602,7 @@ function configFormHTML(layout, config, prefix, opts = {}) { const notBefore = config.constraints?.notBefore || ''; const notAfter = config.constraints?.notAfter || ''; const precision = config.precision || 'full'; + const dateRange = config.dateRange === 'future' ? 'future' : 'past'; html = `
@@ -611,6 +612,14 @@ function configFormHTML(layout, config, prefix, opts = {}) {
+
+ + + Controls which years the app shows. Default is past. +
@@ -717,6 +726,8 @@ function readConfigFromForm(layout, prefix) { case 'date_spinner': { const prec = val('precision') || 'full'; if (prec && prec !== 'full') config.precision = prec; + const dateRange = val('dateRange') || 'past'; + if (dateRange === 'future') config.dateRange = 'future'; const nb = val('notBefore'); const na = val('notAfter'); if (nb || na) { diff --git a/website/js/questionnaire-preview.js b/website/js/questionnaire-preview.js index 5ea2e06..76aff4f 100644 --- a/website/js/questionnaire-preview.js +++ b/website/js/questionnaire-preview.js @@ -333,9 +333,14 @@ function renderQuestionBody(q, sectionIdx) { case 'date_spinner': { const precision = config.precision || 'full'; + const dateRange = config.dateRange === 'future' ? 'future' : 'past'; const years = []; const now = new Date().getFullYear(); - for (let yr = now + 1; yr >= 1900; yr--) years.push(yr); + if (dateRange === 'future') { + for (let yr = now; yr <= now + 50; yr++) years.push(yr); + } else { + for (let yr = now; yr >= 1900; yr--) years.push(yr); + } inner += `
`; if (precision === 'full') { inner += `