-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathboard.html
More file actions
553 lines (466 loc) · 16 KB
/
board.html
File metadata and controls
553 lines (466 loc) · 16 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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Krake Factory – Board Record</title>
<link rel="stylesheet" href="style.css">
<style>
.board-container {
max-width: 960px;
margin: 0 auto 2rem;
padding: 1.5rem 2rem;
background: #ffffff;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}
.search-row {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
align-items: flex-end;
margin-bottom: 1rem;
}
.search-row label {
margin-bottom: 0;
}
.search-row input[type="text"] {
max-width: 220px;
}
.search-row button {
margin-left: auto;
}
.board-card {
border: 1px solid #d5d7e2;
border-radius: 8px;
background: #fafbff;
padding: 0.9rem 1rem;
margin-bottom: 1rem;
font-size: 0.85rem;
}
.board-card h2 {
margin: 0 0 0.4rem;
font-size: 1rem;
}
.board-meta-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 0.3rem 1rem;
}
.board-meta-grid div {
font-size: 0.82rem;
color: #394263;
}
.board-gdt {
margin-top: 0.5rem;
font-size: 0.8rem;
color: #394263;
}
.board-gdt a {
color: #2f6feb;
text-decoration: none;
}
.board-gdt a:hover {
text-decoration: underline;
}
.board-gdt-image {
margin-top: 0.4rem;
}
.board-gdt-image img {
max-width: 100%;
max-height: 260px;
border-radius: 6px;
border: 1px solid #d5d7e2;
display: block;
}
.tests-list {
margin-top: 1rem;
}
.test-item {
border: 1px solid #d5d7e2;
border-radius: 8px;
margin-bottom: 0.8rem;
}
.test-header {
padding: 0.5rem 0.7rem;
background: #f4f5fb;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
}
.test-header-left {
display: flex;
flex-direction: column;
gap: 0.15rem;
}
.test-header-main {
font-size: 0.85rem;
font-weight: 600;
}
.test-header-sub {
font-size: 0.78rem;
color: #555b7a;
}
.test-toggle {
font-size: 0.78rem;
color: #2f3c6e;
}
.test-body {
padding: 0.6rem 0.7rem 0.8rem;
display: none;
font-size: 0.8rem;
}
.test-body.open {
display: block;
}
.test-grids {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 0.7rem;
}
.test-card {
border-radius: 6px;
background: #ffffff;
border: 1px dashed #d5d7e2;
padding: 0.6rem 0.7rem;
}
.test-card h3 {
margin: 0 0 0.4rem;
font-size: 0.82rem;
color: #394263;
}
.mini-table {
width: 100%;
border-collapse: collapse;
}
.mini-table th,
.mini-table td {
padding: 0.14rem 0.2rem;
border: none;
font-size: 0.78rem;
}
.mini-table th {
text-align: left;
color: #555b7a;
width: 60%;
}
.mini-table td {
text-align: right;
font-family: monospace;
}
.test-empty {
font-size: 0.78rem;
color: #7f1d1d;
}
.badge {
display: inline-block;
padding: 0.1rem 0.45rem;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 600;
}
.badge-pass {
background: #e6f6ec;
color: #14532d;
border: 1px solid #83c39c;
}
.badge-fail {
background: #fde8e8;
color: #7f1d1d;
border: 1px solid #f19999;
}
.badge-rework {
background: #fff7e6;
color: #92400e;
border: 1px solid #f3c580;
}
details {
margin-top: 0.5rem;
font-size: 0.78rem;
}
details summary {
cursor: pointer;
color: #2f3c6e;
}
details summary:hover {
text-decoration: underline;
}
@media (max-width: 700px) {
.board-container {
padding: 1.25rem 1.1rem;
margin: 0 0.5rem 1.5rem;
}
}
</style>
</head>
<body>
<h1>Krake Factory – Board Record</h1>
<nav class="top-nav">
<a href="factory-form.html" class="nav-btn">Krake Testing Register</a>
<a href="records.html" class="nav-btn">Inventory</a>
<a href="board.html" class="nav-btn active" aria-current="page">Board Record</a>
<!-- <a href="all-tables.html" class="nav-btn">Data Base</a> -->
</nav>
<div class="board-container">
<div class="search-row">
<label>
Serial number:
<input type="text" id="serial-input" placeholder="e.g. US0001">
</label>
<button type="button" id="search-btn">Load Board</button>
</div>
<p id="status"></p>
<div id="board-info"></div>
<div id="tests-container" class="tests-list"></div>
</div>
<!-- Supabase JS client -->
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
<script>
const SUPABASE_URL = 'https://bkonmvhzzlbrbtnvlfcr.supabase.co'
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJrb25tdmh6emxicmJ0bnZsZmNyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjMyMjUxNjIsImV4cCI6MjA3ODgwMTE2Mn0.yrg1t-aHWuwVEVcUVJ4-sbz1BNSspc7c5tBSQ3APTAg'
const { createClient } = supabase
const db = createClient(SUPABASE_URL, SUPABASE_ANON_KEY)
const serialInput = document.getElementById('serial-input')
const searchBtn = document.getElementById('search-btn')
const statusEl = document.getElementById('status')
const boardInfoEl = document.getElementById('board-info')
const testsContainerEl = document.getElementById('tests-container')
function setStatus(message, isError = false) {
statusEl.textContent = message || ''
statusEl.className = ''
if (!message) return
statusEl.classList.add(isError ? 'error' : 'success')
}
function formatDateTime(isoString) {
if (!isoString) return ''
const d = new Date(isoString)
if (isNaN(d)) return isoString
return d.toLocaleString()
}
function keyValueTable(obj) {
if (!obj) return '<p class="test-empty">No data.</p>'
const rows = Object.entries(obj).map(([k, v]) => {
let val = v
if (val === null || val === undefined) val = ''
else if (typeof val === 'object') val = JSON.stringify(val)
return `<tr><th>${k}</th><td>${val}</td></tr>`
}).join('')
return `<table class="mini-table"><tbody>${rows}</tbody></table>`
}
function renderBoardCard(board) {
const loc = [board.country || '', board.lab || ''].filter(Boolean).join(' / ')
const dateAsm = board.date_assembled ? new Date(board.date_assembled).toLocaleDateString() : '—'
const hasGdt = board.gdt_key || board.gdt_url
boardInfoEl.innerHTML = `
<div class="board-card">
<h2>Board ${board.serial_number || ''}</h2>
<div class="board-meta-grid">
<div><strong>Hardware Rev:</strong> ${board.hardware_rev || '—'}</div>
<div><strong>PCB Rev:</strong> ${board.pcb_rev || '—'}</div>
<div><strong>Batch:</strong> ${board.batch || '—'}</div>
<div><strong>Location:</strong> ${loc || '—'}</div>
<div><strong>Date Assembled:</strong> ${dateAsm}</div>
<div><strong>Assembled By:</strong> ${board.assembled_by || '—'}</div>
<div><strong>Status:</strong> ${board.status || '—'}</div>
</div>
${board.notes ? `<div style="margin-top:0.4rem;font-size:0.8rem;"><strong>Notes:</strong> ${board.notes}</div>` : ''}
${hasGdt ? `
<div class="board-gdt">
<strong>GDT:</strong>
${board.gdt_key ? `Key: ${board.gdt_key} · ` : ''}
${board.gdt_url ? `<a href="${board.gdt_url}" target="_blank" rel="noopener noreferrer">Open GDT link</a>` : ''}
</div>
${board.gdt_url ? `
<div class="board-gdt-image">
<img src="${board.gdt_url}" alt="GDT image for ${board.serial_number || ''}">
</div>
` : ''}
` : ''}
<details>
<summary>All board fields (raw)</summary>
${keyValueTable(board)}
</details>
</div>
`
}
function renderTests(runs) {
testsContainerEl.innerHTML = ''
if (!runs || runs.length === 0) {
testsContainerEl.innerHTML = '<p style="font-size:0.85rem;">No test runs recorded for this board yet.</p>'
return
}
runs.forEach((run, index) => {
const res = (run.overall_result || '').toUpperCase()
let badgeClass = ''
if (res === 'PASS') badgeClass = 'badge badge-pass'
else if (res === 'FAIL') badgeClass = 'badge badge-fail'
else if (res === 'REWORK') badgeClass = 'badge badge-rework'
else badgeClass = 'badge'
const dt = formatDateTime(run.test_datetime)
const unpList = run.unpowered_results || []
const powList = run.powered_results || []
const unp = unpList[0] || null
const pow = powList[0] || null
const testElem = document.createElement('div')
testElem.className = 'test-item'
const header = document.createElement('div')
header.className = 'test-header'
const left = document.createElement('div')
left.className = 'test-header-left'
const runNumber = runs.length - index // oldest = 1, newest = N
left.innerHTML = `
<div class="test-header-main">
Run #${runNumber} · <span class="${badgeClass}">${res || '—'}</span>
</div>
<div class="test-header-sub">
${dt || 'Unknown time'} · Location: ${run.test_location || '—'} · Tester: ${run.tester || '—'} · FW: ${run.firmware_version || '—'}
</div>
`
const right = document.createElement('div')
right.className = 'test-toggle'
right.textContent = 'Show details'
header.appendChild(left)
header.appendChild(right)
const body = document.createElement('div')
body.className = 'test-body'
const unpHtml = unp ? `
<table class="mini-table">
<tbody>
<tr><th>Meter</th><td>${(unp.meter_make || '')} ${(unp.meter_model || '')}</td></tr>
<tr><th>Meter S/N</th><td>${unp.meter_sn || ''}</td></tr>
<tr><th>TP102–TP101 (Vin)</th><td>${unp.res_tp102_tp101_vin || ''}</td></tr>
<tr><th>TP103–TP101 (+5V)</th><td>${unp.res_tp103_tp101_5v || ''}</td></tr>
<tr><th>TP201–TP101 (VBus)</th><td>${unp.res_tp201_tp101_vbus || ''}</td></tr>
<tr><th>TP202–TP101 (V3)</th><td>${unp.res_tp202_tp101_v3 || ''}</td></tr>
<tr><th>J103 Pin2–TP101 (Ctrl Vcc)</th><td>${unp.res_j103pin2_tp101_ctrl_vcc || ''}</td></tr>
<tr><th>Unpowered Result</th><td>${unp.pass_fail || ''}</td></tr>
<tr><th>Unpowered Notes</th><td>${unp.notes || ''}</td></tr>
</tbody>
</table>
` : `<p class="test-empty">No unpowered results recorded.</p>`
const powHtml = pow ? `
<table class="mini-table">
<tbody>
<tr><th>I<sub>in</sub> J101 (mA)</th><td>${pow.supply_current_ma ?? ''}</td></tr>
<tr><th>TP102 Vin (V)</th><td>${pow.vin_tp102_v ?? ''}</td></tr>
<tr><th>TP103 +5V (V)</th><td>${pow.v5_tp103_v ?? ''}</td></tr>
<tr><th>+5 esp32 → U103 (V)</th><td>${pow.v5_esp32_u103_v ?? ''}</td></tr>
<tr><th>+3.3V Tab U103 (V)</th><td>${pow.v3p3_tab_u103_v ?? ''}</td></tr>
<tr><th>TP202 V3 U501 (V)</th><td>${pow.v3_tp202_u501_v ?? ''}</td></tr>
<tr><th>D103 Cathode 3v3Ctrl (V)</th><td>${pow.v3v3_ctrl_d103k_v ?? ''}</td></tr>
<tr><th>TP401 VccLCD (V)</th><td>${pow.vcclcd_tp401_v ?? ''}</td></tr>
<tr><th>C505+ 5VDFP (V)</th><td>${pow.v5_dfp_c505_v ?? ''}</td></tr>
<tr><th>ChargePump + (V)</th><td>${pow.v_charge_pump_plus_v ?? ''}</td></tr>
<tr><th>ChargePump - (V)</th><td>${pow.v_charge_pump_minus_v ?? ''}</td></tr>
<tr><th>Powered Result</th><td>${pow.pass_fail || ''}</td></tr>
<tr><th>Powered Notes</th><td>${pow.notes || ''}</td></tr>
</tbody>
</table>
` : `<p class="test-empty">No powered results recorded.</p>`
const commentsHtml = run.comments ? `
<div style="margin-top:0.5rem;font-size:0.78rem;">
<strong>Run Comments:</strong> ${run.comments}
</div>
` : ''
const rawUnpHtml = (unpList.length === 0)
? '<p class="test-empty">No unpowered rows.</p>'
: unpList.map((row, i) => `
<h4 style="margin:0.3rem 0 0.15rem;font-size:0.78rem;">Unpowered row #${i+1}</h4>
${keyValueTable(row)}
`).join('')
const rawPowHtml = (powList.length === 0)
? '<p class="test-empty">No powered rows.</p>'
: powList.map((row, i) => `
<h4 style="margin:0.3rem 0 0.15rem;font-size:0.78rem;">Powered row #${i+1}</h4>
${keyValueTable(row)}
`).join('')
const rawRunHtml = keyValueTable(run)
body.innerHTML = `
<div class="test-grids">
<div class="test-card">
<h3>Unpowered Test (Resistance)</h3>
${unpHtml}
</div>
<div class="test-card">
<h3>Powered Tests (Current & Voltages)</h3>
${powHtml}
</div>
</div>
${commentsHtml}
<details>
<summary>All fields for this test run (test_runs)</summary>
${rawRunHtml}
</details>
<details>
<summary>All fields from unpowered_results for this run (${unpList.length} row(s))</summary>
${rawUnpHtml}
</details>
<details>
<summary>All fields from powered_results for this run (${powList.length} row(s))</summary>
${rawPowHtml}
</details>
`
header.addEventListener('click', () => {
const isOpen = body.classList.contains('open')
body.classList.toggle('open', !isOpen)
right.textContent = isOpen ? 'Show details' : 'Hide details'
})
testElem.appendChild(header)
testElem.appendChild(body)
testsContainerEl.appendChild(testElem)
})
}
async function loadBoardAndTests() {
const serial = serialInput.value.trim()
if (!serial) {
setStatus('Please enter a serial number.', true)
return
}
setStatus('Loading board…')
boardInfoEl.innerHTML = ''
testsContainerEl.innerHTML = ''
try {
const { data: board, error: boardError } = await db
.from('boards')
.select('*')
.eq('serial_number', serial)
.single()
if (boardError) {
console.error(boardError)
setStatus('Board not found for serial ' + serial, true)
return
}
renderBoardCard(board)
setStatus('Board loaded. Loading test runs…')
const { data: runs, error: runsError } = await db
.from('test_runs')
.select(`
*,
unpowered_results (*),
powered_results (*)
`)
.eq('board_id', board.board_id)
.order('test_datetime', { ascending: false })
if (runsError) {
console.error(runsError)
setStatus('Error loading test runs: ' + runsError.message, true)
testsContainerEl.innerHTML = ''
return
}
setStatus(`Board has ${runs.length} test run(s).`)
renderTests(runs || [])
} catch (err) {
console.error(err)
setStatus('Unexpected error: ' + err.message, true)
}
}
searchBtn.addEventListener('click', loadBoardAndTests)
serialInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault()
loadBoardAndTests()
}
})
</script>
</body>
</html>