use templates to streamline instance creation
This commit is contained in:
parent
36b86e4edb
commit
77673e80fe
@ -4,7 +4,7 @@ article {
|
|||||||
margin: 0px;
|
margin: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.instance-div {
|
.summary-div {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
16
index.html
16
index.html
@ -11,4 +11,20 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="instance-container" class="center-div"></div>
|
<div id="instance-container" class="center-div"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
<template id="instance-template">
|
||||||
|
<article>
|
||||||
|
<div class="summary-div">
|
||||||
|
<div class="summary-sub-div">
|
||||||
|
<img id="instance-type">
|
||||||
|
<p id="instance-id"></p>
|
||||||
|
<p id="instance-name"></p>
|
||||||
|
</div>
|
||||||
|
<div class="summary-sub-div">
|
||||||
|
<img id="node-status">
|
||||||
|
<p id="node-name"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
</html>
|
</html>
|
@ -3,8 +3,9 @@ class Instance extends HTMLElement {
|
|||||||
super();
|
super();
|
||||||
let shadowRoot = this.attachShadow({mode: "open"});
|
let shadowRoot = this.attachShadow({mode: "open"});
|
||||||
|
|
||||||
let instanceArticle = document.createElement("article");
|
let instanceTemplate = document.querySelector("#instance-template");
|
||||||
shadowRoot.append(instanceArticle);
|
let instanceTemplateContent = instanceTemplate.textContent;
|
||||||
|
shadowRoot.append(instanceTemplateContent.cloneNode(true));
|
||||||
|
|
||||||
let styleLink = document.createElement("link");
|
let styleLink = document.createElement("link");
|
||||||
styleLink.rel = "stylesheet";
|
styleLink.rel = "stylesheet";
|
||||||
@ -24,40 +25,20 @@ class Instance extends HTMLElement {
|
|||||||
set data (data) {
|
set data (data) {
|
||||||
let instanceArticle = this.shadowElement.querySelector("article");
|
let instanceArticle = this.shadowElement.querySelector("article");
|
||||||
|
|
||||||
let summaryDiv = document.createElement("div");
|
let typeImg = document.querySelector("#instance-type");
|
||||||
summaryDiv.classList.add("instance-div");
|
|
||||||
|
|
||||||
let instanceSubDiv = document.createElement("div");
|
|
||||||
instanceSubDiv.classList.add("summary-sub-div");
|
|
||||||
|
|
||||||
let typeImg = document.createElement("img");
|
|
||||||
typeImg.src = `images/instances/${data.type}/${data.status}.svg`;
|
typeImg.src = `images/instances/${data.type}/${data.status}.svg`;
|
||||||
instanceSubDiv.append(typeImg);
|
|
||||||
|
|
||||||
let vmidParagraph = document.createElement("p");
|
let vmidParagraph = document.querySelector("#instance-id");
|
||||||
vmidParagraph.innerText = data.vmid;
|
vmidParagraph.innerText = data.vmid;
|
||||||
instanceSubDiv.append(vmidParagraph);
|
|
||||||
|
|
||||||
let nameParagraph = document.createElement("p");
|
let nameParagraph = document.querySelector("#instance-name");
|
||||||
nameParagraph.innerText = data.name;
|
nameParagraph.innerText = data.name;
|
||||||
instanceSubDiv.append(nameParagraph);
|
|
||||||
|
|
||||||
summaryDiv.append(instanceSubDiv);
|
let nodeImg = document.querySelector("#node-status");
|
||||||
|
|
||||||
let nodeSubDiv = document.createElement("div");
|
|
||||||
nodeSubDiv.classList.add("summary-sub-div");
|
|
||||||
|
|
||||||
let nodeImg = document.createElement("img");
|
|
||||||
nodeImg.src = `images/nodes/${data.node.status}.svg`;
|
nodeImg.src = `images/nodes/${data.node.status}.svg`;
|
||||||
nodeSubDiv.append(nodeImg);
|
|
||||||
|
|
||||||
let nodeParagraph = document.createElement("p");
|
let nodeParagraph = document.querySelector("#node-name");
|
||||||
nodeParagraph.innerText = data.node.name;
|
nodeParagraph.innerText = data.node.name;
|
||||||
nodeSubDiv.append(nodeParagraph);
|
|
||||||
|
|
||||||
summaryDiv.append(nodeSubDiv);
|
|
||||||
|
|
||||||
instanceArticle.append(summaryDiv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user