Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minor] Move server selection logic to common.js #4796

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Minor] Move server selection logic to common.js
  • Loading branch information
moisseev committed Jan 2, 2024
commit f44458b19aae42fd58e6faca3af15b1b9b7d3833
5 changes: 5 additions & 0 deletions interface/js/app/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ define(["jquery", "nprogress"],
return e.options[e.selectedIndex].value;
};

ui.getServer = function () {
const checked_server = ui.getSelector("selSrv");
return (checked_server === "All SERVERS") ? "local" : checked_server;
};

/**
* @param {string} url - A string containing the URL to which the request is sent
* @param {Object} [options] - A set of key/value pairs that configure the Ajax request. All settings are optional.
Expand Down
11 changes: 5 additions & 6 deletions interface/js/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(["jquery", "app/common"],
"use strict";
const ui = {};

ui.getActions = function getActions(checked_server) {
ui.getActions = function getActions() {
common.query("actions", {
success: function (data) {
$("#actionsFormField").empty();
Expand Down Expand Up @@ -57,7 +57,7 @@ define(["jquery", "app/common"],
$("#actionsFormField").html(
items.map((e) => e.html).join(""));
},
server: (checked_server === "All SERVERS") ? "local" : checked_server
server: common.getServer()
});
};

Expand Down Expand Up @@ -109,7 +109,7 @@ define(["jquery", "app/common"],
}
};

ui.getMaps = function (checked_server) {
ui.getMaps = function () {
const $listmaps = $("#listMaps");
$listmaps.closest(".card").hide();
common.query("maps", {
Expand All @@ -135,7 +135,7 @@ define(["jquery", "app/common"],
$tbody.appendTo($listmaps);
$listmaps.closest(".card").show();
},
server: (checked_server === "All SERVERS") ? "local" : checked_server
server: common.getServer()
});
};

Expand All @@ -158,7 +158,6 @@ define(["jquery", "app/common"],

// Modal form for maps
$(document).on("click", "[data-bs-toggle=\"modal\"]", function () {
const checked_server = common.getSelector("selSrv");
const item = $(this).data("item");
common.query("getmap", {
headers: {
Expand Down Expand Up @@ -197,7 +196,7 @@ define(["jquery", "app/common"],
$("#modalDialog").modal("show");
},
errorMessage: "Cannot receive maps data",
server: (checked_server === "All SERVERS") ? "local" : checked_server
server: common.getServer()
});
return false;
});
Expand Down
6 changes: 3 additions & 3 deletions interface/js/app/rspamd.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ define(["jquery", "app/common", "stickytabs", "visibility",
break;
case "#configuration_nav":
require(["app/config"], (module) => {
module.getActions(checked_server);
module.getMaps(checked_server);
module.getActions();
module.getMaps();
});
break;
case "#symbols_nav":
require(["app/symbols"], (module) => module.getSymbols(checked_server));
require(["app/symbols"], (module) => module.getSymbols());
break;
case "#scan_nav":
require(["app/upload"]);
Expand Down
11 changes: 3 additions & 8 deletions interface/js/app/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ define(["jquery", "app/common"],
));
}

function get_server() {
const checked_server = common.getSelector("selSrv");
return (checked_server === "All SERVERS") ? "local" : checked_server;
}

function checkMsg(data) {
const selector = $("#selectorsSelArea").val();
common.query("plugins/selectors/check_message?selector=" + encodeURIComponent(selector), {
Expand All @@ -30,7 +25,7 @@ define(["jquery", "app/common"],
common.alertMessage("alert-error", "Unexpected error processing message");
}
},
server: get_server()
server: common.getServer()
});
}

Expand All @@ -50,7 +45,7 @@ define(["jquery", "app/common"],
toggle_form_group_class("valid", "invalid");
}
},
server: get_server()
server: common.getServer()
});
} else {
$("#selectorsSelArea").removeClass("is-valid is-invalid");
Expand All @@ -76,7 +71,7 @@ define(["jquery", "app/common"],
const json = neighbours_status[0].data;
build_table_from_json(json, "#selectorsTable-" + list);
},
server: get_server()
server: common.getServer()
});
}

Expand Down
7 changes: 3 additions & 4 deletions interface/js/app/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ define(["jquery", "app/common", "footable"],
return [items, distinct_groups];
}
// @get symbols into modal form
ui.getSymbols = function (checked_server) {
ui.getSymbols = function () {
clear_altered();
common.query("symbols", {
success: function (json) {
Expand Down Expand Up @@ -220,21 +220,20 @@ define(["jquery", "app/common", "footable"],
}
});
},
server: (checked_server === "All SERVERS") ? "local" : checked_server
server: common.getServer()
});
};


$("#updateSymbols").on("click", (e) => {
e.preventDefault();
clear_altered();
const checked_server = common.getSelector("selSrv");
common.query("symbols", {
success: function (data) {
const [items] = process_symbols_data(data[0].data);
common.tables.symbols.rows.load(items);
},
server: (checked_server === "All SERVERS") ? "local" : checked_server
server: common.getServer()
});
});

Expand Down
9 changes: 2 additions & 7 deletions interface/js/app/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ define(["jquery", "app/common", "app/libft"],
});
}

function get_server() {
const checked_server = common.getSelector("selSrv");
return (checked_server === "All SERVERS") ? "local" : checked_server;
}

// @upload text
function scanText(data, headers) {
common.query("checkv2", {
Expand Down Expand Up @@ -136,7 +131,7 @@ define(["jquery", "app/common", "app/libft"],
common.alertMessage("alert-error", "Cannot tokenize message: no text data");
}
},
server: get_server()
server: common.getServer()
});
}

Expand Down Expand Up @@ -168,7 +163,7 @@ define(["jquery", "app/common", "app/libft"],
common.alertMessage("alert-error", "Unexpected error processing message");
}
},
server: get_server()
server: common.getServer()
});
}

Expand Down