// Linux BenchTools - Devices List Logic const { formatRelativeTime, createScoreBadge, getScoreBadgeText, escapeHtml, showError, showEmptyState, formatTags, debounce } = window.BenchUtils; const api = window.BenchAPI; let currentPage = 1; const pageSize = 20; let searchQuery = ''; let allDevices = []; // Load devices async function loadDevices() { const container = document.getElementById('devicesContainer'); try { const data = await api.getDevices({ page_size: 1000 }); // Get all for client-side filtering allDevices = data.items || []; if (allDevices.length === 0) { showEmptyState(container, 'Aucun device trouvé. Exécutez un benchmark sur une machine pour commencer.', '📊'); return; } renderDevices(); } catch (error) { console.error('Failed to load devices:', error); showError(container, 'Impossible de charger les devices. Vérifiez que le backend est accessible.'); } } // Filter devices based on search query function filterDevices() { if (!searchQuery) { return allDevices; } const query = searchQuery.toLowerCase(); return allDevices.filter(device => { const hostname = (device.hostname || '').toLowerCase(); const description = (device.description || '').toLowerCase(); const tags = (device.tags || '').toLowerCase(); const location = (device.location || '').toLowerCase(); return hostname.includes(query) || description.includes(query) || tags.includes(query) || location.includes(query); }); } // Render devices function renderDevices() { const container = document.getElementById('devicesContainer'); const filteredDevices = filterDevices(); if (filteredDevices.length === 0) { showEmptyState(container, 'Aucun device ne correspond à votre recherche.', '🔍'); return; } // Sort by global_score descending const sortedDevices = filteredDevices.sort((a, b) => { const scoreA = a.last_benchmark?.global_score ?? -1; const scoreB = b.last_benchmark?.global_score ?? -1; return scoreB - scoreA; }); // Pagination const startIndex = (currentPage - 1) * pageSize; const endIndex = startIndex + pageSize; const paginatedDevices = sortedDevices.slice(startIndex, endIndex); // Render device cards container.innerHTML = paginatedDevices.map(device => createDeviceCard(device)).join(''); // Render pagination renderPagination(filteredDevices.length); } // Create device card HTML function createDeviceCard(device) { const bench = device.last_benchmark; const globalScore = bench?.global_score; const cpuScore = bench?.cpu_score; const memScore = bench?.memory_score; const diskScore = bench?.disk_score; const netScore = bench?.network_score; const gpuScore = bench?.gpu_score; const runAt = bench?.run_at; const globalScoreHtml = globalScore !== null && globalScore !== undefined ? `${getScoreBadgeText(globalScore)}` : 'N/A'; return `