finish renaming,
improve search bar and add instance responsiveness
This commit is contained in:
parent
6d9b5279fb
commit
6d8ac3181b
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>proxmox - client</title>
|
<title>proxmox - dashboard</title>
|
||||||
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>proxmox - client</title>
|
<title>proxmox - dashboard</title>
|
||||||
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
38
index.html
38
index.html
@ -3,13 +3,14 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>proxmox - client</title>
|
<title>proxmox - dashboard</title>
|
||||||
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
<link rel="stylesheet" href="css/nav.css">
|
<link rel="stylesheet" href="css/nav.css">
|
||||||
<link rel="stylesheet" href="css/form.css">
|
<link rel="stylesheet" href="css/form.css">
|
||||||
<script src="scripts/index.js" type="module"></script>
|
<script src="scripts/index.js" type="module"></script>
|
||||||
|
<script src="scripts/instance.js" type="module"></script>
|
||||||
<style>
|
<style>
|
||||||
#instance-container > div {
|
#instance-container > div {
|
||||||
border-bottom: 1px solid white;
|
border-bottom: 1px solid white;
|
||||||
@ -17,6 +18,28 @@
|
|||||||
#instance-container > div:last-child {
|
#instance-container > div:last-child {
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
|
@media screen and (width >= 440px) {
|
||||||
|
#vm-search {
|
||||||
|
max-width: calc(100% - 10px - 152px);
|
||||||
|
}
|
||||||
|
button .large {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
button .small {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media screen and (width <= 440px) {
|
||||||
|
#vm-search {
|
||||||
|
max-width: calc(100% - 10px - 47px);
|
||||||
|
}
|
||||||
|
button .large {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
button .small {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -35,12 +58,15 @@
|
|||||||
<section class="w3-container">
|
<section class="w3-container">
|
||||||
<h2>Instances</h2>
|
<h2>Instances</h2>
|
||||||
<div class="w3-card w3-padding">
|
<div class="w3-card w3-padding">
|
||||||
<div class="flex row nowrap" style="justify-content: space-between;">
|
<div class="flex row nowrap" style="margin-top: 1em; justify-content: space-between;">
|
||||||
<form role="search" class="flex row nowrap">
|
<form id="vm-search" role="search" class="flex row nowrap">
|
||||||
<img src="images/static/search.svg">
|
<img src="images/static/search.svg" alt="Search VMs">
|
||||||
<input type="search" id="search" class="w3-input w3-border" style="height: 1lh;">
|
<input type="search" id="search" class="w3-input w3-border" style="height: 1lh; max-width: fit-content;">
|
||||||
</form>
|
</form>
|
||||||
<button type="button" id="instance-add" class="w3-button">Create Instance</button>
|
<button type="button" id="instance-add" class="w3-button" aria-label="Create New Instance">
|
||||||
|
<span class="large" style="margin: 0;">Create Instance</span>
|
||||||
|
<img class="small" style="height: 1lh; width: 1lh;" src="images/actions/instance/add.svg" alt="Create New Instance">
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="instance-container"></div>
|
<div id="instance-container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>proxmox - client</title>
|
<title>proxmox - dashboard</title>
|
||||||
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "proxmoxaas-client",
|
"name": "proxmoxaas-dashboard",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Front-end for ProxmoxAAS",
|
"description": "Front-end for ProxmoxAAS",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
232
scripts/index.js
232
scripts/index.js
@ -1,6 +1,5 @@
|
|||||||
import { requestPVE, requestAPI, goToPage, goToURL, instancesConfig, nodesConfig, setTitleAndHeader } from "./utils.js";
|
import { requestPVE, requestAPI, goToPage, setTitleAndHeader } from "./utils.js";
|
||||||
import { alert, dialog } from "./dialog.js";
|
import { alert, dialog } from "./dialog.js";
|
||||||
import { PVE } from "../vars.js";
|
|
||||||
import { setupClientSync } from "./clientsync.js";
|
import { setupClientSync } from "./clientsync.js";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
@ -12,10 +11,13 @@ async function init () {
|
|||||||
goToPage("login.html");
|
goToPage("login.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
const addInstanceBtn = document.querySelector("#instance-add");
|
document.querySelector("#instance-add").addEventListener("click", handleInstanceAdd);
|
||||||
addInstanceBtn.addEventListener("click", handleInstanceAdd);
|
|
||||||
|
|
||||||
setupClientSync(populateInstances);
|
setupClientSync(populateInstances);
|
||||||
|
|
||||||
|
document.querySelector("#vm-search").addEventListener("input", () => {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populateInstances () {
|
async function populateInstances () {
|
||||||
@ -197,225 +199,3 @@ async function handleInstanceAdd () {
|
|||||||
d.querySelector("#vmid").min = userCluster.vmid.min;
|
d.querySelector("#vmid").min = userCluster.vmid.min;
|
||||||
d.querySelector("#vmid").max = userCluster.vmid.max;
|
d.querySelector("#vmid").max = userCluster.vmid.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
class InstanceCard extends HTMLElement {
|
|
||||||
constructor () {
|
|
||||||
super();
|
|
||||||
this.attachShadow({ mode: "open" });
|
|
||||||
this.shadowRoot.innerHTML = `
|
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
|
||||||
<link rel="stylesheet" href="css/style.css">
|
|
||||||
<div class="w3-row">
|
|
||||||
<div class="w3-col l1 m2 s6">
|
|
||||||
<p id="instance-id"></p>
|
|
||||||
</div>
|
|
||||||
<div class="w3-col l2 m3 s6">
|
|
||||||
<p id="instance-name"></p>
|
|
||||||
</div>
|
|
||||||
<div class="w3-col l1 m2 w3-hide-small">
|
|
||||||
<p id="instance-type"></p>
|
|
||||||
</div>
|
|
||||||
<div class="w3-col l2 m3 s6 flex row nowrap">
|
|
||||||
<img id="instance-status-icon">
|
|
||||||
<p id="instance-status"></p>
|
|
||||||
</div>
|
|
||||||
<div class="w3-col l2 w3-hide-medium w3-hide-small">
|
|
||||||
<p id="node-name"></p>
|
|
||||||
</div>
|
|
||||||
<div class="w3-col l2 w3-hide-medium w3-hide-small flex row nowrap">
|
|
||||||
<img id="node-status-icon">
|
|
||||||
<p id="node-status"></p>
|
|
||||||
</div>
|
|
||||||
<div class="w3-col l2 m2 s6 flex row nowrap" style="height: 1lh; margin-top: 15px; margin-bottom: 15px;">
|
|
||||||
<img id="power-btn">
|
|
||||||
<img id="console-btn">
|
|
||||||
<img id="configure-btn">
|
|
||||||
<img id="delete-btn">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
this.actionLock = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
get data () {
|
|
||||||
return {
|
|
||||||
type: this.type,
|
|
||||||
status: this.status,
|
|
||||||
vmid: this.status,
|
|
||||||
name: this.name,
|
|
||||||
node: this.node
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
set data (data) {
|
|
||||||
if (data.status === "unknown") {
|
|
||||||
data.status = "stopped";
|
|
||||||
}
|
|
||||||
this.type = data.type;
|
|
||||||
this.status = data.status;
|
|
||||||
this.vmid = data.vmid;
|
|
||||||
this.name = data.name;
|
|
||||||
this.node = data.node;
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
update () {
|
|
||||||
const vmidParagraph = this.shadowRoot.querySelector("#instance-id");
|
|
||||||
vmidParagraph.innerText = this.vmid;
|
|
||||||
|
|
||||||
const nameParagraph = this.shadowRoot.querySelector("#instance-name");
|
|
||||||
nameParagraph.innerText = this.name ? this.name : "";
|
|
||||||
|
|
||||||
const typeParagraph = this.shadowRoot.querySelector("#instance-type");
|
|
||||||
typeParagraph.innerText = this.type;
|
|
||||||
|
|
||||||
const statusParagraph = this.shadowRoot.querySelector("#instance-status");
|
|
||||||
statusParagraph.innerText = this.status;
|
|
||||||
|
|
||||||
const statusIcon = this.shadowRoot.querySelector("#instance-status-icon");
|
|
||||||
statusIcon.src = instancesConfig[this.status].status.src;
|
|
||||||
statusIcon.alt = instancesConfig[this.status].status.alt;
|
|
||||||
|
|
||||||
const nodeNameParagraph = this.shadowRoot.querySelector("#node-name");
|
|
||||||
nodeNameParagraph.innerText = this.node.name;
|
|
||||||
|
|
||||||
const nodeStatusParagraph = this.shadowRoot.querySelector("#node-status");
|
|
||||||
nodeStatusParagraph.innerText = this.node.status;
|
|
||||||
|
|
||||||
const nodeStatusIcon = this.shadowRoot.querySelector("#node-status-icon");
|
|
||||||
nodeStatusIcon.src = nodesConfig[this.node.status].status.src;
|
|
||||||
nodeStatusIcon.alt = nodesConfig[this.node.status].status.src;
|
|
||||||
|
|
||||||
const powerButton = this.shadowRoot.querySelector("#power-btn");
|
|
||||||
powerButton.src = instancesConfig[this.status].power.src;
|
|
||||||
powerButton.alt = instancesConfig[this.status].power.alt;
|
|
||||||
powerButton.title = instancesConfig[this.status].power.alt;
|
|
||||||
if (instancesConfig[this.status].power.clickable) {
|
|
||||||
powerButton.classList.add("clickable");
|
|
||||||
powerButton.onclick = this.handlePowerButton.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const configButton = this.shadowRoot.querySelector("#configure-btn");
|
|
||||||
configButton.src = instancesConfig[this.status].config.src;
|
|
||||||
configButton.alt = instancesConfig[this.status].config.alt;
|
|
||||||
configButton.title = instancesConfig[this.status].config.alt;
|
|
||||||
if (instancesConfig[this.status].config.clickable) {
|
|
||||||
configButton.classList.add("clickable");
|
|
||||||
configButton.onclick = this.handleConfigButton.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const consoleButton = this.shadowRoot.querySelector("#console-btn");
|
|
||||||
consoleButton.src = instancesConfig[this.status].console.src;
|
|
||||||
consoleButton.alt = instancesConfig[this.status].console.alt;
|
|
||||||
consoleButton.title = instancesConfig[this.status].console.alt;
|
|
||||||
if (instancesConfig[this.status].console.clickable) {
|
|
||||||
consoleButton.classList.add("clickable");
|
|
||||||
consoleButton.onclick = this.handleConsoleButton.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const deleteButton = this.shadowRoot.querySelector("#delete-btn");
|
|
||||||
deleteButton.src = instancesConfig[this.status].delete.src;
|
|
||||||
deleteButton.alt = instancesConfig[this.status].delete.alt;
|
|
||||||
deleteButton.title = instancesConfig[this.status].delete.alt;
|
|
||||||
if (instancesConfig[this.status].delete.clickable) {
|
|
||||||
deleteButton.classList.add("clickable");
|
|
||||||
deleteButton.onclick = this.handleDeleteButton.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.node.status !== "online") {
|
|
||||||
powerButton.classList.add("hidden");
|
|
||||||
configButton.classList.add("hidden");
|
|
||||||
consoleButton.classList.add("hidden");
|
|
||||||
deleteButton.classList.add("hidden");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async handlePowerButton () {
|
|
||||||
if (!this.actionLock) {
|
|
||||||
const header = `${this.status === "running" ? "Stop" : "Start"} VM ${this.vmid}`;
|
|
||||||
const body = `<p>Are you sure you want to ${this.status === "running" ? "stop" : "start"} VM</p><p>${this.vmid}</p>`;
|
|
||||||
|
|
||||||
dialog(header, body, async (result, form) => {
|
|
||||||
if (result === "confirm") {
|
|
||||||
this.actionLock = true;
|
|
||||||
const targetAction = this.status === "running" ? "stop" : "start";
|
|
||||||
const targetStatus = this.status === "running" ? "stopped" : "running";
|
|
||||||
const prevStatus = this.status;
|
|
||||||
this.status = "loading";
|
|
||||||
|
|
||||||
this.update();
|
|
||||||
|
|
||||||
const result = await requestPVE(`/nodes/${this.node.name}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", { node: this.node.name, vmid: this.vmid });
|
|
||||||
|
|
||||||
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const taskStatus = await requestPVE(`/nodes/${this.node.name}/tasks/${result.data}/status`, "GET");
|
|
||||||
if (taskStatus.data.status === "stopped" && taskStatus.data.exitstatus === "OK") { // task stopped and was successful
|
|
||||||
this.status = targetStatus;
|
|
||||||
this.update();
|
|
||||||
this.actionLock = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (taskStatus.data.status === "stopped") { // task stopped but was not successful
|
|
||||||
this.status = prevStatus;
|
|
||||||
alert(`attempted to ${targetAction} ${this.vmid} but process returned stopped:${result.data.exitstatus}`);
|
|
||||||
this.update();
|
|
||||||
this.actionLock = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else { // task has not stopped
|
|
||||||
await waitFor(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleConfigButton () {
|
|
||||||
if (!this.actionLock && this.status === "stopped") { // if the action lock is false, and the node is stopped, then navigate to the conig page with the node infor in the search query
|
|
||||||
goToPage("config.html", { node: this.node.name, type: this.type, vmid: this.vmid });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleConsoleButton () {
|
|
||||||
if (!this.actionLock && this.status === "running") {
|
|
||||||
const data = { console: `${this.type === "qemu" ? "kvm" : "lxc"}`, vmid: this.vmid, vmname: this.name, node: this.node.name, resize: "off", cmd: "" };
|
|
||||||
data[`${this.type === "qemu" ? "novnc" : "xtermjs"}`] = 1;
|
|
||||||
goToURL(PVE, data, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleDeleteButton () {
|
|
||||||
if (!this.actionLock && this.status === "stopped") {
|
|
||||||
const header = `Delete VM ${this.vmid}`;
|
|
||||||
const body = `<p>Are you sure you want to <strong>delete</strong> VM </p><p>${this.vmid}</p>`;
|
|
||||||
|
|
||||||
dialog(header, body, async (result, form) => {
|
|
||||||
if (result === "confirm") {
|
|
||||||
this.actionLock = true;
|
|
||||||
this.status = "loading";
|
|
||||||
this.update();
|
|
||||||
|
|
||||||
const action = {};
|
|
||||||
action.purge = 1;
|
|
||||||
action["destroy-unreferenced-disks"] = 1;
|
|
||||||
|
|
||||||
const result = await requestAPI(`/cluster/${this.node.name}/${this.type}/${this.vmid}/delete`, "DELETE");
|
|
||||||
if (result.status === 200) {
|
|
||||||
this.parentElement.removeChild(this);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
alert(result.error);
|
|
||||||
this.status = this.prevStatus;
|
|
||||||
this.update();
|
|
||||||
this.actionLock = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
customElements.define("instance-card", InstanceCard);
|
|
||||||
|
231
scripts/instance.js
Normal file
231
scripts/instance.js
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
import { requestPVE, requestAPI, goToPage, goToURL, instancesConfig, nodesConfig } from "./utils.js";
|
||||||
|
import { PVE } from "../vars.js";
|
||||||
|
import { dialog } from "./dialog.js";
|
||||||
|
|
||||||
|
class InstanceCard extends HTMLElement {
|
||||||
|
constructor () {
|
||||||
|
super();
|
||||||
|
this.attachShadow({ mode: "open" });
|
||||||
|
this.shadowRoot.innerHTML = `
|
||||||
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="w3-row" style="margin-top: 1em; margin-bottom: 1em;">
|
||||||
|
<hr class="w3-show-small w3-hide-medium w3-hide-large" style="margin: 0; margin-bottom: 1em;">
|
||||||
|
<div class="w3-col l1 m2 s6">
|
||||||
|
<p id="instance-id"></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-col l2 m3 s6">
|
||||||
|
<p id="instance-name"></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-col l1 m2 w3-hide-small">
|
||||||
|
<p id="instance-type"></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-col l2 m3 s6 flex row nowrap">
|
||||||
|
<img id="instance-status-icon">
|
||||||
|
<p id="instance-status"></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-col l2 w3-hide-medium w3-hide-small">
|
||||||
|
<p id="node-name"></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-col l2 w3-hide-medium w3-hide-small flex row nowrap">
|
||||||
|
<img id="node-status-icon">
|
||||||
|
<p id="node-status"></p>
|
||||||
|
</div>
|
||||||
|
<div class="w3-col l2 m2 s6 flex row nowrap" style="height: 1lh;">
|
||||||
|
<img id="power-btn">
|
||||||
|
<img id="console-btn">
|
||||||
|
<img id="configure-btn">
|
||||||
|
<img id="delete-btn">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
this.actionLock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get data () {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
status: this.status,
|
||||||
|
vmid: this.status,
|
||||||
|
name: this.name,
|
||||||
|
node: this.node
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
set data (data) {
|
||||||
|
if (data.status === "unknown") {
|
||||||
|
data.status = "stopped";
|
||||||
|
}
|
||||||
|
this.type = data.type;
|
||||||
|
this.status = data.status;
|
||||||
|
this.vmid = data.vmid;
|
||||||
|
this.name = data.name;
|
||||||
|
this.node = data.node;
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
update () {
|
||||||
|
const vmidParagraph = this.shadowRoot.querySelector("#instance-id");
|
||||||
|
vmidParagraph.innerText = this.vmid;
|
||||||
|
|
||||||
|
const nameParagraph = this.shadowRoot.querySelector("#instance-name");
|
||||||
|
nameParagraph.innerText = this.name ? this.name : "";
|
||||||
|
|
||||||
|
const typeParagraph = this.shadowRoot.querySelector("#instance-type");
|
||||||
|
typeParagraph.innerText = this.type;
|
||||||
|
|
||||||
|
const statusParagraph = this.shadowRoot.querySelector("#instance-status");
|
||||||
|
statusParagraph.innerText = this.status;
|
||||||
|
|
||||||
|
const statusIcon = this.shadowRoot.querySelector("#instance-status-icon");
|
||||||
|
statusIcon.src = instancesConfig[this.status].status.src;
|
||||||
|
statusIcon.alt = instancesConfig[this.status].status.alt;
|
||||||
|
|
||||||
|
const nodeNameParagraph = this.shadowRoot.querySelector("#node-name");
|
||||||
|
nodeNameParagraph.innerText = this.node.name;
|
||||||
|
|
||||||
|
const nodeStatusParagraph = this.shadowRoot.querySelector("#node-status");
|
||||||
|
nodeStatusParagraph.innerText = this.node.status;
|
||||||
|
|
||||||
|
const nodeStatusIcon = this.shadowRoot.querySelector("#node-status-icon");
|
||||||
|
nodeStatusIcon.src = nodesConfig[this.node.status].status.src;
|
||||||
|
nodeStatusIcon.alt = nodesConfig[this.node.status].status.src;
|
||||||
|
|
||||||
|
const powerButton = this.shadowRoot.querySelector("#power-btn");
|
||||||
|
powerButton.src = instancesConfig[this.status].power.src;
|
||||||
|
powerButton.alt = instancesConfig[this.status].power.alt;
|
||||||
|
powerButton.title = instancesConfig[this.status].power.alt;
|
||||||
|
if (instancesConfig[this.status].power.clickable) {
|
||||||
|
powerButton.classList.add("clickable");
|
||||||
|
powerButton.onclick = this.handlePowerButton.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const configButton = this.shadowRoot.querySelector("#configure-btn");
|
||||||
|
configButton.src = instancesConfig[this.status].config.src;
|
||||||
|
configButton.alt = instancesConfig[this.status].config.alt;
|
||||||
|
configButton.title = instancesConfig[this.status].config.alt;
|
||||||
|
if (instancesConfig[this.status].config.clickable) {
|
||||||
|
configButton.classList.add("clickable");
|
||||||
|
configButton.onclick = this.handleConfigButton.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const consoleButton = this.shadowRoot.querySelector("#console-btn");
|
||||||
|
consoleButton.src = instancesConfig[this.status].console.src;
|
||||||
|
consoleButton.alt = instancesConfig[this.status].console.alt;
|
||||||
|
consoleButton.title = instancesConfig[this.status].console.alt;
|
||||||
|
if (instancesConfig[this.status].console.clickable) {
|
||||||
|
consoleButton.classList.add("clickable");
|
||||||
|
consoleButton.onclick = this.handleConsoleButton.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteButton = this.shadowRoot.querySelector("#delete-btn");
|
||||||
|
deleteButton.src = instancesConfig[this.status].delete.src;
|
||||||
|
deleteButton.alt = instancesConfig[this.status].delete.alt;
|
||||||
|
deleteButton.title = instancesConfig[this.status].delete.alt;
|
||||||
|
if (instancesConfig[this.status].delete.clickable) {
|
||||||
|
deleteButton.classList.add("clickable");
|
||||||
|
deleteButton.onclick = this.handleDeleteButton.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.node.status !== "online") {
|
||||||
|
powerButton.classList.add("hidden");
|
||||||
|
configButton.classList.add("hidden");
|
||||||
|
consoleButton.classList.add("hidden");
|
||||||
|
deleteButton.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handlePowerButton () {
|
||||||
|
if (!this.actionLock) {
|
||||||
|
const header = `${this.status === "running" ? "Stop" : "Start"} VM ${this.vmid}`;
|
||||||
|
const body = `<p>Are you sure you want to ${this.status === "running" ? "stop" : "start"} VM</p><p>${this.vmid}</p>`;
|
||||||
|
|
||||||
|
dialog(header, body, async (result, form) => {
|
||||||
|
if (result === "confirm") {
|
||||||
|
this.actionLock = true;
|
||||||
|
const targetAction = this.status === "running" ? "stop" : "start";
|
||||||
|
const targetStatus = this.status === "running" ? "stopped" : "running";
|
||||||
|
const prevStatus = this.status;
|
||||||
|
this.status = "loading";
|
||||||
|
|
||||||
|
this.update();
|
||||||
|
|
||||||
|
const result = await requestPVE(`/nodes/${this.node.name}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", { node: this.node.name, vmid: this.vmid });
|
||||||
|
|
||||||
|
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const taskStatus = await requestPVE(`/nodes/${this.node.name}/tasks/${result.data}/status`, "GET");
|
||||||
|
if (taskStatus.data.status === "stopped" && taskStatus.data.exitstatus === "OK") { // task stopped and was successful
|
||||||
|
this.status = targetStatus;
|
||||||
|
this.update();
|
||||||
|
this.actionLock = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (taskStatus.data.status === "stopped") { // task stopped but was not successful
|
||||||
|
this.status = prevStatus;
|
||||||
|
alert(`attempted to ${targetAction} ${this.vmid} but process returned stopped:${result.data.exitstatus}`);
|
||||||
|
this.update();
|
||||||
|
this.actionLock = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else { // task has not stopped
|
||||||
|
await waitFor(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleConfigButton () {
|
||||||
|
if (!this.actionLock && this.status === "stopped") { // if the action lock is false, and the node is stopped, then navigate to the conig page with the node infor in the search query
|
||||||
|
goToPage("config.html", { node: this.node.name, type: this.type, vmid: this.vmid });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleConsoleButton () {
|
||||||
|
if (!this.actionLock && this.status === "running") {
|
||||||
|
const data = { console: `${this.type === "qemu" ? "kvm" : "lxc"}`, vmid: this.vmid, vmname: this.name, node: this.node.name, resize: "off", cmd: "" };
|
||||||
|
data[`${this.type === "qemu" ? "novnc" : "xtermjs"}`] = 1;
|
||||||
|
goToURL(PVE, data, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDeleteButton () {
|
||||||
|
if (!this.actionLock && this.status === "stopped") {
|
||||||
|
const header = `Delete VM ${this.vmid}`;
|
||||||
|
const body = `<p>Are you sure you want to <strong>delete</strong> VM </p><p>${this.vmid}</p>`;
|
||||||
|
|
||||||
|
dialog(header, body, async (result, form) => {
|
||||||
|
if (result === "confirm") {
|
||||||
|
this.actionLock = true;
|
||||||
|
this.status = "loading";
|
||||||
|
this.update();
|
||||||
|
|
||||||
|
const action = {};
|
||||||
|
action.purge = 1;
|
||||||
|
action["destroy-unreferenced-disks"] = 1;
|
||||||
|
|
||||||
|
const result = await requestAPI(`/cluster/${this.node.name}/${this.type}/${this.vmid}/delete`, "DELETE");
|
||||||
|
if (result.status === 200) {
|
||||||
|
this.parentElement.removeChild(this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert(result.error);
|
||||||
|
this.status = this.prevStatus;
|
||||||
|
this.update();
|
||||||
|
this.actionLock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define("instance-card", InstanceCard);
|
@ -235,7 +235,7 @@ export function goToPage (page, data = {}, newwindow = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newwindow) {
|
if (newwindow) {
|
||||||
window.open(url, `${organization} - client`, "height=480,width=848");
|
window.open(url, `${organization} - dashboard`, "height=480,width=848");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location.assign(url.toString());
|
window.location.assign(url.toString());
|
||||||
@ -249,7 +249,7 @@ export function goToURL (href, data = {}, newwindow = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newwindow) {
|
if (newwindow) {
|
||||||
window.open(url, `${organization} - client`, "height=480,width=848");
|
window.open(url, `${organization} - dashboard`, "height=480,width=848");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location.assign(url.toString());
|
window.location.assign(url.toString());
|
||||||
@ -266,6 +266,6 @@ export async function deleteAllCookies () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setTitleAndHeader () {
|
export function setTitleAndHeader () {
|
||||||
document.title = `${organization} - client`;
|
document.title = `${organization} - dashboard`;
|
||||||
document.querySelector("h1").innerText = organization;
|
document.querySelector("h1").innerText = organization;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>proxmox - client</title>
|
<title>proxmox - dashboard</title>
|
||||||
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
export const API = "https://client.mydomain.example/api"; // the proxmox-aas api
|
export const API = "https://dashboard.mydomain.example/api"; // the proxmox-aas api
|
||||||
export const PVE = "https://pve.mydomain.example"; // the proxmox api
|
export const PVE = "https://pve.mydomain.example"; // the proxmox api
|
||||||
export const organization = "mydomain"; // org name used in page title and nav bar
|
export const organization = "mydomain"; // org name used in page title and nav bar
|
||||||
|
Loading…
Reference in New Issue
Block a user