summaryrefslogtreecommitdiffstats
path: root/app/configuration/controllers/firmware-controller.js
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2018-03-06 14:49:40 -0600
committerGunnar Mills <gmills@us.ibm.com>2018-04-04 17:36:51 +0000
commit033025f33dd0872c2d23f06c471fd5278c7ddd41 (patch)
treeb02de81a0e172b8fffbf86fa9fe136e315abd16c /app/configuration/controllers/firmware-controller.js
parent7c3e8c1d0c24f499c7140b8df6ed8114597514c1 (diff)
downloadphosphor-webui-033025f33dd0872c2d23f06c471fd5278c7ddd41.tar.gz
phosphor-webui-033025f33dd0872c2d23f06c471fd5278c7ddd41.zip
Update the GUI after an image activated
When activating an image the firmware page does not refresh after the image is activated and show the image as "Active". To get the image to show as "Active", a user must refresh the page. The activating image code now waits until the image is activated and the REST call returns "Active" or "Failed" and then refreshes the page. Resolves openbmc/openbmc#2966 Tested: Activated an image and verfied it refreshed after "Active". Change-Id: Ic68e3c9e6cb5c2ea4f5d66f48fd09252c4807f26 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'app/configuration/controllers/firmware-controller.js')
-rw-r--r--app/configuration/controllers/firmware-controller.js71
1 files changed, 55 insertions, 16 deletions
diff --git a/app/configuration/controllers/firmware-controller.js b/app/configuration/controllers/firmware-controller.js
index b9a87b7..8fe0e83 100644
--- a/app/configuration/controllers/firmware-controller.js
+++ b/app/configuration/controllers/firmware-controller.js
@@ -20,7 +20,9 @@ window.angular && (function (angular) {
'$location',
'$anchorScroll',
'Constants',
- function ($scope, $window, APIUtils, dataService, $location, $anchorScroll, Constants) {
+ '$interval',
+ '$q',
+ function ($scope, $window, APIUtils, dataService, $location, $anchorScroll, Constants, $interval, $q) {
$scope.dataService = dataService;
//Scroll to target anchor
@@ -47,6 +49,8 @@ window.angular && (function (angular) {
$scope.file_empty = true;
$scope.uploading = false;
+ var pollActivationTimer = undefined;
+
$scope.error = {
modal_title: "",
title: "",
@@ -66,22 +70,58 @@ window.angular && (function (angular) {
$scope.display_error = true;
}
+ function waitForActive(imageId){
+ var deferred = $q.defer();
+ var startTime = new Date();
+ pollActivationTimer = $interval(function(){
+ APIUtils.getActivation(imageId).then(function(state){
+ //@TODO: display an error message if image "Failed"
+ if(((/\.Active$/).test(state.data)) || ((/\.Failed$/).test(state.data))){
+ $interval.cancel(pollActivationTimer);
+ pollActivationTimer = undefined;
+ deferred.resolve(state);
+ }
+ }, function(error){
+ $interval.cancel(pollActivationTimer);
+ pollActivationTimer = undefined;
+ console.log(error);
+ deferred.reject(error);
+ });
+ var now = new Date();
+ if((now.getTime() - startTime.getTime()) >= Constants.TIMEOUT.ACTIVATION){
+ $interval.cancel(pollActivationTimer);
+ pollActivationTimer = undefined;
+ console.log("Time out activating image, " + imageId);
+ deferred.reject("Time out. Image did not activate in allotted time.");
+ }
+ }, Constants.POLL_INTERVALS.ACTIVATION);
+ return deferred.promise;
+ }
+
$scope.activateConfirmed = function(){
- $scope.uploading = true;
- APIUtils.activateImage($scope.activate_image_id).then(function(response){
- $scope.uploading = false;
- if(response.status == 'error'){
- $scope.displayError({
- modal_title: response.data.description,
- title: response.data.description,
- desc: response.data.exception,
- type: 'Error'
- });
- }else{
- $scope.loadFirmwares();
- }
+ APIUtils.activateImage($scope.activate_image_id).then(function(state){
+ $scope.loadFirmwares();
+ return state;
+ }, function(error){
+ $scope.displayError({
+ modal_title: 'Error during activation call',
+ title: 'Error during activation call',
+ desc: JSON.stringify(error.data),
+ type: 'Error'
+ });
+ }).then(function(activationState){
+ waitForActive($scope.activate_image_id).then(function(state){
+ $scope.loadFirmwares();
+ }, function(error){
+ $scope.displayError({
+ modal_title: 'Error during image activation',
+ title: 'Error during image activation',
+ desc: JSON.stringify(error.data),
+ type: 'Error'
+ });
});
- $scope.activate_confirm = false;
+ });
+ $scope.activate_confirm = false;
}
$scope.upload = function(){
@@ -188,7 +228,6 @@ window.angular && (function (angular) {
$scope.file_empty = false;
}
- $scope.uploading = false;
$scope.filters = {
bmc: {
imageType: 'BMC'
OpenPOWER on IntegriCloud