Fixes to the current status indicator

This commit is contained in:
Kenneth Skovhede
2015-09-23 21:01:43 +02:00
parent e03314db1d
commit 1abe66c4ed
4 changed files with 34 additions and 14 deletions
+1
View File
@@ -50,6 +50,7 @@
<script type="text/javascript" src="scripts/controllers/PauseController.js"></script>
<script type="text/javascript" src="scripts/filters/localize.js"></script>
<script type="text/javascript" src="scripts/filters/timeremaining.js"></script>
<script type="text/javascript" src="scripts/directives/backupEditUri.js"></script>
<script type="text/javascript" src="scripts/directives/sourceFolderPicker.js"></script>
@@ -1,4 +1,4 @@
backupApp.controller('StateController', function($scope, ServerStatus, BackupList, AppService, AppUtils) {
backupApp.controller('StateController', function($scope, $timeout, ServerStatus, BackupList, AppService, AppUtils) {
$scope.state = ServerStatus.watch($scope);
$scope.backups = BackupList.watch($scope);
@@ -10,6 +10,7 @@ backupApp.controller('StateController', function($scope, ServerStatus, BackupLis
$scope.$on('backuplistchanged', updateActiveTask);
$scope.$on('serverstatechanged', updateActiveTask);
$scope.$on('serverstatechanged.pauseTimeRemain', function() { $timeout(function() {$scope.$digest(); }) });
$scope.sendResume = function() {
ServerStatus.resume().then(function() {}, AppUtils.connectionError);
@@ -1,4 +1,4 @@
backupApp.service('ServerStatus', function($http, $rootScope, $timeout, AppService) {
backupApp.service('ServerStatus', function($http, $rootScope, $timeout, AppService, AppUtils) {
var polltime = 5 * 60 * 1000;
@@ -60,6 +60,24 @@ backupApp.service('ServerStatus', function($http, $rootScope, $timeout, AppServi
}, 500);
};
var updatepausetimer = null;
function pauseTimerUpdater(skipNotify) {
var prev = state.pauseTimeRemain;
state.pauseTimeRemain = Math.max(0, AppUtils.parseDate(state.estimatedPauseEnd) - new Date());
if (state.pauseTimeRemain > 0 && updatepausetimer == null) {
updatepausetimer = setInterval(pauseTimerUpdater, 500);
} else if (state.pauseTimeRemain <= 0 && updatepausetimer != null) {
clearInterval(updatepausetimer);
updatepausetimer = null;
}
if (prev != state.pauseTimeRemain && !skipNotify)
$rootScope.$broadcast('serverstatechanged.pauseTimeRemain', state.pauseTimeRemain);
return prev != state.pauseTimeRemain;
}
var notifyIfChanged = function (data, dataname, varname) {
if (data[dataname] != null) {
if (state[varname] != data[dataname]) {
@@ -91,7 +109,8 @@ backupApp.service('ServerStatus', function($http, $rootScope, $timeout, AppServi
notifyIfChanged(response.data, 'LastDataUpdateID', 'lastDataUpdateId') |
notifyIfChanged(response.data, 'LastNotificationUpdateID', 'lastNotificationUpdateId') |
notifyIfChanged(response.data, 'ActiveTask', 'activeTask') |
notifyIfChanged(response.data, 'ProgramState', 'programState');
notifyIfChanged(response.data, 'ProgramState', 'programState') |
notifyIfChanged(response.data, 'EstimatedPauseEnd', 'estimatedPauseEnd');
if (state.connectionState != 'connected') {
@@ -100,9 +119,12 @@ backupApp.service('ServerStatus', function($http, $rootScope, $timeout, AppServi
anychanged = true;
}
anychanged |= pauseTimerUpdater(true);
if (anychanged)
$rootScope.$broadcast('serverstatechanged');
poll();
},
@@ -115,9 +137,8 @@ backupApp.service('ServerStatus', function($http, $rootScope, $timeout, AppServi
poll();
} else {
// TODO: First request should not long-poll ....
// Real failure, start countdown
state.lastEventId = -1;
state.connectionState = 'disconnected';
countdownForForRePoll(poll);
@@ -1,8 +1,9 @@
<div class="home">
<div class="state" ng-controller="StateController">
<div class="state" ng-controller="StateController" ng-hide="state.programState == 'Running' &amp;&amp; state.ActiveTask == null &amp;&amp; (state.SchedulerQueueIds == null || state.SchedulerQueueIds.length == 0)">
<div ng-hide="state.programState == 'Running'">
<strong>Backups are currently paused, </strong>
<a href ng-click="sendResume()">click to resume</a>
<strong style="margin-right: 0px;">Backups are currently paused,</strong>
<div style="display: inline" ng-show="state.pauseTimeRemain > 0">resuming in {{state.pauseTimeRemain | timeremaining}}</div>
<a href ng-click="sendResume()">click to resume now</a>
</div>
<div ng-hide="state.ActiveTask == null">
@@ -10,16 +11,12 @@
{{task}}
</div>
<div ng-show="state.ActiveTask == null">
<div ng-show="state.ActiveTask == null &amp;&amp; state.SchedulerQueueIds != null &amp;&amp; state.SchedulerQueueIds.length > 0">
<strong>Next task:</strong>
{{nexttask}}
</div>
<div>LastEventID: {{state.lastEventId}}</div>
</div>
<div class="tasks" ng-controller="HomeController">
<div class="tasklist">
<h3><p ng-if="backups.length > 0">Scheduled backups:</p></h3>