Files
gandalf/static/app.js

147 lines
5.2 KiB
JavaScript
Raw Permalink Normal View History

2025-02-07 21:03:31 -05:00
// Initialization
const UPDATE_INTERVALS = {
deviceStatus: 30000,
diagnostics: 60000
};
// Core update functions
function updateDeviceStatus() {
2025-02-07 23:38:49 -05:00
console.log('Fetching device status...');
2025-02-07 21:03:31 -05:00
fetch('/api/status')
.then(response => response.json())
.then(data => {
console.log('Received status data:', data);
Object.entries(data).forEach(([deviceName, status]) => {
2025-02-07 23:38:49 -05:00
const deviceElement = document.querySelector(`.device-status[data-device-name="${deviceName}"]`);
if (deviceElement) {
const indicator = deviceElement.querySelector('.status-indicator');
indicator.className = `status-indicator status-${status ? 'up' : 'down'}`;
}
2025-02-07 21:03:31 -05:00
});
2025-02-07 23:38:49 -05:00
});
2025-02-07 21:03:31 -05:00
}
2025-02-08 00:32:25 -05:00
function toggleInterfaces(header) {
const list = header.nextElementSibling;
const icon = header.querySelector('.expand-icon');
list.classList.toggle('collapsed');
icon.style.transform = list.classList.contains('collapsed') ? 'rotate(-90deg)' : 'rotate(0deg)';
}
2025-02-07 23:54:28 -05:00
function updateInterfaceStatus(deviceName, interfaces) {
const interfaceList = document.querySelector(`.interface-group[data-device-name="${deviceName}"] .interface-list`);
if (interfaceList && interfaces) {
interfaceList.innerHTML = '';
Object.entries(interfaces.ports || {}).forEach(([portName, port]) => {
interfaceList.innerHTML += `
<div class="interface-item">
<span class="port-name">${portName}</span>
<span class="port-speed">${port.speed.current}/${port.speed.max} Mbps</span>
2025-02-08 00:32:25 -05:00
<span class="port-status ${port.state}">${port.state}</span>
2025-02-07 23:54:28 -05:00
</div>
`;
});
}
}
function updateSystemHealth(deviceName, diagnostics) {
const metricsContainer = document.querySelector(`.health-metrics[data-device-name="${deviceName}"] .metrics-list`);
if (metricsContainer && diagnostics) {
const cpu = metricsContainer.querySelector('.cpu');
const memory = metricsContainer.querySelector('.memory');
const temperature = metricsContainer.querySelector('.temperature');
cpu.innerHTML = `CPU: ${diagnostics.system?.cpu || 'N/A'}%`;
memory.innerHTML = `Memory: ${diagnostics.system?.memory || 'N/A'}%`;
temperature.innerHTML = `Temp: ${diagnostics.system?.temperature || 'N/A'}°C`;
}
}
2025-02-07 21:28:54 -05:00
function updateSystemMetrics() {
fetch('/api/metrics')
.then(response => response.json())
.then(data => {
updateInterfaceStatus(data.interfaces);
updatePowerMetrics(data.power);
updateSystemHealth(data.health);
});
}
//Metric updates like interfaces, power, and health
2025-02-07 23:54:28 -05:00
2025-02-07 20:31:56 -05:00
function updateDiagnostics() {
fetch('/api/diagnostics')
2025-01-04 01:42:16 -05:00
.then(response => response.json())
.then(data => {
2025-02-07 23:54:28 -05:00
Object.entries(data).forEach(([deviceName, diagnostics]) => {
updateInterfaceStatus(deviceName, diagnostics.interfaces);
updateSystemHealth(deviceName, diagnostics);
2025-01-04 01:42:16 -05:00
});
});
}
2025-02-07 21:03:31 -05:00
// Element creation functions
2025-02-07 20:55:38 -05:00
function createDiagnosticElement(device, diagnostics) {
const element = document.createElement('div');
element.className = `diagnostic-item ${diagnostics.connection_type}-diagnostic`;
const content = `
<h3>${device}</h3>
<div class="diagnostic-details">
<div class="status-group">
<span class="label">Status:</span>
<span class="value ${diagnostics.state.toLowerCase()}">${diagnostics.state}</span>
</div>
<div class="firmware-group">
<span class="label">Firmware:</span>
<span class="value">${diagnostics.firmware.version}</span>
</div>
${createInterfaceHTML(diagnostics.interfaces)}
</div>
`;
element.innerHTML = content;
return element;
}
function createInterfaceHTML(interfaces) {
let html = '<div class="interfaces-group">';
// Add port information
Object.entries(interfaces.ports || {}).forEach(([portName, port]) => {
html += `
<div class="interface-item">
<span class="label">${portName}:</span>
<span class="value">${port.speed.current}/${port.speed.max} Mbps</span>
<span class="state ${port.state.toLowerCase()}">${port.state}</span>
</div>
`;
});
// Add radio information
Object.entries(interfaces.radios || {}).forEach(([radioName, radio]) => {
html += `
<div class="interface-item">
<span class="label">${radioName}:</span>
<span class="value">${radio.standard} - Ch${radio.channel} (${radio.width})</span>
</div>
`;
});
html += '</div>';
return html;
}
2025-02-07 21:03:31 -05:00
// Initialize updates
function initializeUpdates() {
// Set update intervals
setInterval(updateDeviceStatus, UPDATE_INTERVALS.deviceStatus);
setInterval(updateDiagnostics, UPDATE_INTERVALS.diagnostics);
2025-02-07 20:55:38 -05:00
2025-02-07 21:03:31 -05:00
// Initial updates
updateDeviceStatus();
updateDiagnostics();
}
2025-02-07 20:55:38 -05:00
2025-02-07 21:03:31 -05:00
// Start the application
initializeUpdates();