This commit is contained in:
Gilles Soulier
2026-01-05 16:08:01 +01:00
parent dcba044cd6
commit c67befc549
2215 changed files with 26743 additions and 329 deletions

View File

@@ -1,7 +1,8 @@
// Linux BenchTools - Dashboard Logic
const { formatDate, formatRelativeTime, createScoreBadge, getScoreBadgeText, escapeHtml, showError, showEmptyState, copyToClipboard, showToast, debounce } = window.BenchUtils;
const api = window.BenchAPI;
// Access utilities and API
const utils = window.BenchUtils;
const apiClient = window.BenchAPI;
// Global state
let allDevices = [];
@@ -16,11 +17,21 @@ async function loadBackendConfig() {
if (response.ok) {
const config = await response.json();
apiToken = config.api_token;
iperfServer = config.iperf_server || '10.0.1.97';
iperfServer = config.iperf_server || '10.0.0.50';
updateBenchCommandDisplay();
} else {
console.error('Failed to load backend config - HTTP', response.status);
// Set default values to allow the page to render
apiToken = 'LOADING_ERROR';
iperfServer = '10.0.0.50';
updateBenchCommandDisplay();
}
} catch (error) {
console.error('Failed to load backend config:', error);
// Set default values to allow the page to render
apiToken = 'LOADING_ERROR';
iperfServer = '10.0.0.50';
updateBenchCommandDisplay();
}
}
@@ -42,7 +53,7 @@ async function loadDashboard() {
} catch (error) {
console.error('Failed to load dashboard:', error);
showToast('Erreur lors du chargement des données', 'error');
utils.showToast('Erreur lors du chargement des données', 'error');
} finally {
isLoading = false;
updateRefreshButton(false);
@@ -63,6 +74,28 @@ function updateRefreshButton(loading) {
}
}
async function backupDatabase() {
const btn = document.getElementById('backupBtn');
if (btn) {
btn.disabled = true;
btn.textContent = '💾 Backup...';
}
try {
const result = await apiClient.backupDatabase();
const files = (result.backups || []).map(b => b.filename).join(', ');
utils.showToast(`Backup créé${files ? `: ${files}` : ''}`, 'success');
} catch (error) {
console.error('Backup failed:', error);
utils.showToast(`Backup échoué: ${error.message}`, 'error');
} finally {
if (btn) {
btn.disabled = false;
btn.textContent = '💾 Backup DB';
}
}
}
// Update last refresh time
function updateLastRefreshTime() {
const element = document.getElementById('lastUpdate');
@@ -75,7 +108,7 @@ function updateLastRefreshTime() {
// Load statistics
async function loadStats() {
try {
const devices = await api.getDevices({ page_size: 1000 });
const devices = await apiClient.getDevices({ page_size: 100 });
const totalDevices = devices.total || 0;
let totalBenchmarks = 0;
@@ -107,7 +140,7 @@ async function loadStats() {
document.getElementById('totalBenchmarks').textContent = totalBenchmarks;
document.getElementById('avgScore').textContent = avgScore;
document.getElementById('lastBench').textContent = lastBenchDate
? formatRelativeTime(lastBenchDate.toISOString())
? utils.formatRelativeTime(lastBenchDate.toISOString())
: 'Aucun';
} catch (error) {
@@ -125,10 +158,10 @@ async function loadTopDevices() {
const container = document.getElementById('devicesTable');
try {
const data = await api.getDevices({ page_size: 50 });
const data = await apiClient.getDevices({ page_size: 50 });
if (!data.items || data.items.length === 0) {
showEmptyState(container, 'Aucun device trouvé. Exécutez un benchmark sur une machine pour commencer.', '📊');
utils.showEmptyState(container, 'Aucun device trouvé. Exécutez un benchmark sur une machine pour commencer.', '📊');
allDevices = [];
return;
}
@@ -151,7 +184,7 @@ async function loadTopDevices() {
container.innerHTML = `
<div class="error" style="text-align: center;">
<p style="margin-bottom: 1rem;">❌ Impossible de charger les devices</p>
<p style="font-size: 0.9rem; margin-bottom: 1rem;">${escapeHtml(error.message)}</p>
<p style="font-size: 0.9rem; margin-bottom: 1rem;">${utils.escapeHtml(error.message)}</p>
<button class="btn btn-primary btn-sm" onclick="loadTopDevices()">🔄 Réessayer</button>
</div>
`;
@@ -210,26 +243,26 @@ function createDeviceRow(device, rank) {
const runAt = bench?.run_at;
const globalScoreHtml = globalScore !== null && globalScore !== undefined
? `<span class="${window.BenchUtils.getScoreBadgeClass(globalScore)}">${getScoreBadgeText(globalScore)}</span>`
? `<span class="${utils.getScoreBadgeClass(globalScore)}">${utils.getScoreBadgeText(globalScore)}</span>`
: '<span class="badge">N/A</span>';
return `
<tr onclick="window.location.href='device_detail.html?id=${device.id}'">
<td><strong>${rank}</strong></td>
<td>
<strong style="color: var(--color-success);">${escapeHtml(device.hostname)}</strong>
<strong style="color: var(--color-success);">${utils.escapeHtml(device.hostname)}</strong>
</td>
<td style="color: var(--text-secondary);">
${escapeHtml(device.description || 'Aucune description')}
${utils.escapeHtml(device.description || 'Aucune description')}
</td>
<td>${globalScoreHtml}</td>
<td><span class="${window.BenchUtils.getScoreBadgeClass(cpuScore)}">${getScoreBadgeText(cpuScore)}</span></td>
<td><span class="${window.BenchUtils.getScoreBadgeClass(memScore)}">${getScoreBadgeText(memScore)}</span></td>
<td><span class="${window.BenchUtils.getScoreBadgeClass(diskScore)}">${getScoreBadgeText(diskScore)}</span></td>
<td><span class="${window.BenchUtils.getScoreBadgeClass(netScore)}">${getScoreBadgeText(netScore)}</span></td>
<td><span class="${window.BenchUtils.getScoreBadgeClass(gpuScore)}">${getScoreBadgeText(gpuScore)}</span></td>
<td><span class="${utils.getScoreBadgeClass(cpuScore)}">${utils.getScoreBadgeText(cpuScore)}</span></td>
<td><span class="${utils.getScoreBadgeClass(memScore)}">${utils.getScoreBadgeText(memScore)}</span></td>
<td><span class="${utils.getScoreBadgeClass(diskScore)}">${utils.getScoreBadgeText(diskScore)}</span></td>
<td><span class="${utils.getScoreBadgeClass(netScore)}">${utils.getScoreBadgeText(netScore)}</span></td>
<td><span class="${utils.getScoreBadgeClass(gpuScore)}">${utils.getScoreBadgeText(gpuScore)}</span></td>
<td style="color: var(--text-secondary); font-size: 0.85rem;">
${runAt ? formatRelativeTime(runAt) : 'Jamais'}
${runAt ? utils.formatRelativeTime(runAt) : 'Jamais'}
</td>
<td>
<a href="device_detail.html?id=${device.id}" class="btn btn-sm btn-primary">Voir</a>
@@ -244,7 +277,7 @@ function buildBenchCommand() {
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';
const iperf = iperfServer || '10.0.0.50';
// Extract backend URL without /api suffix
const backendUrl = backendBase.replace(/\/api$/, '');
@@ -261,12 +294,12 @@ function updateBenchCommandDisplay() {
// Copy bench command to clipboard
async function copyBenchCommand() {
const command = document.getElementById('benchCommand').textContent;
const success = await copyToClipboard(command);
const success = await utils.copyToClipboard(command);
if (success) {
showToast('Commande copiée dans le presse-papier !', 'success');
utils.showToast('Commande copiée dans le presse-papier !', 'success');
} else {
showToast('Erreur lors de la copie', 'error');
utils.showToast('Erreur lors de la copie', 'error');
}
}
@@ -292,7 +325,7 @@ function filterDevices(query) {
}
// Debounced search
const debouncedSearch = debounce((query) => {
const debouncedSearch = utils.debounce((query) => {
filterDevices(query);
}, 300);