From a42fa5adb1f61dcd4405179eb0175b7e1ecc45fb Mon Sep 17 00:00:00 2001 From: Michi Date: Tue, 24 Nov 2026 20:40:33 +0100 Subject: [PATCH] settings export/import/reset + interaktive tutorial-tour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings (Einstellungen → Allgemein → Daten): - Exportieren (JSON-Download), Importieren (Datei zurückladen), "Zurücksetzen & als neuer User starten" – sichert settings.json vorher automatisch (timestamped), dann Ersteinrichtung. - Server: GET /api/settings/export, POST /api/settings/import, POST /api/settings/reset; lib/settings.js: exportData/importData/reset. Interaktive Tour (Hilfe-Dialog → "Diesen Bereich zeigen"): - Spotlight wandert animiert über die echten UI-Elemente, Sprechblase mit Text, Auto-Play + Pause/Zurück/Weiter/Schließen, Pfeiltasten/Esc. - Pro Bereich (Ansichten, Finden, Projekt, Backup, Gut zu wissen) eigene Schritte; wechselt bei Bedarf Ansicht/Modus bzw. öffnet ein Projekt und stellt danach den Ausgangszustand wieder her. Fehlende Ziele werden übersprungen. Zweisprachig. Co-Authored-By: Claude Opus 4.8 --- lib/settings.js | 33 ++++++++- public/app.js | 174 ++++++++++++++++++++++++++++++++++++++++++++-- public/index.html | 44 +++++++++++- public/lang.js | 28 ++++++++ server.js | 26 +++++++ 5 files changed, 297 insertions(+), 8 deletions(-) diff --git a/lib/settings.js b/lib/settings.js index a2a3180..7ce3ecb 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -343,4 +343,35 @@ function subfolders(dir) { return { path: p, folders: list.slice(0, 200) } } -module.exports = { setNested, itchOn, get, load, save, setActive, addRoots, activeRootList, subfolders, backupSubdir, configured, targetName, DATA_DIR, APP_DIR, DEFAULT_EXCLUDE_DIRS } +// The persisted shape (what settings.json holds; derived fields stripped) – for "Export settings". +function exportData() { + const { projectsRoot, activeRoot, ...stored } = get() + return stored +} + +// Overwrites settings.json with an imported object and reloads. load() is tolerant and fills gaps. +function importData(obj) { + if (!obj || typeof obj !== 'object' || Array.isArray(obj)) throw new Error('Ungültige Einstellungsdatei.') + fs.mkdirSync(DATA_DIR, { recursive: true }) + fs.writeFileSync(FILE, JSON.stringify(obj, null, 2)) + current = null + return load() +} + +// Backs up settings.json (timestamped) and removes it, so the next load starts as a new user. +function reset() { + let backupFile = '' + try { + if (fs.existsSync(FILE)) { + const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19) + backupFile = path.join(DATA_DIR, `settings-backup-${ts}.json`) + fs.copyFileSync(FILE, backupFile) + fs.rmSync(FILE, { force: true }) + } + } catch (e) { throw new Error(`Zurücksetzen fehlgeschlagen: ${e.message ?? e}`) } + current = null + load() + return { backupFile } +} + +module.exports = { setNested, itchOn, get, load, save, setActive, addRoots, activeRootList, subfolders, backupSubdir, configured, targetName, DATA_DIR, APP_DIR, DEFAULT_EXCLUDE_DIRS, exportData, importData, reset } diff --git a/public/app.js b/public/app.js index 5c93820..6d9e9c4 100644 --- a/public/app.js +++ b/public/app.js @@ -762,6 +762,41 @@ document.getElementById('spOpenData').onclick = async () => { try { await postJson('/api/datadir/open') } catch (e) { toast(e.message, 'triangle-alert') } } +/* settings backup / restore / reset (Einstellungen → Allgemein → Daten) */ +document.getElementById('spExport').onclick = async () => { + try { + const data = await (await fetch('/api/settings/export')).json() + const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }) + const a = document.createElement('a') + a.href = URL.createObjectURL(blob) + a.download = `project-dashboard-settings-${new Date().toISOString().slice(0, 10)}.json` + a.click() + setTimeout(() => URL.revokeObjectURL(a.href), 2000) + toast(t('set.exported'), 'download') + } catch (e) { toast(e.message, 'triangle-alert') } +} +document.getElementById('spImport').onclick = () => document.getElementById('spImportFile').click() +document.getElementById('spImportFile').onchange = async (e) => { + const file = e.target.files?.[0] + e.target.value = '' + if (!file) return + try { + const data = JSON.parse(await file.text()) + if (!confirm(t('set.importConfirm'))) return + await postJson('/api/settings/import', { data }) + toast(t('set.imported'), 'upload') + setTimeout(() => location.reload(), 600) + } catch (ex) { toast(t('set.importBad') + ' ' + (ex.message ?? ''), 'triangle-alert') } +} +document.getElementById('spReset').onclick = async () => { + if (!confirm(t('set.resetConfirm'))) return + try { + const r = await postJson('/api/settings/reset') + toast(r.backupFile ? t('set.resetDone', { file: r.backupFile }) : t('set.resetDoneNoBackup'), 'refresh-cw') + setTimeout(() => location.reload(), 900) + } catch (e) { toast(e.message, 'triangle-alert') } +} + // "Durchsuchen…": data-for = input id, or (in a target/folder row) the row's path input document.getElementById('spanel').addEventListener('click', async (e) => { const b = e.target.closest('.pickbtn') @@ -968,17 +1003,20 @@ document.getElementById('btnSettings').onclick = () => openSettings(false) document.getElementById('btnCloseSettings').onclick = closeSettings /* help / overview dialog – paged, one topic group per page (native : Esc closes it) */ const HELP_PAGES = [ - { t: 'help.g.views', rows: [['kanban', 'help.board'], ['layout-grid', 'help.gallery'], ['list', 'help.list'], ['list-checks', 'help.tasks'], ['activity', 'help.activity'], ['hard-drive', 'help.storage']] }, - { t: 'help.g.find', rows: [['sliders-horizontal', 'help.mode'], ['search', 'help.search'], ['funnel', 'help.filters']] }, - { t: 'help.g.project', rows: [['pencil', 'help.edit'], ['info', 'help.info'], ['play', 'help.actions'], ['folder-open', 'help.quick']] }, - { t: 'help.g.backup', rows: [['hard-drive-upload', 'help.backup'], ['clock-alert', 'help.due']] }, - { t: 'help.g.misc', rows: [['folders', 'help.folders'], ['languages', 'help.lang'], ['keyboard', 'help.keys']] }, + { id: 'views', t: 'help.g.views', rows: [['kanban', 'help.board'], ['layout-grid', 'help.gallery'], ['list', 'help.list'], ['list-checks', 'help.tasks'], ['activity', 'help.activity'], ['hard-drive', 'help.storage']] }, + { id: 'find', t: 'help.g.find', rows: [['sliders-horizontal', 'help.mode'], ['search', 'help.search'], ['funnel', 'help.filters']] }, + { id: 'project', t: 'help.g.project', rows: [['pencil', 'help.edit'], ['info', 'help.info'], ['play', 'help.actions'], ['folder-open', 'help.quick']] }, + { id: 'backup', t: 'help.g.backup', rows: [['hard-drive-upload', 'help.backup'], ['clock-alert', 'help.due']] }, + { id: 'misc', t: 'help.g.misc', rows: [['folders', 'help.folders'], ['languages', 'help.lang'], ['keyboard', 'help.keys']] }, ] let helpPage = 0 function renderHelp() { helpPage = Math.max(0, Math.min(HELP_PAGES.length - 1, helpPage)) document.getElementById('helpNav').innerHTML = HELP_PAGES.map((p, i) => ``).join('') - document.getElementById('helpBody').innerHTML = HELP_PAGES[helpPage].rows.map(([icon, k]) => `
${ic(icon)}
${t(k)}
`).join('') + document.getElementById('helpBody').innerHTML = + `` + + HELP_PAGES[helpPage].rows.map(([icon, k]) => `
${ic(icon)}
${t(k)}
`).join('') + document.getElementById('helpShow').onclick = () => startTour(HELP_PAGES[helpPage].id) document.getElementById('helpDots').innerHTML = HELP_PAGES.map((_, i) => ``).join('') document.getElementById('helpPrev').disabled = helpPage === 0 document.getElementById('helpNext').disabled = helpPage === HELP_PAGES.length - 1 @@ -994,6 +1032,130 @@ document.getElementById('helpDlg').addEventListener('keydown', (e) => { if (e.key === 'ArrowRight' && helpPage < HELP_PAGES.length - 1) gotoHelp(helpPage + 1) if (e.key === 'ArrowLeft' && helpPage > 0) gotoHelp(helpPage - 1) }) + +/* ── interactive tour: spotlight walks over the real UI, section by section ── */ +// Each step points at a real element (sel). before() may switch view/mode or open +// a project so the element exists; steps whose element is missing are skipped. +const TOURS = { + views: { before: () => applyUiMode('advanced'), steps: [ + { sel: '#tabs [data-view="board"]', key: 'help.board' }, + { sel: '#tabs [data-view="gallery"]', key: 'help.gallery' }, + { sel: '#tabs [data-view="list"]', key: 'help.list' }, + { sel: '#tabs [data-view="tasks"]', key: 'help.tasks' }, + { sel: '#tabs [data-view="activity"]', key: 'help.activity' }, + { sel: '#tabs [data-view="storage"]', key: 'help.storage' }, + ] }, + find: { before: () => { applyUiMode('advanced'); setView('board') }, steps: [ + { sel: '#modeSeg', key: 'help.mode' }, + { sel: '.searchbox', key: 'help.search' }, + { sel: '#chipfilters', key: 'help.filters' }, + ] }, + project: { before: () => { applyUiMode('advanced'); setView('board') }, steps: [ + { sel: '#board .card .qsg', key: 'help.quick' }, + { before: () => { const p = visibleProjects()[0] || projects[0]; if (p) { tour.openedEditor = true; openEditor(p) } }, wait: 480, sel: '#ptabs [data-sec="edit"]', key: 'help.edit' }, + { sel: '#ptabs [data-sec="info"]', key: 'help.info' }, + { sel: '#ptabs [data-sec="actions"]', key: 'help.actions' }, + ] }, + backup: { before: () => applyUiMode('advanced'), steps: [ + { sel: '#btnBackup', key: 'help.backup' }, + { sel: '#chipfilters [data-q="due"]', key: 'help.due' }, + ] }, + misc: { before: () => applyUiMode('advanced'), steps: [ + { sel: '#rootBtn', key: 'help.folders' }, + { sel: '#btnSettings', key: 'help.lang' }, + { sel: '#btnHelp', key: 'help.keys' }, + ] }, +} +const AUTO_MS = 3400 +let tour = null +function startTour(id) { + const def = TOURS[id] + if (!def) return + document.getElementById('helpDlg').close() + tour = { def, steps: def.steps, i: -1, playing: true, timer: null, prevView: activeView, prevMode: uiMode, openedEditor: false } + try { def.before?.() } catch {} + document.getElementById('tour').hidden = false + setTimeout(() => tourGo(1), 320) // let a view/mode switch render first +} +const tourTarget = (s) => (s.sel ? document.querySelector(s.sel) : null) +async function tourGo(dir) { + if (!tour) return + clearTimeout(tour.timer) + let i = tour.i + for (;;) { + i += dir + if (i < 0) { i = 0; break } + if (i >= tour.steps.length) { endTour(); return } + const s = tour.steps[i] + if (s.before) { try { s.before() } catch {} } + if (s.wait) await new Promise((r) => setTimeout(r, s.wait)) + if (!tour) return // closed meanwhile + if (!s.sel || tourTarget(s)) break // usable step (has target or is centered) + } + tour.i = i + tourShow() +} +function tourShow() { + if (!tour) return + const s = tour.steps[tour.i] + positionSpot(tourTarget(s)) + document.getElementById('tourText').innerHTML = t(s.key) + document.getElementById('tourStep').textContent = `${tour.i + 1} / ${tour.steps.length}` + document.getElementById('tourPrev').disabled = tour.i === 0 + document.querySelector('#tourNext span').textContent = tour.i === tour.steps.length - 1 ? t('tour.finish') : t('help.next') + document.querySelector('#tourPause use').setAttribute('href', `/icons.svg#${tour.playing ? 'pause' : 'play'}`) + clearTimeout(tour.timer) + if (tour.playing) tour.timer = setTimeout(() => tourGo(1), AUTO_MS) +} +function positionSpot(el) { + const spot = document.getElementById('tourSpot') + const bubble = document.getElementById('tourBubble') + if (el) { + try { el.scrollIntoView({ block: 'nearest', inline: 'nearest' }) } catch {} + const r = el.getBoundingClientRect(), pad = 6 + spot.style.top = (r.top - pad) + 'px' + spot.style.left = (r.left - pad) + 'px' + spot.style.width = (r.width + pad * 2) + 'px' + spot.style.height = (r.height + pad * 2) + 'px' + const bw = Math.min(320, innerWidth - 24), bh = bubble.offsetHeight || 150 + let top = r.bottom + 12 + if (top + bh > innerHeight - 10) top = Math.max(10, r.top - bh - 12) + let left = Math.max(12, Math.min(innerWidth - bw - 12, r.left + r.width / 2 - bw / 2)) + bubble.style.top = top + 'px' + bubble.style.left = left + 'px' + } else { + spot.style.width = spot.style.height = '0px' + spot.style.top = innerHeight / 2 + 'px' + spot.style.left = innerWidth / 2 + 'px' + bubble.style.top = Math.max(12, innerHeight / 2 - 90) + 'px' + bubble.style.left = (innerWidth / 2 - Math.min(320, innerWidth - 24) / 2) + 'px' + } +} +function endTour() { + if (!tour) return + clearTimeout(tour.timer) + const opened = tour.openedEditor, pv = tour.prevView, pm = tour.prevMode + tour = null + document.getElementById('tour').hidden = true + if (opened) try { closeEditor() } catch {} + try { applyUiMode(pm) } catch {} + try { setView(pv) } catch {} +} +document.getElementById('tourClose').onclick = endTour +document.getElementById('tourPrev').onclick = () => tourGo(-1) +document.getElementById('tourNext').onclick = () => tourGo(1) +document.getElementById('tourPause').onclick = () => { + if (!tour) return + tour.playing = !tour.playing + tourShow() +} +addEventListener('resize', () => { if (tour) tourShow() }) +addEventListener('keydown', (e) => { + if (!tour) return + if (e.key === 'Escape') { e.preventDefault(); endTour() } + else if (e.key === 'ArrowRight') tourGo(1) + else if (e.key === 'ArrowLeft') tourGo(-1) +}) document.getElementById('spCancel').onclick = closeSettings document.getElementById('spSave').onclick = saveSettings diff --git a/public/index.html b/public/index.html index 66ccd19..3b8e1e9 100644 --- a/public/index.html +++ b/public/index.html @@ -693,6 +693,7 @@ .hnav:hover { color: var(--text); } .hnav.active { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; font-weight: 600; } .helpbody { padding: 2px 20px 6px; overflow-y: auto; min-height: 0; } + .helpshow { width: 100%; justify-content: center; margin: 4px 0 8px; } .helprow { display: flex; gap: 11px; align-items: flex-start; padding: 6px 0; font-size: 13px; line-height: 1.5; color: var(--text); } .helprow .hc { flex: 0 0 auto; width: 27px; height: 27px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; } .helprow .hc .i { width: 15px; height: 15px; } @@ -820,6 +821,22 @@ .kbd { font-family: "Cascadia Mono", Consolas, ui-monospace, monospace; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; } @media (max-width: 560px) { .sitem .fico, .kbd { display: none; } .sitem { grid-template-columns: minmax(0, 1fr) auto; } } .rowbtns { display: flex; gap: 6px; flex-wrap: wrap; } + /* interactive tour */ + #tour { position: fixed; inset: 0; z-index: 60; } + #tour[hidden] { display: none; } + .tour-spot { position: fixed; top: 50%; left: 50%; width: 0; height: 0; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(8, 10, 16, .66); outline: 2px solid var(--accent); transition: top .45s cubic-bezier(.4,0,.2,1), left .45s cubic-bezier(.4,0,.2,1), width .45s cubic-bezier(.4,0,.2,1), height .45s cubic-bezier(.4,0,.2,1); pointer-events: none; } + .tour-spot::after { content: ""; position: absolute; inset: -3px; border-radius: 12px; outline: 2px solid var(--accent); opacity: .8; animation: tourPulse 1.7s ease-out infinite; } + @keyframes tourPulse { 0% { transform: scale(1); opacity: .7; } 70% { transform: scale(1.12); opacity: 0; } 100% { opacity: 0; } } + .tour-bubble { position: fixed; top: 50%; left: 50%; width: 320px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 14px 16px; z-index: 61; transition: top .45s cubic-bezier(.4,0,.2,1), left .45s cubic-bezier(.4,0,.2,1); } + .tour-bubble .tb-text { font-size: 13.5px; line-height: 1.55; color: var(--text); } + .tour-bubble .tb-text b { font-weight: 650; } + .tour-bubble .tb-foot { display: flex; align-items: center; gap: 6px; margin-top: 12px; } + .tour-bubble .tb-step { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; } + .tour-bubble .btn { padding: 5px 10px; font-size: 12.5px; } + .tour-bubble .iconbtn { width: 30px; height: 30px; } + .resetrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 2px; } + .resetrow .btn { flex: 0 0 auto; } + .resetrow .hint { flex: 1; min-width: 200px; } .importbox { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-top: 8px; background: var(--surface-2); } .importbox[hidden] { display: none; } .implist { max-height: 240px; overflow: auto; margin: 8px 0; display: grid; gap: 2px; } @@ -1219,7 +1236,16 @@

