From: Alexander Moisseev Date: Sun, 2 Sep 2018 19:24:06 +0000 (+0300) Subject: [WebUI] Add progress bar for AJAX requests X-Git-Tag: 1.8.0~193^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F2456%2Fhead;p=rspamd.git [WebUI] Add progress bar for AJAX requests --- diff --git a/.eslintrc.json b/.eslintrc.json index c0f1eeb4b..4f0c4c68e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,7 +18,7 @@ // "func-style": ["error", "declaration"], "id-length": ["error", { "min": 1 }], // "max-len": ["error", { "code": 120 }], - "max-params": ["warn", 9], + "max-params": ["warn", 6], "max-statements": ["warn", 28], "max-statements-per-line": ["error", { "max": 2 }], "multiline-comment-style": "off", diff --git a/interface/css/nprogress.css b/interface/css/nprogress.css new file mode 100644 index 000000000..6752d7f4b --- /dev/null +++ b/interface/css/nprogress.css @@ -0,0 +1,74 @@ +/* Make clicks pass-through */ +#nprogress { + pointer-events: none; +} + +#nprogress .bar { + background: #29d; + + position: fixed; + z-index: 1031; + top: 0; + left: 0; + + width: 100%; + height: 2px; +} + +/* Fancy blur effect */ +#nprogress .peg { + display: block; + position: absolute; + right: 0px; + width: 100px; + height: 100%; + box-shadow: 0 0 10px #29d, 0 0 5px #29d; + opacity: 1.0; + + -webkit-transform: rotate(3deg) translate(0px, -4px); + -ms-transform: rotate(3deg) translate(0px, -4px); + transform: rotate(3deg) translate(0px, -4px); +} + +/* Remove these to get rid of the spinner */ +#nprogress .spinner { + display: block; + position: fixed; + z-index: 1031; + top: 15px; + right: 15px; +} + +#nprogress .spinner-icon { + width: 18px; + height: 18px; + box-sizing: border-box; + + border: solid 2px transparent; + border-top-color: #29d; + border-left-color: #29d; + border-radius: 50%; + + -webkit-animation: nprogress-spinner 400ms linear infinite; + animation: nprogress-spinner 400ms linear infinite; +} + +.nprogress-custom-parent { + overflow: hidden; + position: relative; +} + +.nprogress-custom-parent #nprogress .spinner, +.nprogress-custom-parent #nprogress .bar { + position: absolute; +} + +@-webkit-keyframes nprogress-spinner { + 0% { -webkit-transform: rotate(0deg); } + 100% { -webkit-transform: rotate(360deg); } +} +@keyframes nprogress-spinner { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + diff --git a/interface/css/rspamd.css b/interface/css/rspamd.css index c52e133c1..0628a25bc 100644 --- a/interface/css/rspamd.css +++ b/interface/css/rspamd.css @@ -683,4 +683,8 @@ background: url("../img/asc.png") no-repeat center right; } table.dataTable thead .sorting_desc_disabled { background: url("../img/desc.png") no-repeat center right; -} \ No newline at end of file +} + +#nprogress .bar { + height: 1px; +} diff --git a/interface/index.html b/interface/index.html index a10af453f..0d6f95064 100644 --- a/interface/index.html +++ b/interface/index.html @@ -10,6 +10,7 @@ + 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