From bb0657921987df51c893313eb23cbd4588426f0c Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Sun, 11 Dec 2022 15:06:10 -0800 Subject: [PATCH] add qemu and lxc instance populating --- index.js | 10 +++++----- node.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 63c94e9..9bb7f01 100644 --- a/index.js +++ b/index.js @@ -16,12 +16,12 @@ async function init () { for (let i = 0; i < nodes.data.length; i++) { let newNode = document.createElement("node-card"); newNode.data = nodes.data[i]; - nodeContainer.append(newNode); + let qemu = await request(`/nodes/${nodes.data[i].node}/qemu`, "GET", null); let lxc = await request(`/nodes/${nodes.data[i].node}/lxc`, "GET", null); - console.log(`${nodes.data[i].node} quemu:`); - console.log(qemu); - console.log(`${nodes.data[i].node} lxc:`); - console.log(lxc); + newNode.qemu = qemu; + newNode.lxc = lxc; + + nodeContainer.append(newNode); } } \ No newline at end of file diff --git a/node.js b/node.js index 62f816a..e25e118 100644 --- a/node.js +++ b/node.js @@ -27,6 +27,30 @@ class Node extends HTMLElement { onlineLabel.style.color = data.status === "online" ? "#00ff00" : "#ff0000"; articleElement.append(onlineLabel); } + + set qemu (qemu) { + let articleElement = this.shadowElement.querySelector("article"); + + let qemuDiv = document.createElement("div"); + for (let i = 0; i < qemu.length; i++) { + let instanceParagraph = document.createElement("p"); + instanceParagraph.innerText = `${qemu[i].vmid}: ${qemu[i].name}`; + qemuDiv.append(instanceParagraph); + } + articleElement.append(qemuDiv); + } + + set lxc (lxc) { + let articleElement = this.shadowElement.querySelector("article"); + + let lxcDiv = document.createElement("div"); + for (let i = 0; i < lxc.length; i++) { + let instanceParagraph = document.createElement("p"); + instanceParagraph.innerText = `${lxc[i].vmid}: ${lxc[i].name}`; + lxcDiv.append(instanceParagraph); + } + articleElement.append(lxcDiv); + } } customElements.define("node-card", Node); \ No newline at end of file