Change navigation structure

Change-Id: I12c819293ce1eda188dc9f257ae9370f1b73cb18
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
index 65ae86b..0a96f62 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -19,6 +19,8 @@
               CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE,
               HOST_STATE_TEXT: Constants.HOST_STATE,
               HOST_STATE: Constants.HOST_STATE,
+              LED_STATE: Constants.LED_STATE,
+              LED_STATE_TEXT: Constants.LED_STATE_TEXT,
               getChassisState: function(callback){
                 $http({
                   method: 'GET',
@@ -53,6 +55,23 @@
                   console.log(error);
                 });
               },
+              getLEDState: function(callback){
+                $http({
+                  method: 'GET',
+                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify",
+                  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.Asserted);
+                }).error(function(error){
+                  console.log(error);
+                });
+              },
               login: function(username, password, callback){
                 $http({
                   method: 'POST',
@@ -69,7 +88,11 @@
                   }
                 }).error(function(error){
                   if(callback){
-                      callback(null, true);
+                      if(error && error.status && error.status == 'error'){
+                        callback(error);
+                      }else{
+                        callback(error, true);
+                      }
                   }
                   console.log(error);
                 });
@@ -143,6 +166,30 @@
                   }
                 });
               },
+              setLEDState: function(state, callback){
+                $http({
+                  method: 'PUT',
+                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted",
+                  headers: {
+                      'Accept': 'application/json',
+                      'Content-Type': 'application/json'
+                  },
+                  withCredentials: true,
+                  data: JSON.stringify({"data": state})
+                }).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);
+                  }
+                });
+              },
               bmcReboot: function(callback){
                 $http({
                   method: 'PUT',
@@ -262,6 +309,57 @@
                       console.log(error);
                   }
                 });
+              },
+              getLogs: function(callback){
+                $http({
+                  method: 'GET',
+                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/enumerate",
+                  headers: {
+                      'Accept': 'application/json',
+                      'Content-Type': 'application/json'
+                  },
+                  withCredentials: true
+                }).success(function(response){
+                      var json = JSON.stringify(response);
+                      var content = JSON.parse(json);
+                      var dataClone = JSON.parse(JSON.stringify(content.data));
+                      var data = [];
+                      var severityCode = '';
+                      var priority = '';
+                      var resolved = false;
+                      var relatedItems = [];
+
+                      for(var key in content.data){
+                        if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){
+                          var severityFlags = {low: false, medium: false, high: false};
+                          severityCode = content.data[key].Severity.split(".").pop();
+                          priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
+                          severityFlags[priority.toLowerCase()] = true;
+                          relatedItems = [];
+                          content.data[key].associations.forEach(function(item){
+                            relatedItems.push(item[2]); //@TODO: better way to find the third item?
+                          });
+
+                          data.push(Object.assign({
+                            path: key,
+                            copied: false,
+                            priority: priority,
+                            severity_code: severityCode,
+                            severity_flags: severityFlags,
+                            additional_data: content.data[key].AdditionalData.join("\n"),
+                            selected: false,
+                            search_text: (severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(),
+                            meta: false,
+                            confirm: false,
+                            related_items: relatedItems,
+                            data: {key: key, value: content.data[key]}
+                          }, content.data[key]));
+                        }
+                      }
+                      callback(data, dataClone);
+                }).error(function(error){
+                  console.log(error);
+                });
               }
           };
           return SERVICE;
diff --git a/app/common/services/apiInterceptor.js b/app/common/services/apiInterceptor.js
index 0c75caa..bd4743a 100644
--- a/app/common/services/apiInterceptor.js
+++ b/app/common/services/apiInterceptor.js
@@ -16,16 +16,23 @@
         .service('apiInterceptor', ['$q', '$rootScope', 'dataService', function($q, $rootScope, dataService){
             return {
                 'request': function(config){
-                    dataService.server_unreachable = false;
                     dataService.loading = true;
+                    config.timeout = 10000;
                     return config;
                 },
                 'response': function(response){
                     dataService.loading = false;
-                    dataService.last_updated = new Date();
 
+                    //not interested in template requests
+                    if(!/^https?\:/i.test(response.config.url)){
+                        return response;
+                    }
+
+                    dataService.last_updated = new Date();
                     if(response == null){
                         dataService.server_unreachable = true;
+                    }else{
+                        dataService.server_unreachable = false;
                     }
 
                     if(response && response.status == 'error' &&
diff --git a/app/common/services/constants.js b/app/common/services/constants.js
index b98d5d6..86ba54e 100644
--- a/app/common/services/constants.js
+++ b/app/common/services/constants.js
@@ -20,7 +20,7 @@
                     password: "testpass",
                 },
                 API_CREDENTIALS: {
-                    host: 'https://9.3.164.147'
+                    host: 'https://9.41.165.233/'
                 },
                 API_RESPONSE: {
                     ERROR_STATUS: 'error',
@@ -43,8 +43,24 @@
                     off: -1,
                     booting: 0,
                     unreachable: -2
+                },
+                LED_STATE: {
+                    on: true,
+                    off: false
+                },
+                LED_STATE_TEXT: {
+                    on: 'on',
+                    off: 'off'
+                },
+                SEVERITY_TO_PRIORITY_MAP:{
+                    Informational: 'Low',
+                    Error: 'High',
+                    Warning: 'Medium'
+                },
+                PAGINATION: {
+                    LOG_ITEMS_PER_PAGE: 4
                 }
             };
         });
 
-})(window.angular);
\ No newline at end of file
+})(window.angular);
diff --git a/app/common/services/dataService.js b/app/common/services/dataService.js
index 704df75..2affcc4 100644
--- a/app/common/services/dataService.js
+++ b/app/common/services/dataService.js
@@ -19,7 +19,8 @@
             this.server_state = 'Unreachable';
             this.server_status = -2;
             this.chassis_state = 'On';
-            this.server_id = "Server 9.3.164.147";
+            this.LED_state = Constants.LED_STATE_TEXT.off;
+            this.server_id = Constants.API_CREDENTIALS.host.replace(/[^\d]+/m,"");
             this.last_updated = new Date();
 
             this.loading = false;
diff --git a/app/common/services/userModel.js b/app/common/services/userModel.js
index dba607d..747b288 100644
--- a/app/common/services/userModel.js
+++ b/app/common/services/userModel.js
@@ -41,6 +41,8 @@
                            response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
                             sessionStorage.removeItem('LOGIN_ID');
                             callback(true);
+                        }else if(response.status == APIUtils.API_RESPONSE.ERROR_STATUS){
+                            callback(false);
                         }else{
                             callback(false, error);
                         }