diff --git a/ccp/js/infrastructurelistcontroller.js b/ccp/js/infrastructurelistcontroller.js index 601c231..bb2b9b8 100644 --- a/ccp/js/infrastructurelistcontroller.js +++ b/ccp/js/infrastructurelistcontroller.js @@ -2,7 +2,52 @@ class CCPInfrastructureList extends HTMLElement{ #boot; #socket; - #data = {}; + #infrastructures; + #runtimes; + #rootdoc; + + #style = ` + + + + `; #serviceurl = "https://nubis1.int.d4science.net:8080" #broadcasturl = "ws://nubis1.int.d4science.net:8989/ws/notification" @@ -10,61 +55,181 @@ class CCPInfrastructureList extends HTMLElement{ constructor(){ super() this.#boot = document.querySelector("d4s-boot-2") + this.#rootdoc = this.attachShadow({ "mode" : "open"}) } connectedCallback(){ - this.fetchInfrastructures() - } - - get data(){ - return this.#data + this.connectBroadcast() + this.fetchInfrastructures() } fetchInfrastructures(){ - console.log("Calling fetch infrastructures") - this.#boot.secureFetch(this.#serviceurl + "/infrastructures/cache"). - then(resp=>{ - return resp.json() - }).then(data=>{ - this.#data = data - /*this.updateList()*/ - }).catch(err=>{ - alert("Error while downloading methods: ", err) + const prom1 = this.#boot.secureFetch(this.#serviceurl + "/infrastructures/cache"). + then(resp=>{ + if(resp.status !== 200) throw "Unable to fetch infrastructure cache"; + return resp.json() + }).then(data=>{ + this.#infrastructures = data + }).catch(err=>{ + alert(err) + }) + + const prom2 = this.#boot.secureFetch(this.#serviceurl + "/runtimes"). + then(resp=>{ + if(resp.status !== 200) throw "Unable to fetch runtimes"; + return resp.json() + }).then(data=>{ + this.#runtimes = data + }).catch(err=>{ + alert(err) + }) + + Promise.all([prom1, prom2]).then(results=>{ + this.showList() + }) + } + + refreshInfrastructures(){ + this.#boot.secureFetch(this.#serviceurl + "/infrastructures/cache", { method : "HEAD"}) + } + + showList(){ + if(this.getAttribute("render") !== "true") { + this.#rootdoc.innerHTML = "" + return; + } + this.#rootdoc.innerHTML = ` +