// app_config.js const socket = io(); const btnOrgs = document.getElementById('btnOrgs'); const btnTeams = document.getElementById('btnTeams'); const btnStatus = document.getElementById('btnStatus'); const btnPriority = document.getElementById('btnPriority'); const btnArduino = document.getElementById('btnArduino'); const statusMessage = document.getElementById('statusMessage'); let statusReceived = false; // Arduino does not depend on the API — always enabled btnArduino.disabled = false; btnArduino.style.opacity = "1"; btnArduino.style.cursor = "pointer"; btnArduino.onclick = () => { window.location.href = 'Arduino.html'; }; // Listen for the status data from WebIndex.py socket.on("api_status_data", (data) => { console.log("Status received:", data); statusReceived = true; if (data && data.ready) { // API is Ready btnOrgs.disabled = false; btnOrgs.style.opacity = "1"; btnOrgs.style.cursor = "pointer"; btnOrgs.onclick = () => { window.location.href = 'Organizations.html'; }; btnTeams.disabled = false; btnTeams.style.opacity = "1"; btnTeams.style.cursor = "pointer"; btnTeams.onclick = () => { window.location.href = 'Teams.html'; }; btnStatus.disabled = false; btnStatus.style.opacity = "1"; btnStatus.style.cursor = "pointer"; btnStatus.onclick = () => { window.location.href = 'Status.html'; }; btnPriority.disabled = false; btnPriority.style.opacity = "1"; btnPriority.style.cursor = "pointer"; btnPriority.onclick = () => { window.location.href = 'Priority.html'; }; btnCriticity.disabled = false; btnCriticity.style.opacity = "1"; btnCriticity.style.cursor = "pointer"; btnCriticity.onclick = () => { window.location.href = 'Criticity.html'; }; statusMessage.textContent = ""; } else { // API not configured btnOrgs.disabled = true; btnOrgs.style.opacity = "0.5"; btnOrgs.style.cursor = "not-allowed"; btnTeams.disabled = true; btnTeams.style.opacity = "0.5"; btnTeams.style.cursor = "not-allowed"; btnStatus.disabled = true; btnStatus.style.opacity = "0.5"; btnStatus.style.cursor = "not-allowed"; btnPriority.disabled = true; btnPriority.style.opacity = "0.5"; btnPriority.style.cursor = "not-allowed"; btnCriticity.disabled = true; btnCriticity.style.opacity = "0.5"; btnCriticity.style.cursor = "not-allowed"; statusMessage.textContent = "Please configure API"; } }); // Retry logic: Ask every second until we get an answer const checkInterval = setInterval(() => { if (!statusReceived) { console.log("Probing API status..."); socket.emit("get_api_status", {}); } else { clearInterval(checkInterval); } }, 1000); // Also try once immediately on load document.addEventListener('DOMContentLoaded', () => { socket.emit("get_api_status", {}); });