From 46cd18dbc37ab58e1258b584c7bfc1f526832ca5 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 2 Sep 2018 22:24:06 +0300 Subject: [WebUI] Add progress bar for AJAX requests --- interface/js/app/rspamd.js | 27 +++++++++++++++++++++++++-- interface/js/lib/nprogress.min.js | 4 ++++ interface/js/main.js | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 interface/js/lib/nprogress.min.js (limited to 'interface/js') diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 4e0e57841..8310ccf47 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -25,9 +25,10 @@ /* global jQuery:false, Visibility:false */ -define(["jquery", "d3pie", "visibility", "app/stats", "app/graph", "app/config", +define(["jquery", "d3pie", "visibility", "nprogress", "app/stats", "app/graph", "app/config", "app/symbols", "app/history", "app/upload"], -function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, +// eslint-disable-next-line max-params +function ($, d3pie, visibility, NProgress, tab_stat, tab_graph, tab_config, tab_symbols, tab_history, tab_upload) { "use strict"; // begin @@ -39,6 +40,11 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, var timer_id = []; var selData; // Graph's dataset selector state + NProgress.configure({ + minimum: 0.01, + showSpinner: false, + }); + function cleanCredentials() { sessionStorage.clear(); $("#statWidgets").empty(); @@ -177,6 +183,22 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, data: o.data, headers: $.extend({Password: getPassword()}, o.headers), url: neighbours_status[ind].url + req_url, + xhr: function () { + var xhr = $.ajaxSettings.xhr(); + // Download progress + if (req_url !== "neighbours") { + xhr.addEventListener("progress", function (e) { + if (e.lengthComputable) { + neighbours_status[ind].percentComplete = e.loaded / e.total; + var percentComplete = neighbours_status.reduce(function (prev, curr) { + return curr.percentComplete ? curr.percentComplete + prev : prev; + }, 0); + NProgress.set(percentComplete / neighbours_status.length); + } + }, false); + } + return xhr; + }, success: function (json) { neighbours_status[ind].checked = true; neighbours_status[ind].status = true; @@ -213,6 +235,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, } else { alertMessage("alert-error", "Request failed"); } + NProgress.done(); } }, statusCode: o.statusCode diff --git a/interface/js/lib/nprogress.min.js b/interface/js/lib/nprogress.min.js new file mode 100644 index 000000000..417321528 --- /dev/null +++ b/interface/js/lib/nprogress.min.js @@ -0,0 +1,4 @@ +/* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress + * @version 0.2.0 + * @license MIT */ +!function(e,n){"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n():e.NProgress=n()}(this,function(){var n,t,o={version:"0.2.0"},a=o.settings={minimum:.08,easing:"ease",positionUsing:"",speed:200,trickle:!0,trickleRate:.02,trickleSpeed:800,showSpinner:!0,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'
'};function u(e,n,t){return e