run instance population every second

This commit is contained in:
Arthur Lu 2022-12-17 16:07:18 -08:00
parent fcb28f0a9d
commit 4153d7f76c
3 changed files with 12 additions and 8 deletions

View File

@ -59,10 +59,8 @@ class Instance extends HTMLElement {
let powerButton = this.shadowElement.querySelector("#power-btn");
powerButton.src = data.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg";
powerButton.addEventListener("click", () => {
let targetState = this.status == "running" ? "shutdown" : "start";
let data = request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetState}`, "POST", {node: this.node, vmid: this.vmid});
console.log(data);
this.status = this.status === "running" ? "stopped" : "running";
let targetAction = this.status === "running" ? "shutdown" : "start";
request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid});
});
let configButton = this.shadowElement.querySelector("#configure-btn");

View File

@ -3,8 +3,13 @@ import {requestTicket, setTicket, request} from "./utils.js";
window.addEventListener("DOMContentLoaded", init);
async function init () {
await populateInstances();
setInterval(populateInstances, 1000);
}
async function populateInstances () {
let cookie = document.cookie;
if (cookie === '') {
if (cookie === "") {
window.location.href = "login.html";
}
@ -33,6 +38,7 @@ async function init () {
instances.sort((a, b) => (a.vmid > b.vmid) ? 1 : -1);
instanceContainer.innerText = "";
for(let i = 0; i < instances.length; i++) {
let newInstance = document.createElement("instance-article");
newInstance.data = instances[i];

View File

@ -15,13 +15,13 @@ export class NetworkError extends Error {
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
let ca = decodedCookie.split(";");
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
while (c.charAt(0) === " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}