improved UX in dashboard

This commit is contained in:
2026-05-28 11:29:14 +02:00
parent b049a9ab9f
commit 9cf67e765f
8 changed files with 876 additions and 247 deletions

View File

@ -35,8 +35,9 @@ case 'GET':
$r['conditionJson'] = $r['conditionJson'] ?: '{}';
}
unset($r);
$categoryKeys = qdb_list_category_keys_for_dashboard($pdo);
qdb_discard($tmpDb, $lockFp);
json_success(['questionnaires' => $rows]);
json_success(['questionnaires' => $rows, 'categoryKeys' => $categoryKeys]);
} catch (Throwable $e) {
qdb_discard($tmpDb, $lockFp);
error_log('questionnaires GET: ' . $e->getMessage());
@ -48,6 +49,44 @@ case 'POST':
require_role(['admin', 'supervisor'], $tokenRec);
$body = read_json_body();
if (($body['action'] ?? '') === 'updateCategoryLabel') {
$categoryKey = trim((string)($body['categoryKey'] ?? ''));
$germanLabel = (string)($body['germanLabel'] ?? '');
[$pdo, $tmpDb, $lockFp] = qdb_open(true);
try {
$stringKey = qdb_set_category_german_label($pdo, $categoryKey, $germanLabel);
qdb_save($tmpDb, $lockFp);
json_success([
'categoryKey' => $categoryKey,
'stringKey' => $stringKey,
'germanLabel' => trim($germanLabel),
]);
} catch (Throwable $e) {
qdb_discard($tmpDb, $lockFp);
error_log('updateCategoryLabel: ' . $e->getMessage());
json_error('SERVER_ERROR', 'Server error', 500);
}
break;
}
if (($body['action'] ?? '') === 'deleteCategoryKey') {
$categoryKey = trim((string)($body['categoryKey'] ?? ''));
if ($categoryKey === '') {
json_error('INVALID_FIELD', 'categoryKey is required', 400);
}
[$pdo, $tmpDb, $lockFp] = qdb_open(true);
try {
$cleared = qdb_delete_category_key($pdo, $categoryKey);
qdb_save($tmpDb, $lockFp);
json_success(['deleted' => $categoryKey, 'questionnairesCleared' => $cleared]);
} catch (Throwable $e) {
qdb_discard($tmpDb, $lockFp);
error_log('deleteCategoryKey: ' . $e->getMessage());
json_error('SERVER_ERROR', 'Server error', 500);
}
break;
}
if (($body['action'] ?? '') === 'importBundle') {
$bundle = $body['bundle'] ?? null;
if (!is_array($bundle)) {
@ -86,6 +125,9 @@ case 'POST':
$order = (int)$pdo->query("SELECT COALESCE(MAX(orderIndex),0)+1 FROM questionnaire")->fetchColumn();
}
$catKey = trim($body['categoryKey'] ?? '');
if ($catKey !== '') {
$catKey = qdb_normalize_stable_key($catKey);
}
$pdo->prepare("INSERT INTO questionnaire (questionnaireID, name, version, state, orderIndex, showPoints, conditionJson, categoryKey)
VALUES (:id, :n, :v, :s, :o, :sp, :cj, :ck)")
->execute([':id' => $id, ':n' => $name, ':v' => $version, ':s' => $state,
@ -129,6 +171,9 @@ case 'PUT':
$catKey = array_key_exists('categoryKey', $body)
? trim((string)$body['categoryKey'])
: trim($row['categoryKey'] ?? '');
if ($catKey !== '') {
$catKey = qdb_normalize_stable_key($catKey);
}
$pdo->prepare("UPDATE questionnaire SET name = :n, version = :v, state = :s,
orderIndex = :o, showPoints = :sp, conditionJson = :cj, categoryKey = :ck