-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindex.html
More file actions
480 lines (403 loc) · 12.3 KB
/
index.html
File metadata and controls
480 lines (403 loc) · 12.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>ChilaBoard - Component Library</title>
<script src="https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js"></script>
<style>
:root {
--bg-color: #ffffff;
--text-color: #000000;
--border-color: #e0e0e0;
--header-bg: #f9f9f9;
--hover-bg: #f0f0f0;
--active-bg: #e0e0e0;
--error-color: #d00000;
--sidebar-bg: #fdfdfd;
--sidebar-border: #e0e0e0;
--footer-text: #888888;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
background-color: var(--bg-color);
color: var(--text-color);
display: flex;
min-height: 100vh;
}
/* --- Layout --- */
#sidebar {
width: 280px;
flex-shrink: 0;
background-color: var(--sidebar-bg);
border-right: 1px solid var(--sidebar-border);
padding: 1.5em;
overflow-y: auto;
height: 100vh;
position: sticky;
top: 0;
}
#main-content {
flex-grow: 1;
padding: 2em;
max-width: 1200px;
margin: 0 auto;
display: flex;
flex-direction: column;
}
#content-wrap {
flex: 1;
}
header {
border-bottom: 1px solid var(--border-color);
padding-bottom: 1.5em;
margin-bottom: 1.5em;
}
h2 {
margin: 0 0 0.5em 0;
}
/* --- Sidebar Filters --- */
#sidebar h3 {
font-size: 1.1em;
font-weight: 600;
margin-top: 0;
border-bottom: 1px solid var(--border-color);
padding-bottom: 0.5em;
}
#libraryFilters {
display: flex;
flex-direction: column;
gap: 5px;
}
.filter-btn {
width: 100%;
text-align: left;
padding: 0.6em 0.8em;
border: 1px solid transparent;
background-color: transparent;
color: var(--text-color);
cursor: pointer;
font-size: 0.9em;
border-radius: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.filter-btn:hover {
background-color: var(--hover-bg);
}
.filter-btn.active {
background-color: var(--active-bg);
font-weight: 600;
}
/* --- Search & Errors --- */
#searchInput {
padding: 0.8em 1em;
width: 100%;
font-size: 1em;
border: 1px solid var(--border-color);
border-radius: 6px;
box-sizing: border-box; /* Important for 100% width */
}
.error {
color: var(--error-color);
margin-top: 0.5em;
height: 1.2em;
}
/* --- Results Area --- */
.library-group {
border: 1px solid var(--border-color);
border-radius: 8px;
margin-bottom: 1.5em;
overflow: hidden; /* To contain table borders */
}
.library-header {
background-color: var(--header-bg);
padding: 0.8em 1.2em;
font-weight: 600;
border-bottom: 1px solid var(--border-color);
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 0.8em 1.2em;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
tr:last-child td {
border-bottom: none;
}
tr:nth-child(even) {
background-color: transparent; /* Remove old striping */
}
th {
font-weight: 600;
font-size: 0.9em;
color: #555;
}
#resultsContainer {
margin-top: 1em;
}
#resultsContainer.loading {
text-align: center;
padding: 3em;
font-size: 1.2em;
color: #888;
}
/* --- Pagination --- */
.pagination {
margin-top: 2em;
text-align: center;
}
.pagination button {
margin: 0 3px;
padding: 0.6em 1em;
font-size: 0.9em;
border: 1px solid var(--border-color);
background-color: var(--bg-color);
color: var(--text-color);
cursor: pointer;
border-radius: 5px;
}
.pagination button:hover {
background-color: var(--hover-bg);
}
.pagination button:disabled {
background-color: var(--active-bg);
font-weight: 600;
cursor: default;
}
/* --- Footer --- */
footer {
text-align: center;
padding-top: 3em;
margin-top: 2em;
font-size: 0.9em;
color: var(--footer-text);
border-top: 1px solid var(--border-color);
}
footer span {
color: #e25555; /* Heart color */
}
</style>
</head>
<body>
<aside id="sidebar">
<h3>Libraries</h3>
<div id="libraryFilters">
</div>
</aside>
<main id="main-content">
<div id="content-wrap">
<header>
<h2>ChilaBoard Component Search</h2>
<input type="text" id="searchInput" placeholder="Type regex to search parts or descriptions..." />
<div class="error" id="errorBox"></div>
</header>
<div id="resultsContainer" class="loading">Loading component data...</div>
<div class="pagination" id="paginationControls"></div>
</div>
<footer>
Made with <span><3</span> by ChilaBoard
</footer>
</main>
<script>
let fullData = [];
let filteredData = [];
let uniqueLibraries = [];
let selectedLibrary = null; // null means 'All'
let currentPage = 1;
const pageSize = 100;
// --- Data Loading & Pre-processing ---
async function loadCSV() {
const response = await fetch('component_list.csv');
const csvText = await response.text();
const parseResult = Papa.parse(csvText, {
header: true,
skipEmptyLines: true
});
if (parseResult.errors.length > 0) {
console.error("Errors parsing CSV:", parseResult.errors);
document.getElementById('resultsContainer').innerHTML = 'Error loading CSV file. Check console for details.';
return [];
}
return parseResult.data;
}
function processData(data) {
fullData = data;
filteredData = fullData;
// Get unique library names and sort them
const libSet = new Set(data.map(row => row['lib name']));
uniqueLibraries = Array.from(libSet).sort();
}
// --- Rendering Functions ---
function renderLibraryFilters() {
const container = document.getElementById('libraryFilters');
container.innerHTML = ''; // Clear existing
// Add "All Libraries" button
const allBtn = document.createElement('button');
allBtn.textContent = 'All Libraries';
allBtn.className = 'filter-btn active'; // Active by default
allBtn.onclick = () => {
selectedLibrary = null;
document.querySelectorAll('.filter-btn.active').forEach(btn => btn.classList.remove('active'));
allBtn.classList.add('active');
updateResults();
};
container.appendChild(allBtn);
// Add button for each library
uniqueLibraries.forEach(libName => {
const btn = document.createElement('button');
btn.textContent = libName;
btn.className = 'filter-btn';
btn.title = libName; // For full name on hover
btn.onclick = () => {
selectedLibrary = libName;
document.querySelectorAll('.filter-btn.active').forEach(btn => btn.classList.remove('active'));
btn.classList.add('active');
updateResults();
};
container.appendChild(btn);
});
}
function displayPage(data, page) {
const start = (page - 1) * pageSize;
const end = start + pageSize;
const pageData = data.slice(start, end);
const container = document.getElementById('resultsContainer');
container.innerHTML = '';
container.classList.remove('loading');
if (pageData.length === 0) {
container.innerHTML = '<p>No results found.</p>';
renderPaginationControls(0, 1);
return;
}
// Group the data by library name
const groupedData = pageData.reduce((acc, row) => {
const lib = row['lib name'];
if (!acc[lib]) {
acc[lib] = [];
}
acc[lib].push(row);
return acc;
}, {});
// Render a card for each group
for (const libName in groupedData) {
const components = groupedData[libName];
const groupEl = document.createElement('div');
groupEl.className = 'library-group';
let tableHTML = `
<div class="library-header">${libName} (${components.length} ${components.length > 1 ? 'parts' : 'part'})</div>
<table>
<thead>
<tr>
<th>Part</th>
<th>Description</th>
<th>Num</th>
</tr>
</thead>
<tbody>
`;
components.forEach(row => {
// Display only relevant columns
tableHTML += `
<tr>
<td>${row['part'] || ''}</td>
<td>${row['desc'] || ''}</td>
<td>${row['num'] || ''}</td>
</tr>
`;
});
tableHTML += '</tbody></table>';
groupEl.innerHTML = tableHTML;
container.appendChild(groupEl);
}
renderPaginationControls(data.length, page);
}
function renderPaginationControls(totalItems, page) {
const totalPages = Math.ceil(totalItems / pageSize);
const container = document.getElementById('paginationControls');
container.innerHTML = '';
if (totalPages <= 1) return;
// Simple pagination: Prev, Current / Total, Next
// For 100+ pages, a numbered list is not user-friendly
const prevBtn = document.createElement('button');
prevBtn.textContent = 'Previous';
prevBtn.disabled = page === 1;
prevBtn.onclick = () => {
currentPage--;
displayPage(filteredData, currentPage);
};
container.appendChild(prevBtn);
const pageInfo = document.createElement('span');
pageInfo.textContent = ` Page ${page} of ${totalPages} `;
pageInfo.style.padding = '0 1em';
pageInfo.style.fontSize = '0.9em';
container.appendChild(pageInfo);
const nextBtn = document.createElement('button');
nextBtn.textContent = 'Next';
nextBtn.disabled = page === totalPages;
nextBtn.onclick = () => {
currentPage++;
displayPage(filteredData, currentPage);
};
container.appendChild(nextBtn);
}
// --- Filtering Logic ---
function filterData(query, dataToFilter) {
let regex;
const errorBox = document.getElementById('errorBox');
try {
regex = new RegExp(query, 'i'); // case-insensitive
errorBox.textContent = '';
} catch (e) {
errorBox.textContent = `Invalid regex: ${e.message}`;
return []; // Return no results for invalid regex
}
return dataToFilter.filter(row =>
// Search only 'part' and 'desc' columns
regex.test(row['part']) || regex.test(row['desc'])
);
}
function updateResults() {
const query = document.getElementById('searchInput').value;
// 1. Filter by selected library (if any)
let currentFilter = fullData;
if (selectedLibrary) {
currentFilter = fullData.filter(row => row['lib name'] === selectedLibrary);
}
// 2. Filter by regex query (if any)
if (query) {
currentFilter = filterData(query, currentFilter);
}
filteredData = currentFilter;
currentPage = 1; // Reset to first page
displayPage(filteredData, currentPage);
}
function debounce(fn, delay = 300) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(this, args), delay);
};
}
// --- Initialization ---
document.addEventListener('DOMContentLoaded', async () => {
// 1. Load and process data
const data = await loadCSV();
if (data.length === 0) return; // Stop if CSV failed to load
processData(data);
// 2. Render UI components
renderLibraryFilters();
displayPage(filteredData, currentPage);
// 3. Set up event listeners
const searchInput = document.getElementById('searchInput');
searchInput.addEventListener('input', debounce(updateResults, 300));
});
</script>
</body>
</html>