ProxmoxAAS-Dashboard/scripts/index.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

import {requestPVE, goToPage, deleteAllCookies} from "./utils.js";
2022-12-11 02:02:29 +00:00
window.addEventListener("DOMContentLoaded", init);
async function init () {
2022-12-18 00:07:18 +00:00
await populateInstances();
let instances = document.querySelector("nav #instances");
instances.addEventListener("click", () => {
goToPage("index.html");
});
let logout = document.querySelector("nav #logout");
logout.addEventListener("click", () => {
deleteAllCookies();
goToPage("login.html");
});
2022-12-18 00:07:18 +00:00
}
async function populateInstances () {
2022-12-11 02:02:29 +00:00
let cookie = document.cookie;
2022-12-18 00:07:18 +00:00
if (cookie === "") {
2022-12-19 05:58:46 +00:00
goToPage("login.html");
2022-12-11 02:02:29 +00:00
}
let resources = await requestPVE("/cluster/resources", "GET", null);
2022-12-11 23:24:19 +00:00
2022-12-14 21:37:30 +00:00
let instanceContainer = document.getElementById("instance-container")
let instances = [];
resources.data.forEach((element) => {
if (element.type === "lxc" || element.type === "qemu") {
let nodeName = element.node;
let nodeStatus = resources.data.find(item => item.node === nodeName && item.type === "node").status;
element.node = {name: nodeName, status: nodeStatus};
instances.push(element);
}
});
2022-12-14 21:37:30 +00:00
instances.sort((a, b) => (a.vmid > b.vmid) ? 1 : -1);
2022-12-11 23:06:10 +00:00
2022-12-18 00:07:18 +00:00
instanceContainer.innerText = "";
2022-12-14 21:37:30 +00:00
for(let i = 0; i < instances.length; i++) {
let newInstance = document.createElement("instance-article");
newInstance.data = instances[i];
instanceContainer.append(newInstance);
2022-12-11 02:02:29 +00:00
}
}