Data

-
+
+ + + + +
+
+ + Your current settings are backed up first; then the dashboard starts fresh with the first-run setup. +
+ + +
diff --git a/public/lang.js b/public/lang.js index f6d1a32..d1f35cf 100644 --- a/public/lang.js +++ b/public/lang.js @@ -185,6 +185,17 @@ window.LANG = { 'set.data.h': 'Data', 'set.language': 'Language', 'set.openData': 'Open data folder', + 'set.export': 'Export settings', + 'set.import': 'Import settings', + 'set.reset': 'Reset & start as a new user…', + 'set.resetHint': 'Your current settings are backed up first; then the dashboard starts fresh with the first-run setup.', + 'set.exported': 'Settings exported', + 'set.importConfirm': 'Replace the current settings with the imported file? The page reloads afterwards.', + 'set.imported': 'Settings imported', + 'set.importBad': 'Could not read the settings file.', + 'set.resetConfirm': 'Reset the dashboard to a fresh “new user” state? Your current settings are backed up first, then the page reloads into the first-run setup.', + 'set.resetDone': 'Reset done – backup saved: {file}', + 'set.resetDoneNoBackup': 'Reset done', 'set.window.h': 'Window', 'set.window.p': 'Applies immediately, without saving.', 'set.tray': 'Keep running in the background when closed', @@ -746,6 +757,9 @@ window.LANG = { 'help.keys': 'Shortcuts – Esc closes panels and dialogs; Ctrl+S saves the settings.', 'help.prev': 'Back', 'help.next': 'Next', + 'help.show': 'Show me this section', + 'tour.finish': 'Done', + 'tour.pause': 'Pause / play', }, de: { @@ -929,6 +943,17 @@ window.LANG = { 'set.data.h': 'Daten', 'set.language': 'Sprache', 'set.openData': 'Datenordner öffnen', + 'set.export': 'Einstellungen exportieren', + 'set.import': 'Einstellungen importieren', + 'set.reset': 'Zurücksetzen & als neuer User starten…', + 'set.resetHint': 'Deine aktuellen Einstellungen werden vorher gesichert; danach startet das Dashboard neu mit der Ersteinrichtung.', + 'set.exported': 'Einstellungen exportiert', + 'set.importConfirm': 'Aktuelle Einstellungen durch die importierte Datei ersetzen? Die Seite lädt danach neu.', + 'set.imported': 'Einstellungen importiert', + 'set.importBad': 'Einstellungsdatei konnte nicht gelesen werden.', + 'set.resetConfirm': 'Dashboard auf einen frischen „neuer User“-Zustand zurücksetzen? Deine aktuellen Einstellungen werden vorher gesichert, danach lädt die Seite in die Ersteinrichtung.', + 'set.resetDone': 'Zurückgesetzt – Sicherung gespeichert: {file}', + 'set.resetDoneNoBackup': 'Zurückgesetzt', 'set.window.h': 'Fenster', 'set.window.p': 'Gilt sofort, ohne Speichern.', 'set.tray': 'Beim Schließen im Hintergrund weiterlaufen', @@ -1490,5 +1515,8 @@ window.LANG = { 'help.keys': 'Tastenkürzel – Esc schließt Panels und Dialoge; Strg+S speichert die Einstellungen.', 'help.prev': 'Zurück', 'help.next': 'Weiter', + 'help.show': 'Diesen Bereich zeigen', + 'tour.finish': 'Fertig', + 'tour.pause': 'Pause / Abspielen', }, }; diff --git a/server.js b/server.js index 5cec9b4..dd22ef7 100644 --- a/server.js +++ b/server.js @@ -452,6 +452,32 @@ app.post('/api/settings', (req, res) => { res.status(400).json({ error: String(e.message ?? e) }) } }) +// Export the settings as JSON (client offers it as a download). +app.get('/api/settings/export', (req, res) => { + res.json(settings.exportData()) +}) +// Import a settings object (from a previously exported file) and apply it. +app.post('/api/settings/import', (req, res) => { + if (storage.busy() || backup.busy() || create.busy()) return res.status(409).json({ error: 'Erst warten, bis Scan/Backup fertig ist.' }) + try { + settings.importData(req.body?.data ?? req.body) + applySettings() + res.json({ ...settings.get(), configured: !!ROOT_DIR, dataDir: settings.DATA_DIR }) + } catch (e) { + res.status(400).json({ error: String(e.message ?? e) }) + } +}) +// Reset to a fresh "new user" state. Backs up settings.json first, then starts over. +app.post('/api/settings/reset', (req, res) => { + if (storage.busy() || backup.busy() || create.busy() || archive.busy()) return res.status(409).json({ error: 'Erst warten, bis Scan/Backup fertig ist.' }) + try { + const r = settings.reset() + applySettings() + res.json({ ok: true, backupFile: r.backupFile }) + } catch (e) { + res.status(400).json({ error: String(e.message ?? e) }) + } +}) // Update detection: newest change of the server code (server.js, lib\*.js) and // of the page (public\*). The server code is only read at start, so a newer // file means "restart needed"; the page only needs a reload.