aboutsummaryrefslogtreecommitdiffstats
path: root/interface/js/app/rspamd.js
diff options
context:
space:
mode:
Diffstat (limited to 'interface/js/app/rspamd.js')
-rw-r--r--interface/js/app/rspamd.js83
1 files changed, 41 insertions, 42 deletions
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js
index 634dfcd1d..2f1f66394 100644
--- a/interface/js/app/rspamd.js
+++ b/interface/js/app/rspamd.js
@@ -23,13 +23,11 @@
THE SOFTWARE.
*/
-/* global jQuery, FooTable, Visibility */
+/* global jQuery, FooTable, require, Visibility */
-define(["jquery", "visibility", "nprogress", "stickytabs", "app/stats", "app/graph", "app/config",
- "app/symbols", "app/history", "app/upload", "app/selectors"],
-// eslint-disable-next-line max-params
-function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
- tab_symbols, tab_history, tab_upload, tab_selectors) {
+define(["jquery", "nprogress", "stickytabs", "visibility",
+ "bootstrap", "fontawesome"],
+function ($, NProgress) {
"use strict";
var ui = {
chartLegend: [
@@ -62,7 +60,6 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
let pageSizeTimerId = null;
let pageSizeInvocationCounter = 0;
var locale = (localStorage.getItem("selected_locale") === "custom") ? localStorage.getItem("custom_locale") : null;
- var selData = null; // Graph's dataset selector state
NProgress.configure({
minimum: 0.01,
@@ -111,6 +108,12 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
ui.connect();
}
+ // Get selectors' current state
+ function getSelector(id) {
+ var e = document.getElementById(id);
+ return e.options[e.selectedIndex].value;
+ }
+
function tabClick(id) {
var tab_id = id;
if ($(id).attr("disabled")) return;
@@ -164,19 +167,20 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
switch (tab_id) {
case "#status_nav":
- (function () {
+ require(["app/stats"], (module) => {
var refreshInterval = $(".dropdown-menu a.active.preset").data("value");
setAutoRefresh(refreshInterval, "status",
- function () { return tab_stat.statWidgets(ui, graphs, checked_server); });
- if (id !== "#autoRefresh") tab_stat.statWidgets(ui, graphs, checked_server);
+ function () { return module.statWidgets(graphs, checked_server); });
+ if (id !== "#autoRefresh") module.statWidgets(graphs, checked_server);
$(".preset").show();
$(".history").hide();
$(".dynamic").hide();
- }());
+ });
break;
case "#throughput_nav":
- (function () {
+ require(["app/graph"], (module) => {
+ const selData = getSelector("selData"); // Graph's dataset selector state
var step = {
day: 60000,
week: 300000
@@ -188,26 +192,34 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
refreshInterval = null;
}
setAutoRefresh(refreshInterval, "throughput",
- function () { return tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData); });
- if (id !== "#autoRefresh") tab_graph.draw(ui, graphs, tables, neighbours, checked_server, selData);
+ function () { return module.draw(graphs, neighbours, checked_server, selData); });
+ if (id !== "#autoRefresh") module.draw(graphs, neighbours, checked_server, selData);
$(".preset").hide();
$(".history").hide();
$(".dynamic").show();
- }());
+ });
break;
case "#configuration_nav":
- tab_config.getActions(ui, checked_server);
- tab_config.getMaps(ui, checked_server);
+ require(["app/config"], (module) => {
+ module.getActions(checked_server);
+ module.getMaps(checked_server);
+ });
break;
case "#symbols_nav":
- tab_symbols.getSymbols(ui, tables, checked_server);
+ require(["app/symbols"], (module) => module.getSymbols(checked_server));
+ break;
+ case "#scan_nav":
+ require(["app/upload"]);
+ break;
+ case "#selectors_nav":
+ require(["app/selectors"], (module) => module.displayUI());
break;
case "#history_nav":
- (function () {
+ require(["app/history"], (module) => {
function getHistoryAndErrors() {
- tab_history.getHistory(ui, tables);
- tab_history.getErrors(ui, tables);
+ module.getHistory();
+ module.getErrors();
}
var refreshInterval = $(".dropdown-menu a.active.history").data("value");
setAutoRefresh(refreshInterval, "history",
@@ -217,7 +229,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
$(".preset").hide();
$(".history").show();
$(".dynamic").hide();
- }());
+ });
break;
case "#disconnect":
disconnect();
@@ -237,12 +249,6 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
return sessionStorage.getItem("Password");
}
- // Get selectors' current state
- function getSelector(id) {
- var e = document.getElementById(id);
- return e.options[e.selectedIndex].value;
- }
-
function get_compare_function(table) {
var compare_functions = {
magnitude: function (e1, e2) {
@@ -319,7 +325,6 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
$('#selSrv [value="' + e.name + '"]').prop("disabled", true);
}
});
- if (!ui.read_only) tab_selectors.displayUI(ui);
},
complete: function () {
ajaxSetup(localStorage.getItem("ajax_timeout"));
@@ -434,7 +439,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
// Public functions
ui.alertMessage = alertMessage;
- ui.setup = function () {
+ (() => {
(function initSettings() {
var selected_locale = null;
var custom_locale = null;
@@ -529,7 +534,6 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
}());
$("#selData").change(function () {
- selData = this.value;
tabClick("#throughput_nav");
});
@@ -576,15 +580,9 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
tabClick("#status_nav");
}
});
- tab_config.setup(ui);
- tab_history.setup(ui, tables);
- tab_selectors.setup(ui);
- tab_symbols.setup(ui, tables);
- tab_upload.setup(ui, tables);
- selData = tab_graph.setup(ui);
$("#loading").addClass("d-none");
- };
+ })();
ui.connect = function () {
// Prevent locking out of the WebUI if timeout is too low.
@@ -749,6 +747,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
// Scan and History shared functions
+ ui.tables = tables;
ui.unix_time_format = unix_time_format;
ui.set_page_size = set_page_size;
@@ -782,7 +781,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
};
- ui.initHistoryTable = function (rspamd, data, items, table, columns, expandFirst) {
+ ui.initHistoryTable = function (data, items, table, columns, expandFirst) {
/* eslint-disable no-underscore-dangle */
FooTable.Cell.extend("collapse", function () {
// call the original method
@@ -911,7 +910,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
});
};
- ui.preprocess_item = function (rspamd, item) {
+ ui.preprocess_item = function (item) {
function escape_HTML_array(arr) {
arr.forEach(function (d, i) { arr[i] = ui.escapeHTML(d); });
}
@@ -968,7 +967,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
};
};
- ui.process_history_v2 = function (rspamd, data, table) {
+ ui.process_history_v2 = function (data, table) {
// Display no more than rcpt_lim recipients
var rcpt_lim = 3;
var items = [];
@@ -1014,7 +1013,7 @@ function ($, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_config,
return null;
}
- rspamd.preprocess_item(rspamd, item);
+ ui.preprocess_item(item);
Object.values(item.symbols).forEach(function (sym) {
sym.str = '<span class="symbol-default ' + get_symbol_class(sym.name, sym.score) + '"><strong>';