diff --git a/packages/frontend/src/filters/bytes.ts b/packages/frontend/src/filters/bytes.ts index d40b020a9e..2497ddb775 100644 --- a/packages/frontend/src/filters/bytes.ts +++ b/packages/frontend/src/filters/bytes.ts @@ -5,10 +5,10 @@ export default (v, digits = 0) => { if (v == null) return '?'; - const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'RB', 'QB']; if (v === 0) return '0'; const isMinus = v < 0; if (isMinus) v = -v; const i = Math.floor(Math.log(v) / Math.log(1024)); - return (isMinus ? '-' : '') + (v / Math.pow(1024, i)).toFixed(digits).replace(/\.0+$/, '') + sizes[i]; + return (isMinus ? '-' : '') + (v / Math.pow(1024, i)).toFixed(digits).replace(/(\.[1-9]*)0+$/, '$1').replace(/\.$/, '') + (sizes[i] ?? `e+${ i * 3 }B`); }; diff --git a/packages/frontend/src/filters/kmg.ts b/packages/frontend/src/filters/kmg.ts new file mode 100644 index 0000000000..4dcb5c5800 --- /dev/null +++ b/packages/frontend/src/filters/kmg.ts @@ -0,0 +1,9 @@ +export default (v, fractionDigits = 0) => { + if (v == null) return 'N/A'; + if (v === 0) return '0'; + const sizes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q']; + const isMinus = v < 0; + if (isMinus) v = -v; + const i = Math.floor(Math.log(v) / Math.log(1000)); + return (isMinus ? '-' : '') + (v / Math.pow(1000, i)).toFixed(fractionDigits).replace(/(\.[1-9]*)0+$/, '$1').replace(/\.$/, '') + (sizes[i] ?? `e+${ i * 3 }`); +}; diff --git a/packages/frontend/src/widgets/WidgetJobQueue.vue b/packages/frontend/src/widgets/WidgetJobQueue.vue index 10bc257e12..91983d8474 100644 --- a/packages/frontend/src/widgets/WidgetJobQueue.vue +++ b/packages/frontend/src/widgets/WidgetJobQueue.vue @@ -10,19 +10,19 @@ SPDX-License-Identifier: AGPL-3.0-only
Process
-
{{ number(current.inbox.activeSincePrevTick) }}
+
{{ kmg(current.inbox.activeSincePrevTick, 2) }}
Active
-
{{ number(current.inbox.active) }}
+
{{ kmg(current.inbox.active, 2) }}
Delayed
-
{{ number(current.inbox.delayed) }}
+
{{ kmg(current.inbox.delayed, 2) }}
Waiting
-
{{ number(current.inbox.waiting) }}
+
{{ kmg(current.inbox.waiting, 2) }}
@@ -31,19 +31,19 @@ SPDX-License-Identifier: AGPL-3.0-only
Process
-
{{ number(current.deliver.activeSincePrevTick) }}
+
{{ kmg(current.deliver.activeSincePrevTick, 2) }}
Active
-
{{ number(current.deliver.active) }}
+
{{ kmg(current.deliver.active, 2) }}
Delayed
-
{{ number(current.deliver.delayed) }}
+
{{ kmg(current.deliver.delayed, 2) }}
Waiting
-
{{ number(current.deliver.waiting) }}
+
{{ kmg(current.deliver.waiting, 2) }}
@@ -55,7 +55,7 @@ import { onUnmounted, reactive, ref } from 'vue'; import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js'; import { GetFormResultType } from '@/scripts/form.js'; import { useStream } from '@/stream.js'; -import number from '@/filters/number.js'; +import kmg from '@/filters/kmg.js'; import * as sound from '@/scripts/sound.js'; import { deepClone } from '@/scripts/clone.js'; import { defaultStore } from '@/store.js';