Apply lint

This commit is contained in:
Bastien Wirtz 2022-11-05 15:24:41 +01:00
parent d32f7f6467
commit 24b6dedbe1

View File

@ -1,135 +1,193 @@
<template> <template>
<Generic :item="item"> <Generic :item="item">
<template #content> <template #content>
<p class="title is-4">{{ item.name }}</p> <p class="title is-4">{{ item.name }}</p>
<p class="subtitle is-6"> <p class="subtitle is-6">
<template v-if="item.subtitle"> <template v-if="item.subtitle">
{{ item.subtitle }} {{ item.subtitle }}
</template> </template>
<template v-else-if="vms"> <template v-else-if="vms">
<div v-if="loading"> <div v-if="loading">
<strong>Loading...</strong> <strong>Loading...</strong>
</div> </div>
<div v-else-if="error"> <div v-else-if="error">
<strong class="danger">Error loading info</strong> <strong class="danger">Error loading info</strong>
</div> </div>
<div v-else class="metrics" :class="{'is-size-7-mobile': item.small_font_on_small_screens, 'is-small': item.small_font_on_desktop}"> <div
<span v-if="isValueShown('vms')" class="margined">VMs: <span class="is-number"><span class="has-text-weight-bold">{{ vms.running }}</span><span v-if="isValueShown('vms_total')">/{{vms.total}}</span></span></span> v-else
<span v-if="isValueShown('lxcs')" class="margined">LXCs: <span class="is-number"><span class="has-text-weight-bold">{{ lxcs.running }}</span><span v-if="isValueShown('lxcs_total')">/{{lxcs.total}}</span></span></span> class="metrics"
<span v-if="isValueShown('disk')" class="margined">Disk: <span class="has-text-weight-bold is-number" :class="statusClass(diskUsed)">{{ diskUsed }}%</span></span> :class="{
<span v-if="isValueShown('mem')" class="margined">Mem: <span class="has-text-weight-bold is-number" :class="statusClass(memoryUsed)">{{ memoryUsed }}%</span></span> 'is-size-7-mobile': item.small_font_on_small_screens,
<span v-if="isValueShown('cpu')" class="margined">CPU: <span class="has-text-weight-bold is-number" :class="statusClass(cpuUsed)">{{ cpuUsed }}%</span></span> 'is-small': item.small_font_on_desktop,
</div> }"
</template> >
</p> <span v-if="isValueShown('vms')" class="margined"
</template> >VMs:
<template #indicator> <span class="is-number"
<i v-if="loading" class="fa fa-circle-notch fa-spin fa-2xl"></i> ><span class="has-text-weight-bold">{{ vms.running }}</span
<i v-if="error" class="fa fa-exclamation-circle fa-2xl danger"></i> ><span v-if="isValueShown('vms_total')"
</template> >/{{ vms.total }}</span
</Generic> ></span
</template> ></span
>
<span v-if="isValueShown('lxcs')" class="margined"
>LXCs:
<span class="is-number"
><span class="has-text-weight-bold">{{ lxcs.running }}</span
><span v-if="isValueShown('lxcs_total')"
>/{{ lxcs.total }}</span
></span
></span
>
<span v-if="isValueShown('disk')" class="margined"
>Disk:
<span
class="has-text-weight-bold is-number"
:class="statusClass(diskUsed)"
>{{ diskUsed }}%</span
></span
>
<span v-if="isValueShown('mem')" class="margined"
>Mem:
<span
class="has-text-weight-bold is-number"
:class="statusClass(memoryUsed)"
>{{ memoryUsed }}%</span
></span
>
<span v-if="isValueShown('cpu')" class="margined"
>CPU:
<span
class="has-text-weight-bold is-number"
:class="statusClass(cpuUsed)"
>{{ cpuUsed }}%</span
></span
>
</div>
</template>
</p>
</template>
<template #indicator>
<i v-if="loading" class="fa fa-circle-notch fa-spin fa-2xl"></i>
<i v-if="error" class="fa fa-exclamation-circle fa-2xl danger"></i>
</template>
</Generic>
</template>
<script> <script>
import service from "@/mixins/service.js"; import service from "@/mixins/service.js";
import Generic from "./Generic.vue"; import Generic from "./Generic.vue";
export default { export default {
name: "Proxmox", name: "Proxmox",
mixins: [service], mixins: [service],
props: { props: {
item: Object, item: Object,
},
components: {
Generic,
},
data: () => ({
vms: {
total: 0,
running: 0,
}, },
components: { lxcs: {
Generic, total: 0,
running: 0,
}, },
data: () => ({ memoryUsed: 0,
vms: { diskUsed: 0,
total: 0, cpuUsed: 0,
running: 0 hide: [],
}, error: false,
lxcs: { loading: true,
total: 0, }),
running: 0 created() {
}, if (this.item.hide) this.hide = this.item.hide;
memoryUsed: 0, this.fetchStatus();
diskUsed: 0, },
cpuUsed: 0, methods: {
hide: [], statusClass(value) {
error: false, if (value > this.item.danger_value) return "danger";
loading: true if (value > this.item.warning_value) return "warning";
}), return "healthy";
created() {
if (this.item.hide) this.hide = this.item.hide;
this.fetchStatus();
}, },
methods: { fetchStatus: async function () {
statusClass(value) { try {
if (value > this.item.danger_value) return 'danger'; const options = {
if (value > this.item.warning_value) return 'warning'; headers: {
return 'healthy' Authorization: this.item.api_token,
}, },
fetchStatus: async function () { };
try { const status = await this.fetch(
const options = { `/api2/json/nodes/${this.item.node}/status`,
headers: { options
"Authorization": this.item.api_token );
} // main metrics:
} const decimalsToShow = this.item.hide_decimals ? 0 : 1;
const status = await this.fetch(`/api2/json/nodes/${this.item.node}/status`, options); this.memoryUsed = (
// main metrics: (status.data.memory.used * 100) /
const decimalsToShow = this.item.hide_decimals ? 0 : 1; status.data.memory.total
this.memoryUsed = ( (status.data.memory.used * 100) / status.data.memory.total ).toFixed(decimalsToShow); ).toFixed(decimalsToShow);
this.diskUsed = ( (status.data.rootfs.used * 100) / status.data.rootfs.total ).toFixed(decimalsToShow); this.diskUsed = (
this.cpuUsed = (status.data.cpu * 100).toFixed(decimalsToShow); (status.data.rootfs.used * 100) /
// vms: status.data.rootfs.total
if (this.isValueShown('vms')) { ).toFixed(decimalsToShow);
const vms = await this.fetch(`/api2/json/nodes/${this.item.node}/qemu`, options); this.cpuUsed = (status.data.cpu * 100).toFixed(decimalsToShow);
this.parseVMsAndLXCs(vms, this.vms); // vms:
} if (this.isValueShown("vms")) {
// lxc containers: const vms = await this.fetch(
if (this.isValueShown('lxcs')) { `/api2/json/nodes/${this.item.node}/qemu`,
const lxcs = await this.fetch(`/api2/json/nodes/${this.item.node}/lxc`, options); options
this.parseVMsAndLXCs(lxcs, this.lxcs); );
} this.parseVMsAndLXCs(vms, this.vms);
this.error = false;
} catch(err) {
console.log(err);
this.error = true;
} }
this.loading = false; // lxc containers:
}, if (this.isValueShown("lxcs")) {
parseVMsAndLXCs(items, value) { const lxcs = await this.fetch(
value.total += items.data.length; `/api2/json/nodes/${this.item.node}/lxc`,
value.running += items.data.filter( i => i.status === 'running' ).length; options
// if no vms, hide this value: );
if (value.total == 0) this.hide.push('lxcs'); this.parseVMsAndLXCs(lxcs, this.lxcs);
}, }
isValueShown(value) { this.error = false;
return this.hide.indexOf(value) == -1; } catch (err) {
console.log(err);
this.error = true;
} }
this.loading = false;
}, },
}; parseVMsAndLXCs(items, value) {
</script> value.total += items.data.length;
value.running += items.data.filter((i) => i.status === "running").length;
<style scoped lang="scss"> // if no vms, hide this value:
.is-number { if (value.total == 0) this.hide.push("lxcs");
font-family: "Lato" },
} isValueShown(value) {
.healthy { return this.hide.indexOf(value) == -1;
color: green },
} },
.warning { };
color: orange </script>
}
.danger {
color: red
}
.metrics .margined:not(:first-child) {
margin-left: 0.3rem;
}
.is-small {
font-size: small;
}
</style>
<style scoped lang="scss">
.is-number {
font-family: "Lato";
}
.healthy {
color: green;
}
.warning {
color: orange;
}
.danger {
color: red;
}
.metrics .margined:not(:first-child) {
margin-left: 0.3rem;
}
.is-small {
font-size: small;
}
</style>