Skip to content

Commit

Permalink
✨ Separation of voting session time and bearer token lifetime (#404)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#762
  • Loading branch information
Findeton authored Jul 19, 2024
1 parent e1d5ea7 commit d169dbd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions avUi/common-header-directive/common-header-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ angular

scope.showVersionsModal = ShowVersionsModalService;

function calculateCountdownPercent() {
function calculateCountdownPercent() {
var ratio = (scope.logoutTimeMs - Date.now())/(scope.logoutTimeMs - scope.countdownStartTimeMs);
return Math.min(100, Math.round(10000*ratio)/100) + '%';
}
Expand All @@ -71,6 +71,10 @@ angular
scope.logoutTimeMs = scope.$parent.getSessionEndTime();
}

if (scope.$parent.getSessionStartTime) {
scope.countdownStartTimeMs = scope.$parent.getSessionStartTime(false);
}

scope.showCountdown = true;
var now = Date.now();
scope.countdownSecs = Math.round((scope.logoutTimeMs - now) / 1000);
Expand All @@ -81,12 +85,9 @@ angular
if (scope.countdownSecs <= 1) {
return;
}
var targetMins = Math.floor((scope.logoutTimeMs - now) / (60 * 1000));
var targetNextTime = scope.logoutTimeMs - targetMins * 60 * 1000;
var targetElapsedTime = targetNextTime - now;
setTimeout(
updateTimedown,
targetMins > 0? targetElapsedTime : 1000
1000
);
}

Expand Down Expand Up @@ -116,7 +117,7 @@ angular
scope.countdownSecs = 0;
scope.countdownMins = 0;

var initialTimeMs = scope.$parent.getSessionStartTime && scope.$parent.getSessionStartTime() || Date.now();
var initialTimeMs = scope.$parent.getSessionStartTime && scope.$parent.getSessionStartTime(true) || Date.now();
scope.elapsedCountdownMs = (
election.presentation.booth_log_out__countdown_seconds > 0?
election.presentation.booth_log_out__countdown_seconds :
Expand Down
8 changes: 4 additions & 4 deletions dist/appCommon-v10.4.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,12 +1205,12 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
}
function updateTimedown() {
scope.$parent.getSessionEndTime && (scope.logoutTimeMs = scope.$parent.getSessionEndTime()),
scope.$parent.getSessionStartTime && (scope.countdownStartTimeMs = scope.$parent.getSessionStartTime(!1)),
scope.showCountdown = !0;
var targetMins, targetNextTime, now = Date.now();
var now = Date.now();
scope.countdownSecs = Math.round((scope.logoutTimeMs - now) / 1e3), scope.countdownMins = Math.round((scope.logoutTimeMs - now) / 6e4),
scope.countdownPercent = calculateCountdownPercent(), updateProgressBar(scope.countdownPercent),
scope.$apply(), scope.countdownSecs <= 1 || (targetMins = Math.floor((scope.logoutTimeMs - now) / 6e4),
targetNextTime = scope.logoutTimeMs - 60 * targetMins * 1e3, setTimeout(updateTimedown, 0 < targetMins ? targetNextTime - now : 1e3));
scope.$apply(), scope.countdownSecs <= 1 || setTimeout(updateTimedown, 1e3);
}
scope.parentElection = scope.$parent.parentElection, scope.election = scope.$parent.election,
scope.confirmLogoutModal = scope.$parent.confirmLogoutModal, scope.configService = ConfigService,
Expand All @@ -1223,7 +1223,7 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist
var election, initialTimeMs;
scope.showCountdown = !1, scope.$parent.isStateCompatibleWithCountdown && !scope.$parent.isStateCompatibleWithCountdown() || (election = scope.parentElection || scope.election,
ConfigService.authTokenExpirationSeconds && election && election.presentation && _.isNumber(election.presentation.booth_log_out__countdown_seconds) && (scope.showCountdown = !1,
scope.countdownSecs = 0, scope.countdownMins = 0, initialTimeMs = scope.$parent.getSessionStartTime && scope.$parent.getSessionStartTime() || Date.now(),
scope.countdownSecs = 0, scope.countdownMins = 0, initialTimeMs = scope.$parent.getSessionStartTime && scope.$parent.getSessionStartTime(!0) || Date.now(),
scope.elapsedCountdownMs = 1e3 * (0 < election.presentation.booth_log_out__countdown_seconds ? election.presentation.booth_log_out__countdown_seconds : ConfigService.authTokenExpirationSeconds),
scope.$parent.getSessionEndTime ? scope.logoutTimeMs = scope.$parent.getSessionEndTime() : scope.logoutTimeMs = initialTimeMs + 1e3 * ConfigService.authTokenExpirationSeconds,
scope.countdownStartTimeMs = scope.logoutTimeMs - scope.elapsedCountdownMs, scope.countdownPercent = calculateCountdownPercent(),
Expand Down

0 comments on commit d169dbd

Please sign in to comment.