From: Alexander Moisseev Date: Mon, 30 Jul 2018 09:15:21 +0000 (+0300) Subject: [Minor] Add "errorOnceId" parameter to query function X-Git-Tag: 1.7.9~6^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b932d9baf7af265ba5dac574573fba6efb2ebde7;p=rspamd.git [Minor] Add "errorOnceId" parameter to query function --- diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index 8cb2d0379..46c6062fd 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -245,16 +245,8 @@ define(["jquery", "d3evolution", "footable"], updateWidgets(neighbours_data[0]); } }, - error: function (serv, jqXHR, textStatus, errorThrown) { - var serv_name = (typeof serv === "string") ? serv : serv.name; - var alert_status = "alerted_graph_" + serv_name; - - if (!(alert_status in sessionStorage)) { - sessionStorage.setItem(alert_status, true); - rspamd.alertMessage("alert-error", "Cannot receive throughput data from " + - serv_name + ", error: " + errorThrown); - } - }, + errorMessage: "Cannot receive throughput data", + errorOnceId: "alerted_graph_", data: {type: type} }); }; diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 94fbe4857..e860908d9 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -207,12 +207,21 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, error: function (jqXHR, textStatus, errorThrown) { neighbours_status[ind].status = false; neighbours_status[ind].checked = true; + function errorMessage() { + alertMessage("alert-error", neighbours_status[ind].name + " > " + + ((o.errorMessage) ? o.errorMessage : "Request failed") + ": " + errorThrown); + } if (o.error) { o.error(neighbours_status[ind], jqXHR, textStatus, errorThrown); + } else if (o.errorOnceId) { + var alert_status = o.errorOnceId + neighbours_status[ind].name; + if (!(alert_status in sessionStorage)) { + sessionStorage.setItem(alert_status, true); + errorMessage(); + } } else { - alertMessage("alert-error", neighbours_status[ind].name + " > " + - ((o.errorMessage) ? o.errorMessage : "Request failed") + ": " + errorThrown); + errorMessage(); } }, complete: function () { @@ -460,6 +469,8 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, * @param {Object|string|Array} [options.data] - Data to be sent to the server. * @param {Function} [options.error] - A function to be called if the request fails. * @param {string} [options.errorMessage] - Text to display in the alert message if the request fails. + * @param {string} [options.errorOnceId] - A prefix of the alert ID to be added to the session storage. If the + * parameter is set, the error for each server will be displayed only once per session. * @param {Object} [options.headers] - An object of additional header key/value pairs to send along with requests * using the XMLHttpRequest transport. * @param {string} [options.method] - The HTTP method to use for the request. @@ -473,7 +484,8 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, // Force options to be an object var o = options || {}; Object.keys(o).forEach(function (option) { - if (["data", "error", "errorMessage", "headers", "method", "params", "server", "success"].indexOf(option) < 0) { + if (["data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server", "success"] + .indexOf(option) < 0) { throw new Error("Unknown option: " + option); } }); diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js index 3bac82606..151616052 100644 --- a/interface/js/app/stats.js +++ b/interface/js/app/stats.js @@ -220,15 +220,8 @@ define(["jquery", "d3pie", "humanize"], displayStatWidgets(checked_server); graphs.chart = getChart(rspamd, graphs.chart, checked_server); }, - error: function (serv, jqXHR, textStatus, errorThrown) { - var alert_status = "alerted_stats_" + serv.name; - - if (!(alert_status in sessionStorage)) { - sessionStorage.setItem(alert_status, true); - rspamd.alertMessage("alert-error", "Cannot receive stats data from: " + - serv.name + ", error: " + errorThrown); - } - }, + errorMessage: "Cannot receive stats data", + errorOnceId: "alerted_stats_", server: "All SERVERS" }); },