Skip to content
Snippets Groups Projects
Commit 9977bd25 authored by Elisa Giglio's avatar Elisa Giglio
Browse files

modificato RequestToDomain rendendo i metodi statici

parent a70f6ff7
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -2,11 +2,11 @@
import {createRowDomain} from '../templates/domains-template.js';
import { getToken, logoutKeycloak } from './script.js';
import {createNewUser, createNewService, createControlServices} from '../templates/create-new-domain-template.js';
import RequestToDomain from './requests-to-domain.js';
class App {
constructor(myDomains, requestsToDomain) {
constructor(myDomains) {
// this.myDomains = myDomains;
this.requestsToDomain = requestsToDomain;
this.showAllDomains(myDomains);
this.fillModal();
this.performLogout();
......@@ -27,10 +27,10 @@ class App {
container.insertBefore(tr, plusRow);
if(domainObject.admin) {
const toggle = tr.querySelector('.toggle-button');
this.statoDomainToggle(domainObject, toggle, this.requestsToDomain);
this.statoDomainToggle(domainObject, toggle);
const deleteDomain = tr.querySelector('.fa-trash');
deleteDomain.addEventListener('click', async () => {
const resultDelete = await this.requestsToDomain.deleteDomain(domainObject);
const resultDelete = await RequestToDomain.deleteDomain(domainObject);
if(resultDelete) {
container.removeChild(tr);
}
......@@ -42,14 +42,14 @@ class App {
}
statoDomainToggle(domain, toggle, requestsToDomain) {
statoDomainToggle(domain, toggle) {
toggle.addEventListener('click', async (event) => {
event.preventDefault();
const stop = toggle.classList.contains('active');
const linkDomain = toggle.parentElement.parentElement.previousElementSibling.querySelector('a');
if(stop) {
// toggle attiva. Se clicco richiedo che il dominio sia fermato
const resultStop = await requestsToDomain.stopDomain(domain);
const resultStop = await RequestToDomain.stopDomain(domain);
if(resultStop) {
toggle.classList.remove('active');
linkDomain.setAttribute('href','#');
......@@ -59,11 +59,11 @@ class App {
}
}
else {
const resultStart = await requestsToDomain.startDomain(domain);
const resultStart = await RequestToDomain.startDomain(domain);
if(resultStart) {
toggle.classList.add('active');
linkDomain.setAttribute('href','/secured/home/');
}
else {
throw new Error('Impossibile far partire il dominio, provare piu\' tardi');
......@@ -74,7 +74,7 @@ class App {
async fillModal() {
const allServices = await this.requestsToDomain.getAllServices();
const allServices = await RequestToDomain.getAllServices();
const div = document.createElement('div');
div.id = "checkbox-div";
div.classList.add('pt-4');
......@@ -221,7 +221,7 @@ class App {
};
cancelForm.click();
const resultInstall = await this.requestsToDomain.createNewDomain(json);
const resultInstall = await RequestToDomain.createNewDomain(json);
if(resultInstall) {
const domainCreated = {
nome: domainName,
......
......@@ -37,8 +37,8 @@ else if(uri.includes("#")){
if(token !== null) {
expirationTime = moment().add(token.expires_in,'s');
sessionStorage.setItem("expirationTime", expirationTime.toJSON());
const requestsToDomain = new RequestToDomain();
const myDomains = await requestsToDomain.getMyDomains();
const myDomains = await RequestToDomain.getMyDomains();
// const myDomains = [{nome: "casa1", stato:"on", admin: true},
// {nome: "casa2", stato:"off", admin: false},
// {nome: "casa3", stato:"off", admin: true},
......@@ -49,7 +49,7 @@ else if(uri.includes("#")){
// {nome: "casa4", stato:"on", admin: false}
// ];
const app = new App(myDomains, requestsToDomain);
const app = new App(myDomains);
}
}
} else if(uri.includes('/secured/home/')) {
......
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