Skip to content
Snippets Groups Projects
Commit a70f6ff7 authored by Alfredo Chissotti's avatar Alfredo Chissotti
Browse files

richieste servizi al domain e modifiche webapp

parent 2a848a51
No related branches found
No related tags found
No related merge requests found
...@@ -50,13 +50,13 @@ ...@@ -50,13 +50,13 @@
<!-- container of the top buttons to change what is seen --> <!-- container of the top buttons to change what is seen -->
<div id="mainButtonContainer" class="d-flex flex-row justify-content-around"> <div id="mainButtonContainer" class="d-flex flex-row justify-content-around">
<button class="btn-12 btn btn-dark"> <button class="btn-12 btn btn-dark" id="luci-btn">
<span>Luci</span> <span>Luci</span>
</button> </button>
<button class="btn-12 btn btn-dark"> <button class="btn-12 btn btn-dark" id="scenari-btn">
<span>Scenari</span> <span>Scenari</span>
</button> </button>
<button class="btn-12 btn btn-dark"> <button class="btn-12 btn btn-dark" id="antifurto-btn">
<span>Antifurto</span> <span>Antifurto</span>
</button> </button>
</div> </div>
......
...@@ -9,12 +9,12 @@ class RequestToDomain { ...@@ -9,12 +9,12 @@ class RequestToDomain {
/** /**
* Funzione per ottenenere dal domain manager tutte le informazioni * Funzione per ottenenere dal domain manager tutte le informazioni
* sui domini dell'utente che ha effettuato il login * sui domini dell'utente che ha effettuato il login
*/ */
async getMyDomains() { static async getMyDomains() {
const responseDomain = await fetch('http://localhost:3001/secured/domains', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager const responseDomain = await fetch('http://localhost:3001/secured/domains', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': `Bearer ${await getToken()}` 'Authorization': `Bearer ${await getToken()}`
} }
...@@ -26,7 +26,7 @@ class RequestToDomain { ...@@ -26,7 +26,7 @@ class RequestToDomain {
Domain.from(d) Domain.from(d)
}); });
return myDomains; return myDomains;
} }
else else
throw domainsJson; throw domainsJson;
} }
...@@ -35,10 +35,10 @@ class RequestToDomain { ...@@ -35,10 +35,10 @@ class RequestToDomain {
/** /**
* Effettua la richiesta per creare un nuovo dominio. * Effettua la richiesta per creare un nuovo dominio.
* @param {*} json descrizione json del dominio che si vuole creare. * @param {*} json descrizione json del dominio che si vuole creare.
* @returns true se il dominio &egrave; stato creato, * @returns true se il dominio &egrave; stato creato,
* false altrimenti. * false altrimenti.
*/ */
async createNewDomain(json) { static async createNewDomain(json) {
const response = await fetch('http://localhost:3001/install', { const response = await fetch('http://localhost:3001/install', {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -56,12 +56,12 @@ class RequestToDomain { ...@@ -56,12 +56,12 @@ class RequestToDomain {
/** /**
* Effettua la richiesta al domain manager per ottenere tutti i sevizi * Effettua la richiesta al domain manager per ottenere tutti i sevizi
* disponibili. * disponibili.
*/ */
async getAllServices() { static async getAllServices() {
const responseDomain = await fetch('http://localhost:3001/secured/services', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager const responseDomain = await fetch('http://localhost:3001/secured/services', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': `Bearer ${await getToken()}` 'Authorization': `Bearer ${await getToken()}`
} }
...@@ -70,19 +70,19 @@ class RequestToDomain { ...@@ -70,19 +70,19 @@ class RequestToDomain {
if(responseDomain.ok) { if(responseDomain.ok) {
const servicesArray = servicesJson.response; const servicesArray = servicesJson.response;
return servicesArray; return servicesArray;
} }
else else
throw servicesJson; throw servicesJson;
} }
/** /**
* Effettua la richiesta al domain manager per far partire un dominio. * Effettua la richiesta al domain manager per far partire un dominio.
* @param {*} d dominio che si vuole far partire. * @param {*} d dominio che si vuole far partire.
* @returns true se il dominio &egrave; stato fatto partire, * @returns true se il dominio &egrave; stato fatto partire,
* false altrimenti. * false altrimenti.
*/ */
async startDomain(d) { static async startDomain(d) {
const response = await fetch('http://localhost:3001/start', { const response = await fetch('http://localhost:3001/start', {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -102,10 +102,10 @@ class RequestToDomain { ...@@ -102,10 +102,10 @@ class RequestToDomain {
/** /**
* Effettua la richiesta al domain manager per fermare un dominio. * Effettua la richiesta al domain manager per fermare un dominio.
* @param {*} d dominio che si vuole fermare. * @param {*} d dominio che si vuole fermare.
* @returns true se il dominio &egrave; stato fermato, * @returns true se il dominio &egrave; stato fermato,
* false altrimenti. * false altrimenti.
*/ */
async stopDomain(d) { static async stopDomain(d) {
const response = await fetch('http://localhost:3001/stop', { const response = await fetch('http://localhost:3001/stop', {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -125,10 +125,10 @@ class RequestToDomain { ...@@ -125,10 +125,10 @@ class RequestToDomain {
/** /**
* Effettua la richiesta al domain manager per cancellare un dominio. * Effettua la richiesta al domain manager per cancellare un dominio.
* @param {*} d dominio che si vuole cancellare. * @param {*} d dominio che si vuole cancellare.
* @returns true se la cancellazione &egrave; andata a buon fine, * @returns true se la cancellazione &egrave; andata a buon fine,
* false altrimenti. * false altrimenti.
*/ */
async deleteDomain(d) { static async deleteDomain(d) {
const response = await fetch('http://localhost:3001/delete', { const response = await fetch('http://localhost:3001/delete', {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -141,7 +141,27 @@ class RequestToDomain { ...@@ -141,7 +141,27 @@ class RequestToDomain {
} }
else { else {
return false; return false;
} }
}
/**
* Effettua la richiesta al domain manager per ottenere tutti i servizi in uso dal dominio
* @param {*} domain
* @returns
*/
static async getUsedServices(domain) {
const response = await fetch(`http://localhost:3001/secured/services?domain=${domain}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${await getToken()}`
}
});
const servicesJson = await response.json();//{response: ["servizio1", "servizio2"]};
if(response.ok) {
return servicesJson.response;
}
else
throw servicesJson;
} }
} }
......
"use strict"; "use strict";
import Luci from './luci.js'; import { logoutKeycloak } from './authentication/script.js';//qui lo script si prende il token
import Scenari from "./scenari.js"; import RequestToDomain from './authentication/requests-to-domain.js';
import Antifurto from "./antifurto.js";
import Sensori from './sensori.js'; import Sensori from './sensori.js';
import { logoutKeycloak } from './authentication/script.js'; import Antifurto from "./antifurto.js";
import Scenari from "./scenari.js";
// launch each class import Luci from './luci.js';
new Sensori();
new Antifurto();
new Scenari();
setTimeout(() => {
new Luci();
}, 1000);
const logout = document.getElementById("button-logout"); const logout = document.getElementById("button-logout");
logout.addEventListener('click', () => { logout.addEventListener('click', () => {
logoutKeycloak(); logoutKeycloak();
}); });
\ No newline at end of file
// 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');
}
\ 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