Skip to content
Snippets Groups Projects
Commit e7f7bd8e authored by alfredo's avatar alfredo
Browse files

if only one service, pop up that service

parent 64870a58
No related branches found
No related tags found
No related merge requests found
...@@ -16,18 +16,22 @@ const userPriviledges = await RequestToDomain.getUserPriviledges(domain);// "adm ...@@ -16,18 +16,22 @@ const userPriviledges = await RequestToDomain.getUserPriviledges(domain);// "adm
const boolArray = [false, false, false]; const boolArray = [false, false, false];
let atLeastOneOfOurServices = false; let atLeastOneOfOurServices = false;
let countOurServices = 0;
for (const service of servicesArray) { for (const service of servicesArray) {
if (service === 'antifurto') { if (service === 'antifurto') {
boolArray[0] = true; boolArray[0] = true;
atLeastOneOfOurServices = true; atLeastOneOfOurServices = true;
countOurServices++;
} }
else if (service === 'scenari') { else if (service === 'scenari') {
boolArray[1] = true; boolArray[1] = true;
atLeastOneOfOurServices = true; atLeastOneOfOurServices = true;
countOurServices++;
} }
else if (service === 'luci') { else if (service === 'luci') {
boolArray[2] = true; boolArray[2] = true;
atLeastOneOfOurServices = true; atLeastOneOfOurServices = true;
countOurServices++;
} }
} }
...@@ -42,30 +46,34 @@ if (!atLeastOneOfOurServices) { ...@@ -42,30 +46,34 @@ if (!atLeastOneOfOurServices) {
new api.default(boolArray); new api.default(boolArray);
const sensori = await import('./sensori.js'); const sensori = await import('./sensori.js');
new sensori.default(); new sensori.default();
let usedIfOnlyOneService = null;
// launch each class // launch each class
if (boolArray[0]){ if (boolArray[0]){
const antifurto = await import("./antifurto.js"); const antifurto = await import("./antifurto.js");
new antifurto.default([boolArray[1],boolArray[2]]); new antifurto.default([boolArray[1],boolArray[2]]);
antifurtoBtn.classList.remove('invisible'); antifurtoBtn.classList.remove('invisible');
usedIfOnlyOneService = 'antifurto';
} }
if (boolArray[1]){ if (boolArray[1]){
const scenari = await import("./scenari.js"); const scenari = await import("./scenari.js");
new scenari.default([boolArray[0],boolArray[2]]); new scenari.default([boolArray[0],boolArray[2]]);
scenariBtn.classList.remove('invisible'); scenariBtn.classList.remove('invisible');
usedIfOnlyOneService = 'scenari';
} }
if (boolArray[2]){ if (boolArray[2]){
const luci = await import('./luci.js'); const luci = await import('./luci.js');
new luci.default([boolArray[0],boolArray[1]]); new luci.default([boolArray[0],boolArray[1]]);
luciBtn.classList.remove('invisible'); luciBtn.classList.remove('invisible');
usedIfOnlyOneService = 'luci';
} }
// if there is only one service, click the related button // if there is only one service, click the related button
// search if there's only one true in the boolArray // search if there's only one true in the boolArray
if (servicesArray.length === 1) { if (countOurServices === 1) {
const btn = document.getElementById(`${servicesArray[0]}-btn`); const btn = document.getElementById(`${usedIfOnlyOneService}-btn`);
btn.click(); btn.click();
// btn.classList.add('invisible'); // btn.classList.add('invisible');
} }
...@@ -75,4 +83,4 @@ if (!atLeastOneOfOurServices) { ...@@ -75,4 +83,4 @@ if (!atLeastOneOfOurServices) {
const admin = await import('./adminControls.js'); const admin = await import('./adminControls.js');
new admin.default(); new admin.default();
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment