1
This commit is contained in:
45
frontend/js/dashboard.js
Normal file → Executable file
45
frontend/js/dashboard.js
Normal file → Executable file
@@ -6,6 +6,23 @@ const api = window.BenchAPI;
|
||||
// Global state
|
||||
let allDevices = [];
|
||||
let isLoading = false;
|
||||
let apiToken = null;
|
||||
let iperfServer = null;
|
||||
|
||||
// Load backend config (API token, etc.)
|
||||
async function loadBackendConfig() {
|
||||
try {
|
||||
const response = await fetch(`${window.BenchConfig.backendApiUrl}/config`);
|
||||
if (response.ok) {
|
||||
const config = await response.json();
|
||||
apiToken = config.api_token;
|
||||
iperfServer = config.iperf_server || '10.0.1.97';
|
||||
updateBenchCommandDisplay();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load backend config:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Load dashboard data
|
||||
async function loadDashboard() {
|
||||
@@ -83,7 +100,7 @@ async function loadStats() {
|
||||
}
|
||||
});
|
||||
|
||||
const avgScore = scoreCount > 0 ? Math.round(scoreSum / scoreCount) : 0;
|
||||
const avgScore = scoreCount > 0 ? Math.ceil(scoreSum / scoreCount) : 0;
|
||||
|
||||
// Update UI
|
||||
document.getElementById('totalDevices').textContent = totalDevices;
|
||||
@@ -221,6 +238,26 @@ function createDeviceRow(device, rank) {
|
||||
`;
|
||||
}
|
||||
|
||||
function buildBenchCommand() {
|
||||
const cfg = window.BenchConfig || {};
|
||||
const frontendBase = (cfg.frontendBaseUrl || window.location.origin).replace(/\/$/, '');
|
||||
const scriptPath = cfg.benchScriptPath || '/scripts/bench.sh';
|
||||
const backendBase = (cfg.backendApiUrl || `${window.location.protocol}//${window.location.hostname}:8007/api`).replace(/\/$/, '');
|
||||
const token = apiToken || 'LOADING...';
|
||||
const iperf = iperfServer || '10.0.1.97';
|
||||
|
||||
// Extract backend URL without /api suffix
|
||||
const backendUrl = backendBase.replace(/\/api$/, '');
|
||||
|
||||
return `curl -fsSL ${frontendBase}${scriptPath} | sudo bash -s -- --server ${backendUrl} --token "${token}" --iperf-server ${iperf}`;
|
||||
}
|
||||
|
||||
function updateBenchCommandDisplay() {
|
||||
const element = document.getElementById('benchCommand');
|
||||
if (!element) return;
|
||||
element.textContent = buildBenchCommand();
|
||||
}
|
||||
|
||||
// Copy bench command to clipboard
|
||||
async function copyBenchCommand() {
|
||||
const command = document.getElementById('benchCommand').textContent;
|
||||
@@ -282,7 +319,11 @@ function refreshDashboard() {
|
||||
}
|
||||
|
||||
// Initialize dashboard on page load
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
// Load backend config first to get API token
|
||||
await loadBackendConfig();
|
||||
|
||||
// Then load dashboard data
|
||||
loadDashboard();
|
||||
|
||||
// Setup search input listener
|
||||
|
||||
Reference in New Issue
Block a user