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 health = ''; 373 var relatedItems = []; 374 375 for(var key in content.data){ 376 if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Id')){ 377 var severityFlags = {low: false, medium: false, high: false}; 378 var healthFlags = {critical: false, warning: false, good: false}; 379 severityCode = content.data[key].Severity.split(".").pop(); 380 priority = Constants.SEVERITY_TO_PRIORITY_MAP[severityCode]; 381 severityFlags[priority.toLowerCase()] = true; 382 health = Constants.SEVERITY_TO_HEALTH_MAP[severityCode]; 383 healthFlags[health.toLowerCase()] = true; 384 relatedItems = []; 385 content.data[key].associations.forEach(function(item){ 386 relatedItems.push(item[2]); 387 }); 388 389 data.push(Object.assign({ 390 path: key, 391 copied: false, 392 priority: priority, 393 severity_code: severityCode, 394 severity_flags: severityFlags, 395 health_flags: healthFlags, 396 additional_data: content.data[key].AdditionalData.join("\n"), 397 selected: false, 398 search_text: ("#" + content.data[key].Id + " " + severityCode + " " + content.data[key].Severity + " " + content.data[key].AdditionalData.join(" ")).toLowerCase(), 399 meta: false, 400 confirm: false, 401 related_items: relatedItems, 402 data: {key: key, value: content.data[key]} 403 }, content.data[key])); 404 } 405 } 406 deferred.resolve({data: data, original: dataClone}); 407 }).error(function(error){ 408 console.log(error); 409 deferred.reject(error); 410 }); 411 412 return deferred.promise; 413 }, 414 getAllSensorStatus: function(callback){ 415 $http({ 416 method: 'GET', 417 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/sensors/enumerate", 418 headers: { 419 'Accept': 'application/json', 420 'Content-Type': 'application/json' 421 }, 422 withCredentials: true 423 }).success(function(response){ 424 var json = JSON.stringify(response); 425 var content = JSON.parse(json); 426 var dataClone = JSON.parse(JSON.stringify(content.data)); 427 var sensorData = []; 428 var severity = {}; 429 var title = ""; 430 var tempKeyParts = []; 431 var order = 0; 432 var customOrder = 0; 433 434 function getScaledValue(value, scale){ 435 scale = scale + ""; 436 scale = parseInt(scale, 10); 437 var power = Math.abs(parseInt(scale,10)); 438 439 if(scale > 0){ 440 value = value * Math.pow(10, power); 441 }else if(scale < 0){ 442 value = value / Math.pow(10, power); 443 } 444 return value; 445 } 446 447 function getSensorStatus(reading){ 448 var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0; 449 450 if(reading.hasOwnProperty('CriticalLow') && 451 reading.Value < reading.CriticalLow 452 ){ 453 severityFlags.critical = true; 454 severityText = 'critical'; 455 order = 2; 456 }else if(reading.hasOwnProperty('CriticalHigh') && 457 reading.Value > reading.CriticalHigh 458 ){ 459 severityFlags.critical = true; 460 severityText = 'critical'; 461 order = 2; 462 }else if(reading.hasOwnProperty('CriticalLow') && 463 reading.hasOwnProperty('WarningLow') && 464 reading.Value >= reading.CriticalLow && reading.Value <= reading.WarningLow){ 465 severityFlags.warning = true; 466 severityText = 'warning'; 467 order = 1; 468 }else if(reading.hasOwnProperty('WarningHigh') && 469 reading.hasOwnProperty('CriticalHigh') && 470 reading.Value >= reading.WarningHigh && reading.Value <= reading.CriticalHigh){ 471 severityFlags.warning = true; 472 severityText = 'warning'; 473 order = 1; 474 }else{ 475 severityFlags.normal = true; 476 severityText = 'normal'; 477 } 478 return { flags: severityFlags, severityText: severityText, order: order}; 479 } 480 481 for(var key in content.data){ 482 if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Unit')){ 483 484 severity = getSensorStatus(content.data[key]); 485 486 if(!content.data[key].hasOwnProperty('CriticalLow')){ 487 content.data[key].CriticalLow = "--"; 488 content.data[key].CriticalHigh = "--"; 489 } 490 491 if(!content.data[key].hasOwnProperty('WarningLow')){ 492 content.data[key].WarningLow = "--"; 493 content.data[key].WarningHigh = "--"; 494 } 495 496 tempKeyParts = key.split("/"); 497 title = tempKeyParts.pop(); 498 title = tempKeyParts.pop() + '_' + title; 499 title = title.split("_").map(function(item){ 500 return item.toLowerCase().charAt(0).toUpperCase() + item.slice(1); 501 }).reduce(function(prev, el){ 502 return prev + " " + el; 503 }); 504 505 content.data[key].Value = getScaledValue(content.data[key].Value, content.data[key].Scale); 506 507 if(Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit) > -1){ 508 customOrder = Constants.SENSOR_SORT_ORDER.indexOf(content.data[key].Unit); 509 }else{ 510 customOrder = Constants.SENSOR_SORT_ORDER_DEFAULT; 511 } 512 513 sensorData.push(Object.assign({ 514 path: key, 515 selected: false, 516 confirm: false, 517 copied: false, 518 title: title, 519 unit: Constants.SENSOR_UNIT_MAP[content.data[key].Unit], 520 severity_flags: severity.flags, 521 status: severity.severityText, 522 order: severity.order, 523 custom_order: customOrder, 524 search_text: (title + " " + content.data[key].Value + " " + 525 Constants.SENSOR_UNIT_MAP[content.data[key].Unit] + " " + 526 severity.severityText + " " + 527 content.data[key].CriticalLow + " " + 528 content.data[key].CriticalHigh + " " + 529 content.data[key].WarningLow + " " + 530 content.data[key].WarningHigh + " " 531 ).toLowerCase(), 532 original_data: {key: key, value: content.data[key]} 533 }, content.data[key])); 534 } 535 } 536 537 callback(sensorData, dataClone); 538 }).error(function(error){ 539 console.log(error); 540 }); 541 }, 542 getFirmwares: function(){ 543 var deferred = $q.defer(); 544 $http({ 545 method: 'GET', 546 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/software/enumerate", 547 headers: { 548 'Accept': 'application/json', 549 'Content-Type': 'application/json' 550 }, 551 withCredentials: true 552 }).success(function(response){ 553 var json = JSON.stringify(response); 554 var content = JSON.parse(json); 555 var data = []; 556 var active = false; 557 var isExtended = false; 558 var bmcActiveVersion = ""; 559 var hostActiveVersion = ""; 560 var imageType = ""; 561 var extendedVersions = []; 562 563 function getFormatedExtendedVersions(extendedVersion){ 564 var versions = []; 565 extendedVersion = extendedVersion.split(","); 566 567 extendedVersion.forEach(function(item){ 568 var parts = item.split("-"); 569 var numberIndex = 0; 570 for(var i = 0; i < parts.length; i++){ 571 if(/[0-9]/.test(parts[i])){ 572 numberIndex = i; 573 break; 574 } 575 } 576 var titlePart = parts.splice(0, numberIndex); 577 titlePart = titlePart.join(""); 578 titlePart = titlePart[0].toUpperCase() + titlePart.substr(1, titlePart.length); 579 var versionPart = parts.join("-"); 580 versions.push({ 581 title: titlePart, 582 version: versionPart 583 }); 584 }); 585 586 return versions; 587 } 588 589 for(var key in content.data){ 590 if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){ 591 active = (/\.Active$/).test(content.data[key].Activation); 592 imageType = content.data[key].Purpose.split(".").pop(); 593 isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != ""; 594 if(isExtended){ 595 extendedVersions = getFormatedExtendedVersions(content.data[key].ExtendedVersion); 596 } 597 data.push(Object.assign({ 598 path: key, 599 active: active, 600 imageId: key.split("/").pop(), 601 imageType: imageType, 602 isExtended: isExtended, 603 extended: { 604 show: false, 605 versions: extendedVersions 606 }, 607 data: {key: key, value: content.data[key]} 608 }, content.data[key])); 609 610 if(active && imageType == 'BMC'){ 611 bmcActiveVersion = content.data[key].Version; 612 } 613 614 if(active && imageType == 'Host'){ 615 hostActiveVersion = content.data[key].Version; 616 } 617 } 618 } 619 620 deferred.resolve({ 621 data: data, 622 bmcActiveVersion: bmcActiveVersion, 623 hostActiveVersion: hostActiveVersion 624 }); 625 }).error(function(error){ 626 console.log(error); 627 deferred.reject(error); 628 }); 629 630 return deferred.promise; 631 }, 632 uploadImage: function(file, callback){ 633 $http({ 634 method: 'PUT', 635 timeout: 5 * 60 * 1000, 636 //url: 'http://localhost:3002/upload', 637 url: SERVICE.API_CREDENTIALS.host + "/upload/image/", 638 headers: { 639 'Accept': 'application/octet-stream', 640 'Content-Type': 'application/octet-stream' 641 }, 642 withCredentials: true, 643 data: file 644 }).success(function(response){ 645 var json = JSON.stringify(response); 646 var content = JSON.parse(json); 647 if(callback){ 648 return callback(content); 649 } 650 }).error(function(error){ 651 if(callback){ 652 callback(error); 653 }else{ 654 console.log(error); 655 } 656 }); 657 }, 658 getBMCEthernetInfo: function(){ 659 var deferred = $q.defer(); 660 $http({ 661 method: 'GET', 662 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc/ethernet", 663 headers: { 664 'Accept': 'application/json', 665 'Content-Type': 'application/json' 666 }, 667 withCredentials: true 668 }).success(function(response){ 669 var json = JSON.stringify(response); 670 var content = JSON.parse(json); 671 deferred.resolve(content.data); 672 }).error(function(error){ 673 console.log(error); 674 deferred.reject(error); 675 }); 676 677 return deferred.promise; 678 }, 679 getBMCInfo: function(callback){ 680 var deferred = $q.defer(); 681 $http({ 682 method: 'GET', 683 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/system/chassis/motherboard/boxelder/bmc", 684 headers: { 685 'Accept': 'application/json', 686 'Content-Type': 'application/json' 687 }, 688 withCredentials: true 689 }).success(function(response){ 690 var json = JSON.stringify(response); 691 var content = JSON.parse(json); 692 deferred.resolve(content.data); 693 }).error(function(error){ 694 console.log(error); 695 deferred.reject(error); 696 }); 697 return deferred.promise; 698 }, 699 getHardwares: function(callback){ 700 $http({ 701 method: 'GET', 702 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/inventory/enumerate", 703 headers: { 704 'Accept': 'application/json', 705 'Content-Type': 'application/json' 706 }, 707 withCredentials: true 708 }).success(function(response){ 709 var json = JSON.stringify(response); 710 var content = JSON.parse(json); 711 var hardwareData = []; 712 var keyIndexMap = {}; 713 var title = ""; 714 var data = []; 715 var searchText = ""; 716 var componentIndex = -1; 717 var tempParts = []; 718 719 720 function isSubComponent(key){ 721 722 for(var i = 0; i < Constants.HARDWARE.parent_components.length; i++){ 723 if(key.split(Constants.HARDWARE.parent_components[i]).length == 2) return true; 724 } 725 726 return false; 727 } 728 729 function titlelize(title){ 730 title = title.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); 731 for(var i = 0; i < Constants.HARDWARE.uppercase_titles.length; i++){ 732 if(title.toLowerCase().indexOf((Constants.HARDWARE.uppercase_titles[i] + " ")) > -1){ 733 return title.toUpperCase(); 734 } 735 } 736 737 return title; 738 } 739 740 function camelcaseToLabel(obj){ 741 var transformed = [], label = "", value = ""; 742 for(var key in obj){ 743 label = key.replace(/([A-Z0-9]+)/g, " $1").replace(/^\s+/, ""); 744 if(obj[key] !== ""){ 745 value = obj[key]; 746 if(value == 1 || value == 0){ 747 value = (value == 1) ? 'Yes' : 'No'; 748 } 749 transformed.push({key:label, value: value}); 750 } 751 } 752 753 return transformed; 754 } 755 756 function getSearchText(data){ 757 var searchText = ""; 758 for(var i = 0; i < data.length; i++){ 759 searchText += " " + data[i].key + " " + data[i].value; 760 } 761 762 return searchText; 763 } 764 765 for(var key in content.data){ 766 if(content.data.hasOwnProperty(key) && 767 key.indexOf(Constants.HARDWARE.component_key_filter) == 0){ 768 769 data = camelcaseToLabel(content.data[key]); 770 searchText = getSearchText(data); 771 title = key.split("/").pop(); 772 773 title = titlelize(title); 774 775 if(!isSubComponent(key)){ 776 hardwareData.push(Object.assign({ 777 path: key, 778 title: title, 779 selected: false, 780 expanded: false, 781 search_text: title.toLowerCase() + " " + searchText.toLowerCase(), 782 sub_components: [], 783 original_data: {key: key, value: content.data[key]} 784 }, {items: data})); 785 786 keyIndexMap[key] = hardwareData.length - 1; 787 }else{ 788 var tempParts = key.split("/"); 789 tempParts.pop(); 790 tempParts = tempParts.join("/"); 791 componentIndex = keyIndexMap[tempParts]; 792 data = content.data[key]; 793 data.title = title; 794 hardwareData[componentIndex].sub_components.push(data); 795 hardwareData[componentIndex].search_text += " " + title.toLowerCase(); 796 } 797 } 798 } 799 800 if(callback){ 801 callback(hardwareData, content.data); 802 }else{ 803 return { data: hardwareData, original_data: content.data}; 804 } 805 }); 806 }, 807 deleteLogs: function(logs) { 808 var defer = $q.defer(); 809 var promises = []; 810 811 function finished(){ 812 defer.resolve(); 813 } 814 815 logs.forEach(function(item){ 816 promises.push($http({ 817 method: 'POST', 818 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/action/Delete", 819 headers: { 820 'Accept': 'application/json', 821 'Content-Type': 'application/json' 822 }, 823 withCredentials: true, 824 data: JSON.stringify({"data": []}) 825 })); 826 }); 827 828 $q.all(promises).then(finished); 829 830 return defer.promise; 831 }, 832 resolveLogs: function(logs) { 833 var defer = $q.defer(); 834 var promises = []; 835 836 function finished(){ 837 defer.resolve(); 838 } 839 840 logs.forEach(function(item){ 841 promises.push($http({ 842 method: 'PUT', 843 url: SERVICE.API_CREDENTIALS.host + "/xyz/openbmc_project/logging/entry/"+item.Id+"/attr/Resolved", 844 headers: { 845 'Accept': 'application/json', 846 'Content-Type': 'application/json' 847 }, 848 withCredentials: true, 849 data: JSON.stringify({"data": "1"}) 850 })); 851 }); 852 853 $q.all(promises).then(finished); 854 855 return defer.promise; 856 }, 857 }; 858 return SERVICE; 859 }]); 860 861 })(window.angular); 862