]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add "errorOnceId" parameter to query function 2384/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Mon, 30 Jul 2018 09:15:21 +0000 (12:15 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Mon, 30 Jul 2018 09:15:21 +0000 (12:15 +0300)
interface/js/app/graph.js
interface/js/app/rspamd.js
interface/js/app/stats.js

index 8cb2d03790b90551fa378a6b17a69a926b3fa6f2..46c6062fdd6980f063bc1788f4261ed6544842e6 100644 (file)
@@ -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}
             });
         };
index 94fbe485765e253bc5d51471e03b8d4b4aaed9a8..e860908d9bd7a5421af367dcc0c95803b7c5e67e 100644 (file)
@@ -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);
             }
         });
index 3bac8260676a83e998860cdcc11d28c08a591427..151616052e1c4e119f5d84aa5fc18811401d5541 100644 (file)
@@ -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"
                 });
             },