]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Convert callbacks to arrow functions 4715/head
authormoisseev <moiseev@mezonplus.ru>
Wed, 22 Nov 2023 07:28:30 +0000 (10:28 +0300)
committermoisseev <moiseev@mezonplus.ru>
Wed, 22 Nov 2023 07:28:30 +0000 (10:28 +0300)
.eslintrc.json
interface/js/app/config.js
interface/js/app/graph.js
interface/js/app/history.js
interface/js/app/rspamd.js
interface/js/app/selectors.js
interface/js/app/stats.js
interface/js/app/symbols.js
interface/js/app/upload.js
interface/js/main.js

index 5ae3238eae9aa87322e571602cef5e69cd6bf8b0..f76a38e213ddd15e1407c93fe3c32bf210f643f5 100644 (file)
@@ -33,7 +33,6 @@
         "no-ternary": "off",
         "object-shorthand": "off",
         "one-var": ["error", { "initialized": "never" }],
-        "prefer-arrow-callback": "off",
         "prefer-named-capture-group": "off",
         "prefer-object-has-own": "off",
         "prefer-spread": "off",
index 9f62c97dbc9812420c800bf23aea9a2aaca1427e..1aaf71289e190b053bc2da7392c53e7c52efa37a 100644 (file)
@@ -25,7 +25,7 @@
 /* global require */
 
 define(["jquery", "app/rspamd"],
-    function ($, rspamd) {
+    ($, rspamd) => {
         "use strict";
         const ui = {};
 
@@ -34,7 +34,7 @@ define(["jquery", "app/rspamd"],
                 success: function (data) {
                     $("#actionsFormField").empty();
                     const items = [];
-                    $.each(data[0].data, function (i, item) {
+                    $.each(data[0].data, (i, item) => {
                         const actionsOrder = ["greylist", "add header", "rewrite subject", "reject"];
                         const idx = actionsOrder.indexOf(item.action);
                         if (idx >= 0) {
@@ -52,14 +52,10 @@ define(["jquery", "app/rspamd"],
                         }
                     });
 
-                    items.sort(function (a, b) {
-                        return a.idx - b.idx;
-                    });
+                    items.sort((a, b) => a.idx - b.idx);
 
                     $("#actionsFormField").html(
-                        items.map(function (e) {
-                            return e.html;
-                        }).join(""));
+                        items.map((e) => e.html).join(""));
                 },
                 server: (checked_server === "All SERVERS") ? "local" : checked_server
             });
@@ -68,9 +64,7 @@ define(["jquery", "app/rspamd"],
         ui.saveActions = function (server) {
             function descending(arr) {
                 let desc = true;
-                const filtered = arr.filter(function (el) {
-                    return el !== null;
-                });
+                const filtered = arr.filter((el) => el !== null);
                 for (let i = 0; i < filtered.length - 1; i++) {
                     if (filtered[i + 1] >= filtered[i]) {
                         desc = false;
@@ -125,7 +119,7 @@ define(["jquery", "app/rspamd"],
                     $("#modalBody").empty();
                     const $tbody = $("<tbody>");
 
-                    $.each(data, function (i, item) {
+                    $.each(data, (i, item) => {
                         let $td = '<td><span class="badge text-bg-secondary">Read</span></td>';
                         if (!(item.editable === false || rspamd.read_only)) {
                             $td = $($td).append('&nbsp;<span class="badge text-bg-success">Write</span>');
@@ -178,7 +172,7 @@ define(["jquery", "app/rspamd"],
                         '"></' + editor[mode].elt + ">").appendTo("#modalBody");
 
                     if (editor[mode].codejar) {
-                        require(["codejar", "linenumbers", "prism"], function (CodeJar, withLineNumbers, Prism) {
+                        require(["codejar", "linenumbers", "prism"], (CodeJar, withLineNumbers, Prism) => {
                             jar = new CodeJar(
                                 document.querySelector("#editor"),
                                 withLineNumbers((el) => Prism.highlightElement(el))
@@ -207,7 +201,7 @@ define(["jquery", "app/rspamd"],
             });
             return false;
         });
-        $("#modalDialog").on("hidden.bs.modal", function () {
+        $("#modalDialog").on("hidden.bs.modal", () => {
             if (editor[mode].codejar) {
                 jar.destroy();
                 $(".codejar-wrap").remove();
@@ -216,10 +210,10 @@ define(["jquery", "app/rspamd"],
             }
         });
 
-        $("#saveActionsBtn").on("click", function () {
+        $("#saveActionsBtn").on("click", () => {
             ui.saveActions();
         });
-        $("#saveActionsClusterBtn").on("click", function () {
+        $("#saveActionsClusterBtn").on("click", () => {
             ui.saveActions("All SERVERS");
         });
 
@@ -241,10 +235,10 @@ define(["jquery", "app/rspamd"],
                 server: server
             });
         }
-        $("#modalSave").on("click", function () {
+        $("#modalSave").on("click", () => {
             saveMap();
         });
-        $("#modalSaveAll").on("click", function () {
+        $("#modalSaveAll").on("click", () => {
             saveMap("All SERVERS");
         });
 
index a661d4a19df0f76e7fadf4e7dedebf3d227102fd..2fc00a45758eed1e5a87f1aae697dd66daa3d0a3 100644 (file)
@@ -26,7 +26,7 @@
 /* global FooTable */
 
 define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
-    function ($, rspamd, D3Evolution, D3Pie, d3) {
+    ($, rspamd, D3Evolution, D3Pie, d3) => {
         "use strict";
 
         const rrd_pie_config = {
@@ -96,17 +96,17 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
             }
 
             function getRrdSummary(json, scaleFactor) {
-                const xExtents = d3.extent(d3.merge(json), function (d) { return d.x; });
+                const xExtents = d3.extent(d3.merge(json), (d) => d.x);
                 const timeInterval = xExtents[1] - xExtents[0];
 
                 let total = 0;
-                const rows = json.map(function (curr, i) {
+                const rows = json.map((curr, i) => {
                     // Time intervals that don't have data are excluded from average calculation as d3.mean()ignores nulls
-                    const avg = d3.mean(curr, function (d) { return d.y; });
+                    const avg = d3.mean(curr, (d) => d.y);
                     // To find an integral on the whole time interval we need to convert nulls to zeroes
                     // eslint-disable-next-line no-bitwise
-                    const value = d3.mean(curr, function (d) { return Number(d.y); }) * timeInterval / scaleFactor ^ 0;
-                    const yExtents = d3.extent(curr, function (d) { return d.y; });
+                    const value = d3.mean(curr, (d) => Number(d.y)) * timeInterval / scaleFactor ^ 0;
+                    const yExtents = d3.extent(curr, (d) => d.y);
 
                     total += value;
                     return {
@@ -139,22 +139,20 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
                         {name: "max", title: "Maximum, <span class=\"unit\">" + unit + "</span>", defaultContent: ""},
                         {name: "last", title: "Last, " + unit},
                     ],
-                    rows: rows.map(function (curr, i) {
-                        return {
-                            options: {
-                                style: {
-                                    color: graph_options.legend.entries[i].color
-                                }
-                            },
-                            value: curr
-                        };
-                    }, [])
+                    rows: rows.map((curr, i) => ({
+                        options: {
+                            style: {
+                                color: graph_options.legend.entries[i].color
+                            }
+                        },
+                        value: curr
+                    }), [])
                 });
             }
 
             function drawRrdTable(rows, unit) {
                 if (Object.prototype.hasOwnProperty.call(rspamd.tables, "rrd_summary")) {
-                    $.each(rspamd.tables.rrd_summary.rows.all, function (i, row) {
+                    $.each(rspamd.tables.rrd_summary.rows.all, (i, row) => {
                         row.val(rows[i], false, true);
                     });
                 } else {
@@ -169,12 +167,12 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
                 if (data) {
                     // Autoranging
                     let scaleFactor = 1;
-                    const yMax = d3.max(d3.merge(data), function (d) { return d.y; });
+                    const yMax = d3.max(d3.merge(data), (d) => d.y);
                     if (yMax < 1) {
                         scaleFactor = 60;
                         unit = "msg/min";
-                        data.forEach(function (s) {
-                            s.forEach(function (d) {
+                        data.forEach((s) => {
+                            s.forEach((d) => {
                                 if (d.y !== null) { d.y *= scaleFactor; }
                             });
                         });
@@ -205,14 +203,14 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
                 success: function (req_data) {
                     let data = null;
                     const neighbours_data = req_data
-                        .filter(function (d) { return d.status; }) // filter out unavailable neighbours
-                        .map(function (d) { return d.data; });
+                        .filter((d) => d.status) // filter out unavailable neighbours
+                        .map((d) => d.data);
 
                     if (neighbours_data.length === 1) {
                         [data] = neighbours_data;
                     } else {
                         let time_match = true;
-                        neighbours_data.reduce(function (res, curr, _, arr) {
+                        neighbours_data.reduce((res, curr, _, arr) => {
                             if ((curr[0][0].x !== res[0][0].x) ||
                             (curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
                                 time_match = false;
@@ -224,16 +222,10 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
                         });
 
                         if (time_match) {
-                            data = neighbours_data.reduce(function (res, curr) {
-                                return curr.map(function (action, j) {
-                                    return action.map(function (d, i) {
-                                        return {
-                                            x: d.x,
-                                            y: (res[j][i].y === null) ? d.y : res[j][i].y + d.y
-                                        };
-                                    });
-                                });
-                            });
+                            data = neighbours_data.reduce((res, curr) => curr.map((action, j) => action.map((d, i) => ({
+                                x: d.x,
+                                y: (res[j][i].y === null) ? d.y : res[j][i].y + d.y
+                            }))));
                         }
                     }
                     updateWidgets(data);
@@ -247,11 +239,11 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
 
 
         // Handling mouse events on overlapping elements
-        $("#rrd-pie").mouseover(function () {
+        $("#rrd-pie").mouseover(() => {
             $("#rrd-pie,#rrd-pie-tooltip").css("z-index", "200");
             $("#rrd-table_toggle").css("z-index", "300");
         });
-        $("#rrd-table_toggle").mouseover(function () {
+        $("#rrd-table_toggle").mouseover(() => {
             $("#rrd-pie,#rrd-pie-tooltip").css("z-index", "0");
             $("#rrd-table_toggle").css("z-index", "0");
         });
index 568c697634966b03b4ff53e9730a98ec718b78e1..26b2e96a6cb07a99a5c3cf4f0555c68da5f4808b 100644 (file)
@@ -25,7 +25,7 @@
 /* global FooTable */
 
 define(["jquery", "app/rspamd", "d3", "footable"],
-    function ($, rspamd, d3) {
+    ($, rspamd, d3) => {
         "use strict";
         const ui = {};
         let prevVersion = null;
@@ -37,15 +37,13 @@ define(["jquery", "app/rspamd", "d3", "footable"],
 
             $("#selSymOrder_history, label[for='selSymOrder_history']").hide();
 
-            $.each(data, function (i, item) {
+            $.each(data, (i, item) => {
                 item.time = rspamd.unix_time_format(item.unix_time);
                 rspamd.preprocess_item(item);
                 item.symbols = Object.keys(item.symbols)
-                    .map(function (key) {
-                        return item.symbols[key];
-                    })
+                    .map((key) => item.symbols[key])
                     .sort(compare)
-                    .map(function (e) { return e.name; })
+                    .map((e) => e.name)
                     .join(", ");
                 item.time = {
                     value: rspamd.unix_time_format(item.unix_time),
@@ -324,9 +322,7 @@ define(["jquery", "app/rspamd", "d3", "footable"],
             rspamd.query("history", {
                 success: function (req_data) {
                     function differentVersions(neighbours_data) {
-                        const dv = neighbours_data.some(function (e) {
-                            return e.version !== neighbours_data[0].version;
-                        });
+                        const dv = neighbours_data.some((e) => e.version !== neighbours_data[0].version);
                         if (dv) {
                             rspamd.alertMessage("alert-error",
                                 "Neighbours history backend versions do not match. Cannot display history.");
@@ -336,16 +332,14 @@ define(["jquery", "app/rspamd", "d3", "footable"],
                     }
 
                     const neighbours_data = req_data
-                        .filter(function (d) { return d.status; }) // filter out unavailable neighbours
-                        .map(function (d) { return d.data; });
+                        .filter((d) => d.status) // filter out unavailable neighbours
+                        .map((d) => d.data);
                     if (neighbours_data.length && !differentVersions(neighbours_data)) {
                         let data = {};
                         const [{version}] = neighbours_data;
                         if (version) {
                             data.rows = [].concat.apply([], neighbours_data
-                                .map(function (e) {
-                                    return e.rows;
-                                }));
+                                .map((e) => e.rows));
                             data.version = version;
                             $("#legacy-history-badge").hide();
                         } else {
@@ -363,7 +357,7 @@ define(["jquery", "app/rspamd", "d3", "footable"],
                         } else {
                             rspamd.destroyTable("history");
                             // Is there a way to get an event when the table is destroyed?
-                            setTimeout(function () {
+                            setTimeout(() => {
                                 rspamd.initHistoryTable(data, items, "history", get_history_columns(data), false);
                             }, 200);
                         }
@@ -421,14 +415,10 @@ define(["jquery", "app/rspamd", "d3", "footable"],
             rspamd.query("errors", {
                 success: function (data) {
                     const neighbours_data = data
-                        .filter(function (d) {
-                            return d.status;
-                        }) // filter out unavailable neighbours
-                        .map(function (d) {
-                            return d.data;
-                        });
+                        .filter((d) => d.status) // filter out unavailable neighbours
+                        .map((d) => d.data);
                     const rows = [].concat.apply([], neighbours_data);
-                    $.each(rows, function (i, item) {
+                    $.each(rows, (i, item) => {
                         item.ts = {
                             value: rspamd.unix_time_format(item.ts),
                             options: {
@@ -445,7 +435,7 @@ define(["jquery", "app/rspamd", "d3", "footable"],
             });
 
             $("#updateErrors").off("click");
-            $("#updateErrors").on("click", function (e) {
+            $("#updateErrors").on("click", (e) => {
                 e.preventDefault();
                 ui.getErrors();
             });
@@ -456,14 +446,14 @@ define(["jquery", "app/rspamd", "d3", "footable"],
         rspamd.bindHistoryTableEventHandlers("history", 8);
 
         $("#updateHistory").off("click");
-        $("#updateHistory").on("click", function (e) {
+        $("#updateHistory").on("click", (e) => {
             e.preventDefault();
             ui.getHistory();
         });
 
         // @reset history log
         $("#resetHistory").off("click");
-        $("#resetHistory").on("click", function (e) {
+        $("#resetHistory").on("click", (e) => {
             e.preventDefault();
             if (!confirm("Are you sure you want to reset history log?")) { // eslint-disable-line no-alert
                 return;
index 64eab27a03c88b408c3094f806fba6f836d106ec..1fac8b939890c97a1011a7a21372a4f7c28edb1a 100644 (file)
@@ -27,7 +27,7 @@
 
 define(["jquery", "nprogress", "stickytabs", "visibility",
     "bootstrap", "fontawesome"],
-function ($, NProgress) {
+($, NProgress) => {
     "use strict";
     const ui = {
         chartLegend: [
@@ -92,8 +92,8 @@ function ($, NProgress) {
     }
 
     function disconnect() {
-        [graphs, tables].forEach(function (o) {
-            Object.keys(o).forEach(function (key) {
+        [graphs, tables].forEach((o) => {
+            Object.keys(o).forEach((key) => {
                 o[key].destroy();
                 delete o[key];
             });
@@ -139,7 +139,7 @@ function ($, NProgress) {
 
                 let timeLeft = interval;
                 $("#countdown").text("00:00");
-                timer_id.countdown = Visibility.every(1000, 1000, function () {
+                timer_id.countdown = Visibility.every(1000, 1000, () => {
                     timeLeft -= 1000;
                     $("#countdown").text(new Date(timeLeft).toISOString().substr(14, 5));
                     if (timeLeft <= 0) Visibility.stop(timer_id.countdown);
@@ -151,7 +151,7 @@ function ($, NProgress) {
 
             countdown(refreshInterval);
             if (!refreshInterval) return;
-            timer_id[timer] = Visibility.every(refreshInterval, function () {
+            timer_id[timer] = Visibility.every(refreshInterval, () => {
                 countdown(refreshInterval);
                 if ($("#refresh").attr("disabled")) return;
                 $("#refresh").attr("disabled", true).addClass("disabled", true);
@@ -170,7 +170,7 @@ function ($, NProgress) {
                 require(["app/stats"], (module) => {
                     const refreshInterval = $(".dropdown-menu a.active.preset").data("value");
                     setAutoRefresh(refreshInterval, "status",
-                        function () { return module.statWidgets(graphs, checked_server); });
+                        () => module.statWidgets(graphs, checked_server));
                     if (id !== "#autoRefresh") module.statWidgets(graphs, checked_server);
 
                     $(".preset").show();
@@ -192,7 +192,7 @@ function ($, NProgress) {
                         refreshInterval = null;
                     }
                     setAutoRefresh(refreshInterval, "throughput",
-                        function () { return module.draw(graphs, neighbours, checked_server, selData); });
+                        () => module.draw(graphs, neighbours, checked_server, selData));
                     if (id !== "#autoRefresh") module.draw(graphs, neighbours, checked_server, selData);
 
                     $(".preset").hide();
@@ -223,7 +223,7 @@ function ($, NProgress) {
                     }
                     const refreshInterval = $(".dropdown-menu a.active.history").data("value");
                     setAutoRefresh(refreshInterval, "history",
-                        function () { return getHistoryAndErrors(); });
+                        () => getHistoryAndErrors());
                     if (id !== "#autoRefresh") getHistoryAndErrors();
 
                     $(".preset").hide();
@@ -237,7 +237,7 @@ function ($, NProgress) {
             default:
         }
 
-        setTimeout(function () {
+        setTimeout(() => {
             // Do not enable Refresh button until AJAX requests to all neighbours are finished
             if (tab_id === "#history_nav") navBarControls = $(navBarControls).not("#refresh");
 
@@ -292,11 +292,9 @@ function ($, NProgress) {
 
     function sort_symbols(o, compare_function) {
         return Object.keys(o)
-            .map(function (key) {
-                return o[key];
-            })
+            .map((key) => o[key])
             .sort(compare_function)
-            .map(function (e) { return e.str; })
+            .map((e) => e.str)
             .join("<br>\n");
     }
 
@@ -316,7 +314,7 @@ function ($, NProgress) {
             success: function (neighbours_status) {
                 $("#selSrv").empty();
                 $("#selSrv").append($('<option value="All SERVERS">All SERVERS</option>'));
-                neighbours_status.forEach(function (e) {
+                neighbours_status.forEach((e) => {
                     $("#selSrv").append($('<option value="' + e.name + '">' + e.name + "</option>"));
                     if (checked_server === e.name) {
                         $('#selSrv [value="' + e.name + '"]').prop("selected", true);
@@ -351,7 +349,7 @@ function ($, NProgress) {
                 "<strong>" + alertText + "</strong>");
         $(".notification-area").append(a);
 
-        setTimeout(function () {
+        setTimeout(() => {
             $(a).fadeTo(500, 0).slideUp(500, function () {
                 $(this).alert("close");
             });
@@ -371,12 +369,11 @@ function ($, NProgress) {
                 const xhr = $.ajaxSettings.xhr();
                 // Download progress
                 if (req_url !== "neighbours") {
-                    xhr.addEventListener("progress", function (e) {
+                    xhr.addEventListener("progress", (e) => {
                         if (e.lengthComputable) {
                             neighbours_status[ind].percentComplete = e.loaded / e.total;
-                            const percentComplete = neighbours_status.reduce(function (prev, curr) {
-                                return curr.percentComplete ? curr.percentComplete + prev : prev;
-                            }, 0);
+                            const percentComplete = neighbours_status
+                                .reduce((prev, curr) => (curr.percentComplete ? curr.percentComplete + prev : prev), 0);
                             NProgress.set(percentComplete / neighbours_status.length);
                         }
                     }, false);
@@ -409,8 +406,8 @@ function ($, NProgress) {
                 }
             },
             complete: function (jqXHR) {
-                if (neighbours_status.every(function (elt) { return elt.checked; })) {
-                    if (neighbours_status.some(function (elt) { return elt.status; })) {
+                if (neighbours_status.every((elt) => elt.checked)) {
+                    if (neighbours_status.some((elt) => elt.status)) {
                         if (o.success) {
                             o.success(neighbours_status, jqXHR);
                         } else {
@@ -429,7 +426,7 @@ function ($, NProgress) {
             req_params.method = o.method;
         }
         if (o.params) {
-            $.each(o.params, function (k, v) {
+            $.each(o.params, (k, v) => {
                 req_params[k] = v;
             });
         }
@@ -470,7 +467,7 @@ function ($, NProgress) {
                     })
                     .modal("show");
 
-                $("#connectForm").off("submit").on("submit", function (e) {
+                $("#connectForm").off("submit").on("submit", (e) => {
                     e.preventDefault();
                     const password = $("#connectPassword").val();
 
@@ -546,7 +543,7 @@ function ($, NProgress) {
     ui.query = function (url, options) {
         // Force options to be an object
         const o = options || {};
-        Object.keys(o).forEach(function (option) {
+        Object.keys(o).forEach((option) => {
             if (["complete", "data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server",
                 "statusCode", "success"]
                 .indexOf(option) < 0) {
@@ -575,14 +572,14 @@ function ($, NProgress) {
                         neighbours = data;
                     }
                     neighbours_status = [];
-                    $.each(neighbours, function (ind) {
+                    $.each(neighbours, (ind) => {
                         neighbours_status.push({
                             name: ind,
                             host: neighbours[ind].host,
                             url: neighbours[ind].url,
                         });
                     });
-                    $.each(neighbours_status, function (ind) {
+                    $.each(neighbours_status, (ind) => {
                         queryServer(neighbours_status, ind, url, o);
                     });
                 },
@@ -610,7 +607,7 @@ function ($, NProgress) {
         function change_symbols_order(order) {
             $(".btn-sym-" + table + "-" + order).addClass("active").siblings().removeClass("active");
             const compare_function = get_compare_function(table);
-            $.each(tables[table].rows.all, function (i, row) {
+            $.each(tables[table].rows.all, (i, row) => {
                 const cell_val = sort_symbols(ui.symbols[table][i], compare_function);
                 row.cells[symbolsCol].val(cell_val, false, true);
             });
@@ -690,7 +687,7 @@ function ($, NProgress) {
                         text: self.def
                     })).appendTo($form_grp);
 
-                $.each(self.actions, function (i, action) {
+                $.each(self.actions, (i, action) => {
                     self.$action.append($("<option/>").text(action));
                 });
             },
@@ -738,7 +735,7 @@ function ($, NProgress) {
             },
             on: {
                 "expand.ft.row": function (e, ft, row) {
-                    setTimeout(function () {
+                    setTimeout(() => {
                         const detail_row = row.$el.next();
                         const order = getSelector("selSymOrder_" + table);
                         detail_row.find(".btn-sym-" + table + "-" + order)
@@ -761,14 +758,12 @@ function ($, NProgress) {
             "`": "&#x60;",
             "=": "&#x3D;"
         };
-        return String(string).replace(htmlEscaper, function (match) {
-            return htmlEscapes[match];
-        });
+        return String(string).replace(htmlEscaper, (match) => htmlEscapes[match]);
     };
 
     ui.preprocess_item = function (item) {
         function escape_HTML_array(arr) {
-            arr.forEach(function (d, i) { arr[i] = ui.escapeHTML(d); });
+            arr.forEach((d, i) => { arr[i] = ui.escapeHTML(d); });
         }
 
         for (const prop in item) {
@@ -779,7 +774,7 @@ function ($, NProgress) {
                     escape_HTML_array(item[prop]);
                     break;
                 case "symbols":
-                    Object.keys(item.symbols).forEach(function (key) {
+                    Object.keys(item.symbols).forEach((key) => {
                         const sym = item.symbols[key];
                         if (!sym.name) {
                             sym.name = key;
@@ -833,7 +828,7 @@ function ($, NProgress) {
         $("#selSymOrder_" + table + ", label[for='selSymOrder_" + table + "']").show();
 
         $.each(data.rows,
-            function (i, item) {
+            (i, item) => {
                 function more(p) {
                     const l = item[p].length;
                     return (l > rcpt_lim) ? " â€¦ (" + l + ")" : "";
@@ -870,7 +865,7 @@ function ($, NProgress) {
                 }
 
                 ui.preprocess_item(item);
-                Object.values(item.symbols).forEach(function (sym) {
+                Object.values(item.symbols).forEach((sym) => {
                     sym.str = '<span class="symbol-default ' + get_symbol_class(sym.name, sym.score) + '"><strong>';
 
                     if (sym.description) {
@@ -930,7 +925,7 @@ function ($, NProgress) {
             num_rows === rows_total) {
             return callback();
         } else if (--i) {
-            setTimeout(function () {
+            setTimeout(() => {
                 ui.waitForRowsDisplayed(table, rows_total, callback, i);
             }, 500);
         }
@@ -988,10 +983,10 @@ function ($, NProgress) {
         }).attr("title", function () {
             return $(this).attr("data-original-title");
         });
-        $("#settings").on("click", function (e) {
+        $("#settings").on("click", (e) => {
             e.preventDefault();
         });
-        $("#settings").on("inserted.bs.popover", function () {
+        $("#settings").on("inserted.bs.popover", () => {
             selected_locale = localStorage.getItem("selected_locale") || "browser";
             custom_locale = localStorage.getItem("custom_locale") || "";
             validateLocale();
@@ -1006,19 +1001,19 @@ function ($, NProgress) {
             localStorage.setItem("selected_locale", selected_locale);
             validateLocale();
         });
-        $(document).on("input", localeTextbox, function () {
+        $(document).on("input", localeTextbox, () => {
             custom_locale = $(localeTextbox).val();
             validateLocale(true);
         });
-        $(document).on("input", ajaxTimeoutBox, function () {
+        $(document).on("input", ajaxTimeoutBox, () => {
             ajaxSetup($(ajaxTimeoutBox).val(), false, true);
         });
-        $(document).on("click", ".popover #settings-popover #ajax-timeout-restore", function () {
+        $(document).on("click", ".popover #settings-popover #ajax-timeout-restore", () => {
             ajaxSetup(null, true, true);
         });
 
         // Dismiss Bootstrap popover by clicking outside
-        $("body").on("click", function (e) {
+        $("body").on("click", (e) => {
             $(".popover").each(function () {
                 if (
                     // Popover's descendant
@@ -1031,15 +1026,15 @@ function ($, NProgress) {
         });
     }());
 
-    $("#selData").change(function () {
+    $("#selData").change(() => {
         tabClick("#throughput_nav");
     });
 
-    $(document).ajaxStart(function () {
+    $(document).ajaxStart(() => {
         $("#refresh > svg").addClass("fa-spin");
     });
-    $(document).ajaxComplete(function () {
-        setTimeout(function () {
+    $(document).ajaxComplete(() => {
+        setTimeout(() => {
             $("#refresh > svg").removeClass("fa-spin");
         }, 1000);
     });
index 6535953b565295f539fec374dc94b921397a3d9b..64d103474c9620a62304d79140dc033a18140ee0 100644 (file)
@@ -1,5 +1,5 @@
 define(["jquery", "app/rspamd"],
-    function ($, rspamd) {
+    ($, rspamd) => {
         "use strict";
         const ui = {};
 
@@ -60,7 +60,7 @@ define(["jquery", "app/rspamd"],
 
         function buildLists() {
             function build_table_from_json(json, table_id) {
-                Object.keys(json).forEach(function (key) {
+                Object.keys(json).forEach((key) => {
                     const td = $("<td/>");
                     const tr = $("<tr/>")
                         .append(td.clone().html("<code>" + key + "</code>"))
@@ -109,35 +109,35 @@ define(["jquery", "app/rspamd"],
             $("#content").removeClass("col-lg-12 col-lg-9 col-lg-6")
                 .addClass(contentClass);
         }
-        $("#sidebar-tab-left>a").click(function () {
+        $("#sidebar-tab-left>a").click(() => {
             toggleSidebar("left");
             return false;
         });
-        $("#sidebar-tab-right>a").click(function () {
+        $("#sidebar-tab-right>a").click(() => {
             toggleSidebar("right");
             return false;
         });
 
-        $("#selectorsMsgClean").on("click", function () {
+        $("#selectorsMsgClean").on("click", () => {
             $("#selectorsChkMsgBtn").attr("disabled", true);
             $("#selectorsMsgArea").val("");
             return false;
         });
-        $("#selectorsClean").on("click", function () {
+        $("#selectorsClean").on("click", () => {
             $("#selectorsSelArea").val("");
             checkSelectors();
             return false;
         });
-        $("#selectorsChkMsgBtn").on("click", function () {
+        $("#selectorsChkMsgBtn").on("click", () => {
             $("#selectorsResArea").val("");
             checkMsg($("#selectorsMsgArea").val());
             return false;
         });
 
-        $("#selectorsMsgArea").on("input", function () {
+        $("#selectorsMsgArea").on("input", () => {
             enable_disable_check_btn();
         });
-        $("#selectorsSelArea").on("input", function () {
+        $("#selectorsSelArea").on("input", () => {
             checkSelectors();
         });
 
index c445793d90e8511be869f0ed532eef1d52b9961f..3ee0a907a512855c3732ecc7ee6ed93765bb7005 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 define(["jquery", "app/rspamd", "d3pie", "d3"],
-    function ($, rspamd, D3Pie, d3) {
+    ($, rspamd, D3Pie, d3) => {
         "use strict";
         // @ ms to date
         function msToTime(seconds) {
@@ -63,7 +63,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
 
             const stat_w = [];
             $("#statWidgets").empty().hide();
-            $.each(data, function (i, item) {
+            $.each(data, (i, item) => {
                 const widgetsOrder = ["scanned", "no action", "greylist", "add header", "rewrite subject", "reject", "learned"];
 
                 function widget(k, v, cls) {
@@ -87,14 +87,14 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
                       val + "</strong>" + i + "</div>")
                         .appendTo("#statWidgets");
                 } else if (i === "actions") {
-                    $.each(item, function (action, count) {
+                    $.each(item, (action, count) => {
                         stat_w[widgetsOrder.indexOf(action)] = widget(action, count);
                     });
                 } else {
                     stat_w[widgetsOrder.indexOf(i)] = widget(i, item, " text-capitalize");
                 }
             });
-            $.each(stat_w, function (i, item) {
+            $.each(stat_w, (i, item) => {
                 $(item).appendTo("#statWidgets");
             });
             $("#statWidgets > div:not(.stat-box)")
@@ -105,7 +105,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
 
             $("#clusterTable tbody").empty();
             $("#selSrv").empty();
-            $.each(servers, function (key, val) {
+            $.each(servers, (key, val) => {
                 let row_class = "danger";
                 let glyph_status = "fas fa-times";
                 let version = "???";
@@ -178,7 +178,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
             });
 
             function addStatfiles(server, statfiles) {
-                $.each(statfiles, function (i, statfile) {
+                $.each(statfiles, (i, statfile) => {
                     let cls = "";
                     switch (statfile.symbol) {
                         case "BAYES_SPAM":
@@ -200,7 +200,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
 
             function addFuzzyStorage(server, storages) {
                 let i = 0;
-                $.each(storages, function (storage, hashes) {
+                $.each(storages, (storage, hashes) => {
                     $("#fuzzyTable tbody").append("<tr>" +
                       (i === 0 ? '<td rowspan="' + Object.keys(storages).length + '">' + server + "</td>" : "") +
                       "<td>" + storage + "</td>" +
@@ -211,7 +211,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
 
             $("#bayesTable tbody, #fuzzyTable tbody").empty();
             if (checked_server === "All SERVERS") {
-                $.each(servers, function (server, val) {
+                $.each(servers, (server, val) => {
                     if (server !== "All SERVERS") {
                         addStatfiles(server, val.data.statfiles);
                         addFuzzyStorage(server, val.data.fuzzy_hashes);
@@ -252,9 +252,9 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
                 const {actions} = creds[checked_server].data;
 
                 ["no action", "soft reject", "add header", "rewrite subject", "greylist", "reject"]
-                    .forEach(function (action) {
+                    .forEach((action) => {
                         data.push({
-                            color: rspamd.chartLegend.find(function (item) { return item.label === action; }).color,
+                            color: rspamd.chartLegend.find((item) => item.label === action).color,
                             label: action,
                             value: actions[action]
                         });
@@ -304,7 +304,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
                                     }
                                 }
                             }
-                            ["learned", "scanned", "uptime"].forEach(function (p) {
+                            ["learned", "scanned", "uptime"].forEach((p) => {
                                 neighbours_sum[p] += data[p];
                             });
                             status_count++;
@@ -318,7 +318,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
                                 headers: {Password: rspamd.getPassword()},
                                 success: function (data) {
                                     sessionStorage.removeItem(alerted);
-                                    ["config_id", "version", "uptime"].forEach(function (p) {
+                                    ["config_id", "version", "uptime"].forEach((p) => {
                                         neighbours_status[e].data[p] = data[p];
                                     });
                                     process_node_stat(e);
@@ -349,8 +349,8 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
                                 }
                             }
                         }
-                        setTimeout(function () {
-                            $.when.apply($, promises).always(function () {
+                        setTimeout(() => {
+                            $.when.apply($, promises).always(() => {
                                 neighbours_sum.uptime = Math.floor(neighbours_sum.uptime / status_count);
                                 to_Credentials["All SERVERS"].data = neighbours_sum;
                                 sessionStorage.setItem("Credentials", JSON.stringify(to_Credentials));
index be6ad8d81cebaa3fd04dc0afb2e3a5b0361db46f..5c51c28f4a3cf44956edc85b134e8cb4b14b387b 100644 (file)
@@ -25,7 +25,7 @@
 /* global FooTable */
 
 define(["jquery", "app/rspamd", "footable"],
-    function ($, rspamd) {
+    ($, rspamd) => {
         "use strict";
         const ui = {};
 
@@ -64,8 +64,8 @@ define(["jquery", "app/rspamd", "footable"],
             const distinct_groups = [];
             const selected_server = rspamd.getSelector("selSrv");
 
-            data.forEach(function (group) {
-                group.rules.forEach(function (item) {
+            data.forEach((group) => {
+                group.rules.forEach((item) => {
                     let max = 20;
                     let min = -20;
                     if (item.weight > max) {
@@ -112,11 +112,9 @@ define(["jquery", "app/rspamd", "footable"],
             });
 
             // For better mean calculations
-            const avg_freq = freqs.sort(function (a, b) {
-                return Number(a) < Number(b);
-            }).reduce(function (f1, acc) {
-                return f1 + acc;
-            }) / (freqs.length !== 0 ? freqs.length : 1.0);
+            const avg_freq = freqs
+                .sort((a, b) => Number(a) < Number(b))
+                .reduce((f1, acc) => f1 + acc) / (freqs.length !== 0 ? freqs.length : 1.0);
             let mult = 1.0;
             let exp = 0.0;
 
@@ -126,7 +124,7 @@ define(["jquery", "app/rspamd", "footable"],
                     exp++;
                 }
             }
-            $.each(items, function (i, item) {
+            $.each(items, (i, item) => {
                 item.frequency = Number(item.frequency) * mult;
 
                 if (exp > 0) {
@@ -171,7 +169,7 @@ define(["jquery", "app/rspamd", "footable"],
                                     text: self.def
                                 })).appendTo($form_grp);
 
-                            $.each(self.groups, function (i, group) {
+                            $.each(self.groups, (i, group) => {
                                 self.$group.append($("<option/>").text(group));
                             });
                         },
@@ -249,7 +247,7 @@ define(["jquery", "app/rspamd", "footable"],
         };
 
 
-        $("#updateSymbols").on("click", function (e) {
+        $("#updateSymbols").on("click", (e) => {
             e.preventDefault();
             const checked_server = rspamd.getSelector("selSrv");
             rspamd.query("symbols", {
index 9893477f1d7e240235933f2bb593e643a904caaa..47d9e816fb37f21e5e7aec7d1cda06dbd250701e 100644 (file)
@@ -25,7 +25,7 @@
 /* global require */
 
 define(["jquery", "app/rspamd"],
-    function ($, rspamd) {
+    ($, rspamd) => {
         "use strict";
         const ui = {};
 
@@ -49,7 +49,7 @@ define(["jquery", "app/rspamd"],
             function server() {
                 if (rspamd.getSelector("selSrv") === "All SERVERS" &&
                     rspamd.getSelector("selLearnServers") === "random") {
-                    const servers = $("#selSrv option").slice(1).map(function (_, o) { return o.value; });
+                    const servers = $("#selSrv option").slice(1).map((_, o) => o.value);
                     return servers[Math.floor(Math.random() * servers.length)];
                 }
                 return null;
@@ -158,7 +158,7 @@ define(["jquery", "app/rspamd"],
                 success: function (neighbours_status) {
                     function scrollTop(rows_total) {
                         // Is there a way to get an event when all rows are loaded?
-                        rspamd.waitForRowsDisplayed("scan", rows_total, function () {
+                        rspamd.waitForRowsDisplayed("scan", rows_total, () => {
                             $("#cleanScanHistory").removeAttr("disabled", true);
                             $("html, body").animate({
                                 scrollTop: $("#scanResult").offset().top
@@ -180,9 +180,9 @@ define(["jquery", "app/rspamd"],
                             scrollTop(rows_total);
                         } else {
                             rspamd.destroyTable("scan");
-                            require(["footable"], function () {
+                            require(["footable"], () => {
                                 // Is there a way to get an event when the table is destroyed?
-                                setTimeout(function () {
+                                setTimeout(() => {
                                     rspamd.initHistoryTable(data, items, "scan", columns_v2(), true);
                                     scrollTop(rows_total);
                                 }, 200);
@@ -212,7 +212,7 @@ define(["jquery", "app/rspamd"],
             function fillHashTable(rules) {
                 $("#hashTable tbody").empty();
                 for (const [rule, hashes] of Object.entries(rules)) {
-                    hashes.forEach(function (hash, i) {
+                    hashes.forEach((hash, i) => {
                         $("#hashTable tbody").append("<tr>" +
                           (i === 0 ? '<td rowspan="' + Object.keys(hashes).length + '">' + rule + "</td>" : "") +
                           "<td>" + hash + "</td></tr>");
@@ -245,7 +245,7 @@ define(["jquery", "app/rspamd"],
         rspamd.bindHistoryTableEventHandlers("scan", 3);
 
         $("#cleanScanHistory").off("click");
-        $("#cleanScanHistory").on("click", function (e) {
+        $("#cleanScanHistory").on("click", (e) => {
             e.preventDefault();
             if (!confirm("Are you sure you want to clean scan history?")) { // eslint-disable-line no-alert
                 return;
@@ -260,11 +260,11 @@ define(["jquery", "app/rspamd"],
                 .prop("disabled", ($.trim($("textarea").val()).length === 0));
         }
         enable_disable_scan_btn();
-        $("textarea").on("input", function () {
+        $("textarea").on("input", () => {
             enable_disable_scan_btn();
         });
 
-        $("#scanClean").on("click", function () {
+        $("#scanClean").on("click", () => {
             $("#scan button:not(#cleanScanHistory, #scanOptionsToggle)").attr("disabled", true);
             $("#scanForm")[0].reset();
             $("#scanResult").hide();
@@ -283,7 +283,7 @@ define(["jquery", "app/rspamd"],
             let headers = {};
             if ($.trim(data).length > 0) {
                 if (source === "scan") {
-                    headers = ["IP", "User", "From", "Rcpt", "Helo", "Hostname"].reduce(function (o, header) {
+                    headers = ["IP", "User", "From", "Rcpt", "Helo", "Hostname"].reduce((o, header) => {
                         const value = $("#scan-opt-" + header.toLowerCase()).val();
                         if (value !== "") o[header] = value;
                         return o;
index 1d5ec5c3c99b62d4052f95ce3c553170a17c8152..0e226a0b5e5ad508eee8926b89130e0a4c4699a7 100644 (file)
@@ -41,7 +41,7 @@ document.title = window.location.hostname +
     " - Rspamd Web Interface";
 
 // Ugly hack to get d3pie work with requirejs
-define("d3.global", ["d3"], function (d3global) { // eslint-disable-line strict
+define("d3.global", ["d3"], (d3global) => { // eslint-disable-line strict
     d3 = d3global;
 });