Fixup update UI to use task id

This commit is contained in:
Girish Ramakrishnan
2018-12-09 10:45:01 -08:00
parent 226162ee57
commit 97120a6b04
+19 -8
View File
@@ -31,6 +31,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
percent: 0,
message: '',
errorMessage: '', // this shows inline
taskId: '',
show: function () {
$scope.update.error.generic = null;
@@ -61,16 +62,25 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
},
checkStatus: function () {
Client.getLatestTaskByType('update', function (error, taskId) {
Client.getLatestTaskByType('update', function (error, task) {
if (error) return console.error(error);
$scope.update.updateStatus(taskId);
$scope.update.taskId = task.id;
$scope.update.updateStatus();
});
},
updateStatus: function (taskId) {
Client.getTask(taskId, function (error, data) {
if (error) return window.setTimeout($scope.update.updateStatus.bind(null, taskId), 2000);
reloadIfNeeded: function () {
Client.getStatus(function (error, status) {
if (error) return $scope.error(error);
if (window.localStorage.version !== status.version) window.location.reload(true);
});
},
updateStatus: function () {
Client.getTask($scope.update.taskId, function (error, data) {
if (error) return window.setTimeout($scope.update.updateStatus, 5000);
if (!data.active) {
$scope.update.busy = false;
@@ -78,7 +88,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
$scope.update.percent = 100; // indicates that 'result' is valid
$scope.update.errorMessage = data.errorMessage;
if (!data.errorMessage) window.location.reload(true); // assume success
if (!data.errorMessage) $scope.update.reloadIfNeeded(); // assume success
return;
}
@@ -87,7 +97,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
$scope.update.percent = data.percent;
$scope.update.message = data.message;
window.setTimeout($scope.update.updateStatus.bind(null, taskId), 500);
window.setTimeout($scope.update.updateStatus, 500);
});
},
@@ -107,7 +117,8 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
$('#updateModal').modal('hide');
$scope.update.updateStatus(taskId);
$scope.update.taskId = taskId;
$scope.update.updateStatus();
});
}
};