129 lines
5.4 KiB
HTML
129 lines
5.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>FilaMan - Device Setup</title>
|
|
<link rel="icon" type="image/png" href="/favicon.ico">
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<div class="fm-page">
|
|
<aside class="fm-sidebar">
|
|
<div class="sidebar-brand">
|
|
<img src="/logo.png" alt="Logo" class="sidebar-logo">
|
|
<div class="brand-text">
|
|
<h1>FilaMan <span class="version"></span></h1>
|
|
</div>
|
|
</div>
|
|
<nav class="fm-nav">
|
|
<a href="/">Start</a>
|
|
<a href="/waage">Scale</a>
|
|
<a href="/setup" class="active">Setup</a>
|
|
<a href="/upgrade">Upgrade</a>
|
|
</nav>
|
|
<div class="sidebar-status">
|
|
<div class="status-item">
|
|
<span class="status-dot" id="filamanDot"></span>
|
|
<span>System Sync</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<span id="ramStatus"></span>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<main class="fm-main">
|
|
<header>
|
|
<h1>Device Setup</h1>
|
|
<p>Register your device to connect it with your FilaMan-System account.</p>
|
|
</header>
|
|
|
|
<div class="fm-card">
|
|
<h2>System Registration</h2>
|
|
<p>Current Status: <strong style="color: var(--accent);">{{registered}}</strong></p>
|
|
|
|
<div class="fm-form-group" style="margin-top: 2rem;">
|
|
<label class="fm-label" for="filamanUrl">FilaMan API URL</label>
|
|
<input type="text" id="filamanUrl" class="fm-input" value="{{filamanUrl}}" placeholder="e.g. http://192.168.1.10:8000">
|
|
</div>
|
|
|
|
<div class="fm-form-group">
|
|
<label class="fm-label" for="deviceCode">Registration Code</label>
|
|
<input type="text" id="deviceCode" class="fm-input" maxlength="6" placeholder="6-digit code">
|
|
<p style="font-size: 0.8rem; margin-top: 0.5rem;">Enter the 6-digit code shown in your FilaMan Dashboard.</p>
|
|
</div>
|
|
|
|
<button id="registerBtn" class="fm-btn fm-btn-primary">Register Device</button>
|
|
<div id="statusMessage" style="margin-top: 1.5rem;"></div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<script>
|
|
// Fetch Version
|
|
fetch('/api/version')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const versionSpan = document.querySelector('.version');
|
|
if (versionSpan) versionSpan.textContent = 'v' + data.version;
|
|
})
|
|
.catch(error => console.error('Error fetching version:', error));
|
|
|
|
document.getElementById('registerBtn').addEventListener('click', () => {
|
|
const url = document.getElementById('filamanUrl').value;
|
|
const code = document.getElementById('deviceCode').value;
|
|
const statusMessage = document.getElementById('statusMessage');
|
|
|
|
if (!url || !code) {
|
|
statusMessage.textContent = 'Please provide both URL and Code';
|
|
statusMessage.style.color = 'var(--error-text)';
|
|
return;
|
|
}
|
|
|
|
statusMessage.textContent = 'Registering device...';
|
|
statusMessage.style.color = 'var(--text-muted)';
|
|
|
|
fetch('/api/register', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ url: url, code: code })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
statusMessage.textContent = 'Registration successful!';
|
|
statusMessage.style.color = 'var(--success-text)';
|
|
setTimeout(() => location.reload(), 2000);
|
|
} else {
|
|
statusMessage.textContent = 'Registration failed. Please check your code and URL.';
|
|
statusMessage.style.color = 'var(--error-text)';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
statusMessage.textContent = 'Network error. Please check connection.';
|
|
statusMessage.style.color = 'var(--error-text)';
|
|
});
|
|
});
|
|
|
|
// WebSocket handling
|
|
let ws = null;
|
|
function connectWebSocket() {
|
|
ws = new WebSocket(`ws://${window.location.hostname}/ws`);
|
|
ws.onmessage = (event) => {
|
|
const data = JSON.parse(event.data);
|
|
if (data.type === 'heartbeat') {
|
|
const dot = document.getElementById('filamanDot');
|
|
dot.className = data.filaman_connected ? 'status-dot online' : 'status-dot offline';
|
|
document.getElementById('ramStatus').textContent = data.freeHeap + ' KB free';
|
|
}
|
|
};
|
|
ws.onclose = () => setTimeout(connectWebSocket, 2000);
|
|
}
|
|
connectWebSocket();
|
|
setInterval(() => { if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({type:'heartbeat'})); }, 5000);
|
|
</script>
|
|
</body>
|
|
</html>
|