-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathall-tables.html
More file actions
253 lines (217 loc) · 7.08 KB
/
all-tables.html
File metadata and controls
253 lines (217 loc) · 7.08 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<style>
.tables-container {
max-width: 1100px;
margin: 0 auto 2rem;
padding: 1.5rem 2rem;
background: #ffffff;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}
.table-block {
margin-bottom: 2rem;
}
.table-block h2 {
margin: 0 0 0.25rem;
font-size: 1.1rem;
}
.table-block p {
margin: 0 0 0.4rem;
font-size: 0.82rem;
color: #555b7a;
}
.table-status {
font-size: 0.8rem;
margin-bottom: 0.4rem;
color: #555b7a;
}
.table-wrapper {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.8rem;
}
thead {
background: #eef1fb;
}
th, td {
border: 1px solid #d5d7e2;
padding: 0.3rem 0.4rem;
text-align: left;
white-space: nowrap;
}
th {
font-weight: 600;
color: #394263;
}
tbody tr:nth-child(even) {
background: #f8f9ff;
}
.mono {
font-family: monospace;
}
@media (max-width: 700px) {
.tables-container {
padding: 1.25rem 1.1rem;
margin: 0 0.5rem 1.5rem;
}
}
</style>
</head>
<body>
<!-- <title>Krake Factory – All Tables</title> -->
<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">Board Record</a>
<!-- <a href="all-tables.html" class="nav-btn active" aria-current="page">Data Base</a> -->
</nav>
<div class="tables-container">
<!-- Boards -->
<section class="table-block" id="block-boards">
<h2>Boards</h2>
<p>One row per physical PCB (serial, batch, location, etc.).</p>
<div id="status-boards" class="table-status"></div>
<div class="table-wrapper">
<table>
<thead id="head-boards"></thead>
<tbody id="body-boards"></tbody>
</table>
</div>
</section>
<!-- Test Runs -->
<section class="table-block" id="block-test_runs">
<h2>Test Runs</h2>
<p>Each time you run a factory test on a board.</p>
<div id="status-test_runs" class="table-status"></div>
<div class="table-wrapper">
<table>
<thead id="head-test_runs"></thead>
<tbody id="body-test_runs"></tbody>
</table>
</div>
</section>
<!-- Unpowered Results -->
<section class="table-block" id="block-unpowered_results">
<h2>Unpowered Results</h2>
<p>Resistance checks before power is applied (multimeter readings).</p>
<div id="status-unpowered_results" class="table-status"></div>
<div class="table-wrapper">
<table>
<thead id="head-unpowered_results"></thead>
<tbody id="body-unpowered_results"></tbody>
</table>
</div>
</section>
<!-- Powered Results -->
<section class="table-block" id="block-powered_results">
<h2>Powered Results</h2>
<p>Current and voltage measurements with power applied.</p>
<div id="status-powered_results" class="table-status"></div>
<div class="table-wrapper">
<table>
<thead id="head-powered_results"></thead>
<tbody id="body-powered_results"></tbody>
</table>
</div>
</section>
</div>
<!-- Supabase JS client -->
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
<script>
// ⚠️ Same values as in index.html / records.html
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)
function setStatus(tableName, message, isError = false) {
const el = document.getElementById('status-' + tableName)
if (!el) return
el.textContent = message || ''
el.style.color = isError ? '#7f1d1d' : '#555b7a'
}
function renderTable(tableName, rows) {
const headEl = document.getElementById('head-' + tableName)
const bodyEl = document.getElementById('body-' + tableName)
if (!headEl || !bodyEl) return
headEl.innerHTML = ''
bodyEl.innerHTML = ''
if (!rows || rows.length === 0) {
const tr = document.createElement('tr')
const td = document.createElement('td')
td.textContent = 'No rows found.'
td.colSpan = 1
tr.appendChild(td)
bodyEl.appendChild(tr)
return
}
const cols = Object.keys(rows[0])
// Header
const headerRow = document.createElement('tr')
cols.forEach(col => {
const th = document.createElement('th')
th.textContent = col
headerRow.appendChild(th)
})
headEl.appendChild(headerRow)
// Body
rows.forEach(row => {
const tr = document.createElement('tr')
cols.forEach(col => {
const td = document.createElement('td')
let value = row[col]
if (value === null || value === undefined) {
value = ''
} else if (typeof value === 'object') {
// For safety if any nested object sneaks in
value = JSON.stringify(value)
}
td.textContent = value
// Slight monospace for IDs / numbers
if (typeof row[col] === 'number' || /id$/i.test(col)) {
td.classList.add('mono')
}
tr.appendChild(td)
})
bodyEl.appendChild(tr)
})
}
async function loadTable(tableName, options = {}) {
const { limit = 200, orderColumn = null, ascending = false } = options
setStatus(tableName, 'Loading...')
try {
let query = db.from(tableName).select('*')
if (orderColumn) {
query = query.order(orderColumn, { ascending })
}
if (limit) {
query = query.limit(limit)
}
const { data, error } = await query
if (error) {
console.error('Error loading', tableName, error)
setStatus(tableName, 'Error: ' + error.message, true)
renderTable(tableName, [])
return
}
setStatus(tableName, `Loaded ${data.length} row(s).`)
renderTable(tableName, data)
} catch (err) {
console.error('Unexpected error loading', tableName, err)
setStatus(tableName, 'Unexpected error: ' + err.message, true)
}
}
// Load all four tables
loadTable('boards', { limit: 500, orderColumn: 'board_id', ascending: true })
loadTable('test_runs', { limit: 500, orderColumn: 'test_datetime', ascending: false })
loadTable('unpowered_results', { limit: 500, orderColumn: 'unpowered_id', ascending: false })
loadTable('powered_results', { limit: 500, orderColumn: 'powered_id', ascending: false })
</script>
</body>
</html>