-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress-donuts.html
More file actions
538 lines (494 loc) · 16.2 KB
/
progress-donuts.html
File metadata and controls
538 lines (494 loc) · 16.2 KB
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Project Progress</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap');
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #f5f4f0;
--card: #ffffff;
--text-primary: #1a1a1a;
--text-secondary: #888;
--accent-time: #2d6a4f;
--accent-time-light: #d8f3dc;
--accent-tasks: #1d3557;
--accent-tasks-light: #dce8f5;
--remaining: #e8e6e0;
--border: #e5e3dd;
--status-behind: #e63946;
--status-on-track: #2d6a4f;
--status-ahead: #457b9d;
}
body {
font-family: 'DM Sans', sans-serif;
background: var(--bg);
min-height: 100vh;
padding: 28px 24px;
color: var(--text-primary);
}
/* CONFIG PANEL */
.config-panel {
background: var(--card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 20px 24px;
margin-bottom: 24px;
}
.config-panel h3 {
font-family: 'DM Mono', monospace;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--text-secondary);
margin-bottom: 14px;
}
.config-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.config-grid.full { grid-template-columns: 1fr; }
.config-field label {
display: block;
font-size: 11px;
font-weight: 500;
color: var(--text-secondary);
margin-bottom: 5px;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.config-field input, .config-field select {
width: 100%;
border: 1px solid var(--border);
border-radius: 7px;
padding: 8px 11px;
font-family: 'DM Mono', monospace;
font-size: 12px;
background: var(--bg);
color: var(--text-primary);
outline: none;
transition: border-color 0.2s;
}
.config-field input:focus, .config-field select:focus {
border-color: var(--accent-tasks);
}
.fetch-btn {
margin-top: 14px;
background: var(--text-primary);
color: white;
border: none;
border-radius: 8px;
padding: 10px 20px;
font-family: 'DM Sans', sans-serif;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: opacity 0.2s;
}
.fetch-btn:hover { opacity: 0.8; }
.fetch-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* HEADER */
.dashboard-header {
display: flex;
justify-content: space-between;
align-items: flex-end;
margin-bottom: 20px;
}
.project-title {
font-size: 22px;
font-weight: 600;
letter-spacing: -0.02em;
}
.project-subtitle {
font-family: 'DM Mono', monospace;
font-size: 11px;
color: var(--text-secondary);
margin-top: 3px;
}
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 13px;
border-radius: 20px;
font-size: 12px;
font-weight: 500;
border: 1.5px solid;
}
.status-badge .dot {
width: 7px; height: 7px;
border-radius: 50%;
}
.behind { color: var(--status-behind); border-color: var(--status-behind); }
.behind .dot { background: var(--status-behind); }
.on-track { color: var(--status-on-track); border-color: var(--status-on-track); }
.on-track .dot { background: var(--status-on-track); }
.ahead { color: var(--status-ahead); border-color: var(--status-ahead); }
.ahead .dot { background: var(--status-ahead); }
/* CHARTS ROW */
.charts-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-bottom: 16px;
}
.chart-card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 14px;
padding: 24px;
display: flex;
flex-direction: column;
align-items: center;
}
.chart-label {
font-family: 'DM Mono', monospace;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--text-secondary);
margin-bottom: 18px;
align-self: flex-start;
}
.donut-wrap {
position: relative;
width: 180px;
height: 180px;
margin-bottom: 20px;
}
.donut-center {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
pointer-events: none;
}
.donut-pct {
font-size: 30px;
font-weight: 600;
letter-spacing: -0.03em;
line-height: 1;
}
.donut-sub {
font-size: 10px;
color: var(--text-secondary);
margin-top: 3px;
font-family: 'DM Mono', monospace;
}
.chart-stats {
width: 100%;
display: flex;
flex-direction: column;
gap: 9px;
border-top: 1px solid var(--border);
padding-top: 16px;
}
.stat-row {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 13px;
}
.stat-label {
display: flex;
align-items: center;
gap: 7px;
color: var(--text-secondary);
}
.stat-dot {
width: 8px; height: 8px;
border-radius: 2px;
}
.stat-value {
font-family: 'DM Mono', monospace;
font-size: 12px;
font-weight: 500;
}
/* BOTTOM STATS */
.bottom-stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
}
.stat-card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 16px 18px;
}
.stat-card-label {
font-family: 'DM Mono', monospace;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--text-secondary);
margin-bottom: 8px;
}
.stat-card-value {
font-size: 24px;
font-weight: 600;
letter-spacing: -0.03em;
}
.stat-card-unit {
font-size: 12px;
color: var(--text-secondary);
font-weight: 400;
margin-left: 2px;
}
/* ERROR / LOADING */
.message {
text-align: center;
padding: 20px;
font-family: 'DM Mono', monospace;
font-size: 12px;
color: var(--text-secondary);
}
.error { color: var(--status-behind); }
</style>
</head>
<body>
<!-- CONFIG PANEL -->
<div class="config-panel">
<h3>⚙ Configuration</h3>
<div class="config-grid">
<div class="config-field">
<label>Airtable API Key</label>
<input type="password" id="apiKey" placeholder="patXXXXXXXXXXXXXX" />
</div>
<div class="config-field">
<label>Base ID</label>
<input type="text" id="baseId" placeholder="appXXXXXXXXXXXXXX" />
</div>
<div class="config-field">
<label>Table Name</label>
<input type="text" id="tableName" placeholder="Tasks Progress" value="Tasks Progress" />
</div>
<div class="config-field">
<label>Project to Display</label>
<input type="text" id="projectFilter" placeholder="Pilot Project" />
</div>
</div>
<button class="fetch-btn" onclick="fetchData()">Load Data</button>
</div>
<!-- DASHBOARD -->
<div id="dashboard" style="display:none">
<div class="dashboard-header">
<div>
<div class="project-title" id="projName">—</div>
<div class="project-subtitle" id="projDates">—</div>
</div>
<div class="status-badge" id="statusBadge">
<span class="dot"></span><span id="statusText">Loading</span>
</div>
</div>
<div class="charts-row">
<!-- TIME DONUT -->
<div class="chart-card">
<div class="chart-label">Time Elapsed</div>
<div class="donut-wrap">
<canvas id="timeChart"></canvas>
<div class="donut-center">
<div class="donut-pct" id="timePct" style="color:var(--accent-time)">0%</div>
<div class="donut-sub">elapsed</div>
</div>
</div>
<div class="chart-stats">
<div class="stat-row">
<span class="stat-label"><span class="stat-dot" style="background:var(--accent-time)"></span>Days elapsed</span>
<span class="stat-value" id="daysElapsed">—</span>
</div>
<div class="stat-row">
<span class="stat-label"><span class="stat-dot" style="background:var(--remaining)"></span>Days remaining</span>
<span class="stat-value" id="daysRemaining">—</span>
</div>
<div class="stat-row">
<span class="stat-label">Total days</span>
<span class="stat-value" id="totalDays">—</span>
</div>
</div>
</div>
<!-- TASKS DONUT -->
<div class="chart-card">
<div class="chart-label">Tasks Completed</div>
<div class="donut-wrap">
<canvas id="tasksChart"></canvas>
<div class="donut-center">
<div class="donut-pct" id="tasksPct" style="color:var(--accent-tasks)">0%</div>
<div class="donut-sub">complete</div>
</div>
</div>
<div class="chart-stats">
<div class="stat-row">
<span class="stat-label"><span class="stat-dot" style="background:var(--accent-tasks)"></span>Tasks closed</span>
<span class="stat-value" id="tasksClosed">—</span>
</div>
<div class="stat-row">
<span class="stat-label"><span class="stat-dot" style="background:var(--remaining)"></span>Tasks remaining</span>
<span class="stat-value" id="tasksRemaining">—</span>
</div>
<div class="stat-row">
<span class="stat-label">Total tasks</span>
<span class="stat-value" id="totalTasks">—</span>
</div>
</div>
</div>
</div>
<!-- BOTTOM KPI STRIP -->
<div class="bottom-stats">
<div class="stat-card">
<div class="stat-card-label">Ideal Progress</div>
<div class="stat-card-value" id="idealProg">—<span class="stat-card-unit">tasks</span></div>
</div>
<div class="stat-card">
<div class="stat-card-label">Actual Progress</div>
<div class="stat-card-value" id="actualProg">—<span class="stat-card-unit">tasks</span></div>
</div>
<div class="stat-card">
<div class="stat-card-label">Delta</div>
<div class="stat-card-value" id="deltaProg">—<span class="stat-card-unit">tasks</span></div>
</div>
<div class="stat-card">
<div class="stat-card-label">Last Updated</div>
<div class="stat-card-value" style="font-size:14px;padding-top:6px" id="lastDate">—</div>
</div>
</div>
</div>
<div id="msgBox" class="message">Enter your configuration above and click Load Data.</div>
<script>
let timeChartInst = null;
let tasksChartInst = null;
async function fetchData() {
const apiKey = document.getElementById('apiKey').value.trim();
const baseId = document.getElementById('baseId').value.trim();
const tableName = document.getElementById('tableName').value.trim();
const project = document.getElementById('projectFilter').value.trim();
if (!apiKey || !baseId || !tableName) {
showMsg('Please fill in API Key, Base ID, and Table Name.', true);
return;
}
showMsg('Fetching data…');
document.getElementById('dashboard').style.display = 'none';
const btn = document.querySelector('.fetch-btn');
btn.disabled = true;
try {
const filterFormula = project
? `encodeURIComponent("AND({Project Name}='${project}')")`
: '';
let url = `https://api.airtable.com/v0/${baseId}/${encodeURIComponent(tableName)}?sort[0][field]=Date&sort[0][direction]=desc&pageSize=1`;
if (project) {
url += `&filterByFormula=${encodeURIComponent(`{Project Name}='${project}'`)}`;
}
const res = await fetch(url, {
headers: { Authorization: `Bearer ${apiKey}` }
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error?.message || `HTTP ${res.status}`);
}
const data = await res.json();
if (!data.records || data.records.length === 0) {
throw new Error('No records found. Check project name and table.');
}
const r = data.records[0].fields;
renderDashboard(r, project);
} catch (e) {
showMsg(`Error: ${e.message}`, true);
} finally {
btn.disabled = false;
}
}
function renderDashboard(r, project) {
// Extract values — match your exact field names
const totalDays = r['Total Number of Days (from Project infos)'] || 0;
const spentDays = r['Total Spent Days'] || 0;
const remainDays = r['Remaining Days'] || 0;
const totalTasks = r['Total Number of Tasks'] || 0;
const closedTasks = r['Total Closed Tasks'] || 0;
const remainTasks = r['Remaining Tasks'] || 0;
const idealProg = r['Ideal Progression'] || 0;
const openedTotal = r['Total Opened Tasks'] || 0;
const startDate = r['Start Date'] || '—';
const endDate = r['End Date'] || '—';
const date = r['Date'] || '—';
const timePct = totalDays > 0 ? Math.round((spentDays / totalDays) * 100) : 0;
const tasksPct = totalTasks > 0 ? Math.round((closedTasks / totalTasks) * 100) : 0;
const delta = closedTasks - Math.round(idealProg);
// Status
const diff = tasksPct - timePct;
let statusClass, statusText;
if (diff < -5) { statusClass = 'behind'; statusText = 'Behind Schedule'; }
else if (diff > 5) { statusClass = 'ahead'; statusText = 'Ahead of Schedule'; }
else { statusClass = 'on-track'; statusText = 'On Track'; }
// Header
document.getElementById('projName').textContent = project || r['Project Name'] || 'Project';
document.getElementById('projDates').textContent = `${startDate} → ${endDate}`;
const badge = document.getElementById('statusBadge');
badge.className = `status-badge ${statusClass}`;
document.getElementById('statusText').textContent = statusText;
// Time donut
document.getElementById('timePct').textContent = `${timePct}%`;
document.getElementById('daysElapsed').textContent = spentDays;
document.getElementById('daysRemaining').textContent = remainDays;
document.getElementById('totalDays').textContent = totalDays;
// Tasks donut
document.getElementById('tasksPct').textContent = `${tasksPct}%`;
document.getElementById('tasksClosed').textContent = closedTasks;
document.getElementById('tasksRemaining').textContent = remainTasks;
document.getElementById('totalTasks').textContent = totalTasks;
// KPI strip
document.getElementById('idealProg').innerHTML = `${Math.round(idealProg)}<span class="stat-card-unit">tasks</span>`;
document.getElementById('actualProg').innerHTML = `${closedTasks}<span class="stat-card-unit">tasks</span>`;
const deltaEl = document.getElementById('deltaProg');
deltaEl.innerHTML = `${delta >= 0 ? '+' : ''}${delta}<span class="stat-card-unit">tasks</span>`;
deltaEl.style.color = delta >= 0 ? 'var(--status-on-track)' : 'var(--status-behind)';
document.getElementById('lastDate').textContent = date;
// Draw charts
drawDonut('timeChart', timePct, 'var(--accent-time)', 'var(--remaining)', timeChartInst, inst => timeChartInst = inst);
drawDonut('tasksChart', tasksPct, 'var(--accent-tasks)', 'var(--remaining)', tasksChartInst, inst => tasksChartInst = inst);
document.getElementById('msgBox').style.display = 'none';
document.getElementById('dashboard').style.display = 'block';
}
function drawDonut(canvasId, pct, colorFill, colorRemain, existing, setInst) {
const ctx = document.getElementById(canvasId).getContext('2d');
if (existing) existing.destroy();
const filled = pct;
const remaining = 100 - pct;
// Resolve CSS vars to actual colors
const style = getComputedStyle(document.documentElement);
const fillColor = style.getPropertyValue(colorFill.replace('var(', '').replace(')', '')).trim() || colorFill;
const remColor = style.getPropertyValue(colorRemain.replace('var(', '').replace(')', '')).trim() || colorRemain;
const inst = new Chart(ctx, {
type: 'doughnut',
data: {
datasets: [{
data: [filled, remaining],
backgroundColor: [fillColor || colorFill, remColor || colorRemain],
borderWidth: 0,
hoverOffset: 0,
}]
},
options: {
cutout: '72%',
responsive: true,
maintainAspectRatio: true,
plugins: { legend: { display: false }, tooltip: { enabled: false } },
animation: { animateRotate: true, duration: 700, easing: 'easeInOutQuart' }
}
});
setInst(inst);
}
function showMsg(text, isError = false) {
const el = document.getElementById('msgBox');
el.textContent = text;
el.className = isError ? 'message error' : 'message';
el.style.display = 'block';
}
</script>
</body>
</html>