Show a warning in the superuser panel if a container restart is required, and provide a button to do so. This change also moves the restart and monitoring code into a service

This commit is contained in:
Joseph Schorr 2015-01-26 13:46:57 -05:00
parent c88d97cf8b
commit 6a0158d361
5 changed files with 164 additions and 47 deletions

View file

@ -1,4 +1,4 @@
function SetupCtrl($scope, $timeout, ApiService, Features, UserService, AngularPollChannel, CoreDialog) {
function SetupCtrl($scope, $timeout, ApiService, Features, UserService, ContainerService, CoreDialog) {
if (!Features.SUPER_USERS) {
return;
}
@ -102,6 +102,11 @@ function SetupCtrl($scope, $timeout, ApiService, Features, UserService, AngularP
}
});
$scope.restartContainer = function(state) {
$scope.currentStep = state;
ContainerService.restartContainer();
};
$scope.showSuperuserPanel = function() {
$('#setupModal').modal('hide');
window.location = '/superuser';
@ -160,37 +165,6 @@ function SetupCtrl($scope, $timeout, ApiService, Features, UserService, AngularP
CoreDialog.fatal(title, message);
};
$scope.restartContainer = function(restartState) {
$scope.currentStep = restartState;
ApiService.scShutdownContainer(null, null).then(function(resp) {
$timeout(function() {
$scope.checkStatus();
}, 2000);
}, ApiService.errorDisplay('Cannot restart container. Please report this to support.'))
};
$scope.scheduleStatusCheck = function() {
$timeout(function() {
$scope.checkStatus();
}, 3000);
};
$scope.checkStatus = function() {
var errorHandler = function(resp) {
if (resp.status == 404 || resp.status == 502) {
// Container has not yet come back up, so we schedule another check.
$scope.scheduleStatusCheck();
return;
}
return ApiService.errorDisplay('Cannot load status. Please report this to support')(resp);
};
ApiService.scRegistryStatus(null, null).then(function(resp) {
$scope.currentStep = resp['status'];
}, errorHandler, /* background */true);
};
$scope.parseDbUri = function(value) {
if (!value) { return null; }
@ -276,6 +250,12 @@ function SetupCtrl($scope, $timeout, ApiService, Features, UserService, AngularP
}, ApiService.errorDisplay('Cannot validate database. Please report this to support'));
};
$scope.checkStatus = function() {
ContainerService.checkStatus(function(resp) {
$scope.currentStep = resp['status'];
});
};
// Load the initial status.
$scope.checkStatus();
}

View file

@ -1,4 +1,4 @@
function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService, AngularPollChannel, CoreDialog) {
function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService, ContainerService, AngularPollChannel, CoreDialog) {
if (!Features.SUPER_USERS) {
return;
}
@ -7,6 +7,7 @@ function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService,
UserService.updateUserIn($scope);
$scope.configStatus = null;
$scope.requiresRestart = null;
$scope.logsCounter = 0;
$scope.newUser = {};
$scope.createdUser = null;
@ -17,6 +18,10 @@ function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService,
$scope.logsScrolled = false;
$scope.csrf_token = window.__token;
$scope.configurationSaved = function() {
$scope.requiresRestart = true;
};
$scope.showCreateUser = function() {
$scope.createdUser = null;
$('#createUserModal').modal('show');
@ -183,9 +188,24 @@ function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService,
}, ApiService.errorDisplay('Cannot send recovery email'))
};
$scope.restartContainer = function() {
$('#restartingContainerModal').modal({
keyboard: false,
backdrop: 'static'
});
ContainerService.restartContainer();
$timeout(function() {
$scope.checkStatus();
}, 2000);
};
$scope.checkStatus = function() {
ApiService.scRegistryStatus(null, null).then(function(resp) {
ContainerService.checkStatus(function(resp) {
$('#restartingContainerModal').modal('hide');
$scope.configStatus = resp['status'];
$scope.requiresRestart = resp['requires_restart'];
if ($scope.configStatus == 'ready') {
$scope.loadUsers();
} else {
@ -197,7 +217,7 @@ function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService,
var title = "Installation Incomplete";
CoreDialog.fatal(title, message);
}
}, ApiService.errorDisplay('Cannot load status. Please report this to support'), /* background */true);
});
};
// Load the initial status.