Bugfix/ts style (#17)
Some checks failed
Java CI with Gradle / build (push) Has been cancelled

Fix style warnings.
This commit is contained in:
Michael N. Lipp 2023-10-31 23:03:48 +01:00 committed by GitHub
parent 6f45e7982a
commit 39a2a0389e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 1483 additions and 87 deletions

16
.eslintrc.json Normal file
View file

@ -0,0 +1,16 @@
{
"root": true,
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
"ignorePatterns": ["src/**/*.test.ts", "build/**"]
}

View file

@ -0,0 +1,15 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": ["./tsconfig.json"] },
"plugins": [
"@typescript-eslint"
],
"rules": {
"constructor-super": "off"
}
}

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { ref, Ref, nextTick } from "vue"; import { ref, nextTick } from "vue";
/** /**
* A controller for conditionally shown inputs. "Conditionally shown" * A controller for conditionally shown inputs. "Conditionally shown"
@ -26,16 +26,18 @@ import { ref, Ref, nextTick } from "vue";
*/ */
export default class ConditionlInputController { export default class ConditionlInputController {
private submitCallback: (selected: string, value: any) => string | null; private submitCallback: (selected: string, value: number | null)
=> string | null;
private readonly inputKey = ref(""); private readonly inputKey = ref("");
private startValue: any; private startValue: string | null = null;
private inputElement: HTMLInputElement | null = null; private inputElement: HTMLInputElement | null = null;
private errorMessage = ref(""); private errorMessage = ref("");
/** /**
* Creates a new controller. * Creates a new controller.
*/ */
constructor(submitCallback: (selected: string, value: string) => string | null) { constructor(submitCallback: (selected: string, value: number | null)
=> string | null) {
// this.inputRef = inputRef; // this.inputRef = inputRef;
this.submitCallback = submitCallback; this.submitCallback = submitCallback;
} }
@ -52,7 +54,7 @@ export default class ConditionlInputController {
this.inputElement = element; this.inputElement = element;
} }
startEdit (key: string, value: any) { startEdit (key: string, value: string) {
if (this.inputKey.value != "") { if (this.inputKey.value != "") {
return; return;
} }
@ -65,17 +67,17 @@ export default class ConditionlInputController {
}); });
} }
endEdit (converter?: (value: string) => any | null) : boolean { endEdit (converter?: (value: string) => number | null) : boolean {
if (typeof converter === 'undefined') { if (typeof converter === 'undefined') {
this.inputKey.value = ""; this.inputKey.value = "";
return false; return false;
} }
let newValue = converter(this.inputElement!.value); const newValue = converter(this.inputElement!.value);
if (newValue === this.startValue) { if (newValue === this.startValue) {
this.inputKey.value = ""; this.inputKey.value = "";
return false; return false;
} }
let submitResult = this.submitCallback (this.inputKey.value, newValue); const submitResult = this.submitCallback (this.inputKey.value, newValue);
if (submitResult !== null) { if (submitResult !== null) {
this.errorMessage.value = submitResult; this.errorMessage.value = submitResult;
// Neither doing it directly nor doing it with nextTick works. // Neither doing it directly nor doing it with nextTick works.

View file

@ -22,6 +22,7 @@ import { formatMemory } from "./MemorySize";
import JGConsole from "jgconsole"; import JGConsole from "jgconsole";
import l10nBundles from "l10nBundles"; import l10nBundles from "l10nBundles";
import { JGWC } from "jgwc"; import { JGWC } from "jgwc";
/* eslint-disable @typescript-eslint/no-explicit-any */
export default class CpuRamChart extends Chart { export default class CpuRamChart extends Chart {
@ -83,7 +84,7 @@ export default class CpuRamChart extends Chart {
} }
}); });
let css = getComputedStyle(canvas); const css = getComputedStyle(canvas);
this.setPropValue("options.plugins.legend.labels.font.family", css.fontFamily); this.setPropValue("options.plugins.legend.labels.font.family", css.fontFamily);
this.setPropValue("options.plugins.legend.labels.color", css.color); this.setPropValue("options.plugins.legend.labels.color", css.color);
this.setPropValue("options.scales.x.ticks.font.family", css.fontFamily); this.setPropValue("options.scales.x.ticks.font.family", css.fontFamily);
@ -102,11 +103,12 @@ export default class CpuRamChart extends Chart {
} }
setPropValue(path: string, value: any) { setPropValue(path: string, value: any) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let ptr: any = this; let ptr: any = this;
let segs = path.split("."); const segs = path.split(".");
let lastSeg = segs.pop()!; const lastSeg = segs.pop()!;
for (let seg of segs) { for (const seg of segs) {
let cur = ptr[seg]; const cur = ptr[seg];
if (!cur) { if (!cur) {
ptr[seg] = {}; ptr[seg] = {};
} }

View file

@ -16,15 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
let unitMap = new Map<string, number>(); const unitMap = new Map<string, number>();
let unitMappings = new Array<{ key: string; value: number }>(); const unitMappings = new Array<{ key: string; value: number }>();
let memorySize = /^(\d+(\.\d+)?)\s*(B|kB|MB|GB|TB|PB|EB|KiB|MiB|GiB|TiB|PiB|EiB)?$/; const memorySize = /^(\d+(\.\d+)?)\s*(B|kB|MB|GB|TB|PB|EB|KiB|MiB|GiB|TiB|PiB|EiB)?$/;
// SI units and common abbreviations // SI units and common abbreviations
let factor = 1; let factor = 1;
unitMap.set("", factor); unitMap.set("", factor);
let scale = 1000; let scale = 1000;
for (let unit of ["B", "kB", "MB", "GB", "TB", "PB", "EB"]) { for (const unit of ["B", "kB", "MB", "GB", "TB", "PB", "EB"]) {
unitMap.set(unit, factor); unitMap.set(unit, factor);
factor = factor * scale; factor = factor * scale;
} }
@ -32,7 +32,7 @@ for (let unit of ["B", "kB", "MB", "GB", "TB", "PB", "EB"]) {
// Binary units // Binary units
factor = 1024; factor = 1024;
scale = 1024; scale = 1024;
for (let unit of ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB"]) { for (const unit of ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB"]) {
unitMap.set(unit, factor); unitMap.set(unit, factor);
factor = factor * scale; factor = factor * scale;
} }
@ -42,7 +42,7 @@ unitMap.forEach((value: number, key: string) => {
unitMappings.sort((a, b) => a.value < b.value ? 1 : a.value > b.value ? -1 : 0); unitMappings.sort((a, b) => a.value < b.value ? 1 : a.value > b.value ? -1 : 0);
export function formatMemory(size: number): string { export function formatMemory(size: number): string {
for (let mapping of unitMappings) { for (const mapping of unitMappings) {
if (size >= mapping.value if (size >= mapping.value
&& (size % mapping.value) === 0) { && (size % mapping.value) === 0) {
return (size / mapping.value + " " + mapping.key).trim(); return (size / mapping.value + " " + mapping.key).trim();
@ -52,7 +52,7 @@ export function formatMemory(size: number): string {
} }
export function parseMemory(value: string): number | null { export function parseMemory(value: string): number | null {
let match = value.match(memorySize); const match = value.match(memorySize);
if (!match) { if (!match) {
return null; return null;
} }

View file

@ -36,7 +36,7 @@ export default class TimeSeries {
clear() { clear() {
this.timestamps.length = 0; this.timestamps.length = 0;
for (let values of this.series) { for (const values of this.series) {
values.length = 0; values.length = 0;
} }
if (this.onChange) { if (this.onChange) {
@ -66,12 +66,12 @@ export default class TimeSeries {
} }
// Purge // Purge
let limit = time.getTime() - this.period; const limit = time.getTime() - this.period;
while (this.timestamps.length > 2 while (this.timestamps.length > 2
&& this.timestamps[0].getTime() < limit && this.timestamps[0].getTime() < limit
&& this.timestamps[1].getTime() < limit) { && this.timestamps[1].getTime() < limit) {
this.timestamps.shift(); this.timestamps.shift();
for (let values of this.series) { for (const values of this.series) {
values.shift(); values.shift();
} }
} }

View file

@ -17,7 +17,7 @@
*/ */
import { import {
reactive, ref, Ref, createApp, computed, onMounted, watch, nextTick reactive, ref, Ref, createApp, computed, onMounted, watch
} from "vue"; } from "vue";
import JGConsole from "jgconsole"; import JGConsole from "jgconsole";
import JgwcPlugin, { JGWC } from "jgwc"; import JgwcPlugin, { JGWC } from "jgwc";
@ -32,14 +32,17 @@ import "./VmConlet-style.scss";
// For global access // For global access
declare global { declare global {
interface Window { interface Window {
orgJDrupesVmOperatorVmConlet: any; orgJDrupesVmOperatorVmConlet: {
initPreview?: (previewDom: HTMLElement, isUpdate: boolean) => void,
initView?: (viewDom: HTMLElement, isUpdate: boolean) => void
}
} }
} }
window.orgJDrupesVmOperatorVmConlet = {}; window.orgJDrupesVmOperatorVmConlet = {};
let vmInfos = reactive(new Map()); const vmInfos = reactive(new Map());
let vmSummary = reactive({ const vmSummary = reactive({
totalVms: 0, totalVms: 0,
runningVms: 0, runningVms: 0,
usedCpus: 0, usedCpus: 0,
@ -58,19 +61,16 @@ const shortDateTime = (time: Date) => {
}; };
// Cannot be reactive, leads to infinite recursion. // Cannot be reactive, leads to infinite recursion.
let chartData = new TimeSeries(2); const chartData = new TimeSeries(2);
let chartDateUpdate = ref<Date>(null); const chartDateUpdate = ref<Date>(null);
window.orgJDrupesVmOperatorVmConlet.initPreview = (previewDom: HTMLElement, window.orgJDrupesVmOperatorVmConlet.initPreview = (previewDom: HTMLElement,
_isUpdate: boolean) => { _isUpdate: boolean) => {
const app = createApp({ const app = createApp({
setup(_props: any) { setup(_props: object) {
const conletId: string
= (<HTMLElement>previewDom.parentNode!).dataset["conletId"]!;
let chart: CpuRamChart | null = null; let chart: CpuRamChart | null = null;
onMounted(() => { onMounted(() => {
let canvas: HTMLCanvasElement const canvas: HTMLCanvasElement
= previewDom.querySelector(":scope .vmsChart")!; = previewDom.querySelector(":scope .vmsChart")!;
chart = new CpuRamChart(canvas, chartData); chart = new CpuRamChart(canvas, chartData);
}) })
@ -86,7 +86,7 @@ window.orgJDrupesVmOperatorVmConlet.initPreview = (previewDom: HTMLElement,
const period: Ref<string> = ref<string>("day"); const period: Ref<string> = ref<string>("day");
watch(period, (_) => { watch(period, (_) => {
let hours = (period.value === "day") ? 24 : 1; const hours = (period.value === "day") ? 24 : 1;
chart?.setPeriod(hours * 3600 * 1000); chart?.setPeriod(hours * 3600 * 1000);
}); });
@ -101,7 +101,7 @@ window.orgJDrupesVmOperatorVmConlet.initPreview = (previewDom: HTMLElement,
window.orgJDrupesVmOperatorVmConlet.initView = (viewDom: HTMLElement, window.orgJDrupesVmOperatorVmConlet.initView = (viewDom: HTMLElement,
_isUpdate: boolean) => { _isUpdate: boolean) => {
const app = createApp({ const app = createApp({
setup(_props: any) { setup(_props: object) {
const conletId: string const conletId: string
= (<HTMLElement>viewDom.parentNode!).dataset["conletId"]!; = (<HTMLElement>viewDom.parentNode!).dataset["conletId"]!;
@ -117,8 +117,8 @@ window.orgJDrupesVmOperatorVmConlet.initView = (viewDom: HTMLElement,
sortOrder: "up" sortOrder: "up"
})); }));
let filteredData = computed(() => { const filteredData = computed(() => {
let infos = Array.from(vmInfos.values()); const infos = Array.from(vmInfos.values());
return controller.filter(infos); return controller.filter(infos);
}); });
@ -129,14 +129,14 @@ window.orgJDrupesVmOperatorVmConlet.initView = (viewDom: HTMLElement,
const idScope = JGWC.createIdScope(); const idScope = JGWC.createIdScope();
const detailsByName = reactive(new Set()); const detailsByName = reactive(new Set());
const submitCallback = (selected: string, value: any) => { const submitCallback = (selected: string, value: number | null) => {
if (value === null) { if (value === null) {
return localize("Illegal format"); return localize("Illegal format");
} }
let vmName = selected.substring(0, selected.lastIndexOf(":")); const vmName = selected.substring(0, selected.lastIndexOf(":"));
let property = selected.substring(selected.lastIndexOf(":") + 1); const property = selected.substring(selected.lastIndexOf(":") + 1);
var vmDef = vmInfos.get(vmName); const vmDef = vmInfos.get(vmName);
let maxValue = vmDef.spec.vm["maximum" const maxValue = vmDef.spec.vm["maximum"
+ property.substring(0, 1).toUpperCase() + property.substring(1)]; + property.substring(0, 1).toUpperCase() + property.substring(1)];
if (value > maxValue) { if (value > maxValue) {
return localize("Value is above maximum"); return localize("Value is above maximum");
@ -160,12 +160,13 @@ window.orgJDrupesVmOperatorVmConlet.initView = (viewDom: HTMLElement,
}; };
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet", JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
"updateVm", function(_conletId: String, vmDefinition: any) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
"updateVm", function(_conletId: string, vmDefinition: any) {
// Add some short-cuts for table controller // Add some short-cuts for table controller
vmDefinition.name = vmDefinition.metadata.name; vmDefinition.name = vmDefinition.metadata.name;
vmDefinition.currentCpus = vmDefinition.status.cpus; vmDefinition.currentCpus = vmDefinition.status.cpus;
vmDefinition.currentRam = Number(vmDefinition.status.ram); vmDefinition.currentRam = Number(vmDefinition.status.ram);
for (let condition of vmDefinition.status.conditions) { for (const condition of vmDefinition.status.conditions) {
if (condition.type === "Running") { if (condition.type === "Running") {
vmDefinition.running = condition.status === "True"; vmDefinition.running = condition.status === "True";
vmDefinition.runningConditionSince vmDefinition.runningConditionSince
@ -177,14 +178,15 @@ JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
}); });
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet", JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
"removeVm", function(_conletId: String, vmName: String) { "removeVm", function(_conletId: string, vmName: string) {
vmInfos.delete(vmName); vmInfos.delete(vmName);
}); });
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet", JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
"summarySeries", function(_conletId: String, series: any[]) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
"summarySeries", function(_conletId: string, series: any[]) {
chartData.clear(); chartData.clear();
for (let entry of series) { for (const entry of series) {
chartData.push(new Date(entry.time.epochSecond * 1000 chartData.push(new Date(entry.time.epochSecond * 1000
+ entry.time.nano / 1000000), + entry.time.nano / 1000000),
entry.values[0], entry.values[1]); entry.values[0], entry.values[1]);
@ -193,7 +195,8 @@ JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
}); });
JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet", JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
"updateSummary", function(_conletId: String, summary: any) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
"updateSummary", function(_conletId: string, summary: any) {
chartData.push(new Date(), summary.usedCpus, Number(summary.usedRam)); chartData.push(new Date(), summary.usedCpus, Number(summary.usedRam));
chartDateUpdate.value = new Date(); chartDateUpdate.value = new Date();
Object.assign(vmSummary, summary); Object.assign(vmSummary, summary);

View file

@ -38,57 +38,47 @@
} }
.jdrupes-vmoperator-vmconlet-view-search { .jdrupes-vmoperator-vmconlet-view-search {
display: flex; display: flex;
justify-content: flex-end justify-content: flex-end
}
.jdrupes-vmoperator-vmconlet-view-search form {
white-space: nowrap;
}
.jdrupes-vmoperator-vmconlet-view-action-list {
white-space: nowrap;
}
.jdrupes-vmoperator-vmconlet-view-action-list [role=button]:not(:last-child) {
margin-right: 0.5em;
}
.jdrupes-vmoperator-vmconlet-view td {
vertical-align: top;
&[tabindex] { form {
outline: 1px solid var(--primary); white-space: nowrap;
cursor: text;
} }
} }
.jdrupes-vmoperator-vmconlet-view td:not([colspan]):first-child {
white-space: nowrap;
}
.jdrupes-vmoperator-vmconlet-view table td.details {
padding-left: 1em;
}
.jdrupes-vmoperator-vmconlet-view-table { .jdrupes-vmoperator-vmconlet-view-table {
td.column-running { td {
text-align: center; vertical-align: top;
span { &[tabindex] {
&.fa-check { outline: 1px solid var(--primary);
color: var(--success); cursor: text;
} }
&:not([colspan]):first-child {
white-space: nowrap;
}
&.fa-close { &.column-running {
color: var(--danger); text-align: center;
span {
&.fa-check {
color: var(--success);
}
&.fa-close {
color: var(--danger);
}
} }
} }
} }
td.details { td.details {
padding-left: 1em;
table { table {
td:nth-child(2) { td:nth-child(2) {
min-width: 7em; min-width: 7em;
@ -104,3 +94,11 @@
} }
} }
} }
.jdrupes-vmoperator-vmconlet-view-action-list {
white-space: nowrap;
[role=button]:not(:last-child) {
margin-right: 0.5em;
}
}

1359
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,7 @@
"@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.0", "@rollup/plugin-terser": "^0.4.0",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"documentation": "^14.0.1", "documentation": "^14.0.1",
"install": "^0.13.0", "install": "^0.13.0",
"jsdoc": "^4.0.2", "jsdoc": "^4.0.2",