From 76d527215bbf6e381e1be28f92c966723b587b07 Mon Sep 17 00:00:00 2001 From: dcore94 Date: Tue, 28 Mar 2023 16:05:16 +0200 Subject: [PATCH] refactored code --- ccp/js/infrastructurelistcontroller.js | 130 +++---------------------- 1 file changed, 13 insertions(+), 117 deletions(-) diff --git a/ccp/js/infrastructurelistcontroller.js b/ccp/js/infrastructurelistcontroller.js index 5d76d17..0aef439 100644 --- a/ccp/js/infrastructurelistcontroller.js +++ b/ccp/js/infrastructurelistcontroller.js @@ -4,49 +4,26 @@ class CCPInfrastructureList extends HTMLElement{ #socket; #interval = null; #infrastructures; - #runtimes; #rootdoc; #style = ` - + `; @@ -81,20 +58,6 @@ class CCPInfrastructureList extends HTMLElement{ }).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(){ @@ -107,15 +70,8 @@ class CCPInfrastructureList extends HTMLElement{ return; } this.#rootdoc.innerHTML = ` -
- - - +
+ ${this.#style}
@@ -145,24 +101,12 @@ class CCPInfrastructureList extends HTMLElement{ break; } }) - - /*const forms = Array.prototype.slice.call(this.#rootdoc.querySelectorAll(".ccp_runtime_builder")) - forms.forEach(f=>{ - f.addEventListener("submit", ev=>{ - ev.stopPropagation() - ev.preventDefault() - const sel = ev.target.querySelector("select") - let url = ev.target.action + sel.value - this.#boot.secureFetch(url, { method : ev.target.method}) - return false - }) - })*/ } showInfrastructures(){ return this.#infrastructures.map(i => { return ` -
  • +
  • ${i.name} @@ -175,46 +119,6 @@ class CCPInfrastructureList extends HTMLElement{ }).join("\n") } - /* showDeployableRuntimes(infra){ - const alreadydeployed = infra.runtimes.map(r=>r["descriptor-id"]) - infra.available_runtimes = infra.available_runtimes ? infra.available_runtimes : [] - const options = infra.available_runtimes.filter(r=>{ - return infra.type === r.type && alreadydeployed.indexOf(r.id) === -1 - }).map(r=>{ - return `` - }).join("\n") - return ` -
    -
    - - -
    -
    - ` - } - - showRuntimes(infra){ - return infra.runtimes.map(r =>{ - return ` -
  • -
    - ${r.name} -
    -
  • - ` - }).join("\n") - } - - showInstances(runtime){ - return runtime.instances.map(i =>{ - return ` -
  • ${i.name}
  • - ` - }).join("\n") - }*/ - showAge(infra){ const age = Math.floor(((new Date()) - (new Date(infra.date))) / 3600000) var cls = "badge-success" @@ -230,7 +134,9 @@ class CCPInfrastructureList extends HTMLElement{ } showType(infra){ - return `${infra.type}` + const t = infra.type.match(/docker/i) ? "docker" : null + const t2 = !t && infra.type.match(/lxd/i) ? "lxd" : t + return `${infra.type}` } connectBroadcast(){ @@ -248,16 +154,6 @@ class CCPInfrastructureList extends HTMLElement{ } }, 30000) } - - /*getCompatibleRuntimes(rts){ - const available = Object.keys(this.#infrastructures).reduce((acc, i) => { - const compatiblerts = this.#infrastructures[i].runtimes. - filter(r=>rts.indexOf(r["descriptor-id"]) >= 0). - map(cr=>{ return { runtime : cr, infrastructure : this.#infrastructures[i] } }) - return acc.concat(compatiblerts) - }, []) - return available - }*/ } -window.customElements.define('d4s-ccp-infrastructurelist', CCPInfrastructureList); +window.customElements.define('d4s-ccp-infrastructurelist', CCPInfrastructureList); \ No newline at end of file