Initial scaffold: docs, data manifest, and static dashboard
This commit is contained in:
107
app/app.js
Normal file
107
app/app.js
Normal file
@@ -0,0 +1,107 @@
|
||||
async function loadManifest() {
|
||||
const res = await fetch('../data/manifest.json');
|
||||
if (!res.ok) throw new Error('Failed to load manifest.json');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function parseCSV(text) {
|
||||
const lines = text.trim().split(/\r?\n/);
|
||||
if (!lines.length) return { headers: [], rows: [] };
|
||||
const headers = lines[0].split(',').map(h => h.trim());
|
||||
const rows = lines.slice(1).map(line => {
|
||||
const cols = [];
|
||||
let current = '';
|
||||
let inQuotes = false;
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const ch = line[i];
|
||||
if (ch === '"') {
|
||||
if (inQuotes && line[i + 1] === '"') {
|
||||
current += '"';
|
||||
i++;
|
||||
} else {
|
||||
inQuotes = !inQuotes;
|
||||
}
|
||||
} else if (ch === ',' && !inQuotes) {
|
||||
cols.push(current);
|
||||
current = '';
|
||||
} else {
|
||||
current += ch;
|
||||
}
|
||||
}
|
||||
cols.push(current);
|
||||
return cols;
|
||||
});
|
||||
return { headers, rows };
|
||||
}
|
||||
|
||||
function renderCSVList(files) {
|
||||
const list = document.getElementById('csv-list');
|
||||
list.innerHTML = '';
|
||||
if (!files.length) {
|
||||
list.textContent = 'No CSV files listed in manifest.json yet.';
|
||||
return;
|
||||
}
|
||||
files.forEach(f => {
|
||||
const pill = document.createElement('div');
|
||||
pill.className = 'csv-pill';
|
||||
pill.textContent = f;
|
||||
list.appendChild(pill);
|
||||
});
|
||||
}
|
||||
|
||||
function renderPreview(headers, rows) {
|
||||
const preview = document.getElementById('preview');
|
||||
if (!headers.length) {
|
||||
preview.textContent = 'No data loaded yet.';
|
||||
return;
|
||||
}
|
||||
const table = document.createElement('table');
|
||||
table.className = 'table';
|
||||
const thead = document.createElement('thead');
|
||||
const trh = document.createElement('tr');
|
||||
headers.forEach(h => {
|
||||
const th = document.createElement('th');
|
||||
th.textContent = h;
|
||||
trh.appendChild(th);
|
||||
});
|
||||
thead.appendChild(trh);
|
||||
table.appendChild(thead);
|
||||
|
||||
const tbody = document.createElement('tbody');
|
||||
rows.slice(0, 10).forEach(r => {
|
||||
const tr = document.createElement('tr');
|
||||
r.forEach(cell => {
|
||||
const td = document.createElement('td');
|
||||
td.textContent = cell;
|
||||
tr.appendChild(td);
|
||||
});
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
table.appendChild(tbody);
|
||||
|
||||
preview.innerHTML = '';
|
||||
preview.appendChild(table);
|
||||
}
|
||||
|
||||
async function loadFirstCSV(files) {
|
||||
if (!files.length) return;
|
||||
const res = await fetch(`../data/${files[0]}`);
|
||||
if (!res.ok) throw new Error(`Failed to load ${files[0]}`);
|
||||
const text = await res.text();
|
||||
const { headers, rows } = parseCSV(text);
|
||||
renderPreview(headers, rows);
|
||||
}
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
const manifest = await loadManifest();
|
||||
const files = manifest.csvFiles || [];
|
||||
renderCSVList(files);
|
||||
await loadFirstCSV(files);
|
||||
} catch (err) {
|
||||
document.getElementById('csv-list').textContent = err.message;
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
42
app/index.html
Normal file
42
app/index.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Power BI Dashboard Migration</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Power BI Dashboard Migration</h1>
|
||||
<p class="sub">Loading local CSVs (no database yet)</p>
|
||||
</header>
|
||||
|
||||
<section id="kpis" class="kpi-grid">
|
||||
<div class="kpi-card">
|
||||
<div class="kpi-label">KPI 1</div>
|
||||
<div class="kpi-value" id="kpi-1">—</div>
|
||||
</div>
|
||||
<div class="kpi-card">
|
||||
<div class="kpi-label">KPI 2</div>
|
||||
<div class="kpi-value" id="kpi-2">—</div>
|
||||
</div>
|
||||
<div class="kpi-card">
|
||||
<div class="kpi-label">KPI 3</div>
|
||||
<div class="kpi-value" id="kpi-3">—</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2>Loaded CSVs</h2>
|
||||
<div id="csv-list" class="csv-list">Loading…</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2>Preview (first 10 rows)</h2>
|
||||
<div id="preview" class="table-wrap">No data loaded yet.</div>
|
||||
</section>
|
||||
|
||||
<script src="./app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
74
app/styles.css
Normal file
74
app/styles.css
Normal file
@@ -0,0 +1,74 @@
|
||||
:root {
|
||||
--bg: #0b0f17;
|
||||
--panel: #141a26;
|
||||
--text: #e6ecf2;
|
||||
--muted: #9aa7b2;
|
||||
--accent: #4f8cff;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
header {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
h1 { margin: 0 0 6px 0; }
|
||||
|
||||
.sub { color: var(--muted); margin: 0; }
|
||||
|
||||
.kpi-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.kpi-card {
|
||||
background: var(--panel);
|
||||
border: 1px solid #1f2a3a;
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.kpi-label { color: var(--muted); font-size: 13px; }
|
||||
.kpi-value { font-size: 22px; margin-top: 6px; }
|
||||
|
||||
.panel {
|
||||
background: var(--panel);
|
||||
border: 1px solid #1f2a3a;
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.csv-list { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.csv-pill {
|
||||
background: #1f2a3a;
|
||||
padding: 6px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.table-wrap { overflow-x: auto; }
|
||||
|
||||
.table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.table th, .table td {
|
||||
border-bottom: 1px solid #1f2a3a;
|
||||
padding: 6px 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.table th { color: var(--muted); }
|
||||
Reference in New Issue
Block a user