diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 380bc485..1fd91282 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global utils:false, moment:false */ +/* global utils:false, moment:false, NProgress: false */ //The following functions allow us to display time until pi-hole is enabled after disabling. //Works between all pages @@ -712,3 +712,8 @@ if ($.fn.dataTable) { console.log("DataTables warning: " + message); }; } + +// Page has finished loading +$(window).on("load", function () { + NProgress.done(); +}); diff --git a/scripts/pi-hole/js/login.js b/scripts/pi-hole/js/login.js index a1e4b5ca..6b3a37c3 100644 --- a/scripts/pi-hole/js/login.js +++ b/scripts/pi-hole/js/login.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global utils:false */ +/* global utils:false, NProgress:false */ function getParams() { var GETDict = {}; @@ -104,6 +104,7 @@ function wrongPassword(isError = false, isSuccess = false, data = null) { function doLogin(password) { wrongPassword(false, false, null); + NProgress.start(); utils.disableAll(); $.ajax({ url: "/api/auth", @@ -114,10 +115,12 @@ function doLogin(password) { }) .done(function (data) { wrongPassword(false, true, data); + NProgress.done(); redirect(); }) .fail(function (data) { wrongPassword(true, false, data); + NProgress.done(); utils.enableAll(); }); } diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 534b93a3..0b16d685 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -175,8 +175,8 @@ function saveSettings() { "Successfully saved and applied settings", "" ); - // Reload page - location.reload(); + // Show loading overlay + utils.loadingOverlay(1000, true); }) .fail(function (data) { apiFailure(data); diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 63fc3ec8..7fe17860 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false, apiFailure: false, updateFtlInfo: false */ +/* global moment:false, apiFailure: false, updateFtlInfo: false, NProgress:false */ $(function () { // CSRF protection for AJAX requests, this has to be configured globally @@ -615,6 +615,49 @@ function listAlert(type, items, data) { ); } +var loadingTime = 0; +// Callback function for the loading overlay timeout +function loadingOverlayTimeoutCallback(loadingTimeout, reloadAfterTimeout) { + if (loadingTime <= loadingTimeout) { + // Update progress bar + NProgress.set(loadingTime / loadingTimeout); + // Increase loading time + loadingTime += 100; + // Schedule next update + setTimeout(loadingOverlayTimeoutCallback, 100, loadingTimeout, reloadAfterTimeout); + return; + } + + // Hide loading overlay + NProgress.done(); + + // Reload page if requested + if (reloadAfterTimeout) { + location.reload(); + } +} + +function loadingOverlay(timeout = 6000, reloadAfterTimeout = false) { + // Add three extra seconds to the timeout as safety margin + // timeout is specified in milliseconds + timeout += 3000; + + NProgress.configure({ minimum: 0, trickle: false }); + NProgress.start(); + $(".wrapper").waitMe({ + effect: "bounce", + text: "Pi-hole is currently applying your changes...", + bg: "rgba(0,0,0,0.7)", + color: "#fff", + maxSize: "", + waitTime: timeout, + textPos: "vertical", + }); + setTimeout(loadingOverlayTimeoutCallback, 100, timeout, reloadAfterTimeout); + + return true; +} + window.utils = (function () { return { escapeHtml: escapeHtml, @@ -648,5 +691,6 @@ window.utils = (function () { hexEncode: hexEncode, hexDecode: hexDecode, listsAlert: listAlert, + loadingOverlay: loadingOverlay, }; })(); diff --git a/scripts/pi-hole/lua/footer.lp b/scripts/pi-hole/lua/footer.lp index 3be0b1d9..8e9a4fbc 100644 --- a/scripts/pi-hole/lua/footer.lp +++ b/scripts/pi-hole/lua/footer.lp @@ -61,4 +61,10 @@