| MAC Address | -Signal Strength | -Rate(rx/tx) | -Bytes(rx/tx) | -|||
|---|---|---|---|---|---|---|
| Loading station data... | -||||||
| MAC Address | +Signal Strength | +Rate(rx/tx) | +Bytes(rx/tx) | +|||
|---|---|---|---|---|---|---|
| Loading station data... | +||||||
diff --git a/static/script.js b/static/script.js index fb4a610..ea0e132 100644 --- a/static/script.js +++ b/static/script.js @@ -3,131 +3,153 @@ const API_BASE_URL = '/api/v1/sta'; const REFRESH_INTERVAL = 2000; +const DETAILS_REFRESH_INTERVAL = + 1000; // Refresh selected station details more frequently let isRefreshing = false; +let selectedStation = null; +let detailsRefreshInterval = null; // DOM Elements const stationTableBody = document.getElementById('station-tbody'); const errorMessage = document.getElementById('error-message'); const lastUpdate = document.getElementById('last-update'); +const detailsPanel = document.getElementById('station-details-panel'); +const detailsContent = document.getElementById('station-details-content'); // Initialize the application document.addEventListener('DOMContentLoaded', function() { - // Load initial data - refreshStations(); - - setInterval(refreshStations, REFRESH_INTERVAL); + // Load initial data + refreshStations(); + + setInterval(refreshStations, REFRESH_INTERVAL); }); // Refresh station data async function refreshStations() { - if (isRefreshing) return; // Prevent concurrent refreshes - - isRefreshing = true; - - try { - // Fetch station list - const stations = await fetchStations(); - - if (stations.length === 0) { - showNoStations(); - } else { - // Fetch details for each station and populate table - await populateStationTable(stations); - } - - // Update last refresh time - lastUpdate.textContent = `Last update: ${new Date().toLocaleTimeString()}`; - - // Hide any previous error messages - hideError(); - - } catch (error) { - console.error('Error refreshing stations:', error); - showError('Failed to load station data. Please check if the API is running.'); - } finally { - isRefreshing = false; + if (isRefreshing) + return; // Prevent concurrent refreshes + + isRefreshing = true; + + try { + // Fetch station list + const stations = await fetchStations(); + + if (stations.length === 0) { + showNoStations(); + } else { + // Fetch details for each station and populate table + await populateStationTable(stations); } + + // Update last refresh time + lastUpdate.textContent = `Last update: ${new Date().toLocaleTimeString()}`; + + // Hide any previous error messages + hideError(); + + } catch (error) { + console.error('Error refreshing stations:', error); + showError( + 'Failed to load station data. Please check if the API is running.'); + } finally { + isRefreshing = false; + } } // Fetch list of connected stations async function fetchStations() { - const response = await fetch(`${API_BASE_URL}/list`); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - return await response.json(); + const response = await fetch(`${API_BASE_URL}/list`); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + return await response.json(); } // Populate table with station data async function populateStationTable(stations) { - // Process each station concurrently - const stationPromises = stations.map(async (mac) => { - try { - const details = await fetchStationDetails(mac); - return { mac, details, error: null }; - } catch (error) { - return { mac, details: null, error: error.message }; - } - }); - - const stationResults = await Promise.all(stationPromises); - - const rows = []; - // Add rows to table - stationResults.forEach(({ mac, details, error }) => { - const row = document.createElement('tr'); - - if (error) { - row.innerHTML = ` + // Process each station concurrently + const stationPromises = stations.map(async (mac) => { + try { + const details = await fetchStationDetails(mac); + return {mac, details, error : null}; + } catch (error) { + return {mac, details : null, error : error.message}; + } + }); + + const stationResults = await Promise.all(stationPromises); + + const rows = []; + // Add rows to table + stationResults.forEach(({mac, details, error}) => { + const row = document.createElement('tr'); + row.dataset.mac = mac; // Store MAC address for selection + + if (error) { + row.innerHTML = `
| MAC Address | -Signal Strength | -Rate(rx/tx) | -Bytes(rx/tx) | -|||
|---|---|---|---|---|---|---|
| Loading station data... | -||||||
| MAC Address | +Signal Strength | +Rate(rx/tx) | +Bytes(rx/tx) | +|||
|---|---|---|---|---|---|---|
| Loading station data... | +||||||