From 5e4c14c634aa73a89f57023047c0b0cdd45c65b2 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 3 Feb 2022 16:56:34 +0100 Subject: [PATCH] admin: Make propagation time smarter --- admin/static/js/app.js | 6 +++++- admin/static/js/common.js | 30 ++++++++++++++++++++++++++++++ admin/static/views/settings.html | 11 +++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index fe5b305f..67bc4c12 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -578,10 +578,14 @@ angular.module("FICApp") $scope.saveSettings(); }); } + $scope.updateActivateTime = function() { + $rootScope.settings.activateTime = this.config.activateTime; + } $scope.updActivateTime = function(modulo) { - var ts = Math.floor((new Date(this.config.end) - Date.now()) / (60000 * modulo)) * (60000 * modulo); + var ts = Math.floor((new Date(this.config.end) - Date.now() - (60000 * modulo / 2)) / (60000 * modulo)) * (60000 * modulo); var d = new Date(this.config.end) - ts; this.config.activateTime = new Date(d).toISOString(); + this.updateActivateTime(); } $scope.reset = function(type) { var txts = { diff --git a/admin/static/js/common.js b/admin/static/js/common.js index 62fdc7ca..ec0cc409 100644 --- a/admin/static/js/common.js +++ b/admin/static/js/common.js @@ -125,6 +125,23 @@ angular.module("FICApp") } } }) + .filter("timer", function() { + return function(input) { + input = Math.floor(input / 1000); + var res = "" + + if (input >= 3600) { + res += Math.floor(input / 3600) + ":"; + input = input % 3600; + } + if (input >= 60) { + res += Math.floor(input / 60) + "'"; + input = input % 60; + } + + return res + (input>9?input:"0"+input) + '"'; + } + }) .filter("since", function() { return function(passed) { if (passed < 120000) { @@ -261,6 +278,19 @@ angular.module("FICApp") } $rootScope.timeProgression = 1 - remain / ($rootScope.settings.end - $rootScope.settings.start); + $rootScope.timeRemaining = remain; + + if ($rootScope.settings.activateTime) { + var now = new Date(); + var actTime = new Date($rootScope.settings.activateTime); + + if (actTime > now) + $rootScope.activateTimeCountDown = actTime - now; + else + $rootScope.activateTimeCountDown = null; + } else { + $rootScope.activateTimeCountDown = null; + } remain = remain / 1000; diff --git a/admin/static/views/settings.html b/admin/static/views/settings.html index 446ce70b..cbac41f8 100644 --- a/admin/static/views/settings.html +++ b/admin/static/views/settings.html @@ -96,7 +96,7 @@
+ + Propagation dans : {{ activateTimeCountDown | timer }} + Il restera : {{ timeRemaining - activateTimeCountDown | timer }} +