1/**
2 * API utilities service
3 *
4 * @module app/common/services/api-utils
5 * @exports APIUtils
6 * @name APIUtils
7 * @version 0.0.1
8 */
9
10window.angular && (function (angular) {
11    'use strict';
12    angular
13        .module('app.common.services')
14        .factory('APIUtils', ['$http', 'Constants', '$q', function($http, Constants, $q){
15          var SERVICE = {
16              LOGIN_CREDENTIALS: Constants.LOGIN_CREDENTIALS,
17              API_CREDENTIALS: Constants.API_CREDENTIALS,
18              API_RESPONSE: Constants.API_RESPONSE,
19              CHASSIS_POWER_STATE: Constants.CHASSIS_POWER_STATE,
20              HOST_STATE_TEXT: Constants.HOST_STATE,
21              HOST_STATE: Constants.HOST_STATE,
22              LED_STATE: Constants.LED_STATE,
23              LED_STATE_TEXT: Constants.LED_STATE_TEXT,
24              getChassisState: function(callback){
25                $http({
26                  method: 'GET',
27                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/chassis0",
28                  headers: {
29                      'Accept': 'application/json',
30                      'Content-Type': 'application/json'
31                  },
32                  withCredentials: true
33                }).success(function(response){
34                      var json = JSON.stringify(response);
35                      var content = JSON.parse(json);
36                      callback(content.data.CurrentPowerState);
37                }).error(function(error){
38                  console.log(error);
39                });
40              },
41              getHostState: function(callback){
42                $http({
43                  method: 'GET',
44                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
45                  headers: {
46                      'Accept': 'application/json',
47                      'Content-Type': 'application/json'
48                  },
49                  withCredentials: true
50                }).success(function(response){
51                      var json = JSON.stringify(response);
52                      var content = JSON.parse(json);
53                      callback(content.data.CurrentHostState);
54                }).error(function(error){
55                  console.log(error);
56                });
57              },
58              getNetworkInfo: function(){
59                var deferred = $q.defer();
60                $http({
61                  method: 'GET',
62                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/network/enumerate",
63                  headers: {
64                      'Accept': 'application/json',
65                      'Content-Type': 'application/json'
66                  },
67                  withCredentials: true
68                }).success(function(response){
69                    var json = JSON.stringify(response);
70                    var content = JSON.parse(json);
71                    var hostname = "";
72                    var macAddress = "";
73
74                    if(content.data.hasOwnProperty('/xyz/openbmc_project/network/config') &&
75                      content.data['/xyz/openbmc_project/network/config'].hasOwnProperty('HostName')
76                      ){
77                      hostname = content.data['/xyz/openbmc_project/network/config'].HostName;
78                    }
79
80                    if(content.data.hasOwnProperty('/xyz/openbmc_project/network/eth0') &&
81                      content.data['/xyz/openbmc_project/network/eth0'].hasOwnProperty('MACAddress')
82                      ){
83                      macAddress = content.data['/xyz/openbmc_project/network/eth0'].MACAddress;
84                    }
85
86                    deferred.resolve({
87                      data: content.data,
88                      hostname: hostname,
89                      mac_address: macAddress,
90                    });
91                }).error(function(error){
92                  console.log(error);
93                  deferred.reject(error);
94                });
95                return deferred.promise;
96              },
97              getLEDState: function(){
98                var deferred = $q.defer();
99                $http({
100                  method: 'GET',
101                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify",
102                  headers: {
103                      'Accept': 'application/json',
104                      'Content-Type': 'application/json'
105                  },
106                  withCredentials: true
107                }).success(function(response){
108                    var json = JSON.stringify(response);
109                    var content = JSON.parse(json);
110                    deferred.resolve(content.data.Asserted);
111                }).error(function(error){
112                  console.log(error);
113                  deferred.reject(error);
114                });
115                return deferred.promise;
116              },
117              login: function(username, password, callback){
118                $http({
119                  method: 'POST',
120                  url: SERVICE.API_CREDENTIALS.host + "/login",
121                  headers: {
122                      'Accept': 'application/json',
123                      'Content-Type': 'application/json'
124                  },
125                  withCredentials: true,
126                  data: JSON.stringify({"data": [username, password]})
127                }).success(function(response){
128                  if(callback){
129                      callback(response);
130                  }
131                }).error(function(error){
132                  if(callback){
133                      if(error && error.status && error.status == 'error'){
134                        callback(error);
135                      }else{
136                        callback(error, true);
137                      }
138                  }
139                  console.log(error);
140                });
141              },
142              logout: function(callback){
143                $http({
144                  method: 'POST',
145                  url: SERVICE.API_CREDENTIALS.host + "/logout",
146                  headers: {
147                      'Accept': 'application/json',
148                      'Content-Type': 'application/json'
149                  },
150                  withCredentials: true,
151                  data: JSON.stringify({"data": []})
152                }).success(function(response){
153                  if(callback){
154                      callback(response);
155                  }
156                }).error(function(error){
157                  if(callback){
158                      callback(null, error);
159                  }
160                  console.log(error);
161                });
162              },
163              chassisPowerOn: function(callback){
164                $http({
165                  method: 'POST',
166                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
167                  headers: {
168                      'Accept': 'application/json',
169                      'Content-Type': 'application/json'
170                  },
171                  withCredentials: true,
172                  data: JSON.stringify({"data": []})
173                }).success(function(response){
174                      var json = JSON.stringify(response);
175                      var content = JSON.parse(json);
176                      if(callback){
177                          return callback(content.data.CurrentPowerState);
178                      }
179                }).error(function(error){
180                  if(callback){
181                      callback(error);
182                  }else{
183                      console.log(error);
184                  }
185                });
186              },
187              chassisPowerOff: function(callback){
188                $http({
189                  method: 'POST',
190                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
191                  headers: {
192                      'Accept': 'application/json',
193                      'Content-Type': 'application/json'
194                  },
195                  withCredentials: true,
196                  data: JSON.stringify({"data": []})
197                }).success(function(response){
198                      var json = JSON.stringify(response);
199                      var content = JSON.parse(json);
200                      if(callback){
201                          return callback(content.data.CurrentPowerState);
202                      }
203                }).error(function(error){
204                  if(callback){
205                      callback(error);
206                  }else{
207                      console.log(error);
208                  }
209                });
210              },
211              setLEDState: function(state, callback){
212                $http({
213                  method: 'PUT',
214                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted",
215                  headers: {
216                      'Accept': 'application/json',
217                      'Content-Type': 'application/json'
218                  },
219                  withCredentials: true,
220                  data: JSON.stringify({"data": state})
221                }).success(function(response){
222                      var json = JSON.stringify(response);
223                      var content = JSON.parse(json);
224                      if(callback){
225                          return callback(content.status);
226                      }
227                }).error(function(error){
228                  if(callback){
229                      callback(error);
230                  }else{
231                      console.log(error);
232                  }
233                });
234              },
235              bmcReboot: function(callback){
236                $http({
237                  method: 'PUT',
238                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition",
239                  headers: {
240                      'Accept': 'application/json',
241                      'Content-Type': 'application/json'
242                  },
243                  withCredentials: true,
244                  data: JSON.stringify({"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"})
245                }).success(function(response){
246                      var json = JSON.stringify(response);
247                      var content = JSON.parse(json);
248                      if(callback){
249                          return callback(content.status);
250                      }
251                }).error(function(error){
252                  if(callback){
253                      callback(error);
254                  }else{
255                      console.log(error);
256                  }
257                });
258              },
259              hostPowerOn: function(callback){
260                $http({
261                  method: 'PUT',
262                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
263                  headers: {
264                      'Accept': 'application/json',
265                      'Content-Type': 'application/json'
266                  },
267                  withCredentials: true,
268                  data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.On"})
269                }).success(function(response){
270                      var json = JSON.stringify(response);
271                      var content = JSON.parse(json);
272                      if(callback){
273                          return callback(content.status);
274                      }
275                }).error(function(error){
276                  if(callback){
277                      callback(error);
278                  }else{
279                      console.log(error);
280                  }
281                });
282              },
283              hostPowerOff: function(callback){
284                $http({
285                  method: 'PUT',
286                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0/attr/RequestedHostTransition",
287                  headers: {
288                      'Accept': 'application/json',
289                      'Content-Type': 'application/json'
290                  },
291                  withCredentials: true,
292                  data: JSON.stringify({"data": "xyz.openbmc_project.State.Host.Transition.Off"})
293                }).success(function(response){
294                      var json = JSON.stringify(response);
295                      var content = JSON.parse(json);
296                      if(callback){
297                          return callback(content.status);
298                      }
299                }).error(function(error){
300                  if(callback){
301                      callback(error);
302                  }else{
303                      console.log(error);
304                  }
305                });
306              },
307              hostReboot: function(callback){
308                $http({
309                  method: 'POST',
310                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
311                  headers: {
312                      'Accept': 'application/json',
313                      'Content-Type': 'application/json'
314                  },
315                  withCredentials: true,
316                  data: JSON.stringify({"data": []}),
317                }).success(function(response){
318                      var json = JSON.stringify(response);
319                      var content = JSON.parse(json);
320                      if(callback){
321                          return callback(content);
322                      }
323                }).error(function(error){
324                  if(callback){
325                      callback(error);
326                  }else{
327                      console.log(error);
328                  }
329                });
330              },
331              hostShutdown: function(callback){
332                $http({
333                  method: 'POST',
334                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/state/host0",
335                  headers: {
336                      'Accept': 'application/json',
337                      'Content-Type': 'application/json'
338                  },
339                  withCredentials: true,
340                  data: JSON.stringify({"data": []})
341                }).success(function(response){
342                      var json = JSON.stringify(response);
343                      var content = JSON.parse(json);
344                      if(callback){
345                          return callback(content);
346                      }
347                }).error(function(error){
348                  if(callback){
349                      callback(error);
350                  }else{
351                      console.log(error);
352                  }
353                });
354              },
355              getLogs: function(){
356                var deferred = $q.defer();
357                $http({
358                  method: 'GET',
359                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/enumerate",
360                  headers: {
361                      'Accept': 'application/json',
362                      'Content-Type': 'application/json'
363                  },
364                  withCredentials: true
365                }).success(function(response){
366                      var json = JSON.stringify(response);
367                      var content = JSON.parse(json);
368                      var dataClone = JSON.parse(JSON.stringify(content.data));
369                      var data = [];
370                      var severityCode = '';
371                      var priority = '';
372                      var relatedItems = [];
373
374                      for(var key in content.data){
375                        if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){
376                          var severityFlags = {low: false, medium: false, high: false};
377                          severityCode = content.data[key].Severity.split(".").pop();
378                          priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode];
379                          severityFlags[priority.toLowerCase()] = true;
380                          relatedItems = [];
381                          content.data[key].associations.forEach(function(item){
382                            relatedItems.push(item[2]);
383                          });
384
385                          data.push(Object.assign({
386                            path: key,
387                            copied: false,
388                            priority: priority,
389                            severity_code: severityCode,
390                            severity_flags: severityFlags,
391                            additional_data: content.data[key].AdditionalData.join("\n"),
392                            selected: false,
393                            search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(),
394                            meta: false,
395                            confirm: false,
396                            related_items: relatedItems,
397                            data: {key: key, value: content.data[key]}
398                          }, content.data[key]));
399                        }
400                      }
401                      deferred.resolve({data: data, original: dataClone});
402                }).error(function(error){
403                  console.log(error);
404                  deferred.reject(error);
405                });
406
407                return deferred.promise;
408              },
409              getAllSensorStatus: function(callback){
410                $http({
411                  method: 'GET',
412                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/sensors/enumerate",
413                  headers: {
414                      'Accept': 'application/json',
415                      'Content-Type': 'application/json'
416                  },
417                  withCredentials: true
418                }).success(function(response){
419                      var json = JSON.stringify(response);
420                      var content = JSON.parse(json);
421                      var dataClone = JSON.parse(JSON.stringify(content.data));
422                      var sensorData = [];
423                      var severity = {};
424                      var title = "";
425                      var tempKeyParts = [];
426                      var order = 0;
427
428                      function getScaledValue(value, scale){
429                        scale = scale + "";
430                        var power = parseInt(scale.replace(/[\s\t\+\-]/g,''),10);
431
432                        if(scale.indexOf("+") > -1){
433                          value = value * Math.pow(10, power);
434                        }else if(scale.indexOf("-") > -1){
435                          value = value / Math.pow(10, power);
436                        }
437                        return value;
438                      }
439
440                      function getSensorStatus(reading){
441                        var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0;
442
443                        if(reading.hasOwnProperty('CriticalLow') &&
444                          reading.Value < reading.CriticalLow
445                          ){
446                          severityFlags.critical = true;
447                          severityText = 'critical';
448                          order = 2;
449                        }else if(reading.hasOwnProperty('CriticalHigh') &&
450                          reading.Value > reading.CriticalHigh
451                          ){
452                          severityFlags.critical = true;
453                          severityText = 'critical';
454                          order = 2;
455                        }else if(reading.hasOwnProperty('CriticalLow') &&
456                          reading.hasOwnProperty('WarningLow') &&
457                          reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){
458                          severityFlags.warning = true;
459                          severityText = 'warning';
460                          order = 1;
461                        }else if(reading.hasOwnProperty('WarningHigh') &&
462                          reading.hasOwnProperty('CriticalHigh') &&
463                          reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){
464                          severityFlags.warning = true;
465                          severityText = 'warning';
466                          order = 1;
467                        }else{
468                          severityFlags.normal = true;
469                          severityText = 'normal';
470                        }
471                        return { flags: severityFlags, severityText: severityText, order: order};
472                      }
473
474                      for(var key in content.data){
475                        if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){
476
477                          severity = getSensorStatus(content.data[key]);
478
479                          if(!content.data[key].hasOwnProperty('CriticalLow')){
480                            content.data[key].CriticalLow = "--";
481                            content.data[key].CriticalHigh = "--";
482                          }
483
484                          if(!content.data[key].hasOwnProperty('WarningLow')){
485                            content.data[key].WarningLow = "--";
486                            content.data[key].WarningHigh = "--";
487                          }
488
489                          tempKeyParts = key.split("/");
490                          title = tempKeyParts.pop();
491                          title = tempKeyParts.pop() + '_' + title;
492                          title = title.split("_").map(function(item){
493                             return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1);
494                          }).reduce(function(prev, el){
495                            return prev + " " + el;
496                          });
497
498                          content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale);
499
500                          sensorData.push(Object.assign({
501                            path: key,
502                            selected: false,
503                            confirm: false,
504                            copied: false,
505                            title: title,
506                            unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit],
507                            severity_flags: severity.flags,
508                            status: severity.severityText,
509                            order: severity.order,
510                            search_text: (title + " " + content.data[key].Value + " " +
511                               Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " +
512                               severity.severityText + " " +
513                               content.data[key].CriticalLow + " " +
514                               content.data[key].CriticalHigh + " " +
515                               content.data[key].WarningLow + " " +
516                               content.data[key].WarningHigh + " "
517                               ).toLowerCase(),
518                            original_data: {key: key, value: content.data[key]}
519                          }, content.data[key]));
520                        }
521                      }
522
523                      callback(sensorData, dataClone);
524                }).error(function(error){
525                  console.log(error);
526                });
527              },
528              getFirmwares: function(){
529                var deferred = $q.defer();
530                $http({
531                  method: 'GET',
532                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/software/enumerate",
533                  headers: {
534                      'Accept': 'application/json',
535                      'Content-Type': 'application/json'
536                  },
537                  withCredentials: true
538                }).success(function(response){
539                      var json = JSON.stringify(response);
540                      var content = JSON.parse(json);
541                      var data = [];
542                      var active = false;
543                      var isExtended = false;
544                      var bmcActiveVersion = "";
545                      var hostActiveVersion = "";
546                      var imageType = "";
547                      var extendedVersions = [];
548
549                      function getFormatedExtendedVersions(extendedVersion){
550                        var versions = [];
551                        extendedVersion = extendedVersion.split(",");
552
553                        extendedVersion.forEach(function(item){
554                          var parts = item.split("-");
555                          var numberIndex = 0;
556                          for(var i = 0; i < parts.length; i++){
557                            if(/[0-9]/.test(parts[i])){
558                              numberIndex = i;
559                              break;
560                            }
561                          }
562                          var titlePart = parts.splice(0, numberIndex);
563                          titlePart = titlePart.join("");
564                          titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length);
565                          var versionPart = parts.join("-");
566                          versions.push({
567                            title: titlePart,
568                            version: versionPart
569                          });
570                        });
571
572                        return versions;
573                      }
574
575                      for(var key in content.data){
576                        if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){
577                          active = (/\.Active$/).test(content.data[key].Activation);
578                          imageType = content.data[key].Purpose.split(".").pop();
579                          isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != "";
580                          if(isExtended){
581                            extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion);
582                          }
583                          data.push(Object.assign({
584                            path: key,
585                            active: active,
586                            imageId: key.split("/").pop(),
587                            imageType: imageType,
588                            isExtended: isExtended,
589                            extended: {
590                              show: false,
591                              versions: extendedVersions
592                            },
593                            data: {key: key, value: content.data[key]}
594                          }, content.data[key]));
595
596                          if(active && imageType == 'BMC'){
597                            bmcActiveVersion = content.data[key].Version;
598                          }
599
600                          if(active && imageType == 'Host'){
601                            hostActiveVersion = content.data[key].Version;
602                          }
603                        }
604                      }
605
606                      deferred.resolve({
607                          data: data,
608                          bmcActiveVersion: bmcActiveVersion,
609                          hostActiveVersion: hostActiveVersion
610                      });
611                }).error(function(error){
612                  console.log(error);
613                  deferred.reject(error);
614                });
615
616                return deferred.promise;
617              },
618              uploadImage: function(file, callback){
619                $http({
620                  method: 'PUT',
621                  timeout: 5 * 60 * 1000,
622                  //url: 'http://localhost:3002/upload',
623                  url: SERVICE.API_CREDENTIALS.host + "/upload/image/",
624                  headers: {
625                      'Accept': 'application/octet-stream',
626                      'Content-Type': 'application/octet-stream'
627                  },
628                  withCredentials: true,
629                  data: file
630                }).success(function(response){
631                      var json = JSON.stringify(response);
632                      var content = JSON.parse(json);
633                      if(callback){
634                          return callback(content);
635                      }
636                }).error(function(error){
637                  if(callback){
638                      callback(error);
639                  }else{
640                      console.log(error);
641                  }
642                });
643              },
644              getBMCEthernetInfo: function(){
645                var deferred = $q.defer();
646                $http({
647                  method: 'GET',
648                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet",
649                  headers: {
650                      'Accept': 'application/json',
651                      'Content-Type': 'application/json'
652                  },
653                  withCredentials: true
654                }).success(function(response){
655                    var json = JSON.stringify(response);
656                    var content = JSON.parse(json);
657                    deferred.resolve(content.data);
658                }).error(function(error){
659                  console.log(error);
660                  deferred.reject(error);
661                });
662
663                return deferred.promise;
664              },
665              getBMCInfo: function(callback){
666                var deferred = $q.defer();
667                $http({
668                  method: 'GET',
669                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc",
670                  headers: {
671                      'Accept': 'application/json',
672                      'Content-Type': 'application/json'
673                  },
674                  withCredentials: true
675                }).success(function(response){
676                    var json = JSON.stringify(response);
677                    var content = JSON.parse(json);
678                    deferred.resolve(content.data);
679                }).error(function(error){
680                  console.log(error);
681                  deferred.reject(error);
682                });
683                return deferred.promise;
684              },
685              getHardwares: function(callback){
686                $http({
687                  method: 'GET',
688                  url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/enumerate",
689                  headers: {
690                      'Accept': 'application/json',
691                      'Content-Type': 'application/json'
692                  },
693                  withCredentials: true
694                }).success(function(response){
695                      var json = JSON.stringify(response);
696                      var content = JSON.parse(json);
697                      var hardwareData = [];
698                      var keyIndexMap = {};
699                      var title = "";
700                      var data = [];
701                      var searchText = "";
702                      var componentIndex = -1;
703                      var tempParts = [];
704
705
706                      function isSubComponent(key){
707
708                        for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){
709                          if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true;
710                        }
711
712                        return false;
713                      }
714
715                      function titlelize(title){
716                        title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, "");
717                        for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){
718                          if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){
719                            return title.toUpperCase();
720                          }
721                        }
722
723                        return title;
724                      }
725
726                      function camelcaseToLabel(obj){
727                        var transformed = [], label = "", value = "";
728                        for(var key in obj){
729                          label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, "");
730                          if(obj[key] !== ""){
731                            value = obj[key];
732                            if(value == 1 || value == 0){
733                              value = (value == 1) ? 'Yes' : 'No';
734                            }
735                            transformed.push({key:label, value: value});
736                          }
737                        }
738
739                        return transformed;
740                      }
741
742                      function getSearchText(data){
743                        var searchText = "";
744                        for(var i = 0; i < data.length; i++){
745                          searchText += " " + data[i].key + " " + data[i].value;
746                        }
747
748                        return searchText;
749                      }
750
751                      for(var key in content.data){
752                        if(content.data.hasOwnProperty(key) &&
753                           key.indexOf(Constants.HARDWARE.component_key_filter) == 0){
754
755                          data = camelcaseToLabel(content.data[key]);
756                          searchText = getSearchText(data);
757                          title = key.split("/").pop();
758
759                          title = titlelize(title);
760
761                          if(!isSubComponent(key)){
762                              hardwareData.push(Object.assign({
763                                path: key,
764                                title: title,
765                                selected: false,
766                                expanded: false,
767                                search_text: title.toLowerCase() + " " + searchText.toLowerCase(),
768                                sub_components: [],
769                                original_data: {key: key, value: content.data[key]}
770                              }, {items: data}));
771
772                              keyIndexMap[key] = hardwareData.length - 1;
773                          }else{
774                            var tempParts = key.split("/");
775                            tempParts.pop();
776                            tempParts = tempParts.join("/");
777                            componentIndex = keyIndexMap[tempParts];
778                            data = content.data[key];
779                            data.title = title;
780                            hardwareData[componentIndex].sub_components.push(data);
781                            hardwareData[componentIndex].search_text += " " + title.toLowerCase();
782                          }
783                      }
784                    }
785
786                    if(callback){
787                       callback(hardwareData, content.data);
788                    }else{
789                       return { data: hardwareData, original_data: content.data};
790                    }
791                });
792              },
793              deleteLogs: function(logs) {
794                  var defer = $q.defer();
795                  var promises = [];
796
797                  function finished(){
798                      defer.resolve();
799                  }
800
801                  logs.forEach(function(item){
802                    promises.push($http({
803                                      method: 'POST',
804                                      url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete",
805                                      headers: {
806                                          'Accept': 'application/json',
807                                          'Content-Type': 'application/json'
808                                      },
809                                      withCredentials: true,
810                                      data: JSON.stringify({"data": []})
811                                 }));
812                  });
813
814                  $q.all(promises).then(finished);
815
816                  return defer.promise;
817              },
818              resolveLogs: function(logs) {
819                  var defer = $q.defer();
820                  var promises = [];
821
822                  function finished(){
823                      defer.resolve();
824                  }
825
826                  logs.forEach(function(item){
827                    promises.push($http({
828                                      method: 'PUT',
829                                      url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved",
830                                      headers: {
831                                          'Accept': 'application/json',
832                                          'Content-Type': 'application/json'
833                                      },
834                                      withCredentials: true,
835                                      data: JSON.stringify({"data": "1"})
836                                 }));
837                  });
838
839                  $q.all(promises).then(finished);
840
841                  return defer.promise;
842              },
843          };
844          return SERVICE;
845        }]);
846
847        })(window.angular);
848