From e7f7bd8ef1f59fcd4933a5691cfc8598e6e0f4c3 Mon Sep 17 00:00:00 2001
From: alfredo <alum.banyans0w@icloud.com>
Date: Sat, 26 Nov 2022 08:56:39 +0100
Subject: [PATCH] if only one service, pop up that service

---
 webserver/public/js/scriptIndex.js | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/webserver/public/js/scriptIndex.js b/webserver/public/js/scriptIndex.js
index 53d7ff6..9d25f3f 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
+}
-- 
GitLab