]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Enable strict mode, 2336/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Thu, 12 Jul 2018 09:49:21 +0000 (12:49 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Thu, 12 Jul 2018 09:49:21 +0000 (12:49 +0300)
rename `interface` oblect as it is a reserved keyword,
declare $span and $tbody variables

.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/stats.js
interface/js/app/symbols.js
interface/js/app/upload.js
interface/js/main.js

index 19f85ea9c72c5e0731c763990e512da3928f0c30..9454f85d86e36d576e504f0292138108f487e13b 100644 (file)
@@ -71,6 +71,7 @@
         "no-empty": "off",
         "no-empty-function": "off",
         "no-inline-comments": "off",
+        "no-invalid-this": "off",
         "no-loop-func": "off",
         "no-negated-condition": "off",
         "no-param-reassign": "off",
@@ -80,7 +81,6 @@
         "one-var-declaration-per-line": "off",
         "prefer-spread": "off",
         "sort-keys": "off",
-        "sort-vars": "off",
-        "strict": "off"
+        "sort-vars": "off"
     }
 }
index 1600616946ce30d7a586b15ae633a1b176f22de0..293fd78429cdb40291dc56bb48ab8e7a53e4d2e5 100644 (file)
  THE SOFTWARE.
  */
 
-/* global $span:true, $tbody:true */
-
 define(["jquery"],
     function ($) {
-        var interface = {};
+        "use strict";
+        var ui = {};
 
         function save_map_success(rspamd) {
             rspamd.alertMessage("alert-modal alert-success", "Map data successfully saved");
@@ -74,7 +73,7 @@ define(["jquery"],
                 success: function (data) {
                     $listmaps.empty();
                     $("#modalBody").empty();
-                    $tbody = $("<tbody>");
+                    var $tbody = $("<tbody>");
 
                     $.each(data, function (i, item) {
                         var label;
@@ -85,7 +84,7 @@ define(["jquery"],
                         }
                         var $tr = $("<tr>");
                         $("<td class=\"col-md-2 maps-cell\">" + label + "</td>").appendTo($tr);
-                        $span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item", item);
+                        var $span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item", item);
                         $span.wrap("<td>").parent().appendTo($tr);
                         $("<td>" + item.description + "</td>").appendTo($tr);
                         $tr.appendTo($tbody);
@@ -235,7 +234,7 @@ define(["jquery"],
         }
 
         // @upload edited actions
-        interface.setup = function (rspamd) {
+        ui.setup = function (rspamd) {
         // Modal form for maps
             $(document).on("click", "[data-toggle=\"modal\"]", function () {
                 var item = $(this).data("item");
@@ -279,8 +278,8 @@ define(["jquery"],
             });
         };
 
-        interface.getActions = getActions;
-        interface.getMaps = getMaps;
+        ui.getActions = getActions;
+        ui.getMaps = getMaps;
 
-        return interface;
+        return ui;
     });
index 7ff5708520cee0030b3d643815373be76a2719a1..c7e0041ea0b0448c47b61cf9232e663fc5eb4175 100644 (file)
@@ -27,6 +27,7 @@
 
 define(["jquery", "d3evolution", "footable"],
     function ($, D3Evolution) {
+        "use strict";
         var rrd_pie_config = {
             header: {},
             size: {
@@ -168,10 +169,10 @@ define(["jquery", "d3evolution", "footable"],
             });
         }
 
-        var interface = {};
+        var ui = {};
         var prevUnit = "msg/s";
 
-        interface.draw = function (rspamd, graphs, neighbours, checked_server, type) {
+        ui.draw = function (rspamd, graphs, neighbours, checked_server, type) {
 
             function updateWidgets(data) {
             // Autoranging
@@ -280,7 +281,7 @@ define(["jquery", "d3evolution", "footable"],
             });
         };
 
-        interface.setup = function () {
+        ui.setup = function () {
         // Handling mouse events on overlapping elements
             $("#rrd-pie").mouseover(function () {
                 $("#rrd-pie").css("z-index", "200");
@@ -294,5 +295,5 @@ define(["jquery", "d3evolution", "footable"],
             return getSelector("selData");
         };
 
-        return interface;
+        return ui;
     });
index 122f8df6e66f8e07e4883f3229202b7acd45340d..8e34dff24bd2e78497b7a8d48e5ea85a5b7d84c1 100644 (file)
@@ -26,7 +26,8 @@
 
 define(["jquery", "footable", "humanize"],
     function ($, _, Humanize) {
-        var interface = {};
+        "use strict";
+        var ui = {};
         var ft = {};
         var htmlEscapes = {
             "&": "&amp;",
@@ -483,7 +484,7 @@ define(["jquery", "footable", "humanize"],
             return func();
         }
 
-        interface.getHistory = function (rspamd, tables, neighbours, checked_server) {
+        ui.getHistory = function (rspamd, tables, neighbours, checked_server) {
             FooTable.actionFilter = FooTable.Filtering.extend({
                 construct : function (instance) {
                     this._super(instance);
@@ -661,10 +662,10 @@ define(["jquery", "footable", "humanize"],
             $("#updateHistory").off("click");
             $("#updateHistory").on("click", function (e) {
                 e.preventDefault();
-                interface.getHistory(rspamd, tables, neighbours, checked_server);
+                ui.getHistory(rspamd, tables, neighbours, checked_server);
             });
             $("#selSymOrder").unbind().change(function () {
-                interface.getHistory(rspamd, tables, neighbours, checked_server);
+                ui.getHistory(rspamd, tables, neighbours, checked_server);
             });
 
             // @reset history log
@@ -684,8 +685,8 @@ define(["jquery", "footable", "humanize"],
                 }
                 if (checked_server === "All SERVERS") {
                     rspamd.queryNeighbours("errors", function () {
-                        interface.getHistory(rspamd, tables, neighbours, checked_server);
-                        interface.getErrors(rspamd, tables, neighbours, checked_server);
+                        ui.getHistory(rspamd, tables, neighbours, checked_server);
+                        ui.getErrors(rspamd, tables, neighbours, checked_server);
                     });
                 }
                 else {
@@ -698,8 +699,8 @@ define(["jquery", "footable", "humanize"],
                             xhr.setRequestHeader("Password", rspamd.getPassword());
                         },
                         success: function () {
-                            interface.getHistory(rspamd, tables, neighbours, checked_server);
-                            interface.getErrors(rspamd, tables, neighbours, checked_server);
+                            ui.getHistory(rspamd, tables, neighbours, checked_server);
+                            ui.getErrors(rspamd, tables, neighbours, checked_server);
                         },
                         error: function (data) {
                             rspamd.alertMessage("alert-modal alert-error", data.statusText);
@@ -742,7 +743,7 @@ define(["jquery", "footable", "humanize"],
             });
         }
 
-        interface.getErrors = function (rspamd, tables, neighbours, checked_server) {
+        ui.getErrors = function (rspamd, tables, neighbours, checked_server) {
             if (rspamd.read_only) return;
 
             if (checked_server !== "All SERVERS") {
@@ -775,10 +776,10 @@ define(["jquery", "footable", "humanize"],
             $("#updateErrors").off("click");
             $("#updateErrors").on("click", function (e) {
                 e.preventDefault();
-                interface.getErrors(rspamd, tables, neighbours, checked_server);
+                ui.getErrors(rspamd, tables, neighbours, checked_server);
             });
         };
 
-        interface.setup = function () {};
-        return interface;
+        ui.setup = function () {};
+        return ui;
     });
index b935cf6c2b188236126276cf3b7b0dc5d702e696..a07d4ac03550a025a2f96dfe24434fd5f7b1ec16 100644 (file)
@@ -29,12 +29,13 @@ define(["jquery", "d3pie", "visibility", "app/stats", "app/graph", "app/config",
     "app/symbols", "app/history", "app/upload"],
 function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
     tab_symbols, tab_history, tab_upload) {
+    "use strict";
     // begin
     var graphs = {};
     var tables = {};
     var neighbours = []; // list of clusters
     var checked_server = "All SERVERS";
-    var interface = {
+    var ui = {
         read_only: false,
     };
 
@@ -75,7 +76,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
 
         stopTimers();
         cleanCredentials();
-        interface.connect();
+        ui.connect();
     }
 
     function tabClick(tab_id) {
@@ -90,32 +91,32 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
 
         switch (tab_id) {
         case "#status_nav":
-            tab_stat.statWidgets(interface, graphs, checked_server);
+            tab_stat.statWidgets(ui, graphs, checked_server);
             timer_id.status = Visibility.every(10000, function () {
-                tab_stat.statWidgets(interface, graphs, checked_server);
+                tab_stat.statWidgets(ui, graphs, checked_server);
             });
             break;
         case "#throughput_nav":
-            tab_graph.draw(interface, graphs, neighbours, checked_server, selData);
+            tab_graph.draw(ui, graphs, neighbours, checked_server, selData);
 
             var autoRefresh = {
                 hourly: 60000,
                 daily: 300000
             };
             timer_id.throughput = Visibility.every(autoRefresh[selData] || 3600000, function () {
-                tab_graph.draw(interface, graphs, neighbours, checked_server, selData);
+                tab_graph.draw(ui, graphs, neighbours, checked_server, selData);
             });
             break;
         case "#configuration_nav":
-            tab_config.getActions(interface);
-            tab_config.getMaps(interface);
+            tab_config.getActions(ui);
+            tab_config.getMaps(ui);
             break;
         case "#symbols_nav":
-            tab_symbols.getSymbols(interface, tables, checked_server);
+            tab_symbols.getSymbols(ui, tables, checked_server);
             break;
         case "#history_nav":
-            tab_history.getHistory(interface, tables, neighbours, checked_server);
-            tab_history.getErrors(interface, tables, neighbours, checked_server);
+            tab_history.getHistory(ui, tables, neighbours, checked_server);
+            tab_history.getErrors(ui, tables, neighbours, checked_server);
             break;
         case "#disconnect":
             disconnect();
@@ -180,8 +181,8 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
     }
 
     // Public functions
-    interface.alertMessage = alertMessage;
-    interface.setup = function () {
+    ui.alertMessage = alertMessage;
+    ui.setup = function () {
         $("#selData").change(function () {
             selData = this.value;
             tabClick("#throughput_nav");
@@ -231,25 +232,25 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
                 tabClick("#status_nav");
             }
         });
-        tab_config.setup(interface);
-        tab_symbols.setup(interface, tables);
-        tab_history.setup(interface, tables);
-        tab_upload.setup(interface);
+        tab_config.setup(ui);
+        tab_symbols.setup(ui, tables);
+        tab_history.setup(ui, tables);
+        tab_upload.setup(ui);
         selData = tab_graph.setup();
     };
 
-    interface.connect = function () {
+    ui.connect = function () {
         if (isLogged()) {
             var data = JSON.parse(sessionStorage.getItem("Credentials"));
 
             if (data && data[checked_server].read_only) {
-                interface.read_only = true;
+                ui.read_only = true;
                 $("#learning_nav").hide();
                 $("#resetHistory").attr("disabled", true);
                 $("#errors-history").hide();
             }
             else {
-                interface.read_only = false;
+                ui.read_only = false;
                 $("#learning_nav").show();
                 $("#resetHistory").removeAttr("disabled", true);
             }
@@ -257,10 +258,9 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
             return;
         }
 
-        var ui = $("#mainUI");
         var dialog = $("#connectDialog");
         var backdrop = $("#backDrop");
-        $(ui).hide();
+        $("#mainUI").hide();
         $(dialog).show();
         $(backdrop).show();
         $("#connectPassword").focus();
@@ -290,13 +290,13 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
                         // Is actually never returned by Rspamd
                     } else {
                         if (data.read_only) {
-                            interface.read_only = true;
+                            ui.read_only = true;
                             $("#learning_nav").hide();
                             $("#resetHistory").attr("disabled", true);
                             $("#errors-history").hide();
                         }
                         else {
-                            interface.read_only = false;
+                            ui.read_only = false;
                             $("#learning_nav").show();
                             $("#resetHistory").removeAttr("disabled", true);
                         }
@@ -308,7 +308,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
                     }
                 },
                 error: function (data) {
-                    interface.alertMessage("alert-modal alert-error", data.statusText);
+                    ui.alertMessage("alert-modal alert-error", data.statusText);
                     $("#connectPassword").val("");
                     $("#connectPassword").focus();
                 }
@@ -316,7 +316,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
         });
     };
 
-    interface.queryLocal = function (req_url, on_success, on_error, method, headers, params) {
+    ui.queryLocal = function (req_url, on_success, on_error, method, headers, params) {
         var req_params = {
             type: method,
             jsonp: false,
@@ -355,7 +355,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
         $.ajax(req_params);
     };
 
-    interface.queryNeighbours = function (req_url, on_success, on_error, method, headers, params, req_data) {
+    ui.queryNeighbours = function (req_url, on_success, on_error, method, headers, params, req_data) {
         $.ajax({
             dataType: "json",
             type: "GET",
@@ -387,7 +387,6 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
                     });
                 });
                 $.each(neighbours_status, function (ind) {
-                    "use strict";
                     method = typeof method !== "undefined" ? method : "GET";
                     var req_params = {
                         type: method,
@@ -453,12 +452,12 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
                 });
             },
             error: function () {
-                interface.alertMessage("alert-error", "Cannot receive neighbours data");
+                ui.alertMessage("alert-error", "Cannot receive neighbours data");
             },
         });
     };
 
-    interface.drawPie = function (obj, id, data, conf) {
+    ui.drawPie = function (obj, id, data, conf) {
         if (obj) {
             obj.updateProp("data.content",
                 data.filter(function (elt) {
@@ -548,7 +547,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
         return obj;
     };
 
-    interface.getPassword = getPassword;
+    ui.getPassword = getPassword;
 
-    return interface;
+    return ui;
 });
index 19b1d72a71fb4fa5a49938aaaf98415d491ebb19..56f3e7101df988645b04572b1a858e36c279b939 100644 (file)
@@ -24,7 +24,8 @@
 
 define(["jquery", "d3pie", "humanize"],
     function ($, d3pie, Humanize) {
-    // @ ms to date
+        "use strict";
+        // @ ms to date
         function msToTime(seconds) {
             /* eslint-disable no-bitwise */
             var years = seconds / 31536000 >> 0; // 3600*24*365
@@ -170,7 +171,7 @@ define(["jquery", "d3pie", "humanize"],
             }
         }
         // Public API
-        var interface = {
+        var ui = {
             statWidgets: function (rspamd, graphs, checked_server) {
                 rspamd.queryNeighbours("/auth", function (neighbours_status) {
                     var neighbours_sum = {
@@ -232,6 +233,6 @@ define(["jquery", "d3pie", "humanize"],
             },
         };
 
-        return interface;
+        return ui;
     }
 );
index ac569ee9d98538db7b93f1203710f14bb163db88..9289337394824c5ee5b8ffe7cd791cf9b1cd2e71 100644 (file)
@@ -26,8 +26,9 @@
 
 define(["jquery", "footable"],
     function ($) {
-        var interface = {};
+        "use strict";
         var ft = {};
+        var ui = {};
 
         function saveSymbols(rspamd, action, id, is_cluster) {
             var inputs = $("#" + id + " :input[data-role=\"numerictextbox\"]");
@@ -155,7 +156,7 @@ define(["jquery", "footable"],
             return [items, distinct_groups];
         }
         // @get symbols into modal form
-        interface.getSymbols = function (rspamd) {
+        ui.getSymbols = function (rspamd) {
 
             $.ajax({
                 dataType: "json",
@@ -262,7 +263,7 @@ define(["jquery", "footable"],
             });
         };
 
-        interface.setup = function (rspamd) {
+        ui.setup = function (rspamd) {
             $("#updateSymbols").on("click", function (e) {
                 e.preventDefault();
                 $.ajax({
@@ -284,5 +285,5 @@ define(["jquery", "footable"],
             });
         };
 
-        return interface;
+        return ui;
     });
index 2926e62e2a47a32516c34c5695b115b11dc0824e..fad074668e24deed3387f6b200106c144cf1e785 100644 (file)
@@ -24,7 +24,8 @@
 
 define(["jquery"],
     function ($) {
-        var interface = {};
+        "use strict";
+        var ui = {};
 
         function cleanTextUpload(source) {
             $("#" + source + "TextSource").val("");
@@ -169,7 +170,7 @@ define(["jquery"],
             });
         }
 
-        interface.setup = function (rspamd) {
+        ui.setup = function (rspamd) {
             $("textarea").change(function () {
                 if ($(this).val().length !== "") {
                     $(this).closest("form").find("button").removeAttr("disabled").removeClass("disabled");
@@ -210,5 +211,5 @@ define(["jquery"],
         };
 
 
-        return interface;
+        return ui;
     });
index 51564566736c17bc82efe4ac85aff484a48a858f..bdc89dd5f1d5098835e6bd0e0230d98c961ded6b 100644 (file)
@@ -27,13 +27,14 @@ document.title = window.location.hostname +
     (window.location.pathname !== "/" ? window.location.pathname : "") +
     " - Rspamd Web Interface";
 
-define("d3.global", ["d3"], function (_) {
+define("d3.global", ["d3"], function (_) { // eslint-disable-line strict
     d3 = _; // eslint-disable-line no-global-assign
 });
 
 // Load main UI
 require(["domReady"],
     function (domReady) {
+        "use strict";
         domReady(function () {
             require(["jquery", "d3", "app/rspamd"],
                 function ($, d3, rspamd) {