run instance population every second
This commit is contained in:
parent
e66cf54a2e
commit
d37b8a5bc0
@ -59,10 +59,8 @@ class Instance extends HTMLElement {
|
|||||||
let powerButton = this.shadowElement.querySelector("#power-btn");
|
let powerButton = this.shadowElement.querySelector("#power-btn");
|
||||||
powerButton.src = data.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg";
|
powerButton.src = data.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg";
|
||||||
powerButton.addEventListener("click", () => {
|
powerButton.addEventListener("click", () => {
|
||||||
let targetState = this.status == "running" ? "shutdown" : "start";
|
let targetAction = this.status === "running" ? "shutdown" : "start";
|
||||||
let data = request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetState}`, "POST", {node: this.node, vmid: this.vmid});
|
request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid});
|
||||||
console.log(data);
|
|
||||||
this.status = this.status === "running" ? "stopped" : "running";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let configButton = this.shadowElement.querySelector("#configure-btn");
|
let configButton = this.shadowElement.querySelector("#configure-btn");
|
||||||
|
@ -3,8 +3,13 @@ import {requestTicket, setTicket, request} from "./utils.js";
|
|||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
|
|
||||||
async function init () {
|
async function init () {
|
||||||
|
await populateInstances();
|
||||||
|
setInterval(populateInstances, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function populateInstances () {
|
||||||
let cookie = document.cookie;
|
let cookie = document.cookie;
|
||||||
if (cookie === '') {
|
if (cookie === "") {
|
||||||
window.location.href = "login.html";
|
window.location.href = "login.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +38,7 @@ async function init () {
|
|||||||
|
|
||||||
instances.sort((a, b) => (a.vmid > b.vmid) ? 1 : -1);
|
instances.sort((a, b) => (a.vmid > b.vmid) ? 1 : -1);
|
||||||
|
|
||||||
|
instanceContainer.innerText = "";
|
||||||
for(let i = 0; i < instances.length; i++) {
|
for(let i = 0; i < instances.length; i++) {
|
||||||
let newInstance = document.createElement("instance-article");
|
let newInstance = document.createElement("instance-article");
|
||||||
newInstance.data = instances[i];
|
newInstance.data = instances[i];
|
||||||
|
@ -15,13 +15,13 @@ export class NetworkError extends Error {
|
|||||||
function getCookie(cname) {
|
function getCookie(cname) {
|
||||||
let name = cname + "=";
|
let name = cname + "=";
|
||||||
let decodedCookie = decodeURIComponent(document.cookie);
|
let decodedCookie = decodeURIComponent(document.cookie);
|
||||||
let ca = decodedCookie.split(';');
|
let ca = decodedCookie.split(";");
|
||||||
for(let i = 0; i <ca.length; i++) {
|
for(let i = 0; i <ca.length; i++) {
|
||||||
let c = ca[i];
|
let c = ca[i];
|
||||||
while (c.charAt(0) == ' ') {
|
while (c.charAt(0) === " ") {
|
||||||
c = c.substring(1);
|
c = c.substring(1);
|
||||||
}
|
}
|
||||||
if (c.indexOf(name) == 0) {
|
if (c.indexOf(name) === 0) {
|
||||||
return c.substring(name.length, c.length);
|
return c.substring(name.length, c.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user