1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{.CSRFToken}}">
<title>Settings - Task Dashboard</title>
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<style>
:root {
--bg-primary: #1a1a2e;
--bg-secondary: #16213e;
--bg-tertiary: #0f3460;
--text-primary: #eee;
--text-secondary: #888;
--accent: #e94560;
--success: #28a745;
--danger: #dc3545;
--border: #333;
}
body {
font-family: system-ui, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
margin: 0;
padding: 20px;
min-height: 100vh;
}
.container { max-width: 900px; margin: 0 auto; }
h1 { color: var(--accent); margin-bottom: 8px; }
h2 { color: var(--text-primary); font-size: 1.1em; margin: 24px 0 16px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.subtitle { color: var(--text-secondary); margin-bottom: 24px; }
.back-link { color: var(--accent); text-decoration: none; display: inline-block; margin-bottom: 16px; }
.back-link:hover { text-decoration: underline; }
.card {
background: var(--bg-secondary);
border-radius: 8px;
padding: 20px;
margin-bottom: 16px;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.card-title {
font-size: 1.1em;
font-weight: 600;
display: flex;
align-items: center;
gap: 8px;
}
.source-badge {
display: inline-block;
padding: 2px 8px;
border-radius: 10px;
font-size: 0.7em;
font-weight: normal;
}
.source-trello { background: #0079bf; }
.source-todoist { background: #e44332; }
.source-gcal { background: #9b59b6; }
.source-gtasks { background: #f39c12; }
.btn {
background: var(--bg-tertiary);
color: var(--text-primary);
border: 1px solid var(--border);
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 0.9em;
}
.btn:hover { background: #1a4a80; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); }
.btn-sm { padding: 4px 8px; font-size: 0.8em; }
.items-list { display: grid; gap: 8px; }
.item-row {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
background: var(--bg-tertiary);
border-radius: 4px;
}
.item-row:hover { background: #1a4a80; }
.toggle-switch {
position: relative;
width: 44px;
height: 24px;
flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background-color: #555;
transition: .3s;
border-radius: 24px;
}
.toggle-slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .3s;
border-radius: 50%;
}
input:checked + .toggle-slider { background-color: var(--success); }
input:checked + .toggle-slider:before { transform: translateX(20px); }
.item-name { flex: 1; }
.item-desc { color: var(--text-secondary); font-size: 0.85em; }
.item-id {
font-family: monospace;
font-size: 0.75em;
color: var(--text-secondary);
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
}
.empty-state {
color: var(--text-secondary);
padding: 20px;
text-align: center;
}
.add-form {
display: flex;
gap: 8px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--border);
}
.add-form input {
flex: 1;
background: var(--bg-tertiary);
border: 1px solid var(--border);
color: var(--text-primary);
padding: 8px 12px;
border-radius: 4px;
}
.add-form input:focus { outline: none; border-color: var(--accent); }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-link">← Back to Dashboard</a>
<h1>Settings</h1>
<p class="subtitle">Configure feature toggles and data sources.</p>
<!-- Feature Toggles Section -->
<div class="card">
<div class="card-header">
<div class="card-title">Feature Toggles</div>
</div>
<div class="items-list" id="toggles-list">
{{if .Toggles}}
{{range .Toggles}}
<div class="item-row" id="toggle-{{.Name}}">
<label class="toggle-switch">
<input type="checkbox"
{{if .Enabled}}checked{{end}}
hx-post="/settings/features/toggle"
hx-vals='{"name": "{{.Name}}", "enabled": "{{if .Enabled}}false{{else}}true{{end}}"}'
hx-swap="none"
hx-on::after-request="this.checked = !this.checked; if(event.detail.successful) this.checked = !this.checked;">
<span class="toggle-slider"></span>
</label>
<div class="item-name">
<strong>{{.Name}}</strong>
{{if .Description}}<div class="item-desc">{{.Description}}</div>{{end}}
</div>
<button class="btn btn-danger btn-sm"
hx-delete="/settings/features/{{.Name}}"
hx-target="#toggle-{{.Name}}"
hx-swap="outerHTML"
hx-confirm="Delete feature toggle '{{.Name}}'?">
Delete
</button>
</div>
{{end}}
{{else}}
<div class="empty-state">No feature toggles configured.</div>
{{end}}
</div>
<form class="add-form" hx-post="/settings/features" hx-target="#toggles-list" hx-swap="beforeend">
<input type="text" name="name" placeholder="Feature name (snake_case)" required pattern="[a-z_]+">
<input type="text" name="description" placeholder="Description (optional)">
<button type="submit" class="btn">Add Toggle</button>
</form>
</div>
<!-- Passkeys Section -->
<div class="card" id="passkeys-card">
<div class="card-header">
<div class="card-title">Passkeys</div>
</div>
<div id="passkeys-list" hx-get="/settings/passkeys" hx-trigger="load" hx-swap="innerHTML">
<div class="empty-state">Loading passkeys...</div>
</div>
<div class="add-form" id="passkey-register-form">
<input type="text" id="passkey-name" placeholder="Passkey name (e.g., MacBook Touch ID)" maxlength="100">
<button type="button" class="btn" id="register-passkey-btn">Register New Passkey</button>
</div>
<p id="passkey-status" style="color: var(--text-secondary); font-size: 0.85em; margin-top: 8px; display: none;"></p>
</div>
<script>
(function() {
if (!window.PublicKeyCredential) {
document.getElementById('passkeys-card').style.display = 'none';
return;
}
document.getElementById('register-passkey-btn').addEventListener('click', async function() {
const btn = this;
const statusEl = document.getElementById('passkey-status');
const nameInput = document.getElementById('passkey-name');
const name = nameInput.value.trim() || 'Passkey';
btn.disabled = true;
statusEl.style.display = 'block';
statusEl.style.color = 'var(--text-secondary)';
statusEl.textContent = 'Starting registration...';
try {
const csrfToken = document.querySelector('meta[name="csrf-token"]').content;
const beginResp = await fetch('/passkeys/register/begin', {
method: 'POST',
headers: {'X-CSRF-Token': csrfToken}
});
if (!beginResp.ok) throw new Error('Failed to start registration');
const options = await beginResp.json();
options.publicKey.challenge = base64urlToBuffer(options.publicKey.challenge);
options.publicKey.user.id = base64urlToBuffer(options.publicKey.user.id);
if (options.publicKey.excludeCredentials) {
options.publicKey.excludeCredentials = options.publicKey.excludeCredentials.map(c => ({
...c, id: base64urlToBuffer(c.id)
}));
}
statusEl.textContent = 'Waiting for passkey...';
const credential = await navigator.credentials.create(options);
const body = JSON.stringify({
id: credential.id,
rawId: bufferToBase64url(credential.rawId),
type: credential.type,
response: {
attestationObject: bufferToBase64url(credential.response.attestationObject),
clientDataJSON: bufferToBase64url(credential.response.clientDataJSON)
}
});
const finishResp = await fetch('/passkeys/register/finish?name=' + encodeURIComponent(name), {
method: 'POST',
headers: {'Content-Type': 'application/json', 'X-CSRF-Token': csrfToken},
body: body
});
if (!finishResp.ok) throw new Error('Registration failed');
statusEl.style.color = 'var(--success)';
statusEl.textContent = 'Passkey registered successfully!';
nameInput.value = '';
// Reload passkeys list
htmx.trigger('#passkeys-list', 'load');
} catch (e) {
statusEl.style.color = 'var(--danger)';
if (e.name === 'NotAllowedError') {
statusEl.textContent = 'Registration was cancelled.';
} else {
statusEl.textContent = e.message || 'Registration failed.';
}
}
btn.disabled = false;
});
function base64urlToBuffer(base64url) {
const base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
const pad = base64.length % 4 === 0 ? '' : '='.repeat(4 - (base64.length % 4));
const binary = atob(base64 + pad);
return Uint8Array.from(binary, c => c.charCodeAt(0)).buffer;
}
function bufferToBase64url(buffer) {
const bytes = new Uint8Array(buffer);
let binary = '';
for (const b of bytes) binary += String.fromCharCode(b);
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
}
})();
</script>
<!-- Source Configuration Section -->
<h2>Data Sources</h2>
<form hx-post="/settings/sync" hx-swap="outerHTML" hx-target="#sources-container" hx-indicator=".sync-indicator">
<button type="submit" class="btn">
<span class="sync-indicator htmx-indicator">Syncing...</span>
Sync Available Sources
</button>
</form>
<div id="sources-container" style="margin-top: 16px;">
{{range .Sources}}
<div class="card">
<div class="card-header">
<div class="card-title">
<span class="source-badge source-{{.}}">{{.}}</span>
{{if eq . "trello"}}Trello Boards{{end}}
{{if eq . "todoist"}}Todoist Projects{{end}}
{{if eq . "gcal"}}Google Calendars{{end}}
{{if eq . "gtasks"}}Google Task Lists{{end}}
</div>
</div>
<div class="items-list">
{{$configs := index $.Configs .}}
{{if $configs}}
{{range $configs}}
<div class="item-row">
<label class="toggle-switch">
<input type="checkbox"
{{if .Enabled}}checked{{end}}
hx-post="/settings/toggle"
hx-vals='{"source": "{{.Source}}", "item_type": "{{.ItemType}}", "item_id": "{{.ItemID}}", "enabled": "{{if .Enabled}}false{{else}}true{{end}}"}'
hx-swap="none"
hx-on::after-request="this.checked = !this.checked; if(event.detail.successful) this.checked = !this.checked;">
<span class="toggle-slider"></span>
</label>
<span class="item-name">{{.ItemName}}</span>
<span class="item-id" title="{{.ItemID}}">{{.ItemID}}</span>
</div>
{{end}}
{{else}}
<div class="empty-state">
No items configured. Click "Sync Available Sources" to fetch.
</div>
{{end}}
</div>
</div>
{{end}}
</div>
</div>
</body>
</html>
|