wizard
This commit is contained in:
844
init/wizard.html
Normal file
844
init/wizard.html
Normal file
@@ -0,0 +1,844 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Soleprint - Room Setup</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #1a1a2e;
|
||||
--surface: #16213e;
|
||||
--surface-alt: #1a2744;
|
||||
--primary: #e94560;
|
||||
--primary-hover: #c73e54;
|
||||
--accent: #4ecca3;
|
||||
--text: #eaeaea;
|
||||
--text-muted: #8892b0;
|
||||
--border: #0f3460;
|
||||
--danger: #e94560;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: "Segoe UI", system-ui, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
}
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 280px 1fr 300px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
@media (max-width: 1000px) {
|
||||
.layout { grid-template-columns: 1fr; }
|
||||
.sidebar, .preview-panel { display: none; }
|
||||
}
|
||||
|
||||
/* Sidebar — layer navigation */
|
||||
.sidebar {
|
||||
background: var(--surface);
|
||||
border-right: 1px solid var(--border);
|
||||
padding: 1.5rem 0;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
height: 100vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.sidebar h1 {
|
||||
font-size: 1.1rem;
|
||||
padding: 0 1.2rem 1rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.sidebar h1 span { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.7rem 1.2rem;
|
||||
cursor: pointer;
|
||||
border-left: 3px solid transparent;
|
||||
transition: all 0.15s;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.nav-item:hover { background: var(--surface-alt); }
|
||||
.nav-item.active {
|
||||
background: var(--surface-alt);
|
||||
border-left-color: var(--primary);
|
||||
color: var(--text);
|
||||
}
|
||||
.nav-item.done { color: var(--accent); }
|
||||
.nav-item .num {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
background: var(--border);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.75rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.nav-item.done .num { background: var(--accent); color: var(--bg); }
|
||||
.nav-item.active .num { background: var(--primary); color: white; }
|
||||
|
||||
/* Main content */
|
||||
.main {
|
||||
padding: 2rem 3rem;
|
||||
max-width: 800px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.main h2 {
|
||||
font-size: 1.4rem;
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
.main .subtitle {
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* Form elements */
|
||||
.field { margin-bottom: 1.2rem; }
|
||||
.field label {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
.field input, .field select {
|
||||
width: 100%;
|
||||
padding: 0.6rem 0.8rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.field input:focus, .field select:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
}
|
||||
.field .hint {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
/* Checkbox grid for component selection */
|
||||
.check-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.check-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.7rem;
|
||||
background: var(--surface-alt);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
.check-item:hover { border-color: var(--primary); }
|
||||
.check-item input { width: auto; accent-color: var(--primary); }
|
||||
.check-item .name { flex: 1; }
|
||||
.check-item .status {
|
||||
font-size: 0.75rem;
|
||||
padding: 0.1rem 0.4rem;
|
||||
border-radius: 3px;
|
||||
background: var(--border);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.check-item .status.live { background: #1a3a2a; color: var(--accent); }
|
||||
.check-item .status.ready { background: #1a3a2a; color: var(--accent); }
|
||||
|
||||
.section-label {
|
||||
font-size: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--text-muted);
|
||||
margin: 1.5rem 0 0.6rem;
|
||||
padding-bottom: 0.3rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 0.8rem;
|
||||
margin-top: 2rem;
|
||||
padding-top: 1.5rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.btn {
|
||||
padding: 0.6rem 1.4rem;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 0.95rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.btn-primary { background: var(--primary); color: white; }
|
||||
.btn-primary:hover { background: var(--primary-hover); }
|
||||
.btn-secondary { background: var(--border); color: var(--text); }
|
||||
.btn-secondary:hover { background: #1a4a7a; }
|
||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
/* Preview panel */
|
||||
.preview-panel {
|
||||
background: var(--surface);
|
||||
border-left: 1px solid var(--border);
|
||||
padding: 1.2rem;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
height: 100vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.preview-panel h3 {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
.tree {
|
||||
font-family: "Consolas", "Monaco", monospace;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.tree .folder { color: #82aaff; }
|
||||
.tree .file { color: var(--text-muted); }
|
||||
|
||||
/* Status toast */
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 2rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
padding: 0.8rem 1.5rem;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9rem;
|
||||
display: none;
|
||||
z-index: 100;
|
||||
}
|
||||
.toast.success { display: block; background: #1a3a2a; border: 1px solid var(--accent); color: var(--accent); }
|
||||
.toast.error { display: block; background: #3a1a1a; border: 1px solid var(--danger); color: var(--danger); }
|
||||
|
||||
/* Layer sections hidden by default */
|
||||
.layer { display: none; }
|
||||
.layer.active { display: block; }
|
||||
|
||||
/* Clone mode */
|
||||
.clone-section { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layout">
|
||||
<!-- Sidebar -->
|
||||
<nav class="sidebar">
|
||||
<h1>Room Setup <span>soleprint</span></h1>
|
||||
<div class="nav-item active" data-layer="0">
|
||||
<span class="num">0</span> Config + Data
|
||||
</div>
|
||||
<div class="nav-item" data-layer="1">
|
||||
<span class="num">1</span> Docker
|
||||
</div>
|
||||
<div class="nav-item" data-layer="2">
|
||||
<span class="num">2</span> Managed App
|
||||
</div>
|
||||
<div class="nav-item" data-layer="3">
|
||||
<span class="num">3</span> Link (DB Bridge)
|
||||
</div>
|
||||
<div class="nav-item" data-layer="4">
|
||||
<span class="num">4</span> Scripts
|
||||
</div>
|
||||
<div class="nav-item" data-layer="5">
|
||||
<span class="num">5</span> Systems
|
||||
</div>
|
||||
<div class="nav-item" data-layer="6">
|
||||
<span class="num">6</span> Nginx
|
||||
</div>
|
||||
<div class="nav-item" data-layer="clone" style="margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 1rem;">
|
||||
<span class="num">~</span> Clone Room
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Main content -->
|
||||
<main class="main" id="main">
|
||||
|
||||
<!-- Layer 0: Config -->
|
||||
<section class="layer active" id="layer-0">
|
||||
<h2>Room Configuration</h2>
|
||||
<p class="subtitle">Basic identity and data registry for your room</p>
|
||||
|
||||
<div class="field">
|
||||
<label for="roomName">Room Name</label>
|
||||
<input type="text" id="roomName" placeholder="myroom">
|
||||
<div class="hint">Unique identifier — becomes cfg/<name>/</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label for="roomType">Room Type</label>
|
||||
<select id="roomType">
|
||||
<option value="standalone">Standalone</option>
|
||||
<option value="managed">Managed (wraps an app)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="hubPort">Hub Port</label>
|
||||
<input type="number" id="hubPort" value="12000">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-label">Data Registry</div>
|
||||
<p class="hint" style="margin-bottom: 0.8rem;">
|
||||
Select which items to include in your room's data files.
|
||||
All available components are shown — uncheck what you don't need.
|
||||
</p>
|
||||
<div id="dataRegistry">
|
||||
<!-- Populated by JS from /api/defaults -->
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn btn-primary" onclick="goLayer(1)">Continue to Docker</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Layer 1: Docker -->
|
||||
<section class="layer" id="layer-1">
|
||||
<h2>Docker Configuration</h2>
|
||||
<p class="subtitle">Soleprint runtime — docker-compose and environment</p>
|
||||
<p style="color: var(--text-muted); line-height: 1.6;">
|
||||
Generates <code>soleprint/docker-compose.yml</code> and <code>soleprint/.env</code>
|
||||
with your room name, port, and network settings. These are auto-filled from Layer 0.
|
||||
</p>
|
||||
<div class="field" style="margin-top: 1rem;">
|
||||
<label>Generated files</label>
|
||||
<div class="tree">
|
||||
<div class="file">soleprint/docker-compose.yml</div>
|
||||
<div class="file">soleprint/.env</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="goLayer(0)">Back</button>
|
||||
<button class="btn btn-primary" onclick="goLayer(2)">Continue to Managed App</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Layer 2: Managed App -->
|
||||
<section class="layer" id="layer-2">
|
||||
<h2>Managed Application</h2>
|
||||
<p class="subtitle">The app soleprint wraps — repos, framework, Docker setup</p>
|
||||
|
||||
<div id="managedNotice" style="color: var(--text-muted); padding: 1rem; background: var(--surface-alt); border-radius: 4px;">
|
||||
Room type is "standalone" — no managed app needed.
|
||||
<a href="#" onclick="document.getElementById('roomType').value='managed'; updateManagedVisibility(); goLayer(2); return false;" style="color: var(--primary);">Switch to managed?</a>
|
||||
</div>
|
||||
|
||||
<div id="managedFields" style="display: none;">
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label for="appName">App Name</label>
|
||||
<input type="text" id="appName" placeholder="myapp">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="backendFramework">Backend Framework</label>
|
||||
<select id="backendFramework"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="backendPath">Backend Repo Path</label>
|
||||
<input type="text" id="backendPath" placeholder="/home/user/wdir/myapp-api">
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label for="frontendPath">Frontend Repo Path</label>
|
||||
<input type="text" id="frontendPath" placeholder="(leave empty to skip)">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="frontendFramework">Frontend Framework</label>
|
||||
<select id="frontendFramework">
|
||||
<option value="">(no frontend)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="goLayer(1)">Back</button>
|
||||
<button class="btn btn-primary" onclick="goLayer(3)">Continue to Link</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Layer 3: Link -->
|
||||
<section class="layer" id="layer-3">
|
||||
<h2>Link — DB Bridge</h2>
|
||||
<p class="subtitle">Read access to the managed app's database for soleprint tools</p>
|
||||
<p style="color: var(--text-muted); line-height: 1.6;">
|
||||
Scaffolds a FastAPI service with adapter stubs matching your backend framework.
|
||||
Used by databrowse, datagen, and tester to access app data.
|
||||
</p>
|
||||
<div class="field" style="margin-top: 1rem;">
|
||||
<label>Generated files</label>
|
||||
<div class="tree">
|
||||
<div class="file">link/main.py</div>
|
||||
<div class="file">link/adapters/</div>
|
||||
<div class="file">link/Dockerfile</div>
|
||||
<div class="file">link/docker-compose.yml</div>
|
||||
<div class="file">link/requirements.txt</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="goLayer(2)">Back</button>
|
||||
<button class="btn btn-primary" onclick="goLayer(4)">Continue to Scripts</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Layer 4: Scripts -->
|
||||
<section class="layer" id="layer-4">
|
||||
<h2>Control Scripts</h2>
|
||||
<p class="subtitle">start, stop, status, logs — generated for your room's services</p>
|
||||
<div class="field" style="margin-top: 1rem;">
|
||||
<label>Generated files</label>
|
||||
<div class="tree">
|
||||
<div class="file">ctrl/start.sh</div>
|
||||
<div class="file">ctrl/stop.sh</div>
|
||||
<div class="file">ctrl/status.sh</div>
|
||||
<div class="file">ctrl/logs.sh</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="goLayer(3)">Back</button>
|
||||
<button class="btn btn-primary" onclick="goLayer(5)">Continue to Systems</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Layer 5: Systems (checkbox-driven) -->
|
||||
<section class="layer" id="layer-5">
|
||||
<h2>System Extensions</h2>
|
||||
<p class="subtitle">Select which tools, monitors, and connectors to scaffold for this room</p>
|
||||
|
||||
<div class="section-label">Tester</div>
|
||||
<div class="field">
|
||||
<label>
|
||||
<input type="checkbox" id="enableTester" checked> Enable contract test suite
|
||||
</label>
|
||||
</div>
|
||||
<div class="field" id="testerUrlField">
|
||||
<label for="testUrl">Test Target URL</label>
|
||||
<input type="text" id="testUrl" value="http://localhost:8000">
|
||||
</div>
|
||||
|
||||
<div class="section-label">Available Components</div>
|
||||
<p class="hint" style="margin-bottom: 0.8rem;">
|
||||
These are registered in your data/*.json files (configured in Layer 0).
|
||||
Scaffolding for custom shunts, monitors, and tools can be added after generation.
|
||||
</p>
|
||||
|
||||
<div id="systemComponents">
|
||||
<!-- Populated by JS -->
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="goLayer(4)">Back</button>
|
||||
<button class="btn btn-primary" onclick="goLayer(6)">Continue to Nginx</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Layer 6: Nginx -->
|
||||
<section class="layer" id="layer-6">
|
||||
<h2>Nginx — Sidebar Injection</h2>
|
||||
<p class="subtitle">Reverse proxy that injects the soleprint sidebar into your app's frontend</p>
|
||||
|
||||
<div id="nginxNotice" style="color: var(--text-muted); padding: 1rem; background: var(--surface-alt); border-radius: 4px;">
|
||||
Requires a managed app with a frontend. Configure in Layer 2.
|
||||
</div>
|
||||
|
||||
<div id="nginxFields" style="display: none;">
|
||||
<div class="field" style="margin-top: 1rem;">
|
||||
<label>Generated files</label>
|
||||
<div class="tree">
|
||||
<div class="file">soleprint/nginx/local.conf</div>
|
||||
<div class="file">soleprint/docker-compose.nginx.yml</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Required /etc/hosts entry</label>
|
||||
<code id="hostsEntry" style="color: var(--accent); font-size: 0.85rem;"></code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn btn-secondary" onclick="goLayer(5)">Back</button>
|
||||
<button class="btn btn-primary" onclick="generate()" id="generateBtn">Generate Room</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Clone -->
|
||||
<section class="layer" id="layer-clone">
|
||||
<h2>Clone Existing Room</h2>
|
||||
<p class="subtitle">Create a variant of an existing room with new ports and names</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label for="cloneSource">Source Room</label>
|
||||
<select id="cloneSource"></select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="cloneTarget">New Room Name</label>
|
||||
<input type="text" id="cloneTarget" placeholder="myroom-karen">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hint">
|
||||
Copies the entire cfg/ tree, patches all names and ports.
|
||||
Shares source code repos but gets its own DB, containers, and hostname.
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-primary" onclick="cloneRoom()">Clone</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<!-- Preview panel -->
|
||||
<aside class="preview-panel">
|
||||
<h3>Preview</h3>
|
||||
<div class="tree" id="previewTree">
|
||||
<span class="file" style="color: var(--text-muted);">Configure room to see preview</span>
|
||||
</div>
|
||||
|
||||
<h3 style="margin-top: 1.5rem;">Selected Layers</h3>
|
||||
<div id="selectedLayers" style="font-size: 0.85rem; color: var(--text-muted); line-height: 1.8;"></div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<script>
|
||||
let defaults = {};
|
||||
let currentLayer = 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function init() {
|
||||
const resp = await fetch("/api/defaults");
|
||||
defaults = await resp.json();
|
||||
|
||||
document.getElementById("hubPort").value = defaults.next_port;
|
||||
|
||||
// Populate framework selects
|
||||
const bf = document.getElementById("backendFramework");
|
||||
defaults.backend_frameworks.forEach(f => {
|
||||
bf.add(new Option(f, f));
|
||||
});
|
||||
|
||||
const ff = document.getElementById("frontendFramework");
|
||||
ff.innerHTML = '<option value="">(no frontend)</option>';
|
||||
defaults.frontend_frameworks.forEach(f => {
|
||||
ff.add(new Option(f, f));
|
||||
});
|
||||
|
||||
// Populate data registry (Layer 0)
|
||||
renderDataRegistry();
|
||||
|
||||
// Populate system components (Layer 5)
|
||||
renderSystemComponents();
|
||||
|
||||
// Populate clone source
|
||||
const roomsResp = await fetch("/api/rooms");
|
||||
const roomsData = await roomsResp.json();
|
||||
const cs = document.getElementById("cloneSource");
|
||||
roomsData.rooms.forEach(r => cs.add(new Option(r, r)));
|
||||
|
||||
// Event listeners
|
||||
document.getElementById("roomType").addEventListener("change", updateManagedVisibility);
|
||||
document.getElementById("roomName").addEventListener("input", updatePreview);
|
||||
document.getElementById("roomType").addEventListener("change", updatePreview);
|
||||
|
||||
document.querySelectorAll(".nav-item").forEach(item => {
|
||||
item.addEventListener("click", () => {
|
||||
const layer = item.dataset.layer;
|
||||
goLayer(layer === "clone" ? "clone" : parseInt(layer));
|
||||
});
|
||||
});
|
||||
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Data registry (Layer 0)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function renderDataRegistry() {
|
||||
const container = document.getElementById("dataRegistry");
|
||||
const categories = {
|
||||
"Connectors (Artery)": ["veins", "shunts", "pulses"],
|
||||
"Documentation (Atlas)": ["books", "templates", "depots"],
|
||||
"Tools (Station)": ["tools", "monitors", "desks"],
|
||||
"Other": ["rooms", "tables", "plexuses"],
|
||||
};
|
||||
|
||||
let html = "";
|
||||
for (const [cat, files] of Object.entries(categories)) {
|
||||
html += `<div class="section-label">${cat}</div><div class="check-grid">`;
|
||||
for (const file of files) {
|
||||
const items = (defaults.data[file] || {}).items || [];
|
||||
for (const item of items) {
|
||||
const statusClass = (item.status === "live" || item.status === "ready") ? item.status : "";
|
||||
html += `
|
||||
<label class="check-item">
|
||||
<input type="checkbox" checked data-file="${file}" data-item='${JSON.stringify(item)}'>
|
||||
<span class="name">${item.title || item.name}</span>
|
||||
${item.status ? `<span class="status ${statusClass}">${item.status}</span>` : ""}
|
||||
</label>`;
|
||||
}
|
||||
if (items.length === 0) {
|
||||
html += `<span style="color: var(--text-muted); font-size: 0.85rem; padding: 0.3rem;">No ${file} configured</span>`;
|
||||
}
|
||||
}
|
||||
html += "</div>";
|
||||
}
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// System components (Layer 5)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function renderSystemComponents() {
|
||||
const container = document.getElementById("systemComponents");
|
||||
const sections = {
|
||||
"Shunts (Mock APIs)": "shunts",
|
||||
"Monitors": "monitors",
|
||||
"Tools": "tools",
|
||||
};
|
||||
|
||||
let html = "";
|
||||
for (const [label, file] of Object.entries(sections)) {
|
||||
const items = (defaults.data[file] || {}).items || [];
|
||||
if (items.length === 0) continue;
|
||||
html += `<div class="section-label">${label}</div><div class="check-grid">`;
|
||||
for (const item of items) {
|
||||
const desc = item.description ? ` title="${item.description}"` : "";
|
||||
html += `
|
||||
<label class="check-item"${desc}>
|
||||
<input type="checkbox" checked data-system="${file}" data-name="${item.name}">
|
||||
<span class="name">${item.title || item.name}</span>
|
||||
</label>`;
|
||||
}
|
||||
html += "</div>";
|
||||
}
|
||||
container.innerHTML = html || '<p style="color: var(--text-muted);">No system components available.</p>';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Navigation
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function goLayer(n) {
|
||||
const id = typeof n === "string" ? n : n.toString();
|
||||
|
||||
document.querySelectorAll(".layer").forEach(el => el.classList.remove("active"));
|
||||
document.querySelectorAll(".nav-item").forEach(el => el.classList.remove("active"));
|
||||
|
||||
const section = document.getElementById(`layer-${id}`);
|
||||
if (section) section.classList.add("active");
|
||||
|
||||
const nav = document.querySelector(`.nav-item[data-layer="${id}"]`);
|
||||
if (nav) nav.classList.add("active");
|
||||
|
||||
if (typeof n === "number") currentLayer = n;
|
||||
updateManagedVisibility();
|
||||
updateNginxVisibility();
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
function updateManagedVisibility() {
|
||||
const isManaged = document.getElementById("roomType").value === "managed";
|
||||
document.getElementById("managedNotice").style.display = isManaged ? "none" : "block";
|
||||
document.getElementById("managedFields").style.display = isManaged ? "block" : "none";
|
||||
}
|
||||
|
||||
function updateNginxVisibility() {
|
||||
const isManaged = document.getElementById("roomType").value === "managed";
|
||||
const hasFrontend = !!document.getElementById("frontendPath").value;
|
||||
const show = isManaged && hasFrontend;
|
||||
document.getElementById("nginxNotice").style.display = show ? "none" : "block";
|
||||
document.getElementById("nginxFields").style.display = show ? "block" : "none";
|
||||
const room = document.getElementById("roomName").value || "myroom";
|
||||
document.getElementById("hostsEntry").textContent = `127.0.0.1 ${room}.spr.local.ar ${room}.local.ar`;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Preview
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function updatePreview() {
|
||||
const room = document.getElementById("roomName").value || "myroom";
|
||||
const isManaged = document.getElementById("roomType").value === "managed";
|
||||
const appName = document.getElementById("appName").value || room;
|
||||
const hasFrontend = !!document.getElementById("frontendPath").value;
|
||||
|
||||
let tree = `<div class="folder">cfg/${room}/</div>`;
|
||||
tree += `<div class="file"> config.json</div>`;
|
||||
tree += `<div class="folder"> data/</div>`;
|
||||
tree += `<div class="folder"> soleprint/</div>`;
|
||||
tree += `<div class="file"> docker-compose.yml</div>`;
|
||||
tree += `<div class="file"> .env</div>`;
|
||||
|
||||
if (isManaged) {
|
||||
tree += `<div class="file"> docker-compose.yml</div>`;
|
||||
tree += `<div class="file"> Dockerfile.backend</div>`;
|
||||
if (hasFrontend) tree += `<div class="file"> Dockerfile.frontend</div>`;
|
||||
tree += `<div class="file"> .env</div>`;
|
||||
tree += `<div class="folder"> ${appName}/</div>`;
|
||||
tree += `<div class="folder"> link/</div>`;
|
||||
if (hasFrontend) {
|
||||
tree += `<div class="folder"> soleprint/nginx/</div>`;
|
||||
}
|
||||
}
|
||||
tree += `<div class="folder"> ctrl/</div>`;
|
||||
|
||||
document.getElementById("previewTree").innerHTML = tree;
|
||||
|
||||
// Selected layers summary
|
||||
const layers = getSelectedLayers();
|
||||
document.getElementById("selectedLayers").innerHTML = layers
|
||||
.map(l => `Layer ${l}`)
|
||||
.join("<br>");
|
||||
}
|
||||
|
||||
function getSelectedLayers() {
|
||||
const isManaged = document.getElementById("roomType").value === "managed";
|
||||
const hasFrontend = !!document.getElementById("frontendPath").value;
|
||||
const layers = [0, 1];
|
||||
if (isManaged) { layers.push(2); layers.push(3); }
|
||||
layers.push(4);
|
||||
if (document.getElementById("enableTester").checked) layers.push(5);
|
||||
if (isManaged && hasFrontend) layers.push(6);
|
||||
return layers;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Collect data selections from checkboxes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function collectDataSelections() {
|
||||
const selections = {};
|
||||
document.querySelectorAll('#dataRegistry input[type="checkbox"]').forEach(cb => {
|
||||
const file = cb.dataset.file;
|
||||
if (!selections[file]) selections[file] = [];
|
||||
if (cb.checked) {
|
||||
selections[file].push(JSON.parse(cb.dataset.item));
|
||||
}
|
||||
});
|
||||
return selections;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Generate
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function generate() {
|
||||
const room = document.getElementById("roomName").value.trim();
|
||||
if (!room) { showToast("error", "Room name is required"); return; }
|
||||
|
||||
const isManaged = document.getElementById("roomType").value === "managed";
|
||||
const hasFrontend = !!document.getElementById("frontendPath").value;
|
||||
|
||||
const body = {
|
||||
room: room,
|
||||
room_type: document.getElementById("roomType").value,
|
||||
port: parseInt(document.getElementById("hubPort").value) || 0,
|
||||
layers: getSelectedLayers(),
|
||||
data_selections: collectDataSelections(),
|
||||
};
|
||||
|
||||
if (isManaged) {
|
||||
body.layer2 = {
|
||||
app_name: document.getElementById("appName").value || room,
|
||||
backend_path: document.getElementById("backendPath").value,
|
||||
backend_framework: document.getElementById("backendFramework").value,
|
||||
frontend_path: document.getElementById("frontendPath").value || null,
|
||||
frontend_framework: document.getElementById("frontendFramework").value || null,
|
||||
};
|
||||
}
|
||||
|
||||
if (document.getElementById("enableTester").checked) {
|
||||
body.layer5 = {
|
||||
test_url: document.getElementById("testUrl").value,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await fetch("/api/generate", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (resp.ok) {
|
||||
const result = await resp.json();
|
||||
showToast("success", `Room "${result.room}" created at ${result.path}. Build: ${result.build_command}`);
|
||||
} else {
|
||||
const err = await resp.json();
|
||||
showToast("error", err.detail || "Generation failed");
|
||||
}
|
||||
} catch (e) {
|
||||
showToast("error", `Error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function cloneRoom() {
|
||||
const source = document.getElementById("cloneSource").value;
|
||||
const target = document.getElementById("cloneTarget").value.trim();
|
||||
if (!target) { showToast("error", "Target room name required"); return; }
|
||||
|
||||
try {
|
||||
const resp = await fetch("/api/clone", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({source, target}),
|
||||
});
|
||||
if (resp.ok) {
|
||||
const result = await resp.json();
|
||||
showToast("success", `Cloned ${result.source} -> ${result.target}. Build: ${result.build_command}`);
|
||||
} else {
|
||||
const err = await resp.json();
|
||||
showToast("error", err.detail || "Clone failed");
|
||||
}
|
||||
} catch (e) {
|
||||
showToast("error", `Error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Toast
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function showToast(type, msg) {
|
||||
const toast = document.getElementById("toast");
|
||||
toast.className = `toast ${type}`;
|
||||
toast.textContent = msg;
|
||||
setTimeout(() => { toast.className = "toast"; }, 6000);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Boot
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user