Fix syntax error in dashboard.js (duplicate declaration)

This commit is contained in:
Gemini Bot
2026-01-20 13:42:19 +00:00
parent f94bb088f2
commit 6bc73cd1da

View File

@@ -61,6 +61,8 @@ document.addEventListener('DOMContentLoaded', function() {
fetch('/api/data')
.then(response => response.json())
.then(data => {
console.log("API Data:", data); // Debugging
const summary = data.summary;
const devs = data.devs;
const pools = data.pools;
@@ -81,14 +83,27 @@ document.addEventListener('DOMContentLoaded', function() {
val = parseFloat(mhs).toFixed(2);
}
document.getElementById('stat-mhs').innerText = val;
// Note: HTML might still say MH/s in static part, need to update ID or text node of <p>
// But simplified:
const unitElem = document.querySelector('#stat-mhs').nextElementSibling;
if(unitElem) unitElem.innerText = unit;
const statMhs = document.getElementById('stat-mhs');
if (statMhs) {
statMhs.innerText = val;
const unitElem = document.querySelector('#stat-mhs').nextElementSibling;
if(unitElem) unitElem.innerText = unit;
}
document.getElementById('stat-accepted').innerText = formatNumber(summary['Accepted'] || 0);
document.getElementById('stat-hw').innerText = formatNumber(summary['Hardware Errors'] || 0);
// Update Chart
const now = new Date();
const timeLabel = now.getHours() + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0');
if (hashrateChart.data.labels.length > 60) {
hashrateChart.data.labels.shift();
hashrateChart.data.datasets[0].data.shift();
}
hashrateChart.data.labels.push(timeLabel);
hashrateChart.data.datasets[0].data.push(mhs);
hashrateChart.update();
}
// Update Device Count
@@ -96,28 +111,15 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('stat-devices').innerText = devs.length;
}
// Helper to find temp in stats if missing in devs
// Cgminer 'stats' command returns specific driver info.
// Structure: stats ->STATS -> list of dicts. usually one dict per device with ID keys like 'MM ID 0', etc.
// Or simplified list.
function getTempFallback(devId, statsData) {
// Try to find matching ID in stats
// This is heuristic as structure varies wildy between forks
return 0;
}
// Update Devs Table & Max Temp
let maxTemp = 0;
const tbody = document.getElementById('devs-table-body');
tbody.innerHTML = '';
if (devs && devs.length > 0) {
tbody.innerHTML = ''; // Clear only if we have data
devs.forEach(dev => {
let temp = dev['Temperature'] || 0;
// Fallback logic could go here if we understood the STATS structure for this specific fork
// For now we rely on standard API.
if (temp > maxTemp) maxTemp = temp;
const tr = document.createElement('tr');
@@ -136,50 +138,10 @@ document.addEventListener('DOMContentLoaded', function() {
tbody.appendChild(tr);
});
} else {
tbody.innerHTML = '<tr><td colspan="10" class="text-center text-muted">Keine Geräte gefunden...</td></tr>';
tbody.innerHTML = '<tr><td colspan="10" class="text-center text-muted">Keine Geräte gefunden... (API Connected)</td></tr>';
}
document.getElementById('stat-temp').innerText = maxTemp.toFixed(1);
// Update Chart
const now = new Date();
const timeLabel = now.getHours() + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0');
if (summary) {
const currentMhs = summary['MHS 5s'] || summary['MHS av'] || 0;
if (hashrateChart.data.labels.length > 60) { // Keep last 60 points
hashrateChart.data.labels.shift();
hashrateChart.data.datasets[0].data.shift();
}
hashrateChart.data.labels.push(timeLabel);
hashrateChart.data.datasets[0].data.push(currentMhs);
hashrateChart.update();
}
// Update Devs Table
const tbody = document.getElementById('devs-table-body');
tbody.innerHTML = '';
if (devs && devs.length > 0) {
devs.forEach(dev => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td>${dev['ID']}</td>
<td>${dev['Name'] || 'Gridseed'}</td>
<td>${dev['Enabled']}</td>
<td>${dev['Status']}</td>
<td class="${dev['Temperature'] > 50 ? 'text-warning' : 'text-success'}">${dev['Temperature']}</td>
<td>${parseFloat(dev['MHS 5s'] || 0).toFixed(2)}</td>
<td>${parseFloat(dev['MHS av'] || 0).toFixed(2)}</td>
<td>${dev['Accepted']}</td>
<td>${dev['Rejected']}</td>
<td>${dev['Hardware Errors']}</td>
`;
tbody.appendChild(tr);
});
} else {
tbody.innerHTML = '<tr><td colspan="10" class="text-center text-muted">Keine Geräte gefunden...</td></tr>';
}
// Update Pools
const poolList = document.getElementById('pool-list');
poolList.innerHTML = '';
@@ -226,4 +188,4 @@ document.addEventListener('DOMContentLoaded', function() {
setInterval(updateLog, 5000);
updateDashboard(); // Initial call
updateLog();
});
});