Major update to code structure
* Split files into independent files based on functionality.
* Switch to bower/gulp for build.
Change-Id: Ibc775dd9b7f6a0a49f63c22162b7582e781e2d9c
Signed-off-by: Iftekharul Islam <iislam@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
new file mode 100644
index 0000000..af66f81
--- /dev/null
+++ b/app/common/services/api-utils.js
@@ -0,0 +1,252 @@
+/**
+ * API utilities service
+ *
+ * @module app/common/services/api-utils
+ * @exports APIUtils
+ * @name APIUtils
+ * @version 0.0.1
+ */
+
+window.angular && (function (angular) {
+ 'use strict';
+ angular
+ .module('app.common.services')
+ .factory('APIUtils', ['$http', 'Constants', function($http, Constants){
+ var SERVICE = {
+ LOGIN_CREDENTIALS: Constants.LOGIN_CREDENTIALS,
+ API_CREDENTIALS: Constants.API_CREDENTIALS,
+ API_RESPONSE: Constants.API_RESPONSE,
+ CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE,
+ HOST_STATE_TEXT: Constants.HOST_STATE,
+ HOST_STATE: Constants.HOST_STATE,
+ getChassisState: function(callback){
+ $http({
+ method: 'GET',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/chassis0",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ callback(content.data.CurrentPowerState);
+ }).error(function(error){
+ console.log(error);
+ });
+ },
+ getHostState: function(callback){
+ $http({
+ method: 'GET',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ callback(content.data.CurrentHostState);
+ }).error(function(error){
+ console.log(error);
+ });
+ },
+ login: function(username, password, callback){
+ $http({
+ method: 'POST',
+ url: SERVICE.API_CREDENTIALS.host + "/login",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": [username, password]})
+ }).success(function(response){
+ if(callback){
+ callback(response);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(null, true);
+ }
+ console.log(error);
+ });
+ },
+ logout: function(callback){
+ $http({
+ method: 'POST',
+ url: SERVICE.API_CREDENTIALS.host + "/logout",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": []})
+ }).success(function(response){
+ if(callback){
+ callback(response);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(null, error);
+ }
+ console.log(error);
+ });
+ },
+ chassisPowerOn: function(callback){
+ $http({
+ method: 'POST',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": []})
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ if(callback){
+ return callback(content.data.CurrentPowerState);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(error);
+ }else{
+ console.log(error);
+ }
+ });
+ },
+ chassisPowerOff: function(callback){
+ $http({
+ method: 'POST',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": []})
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ if(callback){
+ return callback(content.data.CurrentPowerState);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(error);
+ }else{
+ console.log(error);
+ }
+ });
+ },
+ hostPowerOn: function(callback){
+ /**
+ curl -c cjar -b cjar -k -H "Content-Type: application/json" -d
+ "{\"data\": \"xyz.openbmc_project.State.Host.Transition.Off\"}"
+ -X PUT
+ https://9.3.164.147/xyz/openbmc_project/state/host0/attr/RequestedHostTransition
+ **/
+ $http({
+ method: 'PUT',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"})
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ if(callback){
+ return callback(content.status);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(error);
+ }else{
+ console.log(error);
+ }
+ });
+ },
+ hostPowerOff: function(callback){
+ $http({
+ method: 'PUT',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"})
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ if(callback){
+ return callback(content.status);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(error);
+ }else{
+ console.log(error);
+ }
+ });
+ },
+ hostReboot: function(callback){
+ $http({
+ method: 'POST',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": []}),
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ if(callback){
+ return callback(content);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(error);
+ }else{
+ console.log(error);
+ }
+ });
+ },
+ hostShutdown: function(callback){
+ $http({
+ method: 'POST',
+ url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({"data": []})
+ }).success(function(response){
+ var json = JSON.stringify(response);
+ var content = JSON.parse(json);
+ if(callback){
+ return callback(content);
+ }
+ }).error(function(error){
+ if(callback){
+ callback(error);
+ }else{
+ console.log(error);
+ }
+ });
+ }
+ };
+ return SERVICE;
+ }]);
+
+ })(window.angular);
diff --git a/app/common/services/apiInterceptor.js b/app/common/services/apiInterceptor.js
new file mode 100644
index 0000000..5a715ec
--- /dev/null
+++ b/app/common/services/apiInterceptor.js
@@ -0,0 +1,46 @@
+/**
+ * api Interceptor
+ *
+ * @module app/common/services/apiInterceptor
+ * @exports apiInterceptor
+ * @name apiInterceptor
+
+ * @version 0.0.1
+ */
+
+window.angular && (function (angular) {
+ 'use strict';
+
+ angular
+ .module('app.common.services')
+ .service('apiInterceptor', ['$q', '$rootScope', 'dataService', function($q, $rootScope, dataService){
+ return {
+ 'request': function(config){
+ dataService.server_unreachable = false;
+ dataService.loading = true;
+ return config;
+ },
+ 'response': function(response){
+ dataService.loading = false;
+ dataService.last_updated = new Date();
+
+ if(response == null){
+ dataService.server_unreachable = true;
+ }
+
+ if(response && response.status == 'error' &&
+ dataService.path != '/login'){
+ $rootScope.$emit('timedout-user', {});
+ }
+
+ return response;
+ },
+ 'responseError': function(rejection){
+ dataService.server_unreachable = true;
+ dataService.loading = false;
+ return $q.reject(rejection);
+ }
+ };
+ }]);
+
+})(window.angular);
\ No newline at end of file
diff --git a/app/common/services/constants.js b/app/common/services/constants.js
new file mode 100644
index 0000000..b98d5d6
--- /dev/null
+++ b/app/common/services/constants.js
@@ -0,0 +1,50 @@
+/**
+ * common Constant service
+ *
+ * @module app/common/services/constants
+ * @exports Constants
+ * @name Constants
+
+ * @version 0.0.1
+ */
+
+window.angular && (function (angular) {
+ 'use strict';
+
+ angular
+ .module('app.common.services')
+ .service('Constants', function () {
+ return {
+ LOGIN_CREDENTIALS: {
+ username: "test",
+ password: "testpass",
+ },
+ API_CREDENTIALS: {
+ host: 'https://9.3.164.147'
+ },
+ API_RESPONSE: {
+ ERROR_STATUS: 'error',
+ ERROR_MESSAGE: '401 Unauthorized',
+ SUCCESS_STATUS: 'ok',
+ SUCCESS_MESSAGE: '200 OK'
+ },
+ CHASSIS_POWER_STATE: {
+ on: 'On',
+ off: 'Off'
+ },
+ HOST_STATE_TEXT: {
+ on: 'Running',
+ off: 'Off',
+ booting: 'Quiesced',
+ unreachable: 'Unreachable'
+ },
+ HOST_STATE: {
+ on: 1,
+ off: -1,
+ booting: 0,
+ unreachable: -2
+ }
+ };
+ });
+
+})(window.angular);
\ No newline at end of file
diff --git a/app/common/services/dataService.js b/app/common/services/dataService.js
new file mode 100644
index 0000000..704df75
--- /dev/null
+++ b/app/common/services/dataService.js
@@ -0,0 +1,53 @@
+/**
+ * data service
+ *
+ * @module app/common/services/dataService
+ * @exports dataService
+ * @name dataService
+
+ * @version 0.0.1
+ */
+
+window.angular && (function (angular) {
+ 'use strict';
+
+ angular
+ .module('app.common.services')
+ .service('dataService', ['Constants', function (Constants) {
+ this.app_version = "openBMC V.0.0.1";
+ this.server_health = 'Error';
+ this.server_state = 'Unreachable';
+ this.server_status = -2;
+ this.chassis_state = 'On';
+ this.server_id = "Server 9.3.164.147";
+ this.last_updated = new Date();
+
+ this.loading = false;
+ this.server_unreachable = false;
+ this.loading_message = "";
+ this.showNavigation = false;
+ this.bodyStyle = {};
+ this.path = '';
+
+ this.setPowerOnState = function(){
+ this.server_state = Constants.HOST_STATE_TEXT.on;
+ this.server_status = Constants.HOST_STATE.on;
+ },
+
+ this.setPowerOffState = function(){
+ this.server_state = Constants.HOST_STATE_TEXT.off;
+ this.server_status = Constants.HOST_STATE.off;
+ },
+
+ this.setBootingState = function(){
+ this.server_state = Constants.HOST_STATE_TEXT.booting;
+ this.server_status = Constants.HOST_STATE.booting;
+ },
+
+ this.setUnreachableState = function(){
+ this.server_state = Constants.HOST_STATE_TEXT.unreachable;
+ this.server_status = Constants.HOST_STATE.unreachable;
+ }
+ }]);
+
+})(window.angular);
\ No newline at end of file
diff --git a/app/common/services/index.js b/app/common/services/index.js
new file mode 100644
index 0000000..f54f6eb
--- /dev/null
+++ b/app/common/services/index.js
@@ -0,0 +1,18 @@
+/**
+ * A module to contain common services
+ *
+ * @module app/common/services/index
+ * @exports app/common/services/index
+ * @version 0.0.1
+ */
+
+window.angular && (function (angular) {
+ 'use strict';
+
+ angular
+ .module('app.common.services', [
+ // Dependencies
+ // Basic resources
+ ]);
+
+})(window.angular);
diff --git a/app/common/services/userModel.js b/app/common/services/userModel.js
new file mode 100644
index 0000000..e44ba8c
--- /dev/null
+++ b/app/common/services/userModel.js
@@ -0,0 +1,49 @@
+/**
+ * userModel
+ *
+ * @module app/common/services/userModel
+ * @exports userModel
+ * @name userModel
+
+ * @version 0.0.1
+ */
+
+window.angular && (function (angular) {
+ 'use strict';
+
+ angular
+ .module('app.common.services')
+ .service('userModel', ['APIUtils',function(APIUtils){
+ return {
+ login : function(username, password, callback){
+ APIUtils.login(username, password, function(response, error){
+ if(response &&
+ response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
+ sessionStorage.setItem('LOGIN_ID', username);
+ callback(true);
+ }else{
+ callback(false, error);
+ }
+ });
+ },
+ isLoggedIn : function(){
+ if(sessionStorage.getItem('LOGIN_ID') === null){
+ return false;
+ }
+ return true;
+ },
+ logout : function(callback){
+ APIUtils.logout(function(response, error){
+ if(response &&
+ response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
+ sessionStorage.removeItem('LOGIN_ID');
+ callback(true);
+ }else{
+ callback(false, error);
+ }
+ });
+ }
+ };
+ }]);
+
+})(window.angular);
\ No newline at end of file