]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Refine symbols score input boxes
authormoisseev <moiseev@mezonplus.ru>
Sun, 3 Dec 2023 13:45:14 +0000 (16:45 +0300)
committermoisseev <moiseev@mezonplus.ru>
Sun, 3 Dec 2023 13:45:14 +0000 (16:45 +0300)
- reduce the minimum number of digits to appear after the decimal from 3 to 2
- remove useless dynamic step
- remove useless dynamic min/max restrictions

.eslintrc.json
interface/js/app/symbols.js

index f76a38e213ddd15e1407c93fe3c32bf210f643f5..49bb81dcf2d5e28ef65c279cc76241ff30b4e68b 100644 (file)
@@ -66,7 +66,6 @@
         "max-lines": "off",
         "max-lines-per-function": "off",
         "no-invalid-this": "off",
-        "prefer-exponentiation-operator": "off",
         "sort-keys": "off",
 
         "@stylistic/function-paren-newline": "off"
index 5c51c28f4a3cf44956edc85b134e8cb4b14b387b..d35715188785c85b0dc2003ee63cd6b61284b842 100644 (file)
@@ -53,10 +53,7 @@ define(["jquery", "app/rspamd", "footable"],
                 server: server
             });
         }
-        function decimalStep(number) {
-            const digits = Number(number).toFixed(20).replace(/^-?\d*\.?|0+$/g, "").length;
-            return (digits === 0 || digits > 4) ? 0.1 : 1.0 / Math.pow(10, digits);
-        }
+
         function process_symbols_data(data) {
             const items = [];
             const lookup = {};
@@ -66,15 +63,12 @@ define(["jquery", "app/rspamd", "footable"],
 
             data.forEach((group) => {
                 group.rules.forEach((item) => {
-                    let max = 20;
-                    let min = -20;
-                    if (item.weight > max) {
-                        max = item.weight * 2;
-                    }
+                    const formatter = new Intl.NumberFormat("en", {
+                        minimumFractionDigits: 2,
+                        maximumFractionDigits: 6,
+                        useGrouping: false
+                    });
                     item.group = group.group;
-                    if (item.weight < min) {
-                        min = item.weight * 2;
-                    }
                     let label_class = "";
                     if (item.weight < 0) {
                         label_class = "scorebar-ham";
@@ -82,10 +76,8 @@ define(["jquery", "app/rspamd", "footable"],
                         label_class = "scorebar-spam";
                     }
                     item.weight = "<input class=\"form-control input-sm mb-disabled " + label_class +
-                    "\" data-role=\"numerictextbox\" autocomplete=\"off\" type=\"number\" class=\"input\" min=\"" +
-                    min + "\" max=\"" +
-                    max + "\" step=\"" + decimalStep(item.weight) +
-                    "\" tabindex=\"1\" value=\"" + Number(item.weight).toFixed(3) +
+                    "\" data-role=\"numerictextbox\" autocomplete=\"off\" type=\"number\"" +
+                    " step=\"0.01\" tabindex=\"1\" value=\"" + formatter.format(item.weight) +
                     "\" id=\"_sym_" + item.symbol + "\"></input>";
                     if (!item.time) {
                         item.time = 0;