cleanup various unused code,
simplify instance action hiding when node is not online
This commit is contained in:
@@ -1,91 +1,3 @@
|
||||
export const resourcesConfig = {
|
||||
cpu: {
|
||||
name: "CPU Type",
|
||||
icon: "images/resources/cpu.svg",
|
||||
id: "proctype",
|
||||
unitText: null
|
||||
},
|
||||
cores: {
|
||||
name: "CPU Amount",
|
||||
icon: "images/resources/cpu.svg",
|
||||
id: "cores",
|
||||
unitText: "Cores"
|
||||
},
|
||||
memory: {
|
||||
name: "Memory",
|
||||
icon: "images/resources/ram.svg",
|
||||
id: "ram",
|
||||
unitText: "MiB"
|
||||
},
|
||||
swap: {
|
||||
name: "Swap",
|
||||
icon: "images/resources/swap.svg",
|
||||
id: "swap",
|
||||
unitText: "MiB"
|
||||
},
|
||||
disk: {
|
||||
actionBarOrder: ["move", "resize", "detach_attach", "delete"],
|
||||
lxc: {
|
||||
prefixOrder: ["rootfs", "mp", "unused"],
|
||||
rootfs: { name: "ROOTFS", icon: "images/resources/drive.svg", actions: ["move", "resize"] },
|
||||
mp: { name: "MP", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"] },
|
||||
unused: { name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"] }
|
||||
},
|
||||
qemu: {
|
||||
prefixOrder: ["ide", "sata", "scsi", "unused"],
|
||||
ide: { name: "IDE", icon: "images/resources/disk.svg", actions: ["delete"] },
|
||||
sata: { name: "SATA", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"] },
|
||||
scsi: { name: "SCSI", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"] },
|
||||
unused: { name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"] }
|
||||
},
|
||||
actions: {
|
||||
attach: {
|
||||
src: "images/actions/disk/attach.svg",
|
||||
title: "Attach Disk"
|
||||
},
|
||||
detach: {
|
||||
src: "images/actions/disk/detach.svg",
|
||||
title: "Detach Disk"
|
||||
},
|
||||
delete: null
|
||||
}
|
||||
},
|
||||
network: {
|
||||
name: "Network",
|
||||
icon: "images/resources/network.svg",
|
||||
id: "network",
|
||||
unitText: "MB/s",
|
||||
prefix: "net"
|
||||
},
|
||||
pci: {
|
||||
name: "Devices",
|
||||
icon: "images/resources/device.svg",
|
||||
id: "devices",
|
||||
unitText: null,
|
||||
prefix: "hostpci"
|
||||
}
|
||||
};
|
||||
|
||||
export const bootConfig = {
|
||||
eligiblePrefixes: ["ide", "sata", "scsi", "net"],
|
||||
ide: {
|
||||
icon: "images/resources/disk.svg",
|
||||
alt: "IDE Bootable Icon"
|
||||
},
|
||||
sata: {
|
||||
icon: "images/resources/drive.svg",
|
||||
alt: "SATA Bootable Icon"
|
||||
},
|
||||
scsi: {
|
||||
icon: "images/resources/drive.svg",
|
||||
alt: "SCSI Bootable Icon"
|
||||
},
|
||||
net: {
|
||||
icon: "images/resources/network.svg",
|
||||
alt: "NET Bootable Icon"
|
||||
}
|
||||
};
|
||||
|
||||
export function setCookie (cname, cval) {
|
||||
document.cookie = `${cname}=${cval}`;
|
||||
}
|
||||
@@ -301,135 +213,3 @@ export function setSVGSrc (svgElem, href) {
|
||||
export function setSVGAlt (svgElem, alt) {
|
||||
svgElem.setAttribute("aria-label", alt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple object check.
|
||||
* @param item
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isObject (item) {
|
||||
return (item && typeof item === "object" && !Array.isArray(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep merge two objects.
|
||||
* @param target
|
||||
* @param ...sources
|
||||
*/
|
||||
export function mergeDeep (target, ...sources) {
|
||||
if (!sources.length) return target;
|
||||
const source = sources.shift();
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
for (const key in source) {
|
||||
if (isObject(source[key])) {
|
||||
if (!target[key]) Object.assign(target, { [key]: {} });
|
||||
mergeDeep(target[key], source[key]);
|
||||
}
|
||||
else {
|
||||
Object.assign(target, { [key]: source[key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mergeDeep(target, ...sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if object or array is empty
|
||||
* @param {*} obj
|
||||
* @returns
|
||||
*/
|
||||
export function isEmpty (obj) {
|
||||
if (obj instanceof Array) {
|
||||
return obj.length === 0;
|
||||
}
|
||||
else {
|
||||
for (const prop in obj) {
|
||||
if (Object.hasOwn(obj, prop)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
export function addResourceLine (resourceConfig, field, attributesOverride, labelPrefix = null) {
|
||||
const iconHref = resourceConfig.icon;
|
||||
const elementType = resourceConfig.element;
|
||||
const labelText = labelPrefix ? `${labelPrefix} ${resourceConfig.name}` : resourceConfig.name;
|
||||
const id = resourceConfig.id;
|
||||
const unitText = resourceConfig.unitText;
|
||||
const attributes = { ...(resourceConfig.attributes), ...(attributesOverride) };
|
||||
|
||||
const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
setSVGSrc(icon, iconHref);
|
||||
setSVGAlt(icon, labelText);
|
||||
field.append(icon);
|
||||
|
||||
const label = document.createElement("label");
|
||||
label.innerText = labelText;
|
||||
label.htmlFor = id;
|
||||
field.append(label);
|
||||
|
||||
let element;
|
||||
|
||||
if (elementType === "input") {
|
||||
element = document.createElement("input");
|
||||
for (const k in attributes) {
|
||||
element.setAttribute(k, attributes[k]);
|
||||
}
|
||||
element.id = id;
|
||||
element.name = id;
|
||||
element.required = true;
|
||||
element.classList.add("w3-input");
|
||||
element.classList.add("w3-border");
|
||||
field.append(element);
|
||||
}
|
||||
else if (elementType === "select" || elementType === "multi-select") {
|
||||
element = document.createElement("select");
|
||||
for (const option of attributes.options) {
|
||||
element.append(new Option(option));
|
||||
}
|
||||
element.value = attributes.value;
|
||||
element.id = id;
|
||||
element.name = id;
|
||||
element.required = true;
|
||||
element.classList.add("w3-select");
|
||||
element.classList.add("w3-border");
|
||||
if (elementType === "multi-select") {
|
||||
element.setAttribute("multiple", true);
|
||||
}
|
||||
field.append(element);
|
||||
}
|
||||
else if (customElements.get(elementType)) {
|
||||
element = document.createElement(elementType);
|
||||
if (attributes.options) {
|
||||
for (const option of attributes.options) {
|
||||
element.append(new Option(option));
|
||||
}
|
||||
}
|
||||
element.value = attributes.value;
|
||||
element.id = id;
|
||||
element.name = id;
|
||||
element.required = true;
|
||||
field.append(element);
|
||||
}
|
||||
|
||||
let unit;
|
||||
|
||||
if (unitText) {
|
||||
unit = document.createElement("p");
|
||||
unit.innerText = unitText;
|
||||
field.append(unit);
|
||||
}
|
||||
else {
|
||||
unit = document.createElement("div");
|
||||
unit.classList.add("hidden");
|
||||
field.append(unit);
|
||||
}
|
||||
|
||||
return { icon, label, element, unit };
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user