]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Show message size in IEC (base 1024) units 4765/head
authormoisseev <moiseev@mezonplus.ru>
Sat, 30 Dec 2023 15:06:40 +0000 (18:06 +0300)
committermoisseev <moiseev@mezonplus.ru>
Sat, 30 Dec 2023 15:06:40 +0000 (18:06 +0300)
.eslintrc.json
interface/js/app/history.js
interface/js/app/libft.js

index 6aa347e1d933e2b55917224f413723fdd033b47f..b9dbe167908a1650c61b38989cc6f176ba36f7d0 100644 (file)
@@ -10,6 +10,9 @@
     "globals": {
         "define": false
     },
+    "parserOptions": {
+        "ecmaVersion": 2016
+    },
     "plugins": [
       "@stylistic"
     ],
index f2b8b8e46b3d2d67134cae274602265108881a95..0d953ec1e52d615c5e156c1a6cbce9b8b7333ab4 100644 (file)
@@ -24,8 +24,8 @@
 
 /* global FooTable */
 
-define(["jquery", "app/common", "app/libft", "d3", "footable"],
-    ($, common, libft, d3) => {
+define(["jquery", "app/common", "app/libft", "footable"],
+    ($, common, libft) => {
         "use strict";
         const ui = {};
         let prevVersion = null;
@@ -94,7 +94,7 @@ define(["jquery", "app/common", "app/libft", "d3", "footable"],
                 title: "Message size",
                 breakpoints: "xs sm",
                 style: {width: 120, maxWidth: 120},
-                formatter: d3.format(".3~s")
+                formatter: libft.formatBytesIEC
             }, {
                 name: "scan_time",
                 title: "Scan time",
index eab3b6d3a35a996134b0de12170c580a5e23d9c7..463ddec1637a7cb2d24d7c12eb931e98967dd98e 100644 (file)
@@ -1,7 +1,7 @@
 /* global FooTable */
 
-define(["jquery", "app/common", "d3", "footable"],
-    ($, common, d3) => {
+define(["jquery", "app/common", "footable"],
+    ($, common) => {
         "use strict";
         const ui = {};
 
@@ -35,6 +35,22 @@ define(["jquery", "app/common", "d3", "footable"],
 
         // Public functions
 
+        ui.formatBytesIEC = function (bytes) {
+            // FooTable represents data as text even column type is "number".
+            if (!Number.isInteger(Number(bytes)) || bytes < 0) return "NaN";
+
+            const base = 1024;
+            const exponent = Math.floor(Math.log(bytes) / Math.log(base));
+
+            if (exponent > 8) return "∞";
+
+            const value = parseFloat((bytes / (base ** exponent)).toPrecision(3));
+            let unit = "BKMGTPEZY"[exponent];
+            if (exponent) unit += "iB";
+
+            return value + " " + unit;
+        };
+
         ui.columns_v2 = function (table) {
             return [{
                 name: "id",
@@ -125,7 +141,7 @@ define(["jquery", "app/common", "d3", "footable"],
                 title: "Msg size",
                 breakpoints: "xs sm md",
                 style: {minwidth: 50},
-                formatter: d3.format(".3~s")
+                formatter: ui.formatBytesIEC
             }, {
                 name: "time_real",
                 title: "Scan time",