Skip to content
Snippets Groups Projects
scriptIndex.js 1.56 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alfredo Chissotti's avatar
    Alfredo Chissotti committed
    "use strict";
    
    import { logoutKeycloak } from './authentication/script.js';//qui lo script si prende il token
    import RequestToDomain from './authentication/requests-to-domain.js';
    
    Alfredo Chissotti's avatar
    Alfredo Chissotti committed
    import Sensori from './sensori.js';
    
    import Antifurto from "./antifurto.js";
    import Scenari from "./scenari.js";
    import Luci from './luci.js';
    
    Elisa Giglio's avatar
    Elisa Giglio committed
    
    
    
    const logout = document.getElementById("button-logout");
    logout.addEventListener('click', () => {
        logoutKeycloak();
    
    });
    
    // ask domain to know which service should be used
    const servicesArray = await RequestToDomain.getUsedServices();
    
    new Sensori();
    const boolArray = [false,false,false];
    
    for(const service of servicesArray) {
        if(service === 'antifurto') {
            boolArray[0] = true;
        }
        else if(service === 'scenari') {
            boolArray[1] = true;
        }
        else if(service === 'luci') {
            boolArray[2] = true;
        }
    }
    
    // launch each class
    const antifurtobtn = document.getElementById("antifurto-btn");
    if(boolArray[0])
        new Antifurto();
    else {
        antifurtobtn.classList.add('invisible');
    }
    
    
    const scenariBtn = document.getElementById("scenari-btn");
    if(boolArray[1])
        new Scenari();
    else {
        scenariBtn.classList.add('invisible');
    }
    
    const luciBtn = document.getElementById("luci-btn");
    if(boolArray[2])
        new Luci();
    else {
        luciBtn.classList.add('invisible');
    }
    
    // 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`);
        btn.click();
        // btn.classList.add('invisible');
    }