Modernize web GUI and make it installable on BMC
1. Move from gulp server to webpack. This allows the proper
compression to allow the webui to be embedded in the BMC.
2. Update js paths to use requires, not hardcoded paths. This was
required to make the packaging work correctly.
3. Add babel config to do translation.
4. Update angularjs directive calls to use the angular 1.6 syntax for
promises intead of success and fail.
https://docs.angularjs.org/guide/migration#migrate1.5to1.6-ng-services-$http
5. As a consequence of using NPM/webpack, the versions of angular and
associated modules that were checked in have been updated.
Change-Id: Icb71e2eedb0d9a8943fc914f9dc4be11d0983c00
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index a7a6a58..3d0f853 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -31,11 +31,11 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
callback(content.data.CurrentPowerState);
- }).error(function(error){
+ }, function(error){
console.log(error);
});
},
@@ -48,11 +48,11 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
callback(content.data.CurrentHostState);
- }).error(function(error){
+ }, function(error){
console.log(error);
});
},
@@ -66,8 +66,8 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
var hostname = "";
var macAddress = "";
@@ -139,7 +139,7 @@
mac_address: macAddress,
formatted_data: parseNetworkData(content)
});
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -155,11 +155,11 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content.data.Asserted);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -175,11 +175,11 @@
},
withCredentials: true,
data: JSON.stringify({"data": [username, password]})
- }).success(function(response){
+ }).then(function(response){
if(callback){
- callback(response);
+ callback(response.data);
}
- }).error(function(error){
+ }, function(error){
if(callback){
if(error && error.status && error.status == 'error'){
callback(error);
@@ -200,11 +200,11 @@
},
withCredentials: true,
data: JSON.stringify({"data": []})
- }).success(function(response){
+ }).then(function(response){
if(callback){
callback(response);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(null, error);
}
@@ -221,13 +221,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": []})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content.data.CurrentPowerState);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -245,13 +245,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": []})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content.data.CurrentPowerState);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -269,13 +269,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": state})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content.status);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -293,13 +293,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content.status);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -317,13 +317,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content.status);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -341,13 +341,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content.status);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -365,13 +365,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": []}),
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -389,13 +389,13 @@
},
withCredentials: true,
data: JSON.stringify({"data": []})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
if(callback){
return callback(content);
}
- }).error(function(error){
+ }, function(error){
if(callback){
callback(error);
}else{
@@ -413,8 +413,8 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
var dataClone = JSON.parse(JSON.stringify(content.data));
var data = [];
@@ -455,7 +455,7 @@
}
}
deferred.resolve({data: data, original: dataClone});
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -471,8 +471,8 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
var dataClone = JSON.parse(JSON.stringify(content.data));
var sensorData = [];
@@ -586,7 +586,7 @@
}
callback(sensorData, dataClone);
- }).error(function(error){
+ }, function(error){
console.log(error);
});
},
@@ -600,8 +600,8 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
var data = [];
var active = false;
@@ -681,7 +681,7 @@
bmcActiveVersion: bmcActiveVersion,
hostActiveVersion: hostActiveVersion
});
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -699,11 +699,11 @@
},
withCredentials: true,
data: JSON.stringify({"data": priority})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -721,11 +721,11 @@
},
withCredentials: true,
data: JSON.stringify({"data": []})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -743,11 +743,11 @@
},
withCredentials: true,
data: JSON.stringify({"data": Constants.FIRMWARE.ACTIVATE_FIRMWARE})
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -765,11 +765,11 @@
},
withCredentials: true,
data: file
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -788,13 +788,13 @@
withCredentials: true,
data: JSON.stringify({"data": [host, filename]}),
responseType: 'arraybuffer'
- }).success(function(response, status, headers){
+ }).then(function(response, status, headers){
deferred.resolve({
data: response,
status: status,
headers: headers
});
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -811,11 +811,11 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content.data);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -832,11 +832,11 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
deferred.resolve(content.data);
- }).error(function(error){
+ }, function(error){
console.log(error);
deferred.reject(error);
});
@@ -851,8 +851,8 @@
'Content-Type': 'application/json'
},
withCredentials: true
- }).success(function(response){
- var json = JSON.stringify(response);
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
var content = JSON.parse(json);
var hardwareData = [];
var keyIndexMap = {};
diff --git a/app/common/services/apiInterceptor.js b/app/common/services/apiInterceptor.js
index d1a23ad..8bbb6f4 100644
--- a/app/common/services/apiInterceptor.js
+++ b/app/common/services/apiInterceptor.js
@@ -43,14 +43,19 @@
return response;
},
'responseError': function(rejection){
- dataService.server_unreachable = true;
- dataService.loading = false;
- if(dataService.path != '/login'){
- $rootScope.$emit('timedout-user', {});
+ // If unauthorized, log out
+ if (rejection.status == 401){
+ if (dataService.path != '/login'){
+ $rootScope.$emit('timedout-user', {});
+ }
+ } else if (rejection.status == -1){
+ dataService.server_unreachable = true;
}
+
+ dataService.loading = false;
return $q.reject(rejection);
}
};
}]);
-})(window.angular);
\ No newline at end of file
+})(window.angular);
diff --git a/app/common/services/constants.js b/app/common/services/constants.js
index 76bc590..373fab1 100644
--- a/app/common/services/constants.js
+++ b/app/common/services/constants.js
@@ -12,7 +12,7 @@
'use strict';
angular
- .module('app.common.services')
+ .module('app.common.services', [])
.service('Constants', function () {
return {
LOGIN_CREDENTIALS: {
@@ -122,4 +122,4 @@
};
});
-})(window.angular);
\ No newline at end of file
+})(window.angular);
diff --git a/app/common/services/userModel.js b/app/common/services/userModel.js
index a3fc277..2c9de65 100644
--- a/app/common/services/userModel.js
+++ b/app/common/services/userModel.js
@@ -20,8 +20,9 @@
},
login : function(username, password, callback){
APIUtils.login(username, password, function(response, error){
- if(response &&
- response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
+ if(response &&
+ (response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS
+ || response.status === undefined)){
sessionStorage.setItem('LOGIN_ID', username);
callback(true);
}else{
@@ -52,4 +53,4 @@
};
}]);
-})(window.angular);
\ No newline at end of file
+})(window.angular);