199d199f3SIftekharul Islam/** 299d199f3SIftekharul Islam * API utilities service 399d199f3SIftekharul Islam * 499d199f3SIftekharul Islam * @module app/common/services/api-utils 599d199f3SIftekharul Islam * @exports APIUtils 699d199f3SIftekharul Islam * @name APIUtils 799d199f3SIftekharul Islam * @version 0.0.1 899d199f3SIftekharul Islam */ 999d199f3SIftekharul Islam 1099d199f3SIftekharul Islamwindow.angular && (function (angular) { 1199d199f3SIftekharul Islam 'use strict'; 1299d199f3SIftekharul Islam angular 1399d199f3SIftekharul Islam .module('app.common.services') 14f2d74644SIftekharul Islam .factory('APIUtils', ['$http', 'Constants', '$q', function($http, Constants, $q){ 1599d199f3SIftekharul Islam var SERVICE = { 1699d199f3SIftekharul Islam LOGIN_CREDENTIALS: Constants.LOGIN_CREDENTIALS, 1799d199f3SIftekharul Islam API_CREDENTIALS: Constants.API_CREDENTIALS, 1899d199f3SIftekharul Islam API_RESPONSE: Constants.API_RESPONSE, 1999d199f3SIftekharul Islam CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE, 2099d199f3SIftekharul Islam HOST_STATE_TEXT: Constants.HOST_STATE, 2199d199f3SIftekharul Islam HOST_STATE: Constants.HOST_STATE, 22cd789508SIftekharul Islam LED_STATE: Constants.LED_STATE, 23cd789508SIftekharul Islam LED_STATE_TEXT: Constants.LED_STATE_TEXT, 2499d199f3SIftekharul Islam getChassisState: function(callback){ 2599d199f3SIftekharul Islam $http({ 2699d199f3SIftekharul Islam method: 'GET', 2799d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/chassis0", 2899d199f3SIftekharul Islam headers: { 2999d199f3SIftekharul Islam 'Accept': 'application/json', 3099d199f3SIftekharul Islam 'Content-Type': 'application/json' 3199d199f3SIftekharul Islam }, 3299d199f3SIftekharul Islam withCredentials: true 3399d199f3SIftekharul Islam }).success(function(response){ 3499d199f3SIftekharul Islam var json = JSON.stringify(response); 3599d199f3SIftekharul Islam var content = JSON.parse(json); 3699d199f3SIftekharul Islam callback(content.data.CurrentPowerState); 3799d199f3SIftekharul Islam }).error(function(error){ 3899d199f3SIftekharul Islam console.log(error); 3999d199f3SIftekharul Islam }); 4099d199f3SIftekharul Islam }, 4199d199f3SIftekharul Islam getHostState: function(callback){ 4299d199f3SIftekharul Islam $http({ 4399d199f3SIftekharul Islam method: 'GET', 4499d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 4599d199f3SIftekharul Islam headers: { 4699d199f3SIftekharul Islam 'Accept': 'application/json', 4799d199f3SIftekharul Islam 'Content-Type': 'application/json' 4899d199f3SIftekharul Islam }, 4999d199f3SIftekharul Islam withCredentials: true 5099d199f3SIftekharul Islam }).success(function(response){ 5199d199f3SIftekharul Islam var json = JSON.stringify(response); 5299d199f3SIftekharul Islam var content = JSON.parse(json); 5399d199f3SIftekharul Islam callback(content.data.CurrentHostState); 5499d199f3SIftekharul Islam }).error(function(error){ 5599d199f3SIftekharul Islam console.log(error); 5699d199f3SIftekharul Islam }); 5799d199f3SIftekharul Islam }, 58171c6a1eSIftekharul Islam getNetworkInfo: function(){ 59171c6a1eSIftekharul Islam var deferred = $q.defer(); 60171c6a1eSIftekharul Islam $http({ 61171c6a1eSIftekharul Islam method: 'GET', 62171c6a1eSIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/network/enumerate", 63171c6a1eSIftekharul Islam headers: { 64171c6a1eSIftekharul Islam 'Accept': 'application/json', 65171c6a1eSIftekharul Islam 'Content-Type': 'application/json' 66171c6a1eSIftekharul Islam }, 67171c6a1eSIftekharul Islam withCredentials: true 68171c6a1eSIftekharul Islam }).success(function(response){ 69171c6a1eSIftekharul Islam var json = JSON.stringify(response); 70171c6a1eSIftekharul Islam var content = JSON.parse(json); 71171c6a1eSIftekharul Islam var hostname = ""; 72171c6a1eSIftekharul Islam var macAddress = ""; 73171c6a1eSIftekharul Islam 74171c6a1eSIftekharul Islam if(content.data.hasOwnProperty('/xyz/openbmc_project/network/config') && 75171c6a1eSIftekharul Islam content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName') 76171c6a1eSIftekharul Islam ){ 77171c6a1eSIftekharul Islam hostname = content.data['/xyz/openbmc_project/network/config'].HostName; 78171c6a1eSIftekharul Islam } 79171c6a1eSIftekharul Islam 80171c6a1eSIftekharul Islam if(content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') && 81171c6a1eSIftekharul Islam content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress') 82171c6a1eSIftekharul Islam ){ 83171c6a1eSIftekharul Islam macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress; 84171c6a1eSIftekharul Islam } 85171c6a1eSIftekharul Islam 86171c6a1eSIftekharul Islam deferred.resolve({ 87171c6a1eSIftekharul Islam data: content.data, 88171c6a1eSIftekharul Islam hostname: hostname, 89171c6a1eSIftekharul Islam mac_address: macAddress, 90171c6a1eSIftekharul Islam }); 91171c6a1eSIftekharul Islam }).error(function(error){ 92171c6a1eSIftekharul Islam console.log(error); 93171c6a1eSIftekharul Islam deferred.reject(error); 94171c6a1eSIftekharul Islam }); 95171c6a1eSIftekharul Islam return deferred.promise; 96171c6a1eSIftekharul Islam }, 97df3bd124SMichael Davis getLEDState: function(){ 98df3bd124SMichael Davis var deferred = $q.defer(); 99cd789508SIftekharul Islam $http({ 100cd789508SIftekharul Islam method: 'GET', 101cd789508SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify", 102cd789508SIftekharul Islam headers: { 103cd789508SIftekharul Islam 'Accept': 'application/json', 104cd789508SIftekharul Islam 'Content-Type': 'application/json' 105cd789508SIftekharul Islam }, 106cd789508SIftekharul Islam withCredentials: true 107cd789508SIftekharul Islam }).success(function(response){ 108cd789508SIftekharul Islam var json = JSON.stringify(response); 109cd789508SIftekharul Islam var content = JSON.parse(json); 110df3bd124SMichael Davis deferred.resolve(content.data.Asserted); 111cd789508SIftekharul Islam }).error(function(error){ 112cd789508SIftekharul Islam console.log(error); 113df3bd124SMichael Davis deferred.reject(error); 114cd789508SIftekharul Islam }); 115df3bd124SMichael Davis return deferred.promise; 116cd789508SIftekharul Islam }, 11799d199f3SIftekharul Islam login: function(username, password, callback){ 11899d199f3SIftekharul Islam $http({ 11999d199f3SIftekharul Islam method: 'POST', 12099d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/login", 12199d199f3SIftekharul Islam headers: { 12299d199f3SIftekharul Islam 'Accept': 'application/json', 12399d199f3SIftekharul Islam 'Content-Type': 'application/json' 12499d199f3SIftekharul Islam }, 12599d199f3SIftekharul Islam withCredentials: true, 12699d199f3SIftekharul Islam data: JSON.stringify({"data": [username, password]}) 12799d199f3SIftekharul Islam }).success(function(response){ 12899d199f3SIftekharul Islam if(callback){ 12999d199f3SIftekharul Islam callback(response); 13099d199f3SIftekharul Islam } 13199d199f3SIftekharul Islam }).error(function(error){ 13299d199f3SIftekharul Islam if(callback){ 133cd789508SIftekharul Islam if(error && error.status && error.status == 'error'){ 134cd789508SIftekharul Islam callback(error); 135cd789508SIftekharul Islam }else{ 136cd789508SIftekharul Islam callback(error, true); 137cd789508SIftekharul Islam } 13899d199f3SIftekharul Islam } 13999d199f3SIftekharul Islam console.log(error); 14099d199f3SIftekharul Islam }); 14199d199f3SIftekharul Islam }, 14299d199f3SIftekharul Islam logout: function(callback){ 14399d199f3SIftekharul Islam $http({ 14499d199f3SIftekharul Islam method: 'POST', 14599d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/logout", 14699d199f3SIftekharul Islam headers: { 14799d199f3SIftekharul Islam 'Accept': 'application/json', 14899d199f3SIftekharul Islam 'Content-Type': 'application/json' 14999d199f3SIftekharul Islam }, 15099d199f3SIftekharul Islam withCredentials: true, 15199d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 15299d199f3SIftekharul Islam }).success(function(response){ 15399d199f3SIftekharul Islam if(callback){ 15499d199f3SIftekharul Islam callback(response); 15599d199f3SIftekharul Islam } 15699d199f3SIftekharul Islam }).error(function(error){ 15799d199f3SIftekharul Islam if(callback){ 15899d199f3SIftekharul Islam callback(null, error); 15999d199f3SIftekharul Islam } 16099d199f3SIftekharul Islam console.log(error); 16199d199f3SIftekharul Islam }); 16299d199f3SIftekharul Islam }, 16399d199f3SIftekharul Islam chassisPowerOn: function(callback){ 16499d199f3SIftekharul Islam $http({ 16599d199f3SIftekharul Islam method: 'POST', 16699d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 16799d199f3SIftekharul Islam headers: { 16899d199f3SIftekharul Islam 'Accept': 'application/json', 16999d199f3SIftekharul Islam 'Content-Type': 'application/json' 17099d199f3SIftekharul Islam }, 17199d199f3SIftekharul Islam withCredentials: true, 17299d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 17399d199f3SIftekharul Islam }).success(function(response){ 17499d199f3SIftekharul Islam var json = JSON.stringify(response); 17599d199f3SIftekharul Islam var content = JSON.parse(json); 17699d199f3SIftekharul Islam if(callback){ 17799d199f3SIftekharul Islam return callback(content.data.CurrentPowerState); 17899d199f3SIftekharul Islam } 17999d199f3SIftekharul Islam }).error(function(error){ 18099d199f3SIftekharul Islam if(callback){ 18199d199f3SIftekharul Islam callback(error); 18299d199f3SIftekharul Islam }else{ 18399d199f3SIftekharul Islam console.log(error); 18499d199f3SIftekharul Islam } 18599d199f3SIftekharul Islam }); 18699d199f3SIftekharul Islam }, 18799d199f3SIftekharul Islam chassisPowerOff: function(callback){ 18899d199f3SIftekharul Islam $http({ 18999d199f3SIftekharul Islam method: 'POST', 19099d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 19199d199f3SIftekharul Islam headers: { 19299d199f3SIftekharul Islam 'Accept': 'application/json', 19399d199f3SIftekharul Islam 'Content-Type': 'application/json' 19499d199f3SIftekharul Islam }, 19599d199f3SIftekharul Islam withCredentials: true, 19699d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 19799d199f3SIftekharul Islam }).success(function(response){ 19899d199f3SIftekharul Islam var json = JSON.stringify(response); 19999d199f3SIftekharul Islam var content = JSON.parse(json); 20099d199f3SIftekharul Islam if(callback){ 20199d199f3SIftekharul Islam return callback(content.data.CurrentPowerState); 20299d199f3SIftekharul Islam } 20399d199f3SIftekharul Islam }).error(function(error){ 20499d199f3SIftekharul Islam if(callback){ 20599d199f3SIftekharul Islam callback(error); 20699d199f3SIftekharul Islam }else{ 20799d199f3SIftekharul Islam console.log(error); 20899d199f3SIftekharul Islam } 20999d199f3SIftekharul Islam }); 21099d199f3SIftekharul Islam }, 211cd789508SIftekharul Islam setLEDState: function(state, callback){ 212cd789508SIftekharul Islam $http({ 213cd789508SIftekharul Islam method: 'PUT', 214cd789508SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted", 215cd789508SIftekharul Islam headers: { 216cd789508SIftekharul Islam 'Accept': 'application/json', 217cd789508SIftekharul Islam 'Content-Type': 'application/json' 218cd789508SIftekharul Islam }, 219cd789508SIftekharul Islam withCredentials: true, 220cd789508SIftekharul Islam data: JSON.stringify({"data": state}) 221cd789508SIftekharul Islam }).success(function(response){ 222cd789508SIftekharul Islam var json = JSON.stringify(response); 223cd789508SIftekharul Islam var content = JSON.parse(json); 224cd789508SIftekharul Islam if(callback){ 225cd789508SIftekharul Islam return callback(content.status); 226cd789508SIftekharul Islam } 227cd789508SIftekharul Islam }).error(function(error){ 228cd789508SIftekharul Islam if(callback){ 229cd789508SIftekharul Islam callback(error); 230cd789508SIftekharul Islam }else{ 231cd789508SIftekharul Islam console.log(error); 232cd789508SIftekharul Islam } 233cd789508SIftekharul Islam }); 234cd789508SIftekharul Islam }, 23555368129SIftekharul Islam bmcReboot: function(callback){ 23655368129SIftekharul Islam $http({ 23755368129SIftekharul Islam method: 'PUT', 23855368129SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition", 23955368129SIftekharul Islam headers: { 24055368129SIftekharul Islam 'Accept': 'application/json', 24155368129SIftekharul Islam 'Content-Type': 'application/json' 24255368129SIftekharul Islam }, 24355368129SIftekharul Islam withCredentials: true, 24455368129SIftekharul Islam data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}) 24555368129SIftekharul Islam }).success(function(response){ 24655368129SIftekharul Islam var json = JSON.stringify(response); 24755368129SIftekharul Islam var content = JSON.parse(json); 24855368129SIftekharul Islam if(callback){ 24955368129SIftekharul Islam return callback(content.status); 25055368129SIftekharul Islam } 25155368129SIftekharul Islam }).error(function(error){ 25255368129SIftekharul Islam if(callback){ 25355368129SIftekharul Islam callback(error); 25455368129SIftekharul Islam }else{ 25555368129SIftekharul Islam console.log(error); 25655368129SIftekharul Islam } 25755368129SIftekharul Islam }); 25855368129SIftekharul Islam }, 25999d199f3SIftekharul Islam hostPowerOn: function(callback){ 26099d199f3SIftekharul Islam $http({ 26199d199f3SIftekharul Islam method: 'PUT', 26299d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", 26399d199f3SIftekharul Islam headers: { 26499d199f3SIftekharul Islam 'Accept': 'application/json', 26599d199f3SIftekharul Islam 'Content-Type': 'application/json' 26699d199f3SIftekharul Islam }, 26799d199f3SIftekharul Islam withCredentials: true, 26899d199f3SIftekharul Islam data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"}) 26999d199f3SIftekharul Islam }).success(function(response){ 27099d199f3SIftekharul Islam var json = JSON.stringify(response); 27199d199f3SIftekharul Islam var content = JSON.parse(json); 27299d199f3SIftekharul Islam if(callback){ 27399d199f3SIftekharul Islam return callback(content.status); 27499d199f3SIftekharul Islam } 27599d199f3SIftekharul Islam }).error(function(error){ 27699d199f3SIftekharul Islam if(callback){ 27799d199f3SIftekharul Islam callback(error); 27899d199f3SIftekharul Islam }else{ 27999d199f3SIftekharul Islam console.log(error); 28099d199f3SIftekharul Islam } 28199d199f3SIftekharul Islam }); 28299d199f3SIftekharul Islam }, 28399d199f3SIftekharul Islam hostPowerOff: function(callback){ 28499d199f3SIftekharul Islam $http({ 28599d199f3SIftekharul Islam method: 'PUT', 28699d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition", 28799d199f3SIftekharul Islam headers: { 28899d199f3SIftekharul Islam 'Accept': 'application/json', 28999d199f3SIftekharul Islam 'Content-Type': 'application/json' 29099d199f3SIftekharul Islam }, 29199d199f3SIftekharul Islam withCredentials: true, 29299d199f3SIftekharul Islam data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"}) 29399d199f3SIftekharul Islam }).success(function(response){ 29499d199f3SIftekharul Islam var json = JSON.stringify(response); 29599d199f3SIftekharul Islam var content = JSON.parse(json); 29699d199f3SIftekharul Islam if(callback){ 29799d199f3SIftekharul Islam return callback(content.status); 29899d199f3SIftekharul Islam } 29999d199f3SIftekharul Islam }).error(function(error){ 30099d199f3SIftekharul Islam if(callback){ 30199d199f3SIftekharul Islam callback(error); 30299d199f3SIftekharul Islam }else{ 30399d199f3SIftekharul Islam console.log(error); 30499d199f3SIftekharul Islam } 30599d199f3SIftekharul Islam }); 30699d199f3SIftekharul Islam }, 30799d199f3SIftekharul Islam hostReboot: function(callback){ 30899d199f3SIftekharul Islam $http({ 30999d199f3SIftekharul Islam method: 'POST', 31099d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 31199d199f3SIftekharul Islam headers: { 31299d199f3SIftekharul Islam 'Accept': 'application/json', 31399d199f3SIftekharul Islam 'Content-Type': 'application/json' 31499d199f3SIftekharul Islam }, 31599d199f3SIftekharul Islam withCredentials: true, 31699d199f3SIftekharul Islam data: JSON.stringify({"data": []}), 31799d199f3SIftekharul Islam }).success(function(response){ 31899d199f3SIftekharul Islam var json = JSON.stringify(response); 31999d199f3SIftekharul Islam var content = JSON.parse(json); 32099d199f3SIftekharul Islam if(callback){ 32199d199f3SIftekharul Islam return callback(content); 32299d199f3SIftekharul Islam } 32399d199f3SIftekharul Islam }).error(function(error){ 32499d199f3SIftekharul Islam if(callback){ 32599d199f3SIftekharul Islam callback(error); 32699d199f3SIftekharul Islam }else{ 32799d199f3SIftekharul Islam console.log(error); 32899d199f3SIftekharul Islam } 32999d199f3SIftekharul Islam }); 33099d199f3SIftekharul Islam }, 33199d199f3SIftekharul Islam hostShutdown: function(callback){ 33299d199f3SIftekharul Islam $http({ 33399d199f3SIftekharul Islam method: 'POST', 33499d199f3SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0", 33599d199f3SIftekharul Islam headers: { 33699d199f3SIftekharul Islam 'Accept': 'application/json', 33799d199f3SIftekharul Islam 'Content-Type': 'application/json' 33899d199f3SIftekharul Islam }, 33999d199f3SIftekharul Islam withCredentials: true, 34099d199f3SIftekharul Islam data: JSON.stringify({"data": []}) 34199d199f3SIftekharul Islam }).success(function(response){ 34299d199f3SIftekharul Islam var json = JSON.stringify(response); 34399d199f3SIftekharul Islam var content = JSON.parse(json); 34499d199f3SIftekharul Islam if(callback){ 34599d199f3SIftekharul Islam return callback(content); 34699d199f3SIftekharul Islam } 34799d199f3SIftekharul Islam }).error(function(error){ 34899d199f3SIftekharul Islam if(callback){ 34999d199f3SIftekharul Islam callback(error); 35099d199f3SIftekharul Islam }else{ 35199d199f3SIftekharul Islam console.log(error); 35299d199f3SIftekharul Islam } 35399d199f3SIftekharul Islam }); 354cd789508SIftekharul Islam }, 355df3bd124SMichael Davis getLogs: function(){ 356df3bd124SMichael Davis var deferred = $q.defer(); 357cd789508SIftekharul Islam $http({ 358cd789508SIftekharul Islam method: 'GET', 359cd789508SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/enumerate", 360cd789508SIftekharul Islam headers: { 361cd789508SIftekharul Islam 'Accept': 'application/json', 362cd789508SIftekharul Islam 'Content-Type': 'application/json' 363cd789508SIftekharul Islam }, 364cd789508SIftekharul Islam withCredentials: true 365cd789508SIftekharul Islam }).success(function(response){ 366cd789508SIftekharul Islam var json = JSON.stringify(response); 367cd789508SIftekharul Islam var content = JSON.parse(json); 368cd789508SIftekharul Islam var dataClone = JSON.parse(JSON.stringify(content.data)); 369cd789508SIftekharul Islam var data = []; 370cd789508SIftekharul Islam var severityCode = ''; 371cd789508SIftekharul Islam var priority = ''; 372cd789508SIftekharul Islam var relatedItems = []; 373cd789508SIftekharul Islam 374cd789508SIftekharul Islam for(var key in content.data){ 375cd789508SIftekharul Islam if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){ 376cd789508SIftekharul Islam var severityFlags = {low: false, medium: false, high: false}; 377cd789508SIftekharul Islam severityCode = content.data[key].Severity.split(".").pop(); 378cd789508SIftekharul Islam priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; 379cd789508SIftekharul Islam severityFlags[priority.toLowerCase()] = true; 380cd789508SIftekharul Islam relatedItems = []; 381cd789508SIftekharul Islam content.data[key].associations.forEach(function(item){ 382532763f4SIftekharul Islam relatedItems.push(item[2]); 383cd789508SIftekharul Islam }); 384cd789508SIftekharul Islam 385cd789508SIftekharul Islam data.push(Object.assign({ 386cd789508SIftekharul Islam path: key, 387cd789508SIftekharul Islam copied: false, 388cd789508SIftekharul Islam priority: priority, 389cd789508SIftekharul Islam severity_code: severityCode, 390cd789508SIftekharul Islam severity_flags: severityFlags, 391cd789508SIftekharul Islam additional_data: content.data[key].AdditionalData.join("\n"), 392cd789508SIftekharul Islam selected: false, 3938b4828a6SIftekharul Islam search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(), 394cd789508SIftekharul Islam meta: false, 395cd789508SIftekharul Islam confirm: false, 396cd789508SIftekharul Islam related_items: relatedItems, 397cd789508SIftekharul Islam data: {key: key, value: content.data[key]} 398cd789508SIftekharul Islam }, content.data[key])); 399cd789508SIftekharul Islam } 400cd789508SIftekharul Islam } 401df3bd124SMichael Davis deferred.resolve({data: data, original: dataClone}); 402cd789508SIftekharul Islam }).error(function(error){ 403cd789508SIftekharul Islam console.log(error); 404df3bd124SMichael Davis deferred.reject(error); 405cd789508SIftekharul Islam }); 406df3bd124SMichael Davis 407df3bd124SMichael Davis return deferred.promise; 408d2269e22SIftekharul Islam }, 409d2269e22SIftekharul Islam getAllSensorStatus: function(callback){ 410d2269e22SIftekharul Islam $http({ 411d2269e22SIftekharul Islam method: 'GET', 4128947e701SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/sensors/enumerate", 413d2269e22SIftekharul Islam headers: { 414d2269e22SIftekharul Islam 'Accept': 'application/json', 415d2269e22SIftekharul Islam 'Content-Type': 'application/json' 416d2269e22SIftekharul Islam }, 417d2269e22SIftekharul Islam withCredentials: true 418d2269e22SIftekharul Islam }).success(function(response){ 419d2269e22SIftekharul Islam var json = JSON.stringify(response); 420d2269e22SIftekharul Islam var content = JSON.parse(json); 421d2269e22SIftekharul Islam var dataClone = JSON.parse(JSON.stringify(content.data)); 422d2269e22SIftekharul Islam var sensorData = []; 4238947e701SIftekharul Islam var severity = {}; 4248947e701SIftekharul Islam var title = ""; 4258947e701SIftekharul Islam var tempKeyParts = []; 4268947e701SIftekharul Islam var order = 0; 427d2269e22SIftekharul Islam 428*96bbf310SIftekharul Islam function getScaledValue(value, scale){ 429*96bbf310SIftekharul Islam scale = scale + ""; 430*96bbf310SIftekharul Islam var power = parseInt(scale.replace(/[\s\t\+\-]/g,''),10); 431*96bbf310SIftekharul Islam 432*96bbf310SIftekharul Islam if(scale.indexOf("+") > -1){ 433*96bbf310SIftekharul Islam value = value * Math.pow(10, power); 434*96bbf310SIftekharul Islam }else if(scale.indexOf("-") > -1){ 435*96bbf310SIftekharul Islam value = value / Math.pow(10, power); 436*96bbf310SIftekharul Islam } 437*96bbf310SIftekharul Islam return value; 438*96bbf310SIftekharul Islam } 439*96bbf310SIftekharul Islam 440d2269e22SIftekharul Islam function getSensorStatus(reading){ 4418947e701SIftekharul Islam var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0; 4428947e701SIftekharul Islam 4438947e701SIftekharul Islam if(reading.hasOwnProperty('CriticalLow') && 4448947e701SIftekharul Islam reading.Value < reading.CriticalLow 4458947e701SIftekharul Islam ){ 446d2269e22SIftekharul Islam severityFlags.critical = true; 447d2269e22SIftekharul Islam severityText = 'critical'; 4488947e701SIftekharul Islam order = 2; 4498947e701SIftekharul Islam }else if(reading.hasOwnProperty('CriticalHigh') && 4508947e701SIftekharul Islam reading.Value > reading.CriticalHigh 4518947e701SIftekharul Islam ){ 4528947e701SIftekharul Islam severityFlags.critical = true; 4538947e701SIftekharul Islam severityText = 'critical'; 4548947e701SIftekharul Islam order = 2; 4558947e701SIftekharul Islam }else if(reading.hasOwnProperty('CriticalLow') && 4568947e701SIftekharul Islam reading.hasOwnProperty('WarningLow') && 4578947e701SIftekharul Islam reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){ 458d2269e22SIftekharul Islam severityFlags.warning = true; 459d2269e22SIftekharul Islam severityText = 'warning'; 4608947e701SIftekharul Islam order = 1; 4618947e701SIftekharul Islam }else if(reading.hasOwnProperty('WarningHigh') && 4628947e701SIftekharul Islam reading.hasOwnProperty('CriticalHigh') && 4638947e701SIftekharul Islam reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){ 4648947e701SIftekharul Islam severityFlags.warning = true; 4658947e701SIftekharul Islam severityText = 'warning'; 4668947e701SIftekharul Islam order = 1; 467d2269e22SIftekharul Islam }else{ 468d2269e22SIftekharul Islam severityFlags.normal = true; 469d2269e22SIftekharul Islam severityText = 'normal'; 470d2269e22SIftekharul Islam } 4718947e701SIftekharul Islam return { flags: severityFlags, severityText: severityText, order: order}; 472d2269e22SIftekharul Islam } 473d2269e22SIftekharul Islam 474d2269e22SIftekharul Islam for(var key in content.data){ 475d2269e22SIftekharul Islam if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){ 4768947e701SIftekharul Islam 4778947e701SIftekharul Islam severity = getSensorStatus(content.data[key]); 4788947e701SIftekharul Islam 4798947e701SIftekharul Islam if(!content.data[key].hasOwnProperty('CriticalLow')){ 4808947e701SIftekharul Islam content.data[key].CriticalLow = "--"; 4818947e701SIftekharul Islam content.data[key].CriticalHigh = "--"; 4828947e701SIftekharul Islam } 4838947e701SIftekharul Islam 4848947e701SIftekharul Islam if(!content.data[key].hasOwnProperty('WarningLow')){ 4858947e701SIftekharul Islam content.data[key].WarningLow = "--"; 4868947e701SIftekharul Islam content.data[key].WarningHigh = "--"; 4878947e701SIftekharul Islam } 4888947e701SIftekharul Islam 4898947e701SIftekharul Islam tempKeyParts = key.split("/"); 4908947e701SIftekharul Islam title = tempKeyParts.pop(); 4918947e701SIftekharul Islam title = tempKeyParts.pop() + '_' + title; 4928947e701SIftekharul Islam title = title.split("_").map(function(item){ 4938947e701SIftekharul Islam return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1); 4948947e701SIftekharul Islam }).reduce(function(prev, el){ 4958947e701SIftekharul Islam return prev + " " + el; 4968947e701SIftekharul Islam }); 4978947e701SIftekharul Islam 498*96bbf310SIftekharul Islam content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale); 499*96bbf310SIftekharul Islam 500d2269e22SIftekharul Islam sensorData.push(Object.assign({ 501d2269e22SIftekharul Islam path: key, 502d2269e22SIftekharul Islam selected: false, 503d2269e22SIftekharul Islam confirm: false, 504d2269e22SIftekharul Islam copied: false, 5058947e701SIftekharul Islam title: title, 5068947e701SIftekharul Islam unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit], 5078947e701SIftekharul Islam severity_flags: severity.flags, 5088947e701SIftekharul Islam status: severity.severityText, 5098947e701SIftekharul Islam order: severity.order, 5108947e701SIftekharul Islam search_text: (title + " " + content.data[key].Value + " " + 5118947e701SIftekharul Islam Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " + 5128947e701SIftekharul Islam severity.severityText + " " + 5138947e701SIftekharul Islam content.data[key].CriticalLow + " " + 5148947e701SIftekharul Islam content.data[key].CriticalHigh + " " + 5158947e701SIftekharul Islam content.data[key].WarningLow + " " + 5168947e701SIftekharul Islam content.data[key].WarningHigh + " " 5178947e701SIftekharul Islam ).toLowerCase(), 518d2269e22SIftekharul Islam original_data: {key: key, value: content.data[key]} 519d2269e22SIftekharul Islam }, content.data[key])); 520d2269e22SIftekharul Islam } 521d2269e22SIftekharul Islam } 522d2269e22SIftekharul Islam 5238947e701SIftekharul Islam callback(sensorData, dataClone); 524d2269e22SIftekharul Islam }).error(function(error){ 525d2269e22SIftekharul Islam console.log(error); 526d2269e22SIftekharul Islam }); 527c016139fSIftekharul Islam }, 528df3bd124SMichael Davis getFirmwares: function(){ 529df3bd124SMichael Davis var deferred = $q.defer(); 530c016139fSIftekharul Islam $http({ 531c016139fSIftekharul Islam method: 'GET', 532c016139fSIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/software/enumerate", 533c016139fSIftekharul Islam headers: { 534c016139fSIftekharul Islam 'Accept': 'application/json', 535c016139fSIftekharul Islam 'Content-Type': 'application/json' 536c016139fSIftekharul Islam }, 537c016139fSIftekharul Islam withCredentials: true 538c016139fSIftekharul Islam }).success(function(response){ 539c016139fSIftekharul Islam var json = JSON.stringify(response); 540c016139fSIftekharul Islam var content = JSON.parse(json); 541c016139fSIftekharul Islam var data = []; 542c016139fSIftekharul Islam var active = false; 543c016139fSIftekharul Islam var isExtended = false; 544c016139fSIftekharul Islam var bmcActiveVersion = ""; 545c016139fSIftekharul Islam var hostActiveVersion = ""; 546c016139fSIftekharul Islam var imageType = ""; 547c016139fSIftekharul Islam var extendedVersions = []; 548c016139fSIftekharul Islam 549c016139fSIftekharul Islam function getFormatedExtendedVersions(extendedVersion){ 550c016139fSIftekharul Islam var versions = []; 551c016139fSIftekharul Islam extendedVersion = extendedVersion.split(","); 552c016139fSIftekharul Islam 553c016139fSIftekharul Islam extendedVersion.forEach(function(item){ 554c016139fSIftekharul Islam var parts = item.split("-"); 555c016139fSIftekharul Islam var numberIndex = 0; 556c016139fSIftekharul Islam for(var i = 0; i < parts.length; i++){ 557c016139fSIftekharul Islam if(/[0-9]/.test(parts[i])){ 558c016139fSIftekharul Islam numberIndex = i; 559c016139fSIftekharul Islam break; 56099d199f3SIftekharul Islam } 561c016139fSIftekharul Islam } 562c016139fSIftekharul Islam var titlePart = parts.splice(0, numberIndex); 563c016139fSIftekharul Islam titlePart = titlePart.join(""); 564c016139fSIftekharul Islam titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length); 565c016139fSIftekharul Islam var versionPart = parts.join("-"); 566c016139fSIftekharul Islam versions.push({ 567c016139fSIftekharul Islam title: titlePart, 568c016139fSIftekharul Islam version: versionPart 569c016139fSIftekharul Islam }); 570c016139fSIftekharul Islam }); 571c016139fSIftekharul Islam 572c016139fSIftekharul Islam return versions; 573c016139fSIftekharul Islam } 574c016139fSIftekharul Islam 575c016139fSIftekharul Islam for(var key in content.data){ 576c016139fSIftekharul Islam if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){ 577c016139fSIftekharul Islam active = (/\.Active$/).test(content.data[key].Activation); 578c016139fSIftekharul Islam imageType = content.data[key].Purpose.split(".").pop(); 579c016139fSIftekharul Islam isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != ""; 580c016139fSIftekharul Islam if(isExtended){ 581c016139fSIftekharul Islam extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion); 582c016139fSIftekharul Islam } 583c016139fSIftekharul Islam data.push(Object.assign({ 584c016139fSIftekharul Islam path: key, 585c016139fSIftekharul Islam active: active, 586c016139fSIftekharul Islam imageId: key.split("/").pop(), 587c016139fSIftekharul Islam imageType: imageType, 588c016139fSIftekharul Islam isExtended: isExtended, 589c016139fSIftekharul Islam extended: { 590c016139fSIftekharul Islam show: false, 591c016139fSIftekharul Islam versions: extendedVersions 592c016139fSIftekharul Islam }, 593c016139fSIftekharul Islam data: {key: key, value: content.data[key]} 594c016139fSIftekharul Islam }, content.data[key])); 595c016139fSIftekharul Islam 596c016139fSIftekharul Islam if(active && imageType == 'BMC'){ 597c016139fSIftekharul Islam bmcActiveVersion = content.data[key].Version; 598c016139fSIftekharul Islam } 599c016139fSIftekharul Islam 600c016139fSIftekharul Islam if(active && imageType == 'Host'){ 601c016139fSIftekharul Islam hostActiveVersion = content.data[key].Version; 602c016139fSIftekharul Islam } 603c016139fSIftekharul Islam } 604c016139fSIftekharul Islam } 605df3bd124SMichael Davis 606df3bd124SMichael Davis deferred.resolve({ 607df3bd124SMichael Davis data: data, 608df3bd124SMichael Davis bmcActiveVersion: bmcActiveVersion, 609df3bd124SMichael Davis hostActiveVersion: hostActiveVersion 610df3bd124SMichael Davis }); 611c016139fSIftekharul Islam }).error(function(error){ 612c016139fSIftekharul Islam console.log(error); 613df3bd124SMichael Davis deferred.reject(error); 614c016139fSIftekharul Islam }); 615df3bd124SMichael Davis 616df3bd124SMichael Davis return deferred.promise; 617c016139fSIftekharul Islam }, 618c016139fSIftekharul Islam uploadImage: function(file, callback){ 619c016139fSIftekharul Islam $http({ 620c016139fSIftekharul Islam method: 'PUT', 621c016139fSIftekharul Islam timeout: 5 * 60 * 1000, 622c016139fSIftekharul Islam //url: 'http://localhost:3002/upload', 623c016139fSIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/upload/image/", 624c016139fSIftekharul Islam headers: { 625c016139fSIftekharul Islam 'Accept': 'application/octet-stream', 626c016139fSIftekharul Islam 'Content-Type': 'application/octet-stream' 627c016139fSIftekharul Islam }, 628c016139fSIftekharul Islam withCredentials: true, 629c016139fSIftekharul Islam data: file 630c016139fSIftekharul Islam }).success(function(response){ 631c016139fSIftekharul Islam var json = JSON.stringify(response); 632c016139fSIftekharul Islam var content = JSON.parse(json); 633c016139fSIftekharul Islam if(callback){ 634c016139fSIftekharul Islam return callback(content); 635c016139fSIftekharul Islam } 636c016139fSIftekharul Islam }).error(function(error){ 637c016139fSIftekharul Islam if(callback){ 638c016139fSIftekharul Islam callback(error); 639c016139fSIftekharul Islam }else{ 640c016139fSIftekharul Islam console.log(error); 641c016139fSIftekharul Islam } 642c016139fSIftekharul Islam }); 643c016139fSIftekharul Islam }, 644df3bd124SMichael Davis getBMCEthernetInfo: function(){ 645df3bd124SMichael Davis var deferred = $q.defer(); 64654c22e4fSIftekharul Islam $http({ 64754c22e4fSIftekharul Islam method: 'GET', 648f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet", 64954c22e4fSIftekharul Islam headers: { 65054c22e4fSIftekharul Islam 'Accept': 'application/json', 65154c22e4fSIftekharul Islam 'Content-Type': 'application/json' 65254c22e4fSIftekharul Islam }, 65354c22e4fSIftekharul Islam withCredentials: true 65454c22e4fSIftekharul Islam }).success(function(response){ 65554c22e4fSIftekharul Islam var json = JSON.stringify(response); 65654c22e4fSIftekharul Islam var content = JSON.parse(json); 657df3bd124SMichael Davis deferred.resolve(content.data); 65854c22e4fSIftekharul Islam }).error(function(error){ 65954c22e4fSIftekharul Islam console.log(error); 660df3bd124SMichael Davis deferred.reject(error); 66154c22e4fSIftekharul Islam }); 662df3bd124SMichael Davis 663df3bd124SMichael Davis return deferred.promise; 66454c22e4fSIftekharul Islam }, 66554c22e4fSIftekharul Islam getBMCInfo: function(callback){ 666df3bd124SMichael Davis var deferred = $q.defer(); 66754c22e4fSIftekharul Islam $http({ 66854c22e4fSIftekharul Islam method: 'GET', 669f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc", 67054c22e4fSIftekharul Islam headers: { 67154c22e4fSIftekharul Islam 'Accept': 'application/json', 67254c22e4fSIftekharul Islam 'Content-Type': 'application/json' 67354c22e4fSIftekharul Islam }, 67454c22e4fSIftekharul Islam withCredentials: true 67554c22e4fSIftekharul Islam }).success(function(response){ 67654c22e4fSIftekharul Islam var json = JSON.stringify(response); 67754c22e4fSIftekharul Islam var content = JSON.parse(json); 678df3bd124SMichael Davis deferred.resolve(content.data); 67954c22e4fSIftekharul Islam }).error(function(error){ 68054c22e4fSIftekharul Islam console.log(error); 681df3bd124SMichael Davis deferred.reject(error); 68254c22e4fSIftekharul Islam }); 683df3bd124SMichael Davis return deferred.promise; 68454c22e4fSIftekharul Islam }, 685ee27d754SIftekharul Islam getHardwares: function(callback){ 686ee27d754SIftekharul Islam $http({ 687ee27d754SIftekharul Islam method: 'GET', 688f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/enumerate", 689ee27d754SIftekharul Islam headers: { 690ee27d754SIftekharul Islam 'Accept': 'application/json', 691ee27d754SIftekharul Islam 'Content-Type': 'application/json' 692ee27d754SIftekharul Islam }, 693ee27d754SIftekharul Islam withCredentials: true 694ee27d754SIftekharul Islam }).success(function(response){ 695ee27d754SIftekharul Islam var json = JSON.stringify(response); 696ee27d754SIftekharul Islam var content = JSON.parse(json); 697ee27d754SIftekharul Islam var hardwareData = []; 698ee27d754SIftekharul Islam var keyIndexMap = {}; 699ee27d754SIftekharul Islam var title = ""; 700ee27d754SIftekharul Islam var data = []; 701ee27d754SIftekharul Islam var searchText = ""; 702ee27d754SIftekharul Islam var componentIndex = -1; 703ee27d754SIftekharul Islam var tempParts = []; 704ee27d754SIftekharul Islam 705ee27d754SIftekharul Islam 706ee27d754SIftekharul Islam function isSubComponent(key){ 707ee27d754SIftekharul Islam 708ee27d754SIftekharul Islam for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){ 709ee27d754SIftekharul Islam if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true; 710ee27d754SIftekharul Islam } 711ee27d754SIftekharul Islam 712ee27d754SIftekharul Islam return false; 713ee27d754SIftekharul Islam } 714ee27d754SIftekharul Islam 715ee27d754SIftekharul Islam function titlelize(title){ 716ee27d754SIftekharul Islam title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); 717ee27d754SIftekharul Islam for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){ 718ee27d754SIftekharul Islam if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){ 719ee27d754SIftekharul Islam return title.toUpperCase(); 720ee27d754SIftekharul Islam } 721ee27d754SIftekharul Islam } 722ee27d754SIftekharul Islam 723ee27d754SIftekharul Islam return title; 724ee27d754SIftekharul Islam } 725ee27d754SIftekharul Islam 726ee27d754SIftekharul Islam function camelcaseToLabel(obj){ 7278947e701SIftekharul Islam var transformed = [], label = "", value = ""; 728ee27d754SIftekharul Islam for(var key in obj){ 729ee27d754SIftekharul Islam label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); 730ee27d754SIftekharul Islam if(obj[key] !== ""){ 7318947e701SIftekharul Islam value = obj[key]; 7328947e701SIftekharul Islam if(value == 1 || value == 0){ 7338947e701SIftekharul Islam value = (value == 1) ? 'Yes' : 'No'; 7348947e701SIftekharul Islam } 7358947e701SIftekharul Islam transformed.push({key:label, value: value}); 736ee27d754SIftekharul Islam } 737ee27d754SIftekharul Islam } 738ee27d754SIftekharul Islam 739ee27d754SIftekharul Islam return transformed; 740ee27d754SIftekharul Islam } 741ee27d754SIftekharul Islam 742ee27d754SIftekharul Islam function getSearchText(data){ 743ee27d754SIftekharul Islam var searchText = ""; 744ee27d754SIftekharul Islam for(var i = 0; i < data.length; i++){ 745ee27d754SIftekharul Islam searchText += " " + data[i].key + " " + data[i].value; 746ee27d754SIftekharul Islam } 747ee27d754SIftekharul Islam 748ee27d754SIftekharul Islam return searchText; 749ee27d754SIftekharul Islam } 750ee27d754SIftekharul Islam 751ee27d754SIftekharul Islam for(var key in content.data){ 752ee27d754SIftekharul Islam if(content.data.hasOwnProperty(key) && 753ee27d754SIftekharul Islam key.indexOf(Constants.HARDWARE.component_key_filter) == 0){ 754ee27d754SIftekharul Islam 755ee27d754SIftekharul Islam data = camelcaseToLabel(content.data[key]); 756ee27d754SIftekharul Islam searchText = getSearchText(data); 757ee27d754SIftekharul Islam title = key.split("/").pop(); 758ee27d754SIftekharul Islam 759ee27d754SIftekharul Islam title = titlelize(title); 760ee27d754SIftekharul Islam 761ee27d754SIftekharul Islam if(!isSubComponent(key)){ 762ee27d754SIftekharul Islam hardwareData.push(Object.assign({ 763ee27d754SIftekharul Islam path: key, 764ee27d754SIftekharul Islam title: title, 765ee27d754SIftekharul Islam selected: false, 766ee27d754SIftekharul Islam expanded: false, 767ee27d754SIftekharul Islam search_text: title.toLowerCase() + " " + searchText.toLowerCase(), 768ee27d754SIftekharul Islam sub_components: [], 769ee27d754SIftekharul Islam original_data: {key: key, value: content.data[key]} 770ee27d754SIftekharul Islam }, {items: data})); 771ee27d754SIftekharul Islam 772ee27d754SIftekharul Islam keyIndexMap[key] = hardwareData.length - 1; 773ee27d754SIftekharul Islam }else{ 774ee27d754SIftekharul Islam var tempParts = key.split("/"); 775ee27d754SIftekharul Islam tempParts.pop(); 776ee27d754SIftekharul Islam tempParts = tempParts.join("/"); 777ee27d754SIftekharul Islam componentIndex = keyIndexMap[tempParts]; 778ee27d754SIftekharul Islam data = content.data[key]; 779ee27d754SIftekharul Islam data.title = title; 780ee27d754SIftekharul Islam hardwareData[componentIndex].sub_components.push(data); 781ee27d754SIftekharul Islam hardwareData[componentIndex].search_text += " " + title.toLowerCase(); 782ee27d754SIftekharul Islam } 783ee27d754SIftekharul Islam } 784ee27d754SIftekharul Islam } 785ee27d754SIftekharul Islam 786ee27d754SIftekharul Islam if(callback){ 787ee27d754SIftekharul Islam callback(hardwareData, content.data); 788ee27d754SIftekharul Islam }else{ 789ee27d754SIftekharul Islam return { data: hardwareData, original_data: content.data}; 790ee27d754SIftekharul Islam } 791ee27d754SIftekharul Islam }); 792ee27d754SIftekharul Islam }, 793f2d74644SIftekharul Islam deleteLogs: function(logs) { 794f2d74644SIftekharul Islam var defer = $q.defer(); 795f2d74644SIftekharul Islam var promises = []; 796f2d74644SIftekharul Islam 797f2d74644SIftekharul Islam function finished(){ 798f2d74644SIftekharul Islam defer.resolve(); 799f2d74644SIftekharul Islam } 800f2d74644SIftekharul Islam 801f2d74644SIftekharul Islam logs.forEach(function(item){ 802f2d74644SIftekharul Islam promises.push($http({ 803f2d74644SIftekharul Islam method: 'POST', 804f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete", 805f2d74644SIftekharul Islam headers: { 806f2d74644SIftekharul Islam 'Accept': 'application/json', 807f2d74644SIftekharul Islam 'Content-Type': 'application/json' 808f2d74644SIftekharul Islam }, 809f2d74644SIftekharul Islam withCredentials: true, 810f2d74644SIftekharul Islam data: JSON.stringify({"data": []}) 811f2d74644SIftekharul Islam })); 812f2d74644SIftekharul Islam }); 813f2d74644SIftekharul Islam 814f2d74644SIftekharul Islam $q.all(promises).then(finished); 815f2d74644SIftekharul Islam 816f2d74644SIftekharul Islam return defer.promise; 817f2d74644SIftekharul Islam }, 818f2d74644SIftekharul Islam resolveLogs: function(logs) { 819f2d74644SIftekharul Islam var defer = $q.defer(); 820f2d74644SIftekharul Islam var promises = []; 821f2d74644SIftekharul Islam 822f2d74644SIftekharul Islam function finished(){ 823f2d74644SIftekharul Islam defer.resolve(); 824f2d74644SIftekharul Islam } 825f2d74644SIftekharul Islam 826f2d74644SIftekharul Islam logs.forEach(function(item){ 827f2d74644SIftekharul Islam promises.push($http({ 828f2d74644SIftekharul Islam method: 'PUT', 829f2d74644SIftekharul Islam url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved", 830f2d74644SIftekharul Islam headers: { 831f2d74644SIftekharul Islam 'Accept': 'application/json', 832f2d74644SIftekharul Islam 'Content-Type': 'application/json' 833f2d74644SIftekharul Islam }, 834f2d74644SIftekharul Islam withCredentials: true, 835f2d74644SIftekharul Islam data: JSON.stringify({"data": "1"}) 836f2d74644SIftekharul Islam })); 837f2d74644SIftekharul Islam }); 838f2d74644SIftekharul Islam 839f2d74644SIftekharul Islam $q.all(promises).then(finished); 840f2d74644SIftekharul Islam 841f2d74644SIftekharul Islam return defer.promise; 842f2d74644SIftekharul Islam }, 84399d199f3SIftekharul Islam }; 84499d199f3SIftekharul Islam return SERVICE; 84599d199f3SIftekharul Islam }]); 84699d199f3SIftekharul Islam 84799d199f3SIftekharul Islam })(window.angular); 848