terminal: use Client.getApp instead of refreshInstalledApps

This commit is contained in:
Girish Ramakrishnan
2018-06-25 19:19:56 -07:00
parent 8d98cefcca
commit f3cf640e21

View File

@@ -123,15 +123,11 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
var appId = $scope.selected.value;
function waitUntilStopped(callback) {
Client.refreshInstalledApps(function (error) {
refreshApp(appId, function (error, result) {
if (error) return callback(error);
Client.getCachedApp(appId, function (error, result) {
if (error) return callback(error);
if (result.runState === 'stopped') return callback();
setTimeout(waitUntilStopped.bind(null, callback), 2000);
});
if (result.runState === 'stopped') return callback();
setTimeout(waitUntilStopped.bind(null, callback), 2000);
});
}
@@ -158,28 +154,20 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
$scope.appBusy = true;
function waitUntilInRepairState() {
Client.refreshInstalledApps(function (error) {
if (error) return console.error('Failed to refresh app status.', error);
refreshApp($scope.selected.value, function (error, result) {
if (error) return console.error('Failed to get app status.', error);
Client.getCachedApp($scope.selected.value, function (error, result) {
if (error) return console.error('Failed to get app status.', error);
if (result.installationState === 'installed') $scope.appBusy = false;
else setTimeout(waitUntilInRepairState, 2000);
});
if (result.installationState === 'installed') $scope.appBusy = false;
else setTimeout(waitUntilInRepairState, 2000);
});
}
Client.debugApp($scope.selected.value, true, function (error) {
if (error) return console.error(error);
Client.refreshInstalledApps(function (error) {
if (error) console.error(error);
$('#repairAppModal').modal('hide');
$('#repairAppModal').modal('hide');
waitUntilInRepairState();
});
waitUntilInRepairState();
});
};
@@ -187,26 +175,18 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
$scope.appBusy = true;
function waitUntilInNormalState() {
Client.refreshInstalledApps(function (error) {
if (error) return console.error('Failed to refresh app status.', error);
refreshApp($scope.selected.value, function (error, result) {
if (error) return console.error('Failed to get app status.', error);
Client.getCachedApp($scope.selected.value, function (error, result) {
if (error) return console.error('Failed to get app status.', error);
if (result.installationState === 'installed') $scope.appBusy = false;
else setTimeout(waitUntilInNormalState, 2000);
});
if (result.installationState === 'installed') $scope.appBusy = false;
else setTimeout(waitUntilInNormalState, 2000);
});
}
Client.debugApp($scope.selected.value, false, function (error) {
if (error) return console.error(error);
Client.refreshInstalledApps(function (error) {
if (error) console.error(error);
waitUntilInNormalState();
});
waitUntilInNormalState();
});
};
@@ -229,6 +209,16 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
}
}
function refreshApp(id, callback) {
Client.getApp(id, function (error, result) {
if (error) return callback(error);
$scope.selectedAppInfo = result;
callback(null, result);
});
}
function showTerminal(retry) {
reset();
@@ -236,9 +226,11 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
var appId = $scope.selected.value;
Client.getCachedApp(appId, function (error, result) {
refreshApp(appId, function (error) {
if (error) return console.error(error);
var result = $scope.selectedAppInfo;
// we expect this to be called _after_ a reconfigure was issued
if (result.installationState === 'pending_configure') {
$scope.appBusy = true;
@@ -246,7 +238,6 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
$scope.appBusy = false;
}
$scope.selectedAppInfo = result;
$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();
@@ -365,21 +356,13 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
Client.refreshConfig(function (error) {
if (error) return $scope.error(error);
Client.refreshInstalledApps(function (error) {
if (error) return $scope.error(error);
Client.getInstalledApps().forEach(function (app) {
$scope.apps.push({
type: 'app',
value: app.id,
name: app.fqdn + ' (' + app.manifest.title + ')',
addons: app.manifest.addons
});
});
// activate pre-selected log from query otherwise choose the first one
$scope.selected = $scope.apps.find(function (e) { return e.value === search.id; });
if (!$scope.selected) $scope.selected = $scope.apps[0];
refreshApp(search.id, function (error, app) {
$scope.selected = {
type: 'app',
value: app.id,
name: app.fqdn + ' (' + app.manifest.title + ')',
addons: app.manifest.addons
};
// now mark the Client to be ready
Client.setReady();