Fix terminal restart and other state issues

This commit is contained in:
Johannes Zellner
2019-09-27 19:13:01 +02:00
parent 2d8dc36f28
commit 57f1751309
2 changed files with 19 additions and 23 deletions

View File

@@ -3,7 +3,7 @@
/* global angular */
/* global $ */
/* global Terminal */
/* global RSTATES */
/* global RSTATES,ISTATES */
// create main application module
var app = angular.module('Application', ['angular-md5', 'ui-notification']);
@@ -123,13 +123,15 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
$scope.restartApp = function () {
$scope.restartAppBusy = true;
$scope.appBusy = true;
var appId = $scope.selected.value;
function waitUntilStopped(callback) {
refreshApp(appId, function (error, result) {
if (error) return callback(error);
if (result.runState === RSTATES.STOPPED) return callback();
if (result.installationState === ISTATES.INSTALLED && result.runState === RSTATES.STOPPED) return callback();
setTimeout(waitUntilStopped.bind(null, callback), 2000);
});
}
@@ -138,12 +140,13 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
if (error) console.error('Failed to stop app.', error);
waitUntilStopped(function (error) {
if (error) return console.error('Failed to get app status.', error);
if (error) console.error('Failed to get app status.', error);
Client.startApp(appId, function (error) {
if (error) console.error('Failed to start app.', error);
$scope.restartAppBusy = false;
$scope.appBusy = false;
});
});
});
@@ -234,13 +237,6 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
var result = $scope.selectedAppInfo;
// we expect this to be called _after_ a reconfigure was issued
if (result.installationState === 'installed') {
$scope.appBusy = false;
} else if (result.installationState !== 'error') {
$scope.appBusy = true;
}
$scope.schedulerTasks = result.manifest.addons.scheduler ? Object.keys(result.manifest.addons.scheduler).map(function (k) { return { name: k, command: result.manifest.addons.scheduler[k].command }; }) : [];
$scope.terminal = new Terminal();