diff --git a/webserver/public/js/scriptIndex.js b/webserver/public/js/scriptIndex.js index 53d7ff6601859314321767805987294a1ee884a9..9d25f3fe9b0c391b7a19727bf5248f8e7f1706ba 100644 --- a/webserver/public/js/scriptIndex.js +++ b/webserver/public/js/scriptIndex.js @@ -16,18 +16,22 @@ const userPriviledges = await RequestToDomain.getUserPriviledges(domain);// "adm const boolArray = [false, false, false]; let atLeastOneOfOurServices = false; +let countOurServices = 0; for (const service of servicesArray) { if (service === 'antifurto') { boolArray[0] = true; atLeastOneOfOurServices = true; + countOurServices++; } else if (service === 'scenari') { boolArray[1] = true; atLeastOneOfOurServices = true; + countOurServices++; } else if (service === 'luci') { boolArray[2] = true; atLeastOneOfOurServices = true; + countOurServices++; } } @@ -42,30 +46,34 @@ if (!atLeastOneOfOurServices) { new api.default(boolArray); const sensori = await import('./sensori.js'); new sensori.default(); + let usedIfOnlyOneService = null; // launch each class if (boolArray[0]){ const antifurto = await import("./antifurto.js"); new antifurto.default([boolArray[1],boolArray[2]]); antifurtoBtn.classList.remove('invisible'); + usedIfOnlyOneService = 'antifurto'; } if (boolArray[1]){ const scenari = await import("./scenari.js"); new scenari.default([boolArray[0],boolArray[2]]); scenariBtn.classList.remove('invisible'); + usedIfOnlyOneService = 'scenari'; } if (boolArray[2]){ const luci = await import('./luci.js'); new luci.default([boolArray[0],boolArray[1]]); luciBtn.classList.remove('invisible'); + usedIfOnlyOneService = 'luci'; } // if there is only one service, click the related button // search if there's only one true in the boolArray - if (servicesArray.length === 1) { - const btn = document.getElementById(`${servicesArray[0]}-btn`); + if (countOurServices === 1) { + const btn = document.getElementById(`${usedIfOnlyOneService}-btn`); btn.click(); // btn.classList.add('invisible'); } @@ -75,4 +83,4 @@ if (!atLeastOneOfOurServices) { const admin = await import('./adminControls.js'); new admin.default(); } -} \ No newline at end of file +}