1cd789508SIftekharul Islam/** 2cd789508SIftekharul Islam * Controller for power-operations 3cd789508SIftekharul Islam * 4cd789508SIftekharul Islam * @module app/serverControl 5cd789508SIftekharul Islam * @exports powerOperationsController 6cd789508SIftekharul Islam * @name powerOperationsController 7cd789508SIftekharul Islam */ 8cd789508SIftekharul Islam 9cd789508SIftekharul Islamwindow.angular && (function(angular) { 10cd789508SIftekharul Islam 'use strict'; 11cd789508SIftekharul Islam 12d27bb135SAndrew Geissler angular.module('app.serverControl').controller('powerOperationsController', [ 135ff98780SYoshie Muranaka '$scope', 'APIUtils', 'dataService', 'Constants', '$interval', '$q', 14*e368108fSDixsie Wolmers 'toastService', '$uibModal', 15d27bb135SAndrew Geissler function( 16*e368108fSDixsie Wolmers $scope, APIUtils, dataService, Constants, $interval, $q, toastService, 17*e368108fSDixsie Wolmers $uibModal) { 18cd789508SIftekharul Islam $scope.dataService = dataService; 196add8325SGunnar Mills $scope.loading = true; 20*e368108fSDixsie Wolmers $scope.oneTimeBootEnabled = false; 21*e368108fSDixsie Wolmers $scope.bootOverrideError = false; 22*e368108fSDixsie Wolmers $scope.bootSources = []; 23*e368108fSDixsie Wolmers $scope.boot = {}; 24*e368108fSDixsie Wolmers $scope.defaultRebootSetting = 'warm-reboot'; 25*e368108fSDixsie Wolmers $scope.defaultShutdownSetting = 'warm-shutdown'; 26*e368108fSDixsie Wolmers 27*e368108fSDixsie Wolmers $scope.activeModal; 28a1d238f3SIftekharul Islam 295ff98780SYoshie Muranaka // When a power operation is in progress, set to true, 305ff98780SYoshie Muranaka // when a power operation completes (success/fail) set to false. 315ff98780SYoshie Muranaka // This property is used to show/hide the 'in progress' message 325ff98780SYoshie Muranaka // in markup. 335ff98780SYoshie Muranaka $scope.operationPending = false; 34cd789508SIftekharul Islam 35*e368108fSDixsie Wolmers const modalTemplate = require('./power-operations-modal.html'); 36*e368108fSDixsie Wolmers 37*e368108fSDixsie Wolmers const powerOperations = 38*e368108fSDixsie Wolmers {WARM_REBOOT: 0, COLD_REBOOT: 1, WARM_SHUTDOWN: 2, COLD_SHUTDOWN: 3}; 39*e368108fSDixsie Wolmers 40afcfda7bSYoshie Muranaka /** 41afcfda7bSYoshie Muranaka * Checks the host status provided by the dataService using an 42afcfda7bSYoshie Muranaka * interval timer 43afcfda7bSYoshie Muranaka * @param {string} statusType : host status type to check for 445ff98780SYoshie Muranaka * @param {number} timeout : timeout limit, defaults to 5 minutes 455ff98780SYoshie Muranaka * @param {string} error : error message, defaults to 'Time out' 46afcfda7bSYoshie Muranaka * @returns {Promise} : returns a deferred promise that will be fulfilled 47afcfda7bSYoshie Muranaka * if the status is met or be rejected if the timeout is reached 48afcfda7bSYoshie Muranaka */ 49*e368108fSDixsie Wolmers const checkHostStatus = 505ff98780SYoshie Muranaka (statusType, timeout = 300000, error = 'Time out.') => { 51afcfda7bSYoshie Muranaka const deferred = $q.defer(); 52afcfda7bSYoshie Muranaka const start = new Date(); 53afcfda7bSYoshie Muranaka const checkHostStatusInverval = $interval(() => { 54afcfda7bSYoshie Muranaka let now = new Date(); 55afcfda7bSYoshie Muranaka let timePassed = now.getTime() - start.getTime(); 56afcfda7bSYoshie Muranaka if (timePassed > timeout) { 57afcfda7bSYoshie Muranaka deferred.reject(error); 58afcfda7bSYoshie Muranaka $interval.cancel(checkHostStatusInverval); 59afcfda7bSYoshie Muranaka } 60afcfda7bSYoshie Muranaka if (dataService.server_state === statusType) { 61afcfda7bSYoshie Muranaka deferred.resolve(); 62afcfda7bSYoshie Muranaka $interval.cancel(checkHostStatusInverval); 63afcfda7bSYoshie Muranaka } 64afcfda7bSYoshie Muranaka }, Constants.POLL_INTERVALS.POWER_OP); 65afcfda7bSYoshie Muranaka return deferred.promise; 66afcfda7bSYoshie Muranaka }; 67afcfda7bSYoshie Muranaka 685ff98780SYoshie Muranaka /** 695ff98780SYoshie Muranaka * Initiate Orderly reboot 705ff98780SYoshie Muranaka * Attempts to stop all software 715ff98780SYoshie Muranaka */ 72*e368108fSDixsie Wolmers const warmReboot = () => { 735ff98780SYoshie Muranaka $scope.operationPending = true; 74d80c280bSCamVan Nguyen dataService.setUnreachableState(); 75d27bb135SAndrew Geissler APIUtils.hostReboot() 765ff98780SYoshie Muranaka .then(() => { 775ff98780SYoshie Muranaka // Check for off state 785ff98780SYoshie Muranaka return checkHostStatus( 795ff98780SYoshie Muranaka Constants.HOST_STATE_TEXT.off, Constants.TIMEOUT.HOST_OFF, 805ff98780SYoshie Muranaka Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); 81d27bb135SAndrew Geissler }) 825ff98780SYoshie Muranaka .then(() => { 835ff98780SYoshie Muranaka // Check for on state 845ff98780SYoshie Muranaka return checkHostStatus( 855ff98780SYoshie Muranaka Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, 865ff98780SYoshie Muranaka Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); 87d27bb135SAndrew Geissler }) 88*e368108fSDixsie Wolmers .catch(error => { 895ff98780SYoshie Muranaka console.log(error); 9027ce84d2Sbeccabroek toastService.error( 9127ce84d2Sbeccabroek Constants.MESSAGES.POWER_OP.WARM_REBOOT_FAILED); 925ff98780SYoshie Muranaka }) 935ff98780SYoshie Muranaka .finally(() => { 945ff98780SYoshie Muranaka $scope.operationPending = false; 95*e368108fSDixsie Wolmers }); 96cd789508SIftekharul Islam }; 97cd789508SIftekharul Islam 985ff98780SYoshie Muranaka /** 995ff98780SYoshie Muranaka * Initiate Immediate reboot 1005ff98780SYoshie Muranaka * Does not attempt to stop all software 1015ff98780SYoshie Muranaka */ 102*e368108fSDixsie Wolmers const coldReboot = () => { 1035ff98780SYoshie Muranaka $scope.operationPending = true; 104d80c280bSCamVan Nguyen dataService.setUnreachableState(); 105d27bb135SAndrew Geissler APIUtils.chassisPowerOff() 1065ff98780SYoshie Muranaka .then(() => { 1075ff98780SYoshie Muranaka // Check for off state 108afcfda7bSYoshie Muranaka return checkHostStatus( 109afcfda7bSYoshie Muranaka Constants.HOST_STATE_TEXT.off, 110afcfda7bSYoshie Muranaka Constants.TIMEOUT.HOST_OFF_IMMEDIATE, 111afcfda7bSYoshie Muranaka Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); 112d27bb135SAndrew Geissler }) 1135ff98780SYoshie Muranaka .then(() => { 114afcfda7bSYoshie Muranaka return APIUtils.hostPowerOn(); 115d27bb135SAndrew Geissler }) 1165ff98780SYoshie Muranaka .then(() => { 1175ff98780SYoshie Muranaka // Check for on state 118afcfda7bSYoshie Muranaka return checkHostStatus( 119afcfda7bSYoshie Muranaka Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, 120afcfda7bSYoshie Muranaka Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); 121d27bb135SAndrew Geissler }) 122*e368108fSDixsie Wolmers .catch(error => { 123afcfda7bSYoshie Muranaka console.log(error); 12427ce84d2Sbeccabroek toastService.error( 12527ce84d2Sbeccabroek Constants.MESSAGES.POWER_OP.COLD_REBOOT_FAILED); 126afcfda7bSYoshie Muranaka }) 1275ff98780SYoshie Muranaka .finally(() => { 1285ff98780SYoshie Muranaka $scope.operationPending = false; 129*e368108fSDixsie Wolmers }); 130cd789508SIftekharul Islam }; 131cd789508SIftekharul Islam 1325ff98780SYoshie Muranaka /** 1335ff98780SYoshie Muranaka * Initiate Orderly shutdown 1345ff98780SYoshie Muranaka * Attempts to stop all software 1355ff98780SYoshie Muranaka */ 136*e368108fSDixsie Wolmers const orderlyShutdown = () => { 1375ff98780SYoshie Muranaka $scope.operationPending = true; 138d80c280bSCamVan Nguyen dataService.setUnreachableState(); 139d27bb135SAndrew Geissler APIUtils.hostPowerOff() 1405ff98780SYoshie Muranaka .then(() => { 1415ff98780SYoshie Muranaka // Check for off state 1425ff98780SYoshie Muranaka return checkHostStatus( 1435ff98780SYoshie Muranaka Constants.HOST_STATE_TEXT.off, Constants.TIMEOUT.HOST_OFF, 1445ff98780SYoshie Muranaka Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); 145d27bb135SAndrew Geissler }) 146*e368108fSDixsie Wolmers .catch(error => { 1475ff98780SYoshie Muranaka console.log(error); 14827ce84d2Sbeccabroek toastService.error( 14992d13b62Sbeccabroek Constants.MESSAGES.POWER_OP.ORDERLY_SHUTDOWN_FAILED); 1505ff98780SYoshie Muranaka }) 1515ff98780SYoshie Muranaka .finally(() => { 1525ff98780SYoshie Muranaka $scope.operationPending = false; 153*e368108fSDixsie Wolmers }); 154cd789508SIftekharul Islam }; 155cd789508SIftekharul Islam 1565ff98780SYoshie Muranaka /** 1575ff98780SYoshie Muranaka * Initiate Immediate shutdown 1585ff98780SYoshie Muranaka * Does not attempt to stop all software 1595ff98780SYoshie Muranaka */ 160*e368108fSDixsie Wolmers const immediateShutdown = () => { 1615ff98780SYoshie Muranaka $scope.operationPending = true; 162d80c280bSCamVan Nguyen dataService.setUnreachableState(); 163d27bb135SAndrew Geissler APIUtils.chassisPowerOff() 1645ff98780SYoshie Muranaka .then(() => { 1655ff98780SYoshie Muranaka // Check for off state 1665ff98780SYoshie Muranaka return checkHostStatus( 1675ff98780SYoshie Muranaka Constants.HOST_STATE_TEXT.off, 1685ff98780SYoshie Muranaka Constants.TIMEOUT.HOST_OFF_IMMEDIATE, 1695ff98780SYoshie Muranaka Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); 170d27bb135SAndrew Geissler }) 1715ff98780SYoshie Muranaka .then(() => { 1723aa8b535SGunnar Mills dataService.setPowerOffState(); 173d27bb135SAndrew Geissler }) 174*e368108fSDixsie Wolmers .catch(error => { 1755ff98780SYoshie Muranaka console.log(error); 17627ce84d2Sbeccabroek toastService.error( 17792d13b62Sbeccabroek Constants.MESSAGES.POWER_OP.IMMEDIATE_SHUTDOWN_FAILED); 1785ff98780SYoshie Muranaka }) 1795ff98780SYoshie Muranaka .finally(() => { 1805ff98780SYoshie Muranaka $scope.operationPending = false; 181*e368108fSDixsie Wolmers }); 182cd789508SIftekharul Islam }; 1835ff98780SYoshie Muranaka 184*e368108fSDixsie Wolmers /** 185*e368108fSDixsie Wolmers * Initiate Power on 186*e368108fSDixsie Wolmers */ 187*e368108fSDixsie Wolmers $scope.powerOn = () => { 188*e368108fSDixsie Wolmers $scope.operationPending = true; 189*e368108fSDixsie Wolmers dataService.setUnreachableState(); 190*e368108fSDixsie Wolmers APIUtils.hostPowerOn() 191*e368108fSDixsie Wolmers .then(() => { 192*e368108fSDixsie Wolmers // Check for on state 193*e368108fSDixsie Wolmers return checkHostStatus( 194*e368108fSDixsie Wolmers Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, 195*e368108fSDixsie Wolmers Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); 196*e368108fSDixsie Wolmers }) 197*e368108fSDixsie Wolmers .catch(error => { 198*e368108fSDixsie Wolmers console.log(error); 199*e368108fSDixsie Wolmers toastService.error(Constants.MESSAGES.POWER_OP.POWER_ON_FAILED); 200*e368108fSDixsie Wolmers }) 201*e368108fSDixsie Wolmers .finally(() => { 202*e368108fSDixsie Wolmers $scope.operationPending = false; 203*e368108fSDixsie Wolmers }); 204*e368108fSDixsie Wolmers }; 205*e368108fSDixsie Wolmers 206*e368108fSDixsie Wolmers /* 207*e368108fSDixsie Wolmers * Power operations modal 208*e368108fSDixsie Wolmers */ 209*e368108fSDixsie Wolmers const initPowerOperation = function(powerOperation) { 210*e368108fSDixsie Wolmers switch (powerOperation) { 211*e368108fSDixsie Wolmers case powerOperations.WARM_REBOOT: 212*e368108fSDixsie Wolmers warmReboot(); 213*e368108fSDixsie Wolmers break; 214*e368108fSDixsie Wolmers case powerOperations.COLD_REBOOT: 215*e368108fSDixsie Wolmers coldReboot(); 216*e368108fSDixsie Wolmers break; 217*e368108fSDixsie Wolmers case powerOperations.WARM_SHUTDOWN: 218*e368108fSDixsie Wolmers orderlyShutdown(); 219*e368108fSDixsie Wolmers break; 220*e368108fSDixsie Wolmers case powerOperations.COLD_SHUTDOWN: 221*e368108fSDixsie Wolmers immediateShutdown(); 222*e368108fSDixsie Wolmers break; 223*e368108fSDixsie Wolmers default: 224*e368108fSDixsie Wolmers // do nothing 225*e368108fSDixsie Wolmers } 226*e368108fSDixsie Wolmers }; 227*e368108fSDixsie Wolmers 228*e368108fSDixsie Wolmers const powerOperationModal = function() { 229*e368108fSDixsie Wolmers $uibModal 230*e368108fSDixsie Wolmers .open({ 231*e368108fSDixsie Wolmers template: modalTemplate, 232*e368108fSDixsie Wolmers windowTopClass: 'uib-modal', 233*e368108fSDixsie Wolmers scope: $scope, 234*e368108fSDixsie Wolmers ariaLabelledBy: 'modal-operation' 235*e368108fSDixsie Wolmers }) 236*e368108fSDixsie Wolmers .result 237*e368108fSDixsie Wolmers .then(function(activeModal) { 238*e368108fSDixsie Wolmers initPowerOperation(activeModal); 239*e368108fSDixsie Wolmers }) 240*e368108fSDixsie Wolmers .finally(function() { 241*e368108fSDixsie Wolmers $scope.activeModal = undefined; 242*e368108fSDixsie Wolmers }); 243*e368108fSDixsie Wolmers }; 244*e368108fSDixsie Wolmers 245*e368108fSDixsie Wolmers $scope.rebootConfirmModal = function() { 246*e368108fSDixsie Wolmers if ($scope.rebootForm.radioReboot.$modelValue == 'warm-reboot') { 247*e368108fSDixsie Wolmers $scope.activeModal = powerOperations.WARM_REBOOT; 248*e368108fSDixsie Wolmers } else if ($scope.rebootForm.radioReboot.$modelValue == 'cold-reboot') { 249*e368108fSDixsie Wolmers $scope.activeModal = powerOperations.COLD_REBOOT; 250*e368108fSDixsie Wolmers } 251*e368108fSDixsie Wolmers powerOperationModal(); 252*e368108fSDixsie Wolmers }; 253*e368108fSDixsie Wolmers 254*e368108fSDixsie Wolmers $scope.shutdownConfirmModal = function() { 255*e368108fSDixsie Wolmers if ($scope.shutdownForm.radioShutdown.$modelValue == 'warm-shutdown') { 256*e368108fSDixsie Wolmers $scope.activeModal = powerOperations.WARM_SHUTDOWN; 257*e368108fSDixsie Wolmers } else if ( 258*e368108fSDixsie Wolmers $scope.shutdownForm.radioShutdown.$modelValue == 'cold-shutdown') { 259*e368108fSDixsie Wolmers $scope.activeModal = powerOperations.COLD_SHUTDOWN; 260*e368108fSDixsie Wolmers } 261*e368108fSDixsie Wolmers powerOperationModal(); 262*e368108fSDixsie Wolmers }; 263*e368108fSDixsie Wolmers 264*e368108fSDixsie Wolmers $scope.resetForm = function() { 265*e368108fSDixsie Wolmers $scope.boot = angular.copy($scope.originalBoot); 266*e368108fSDixsie Wolmers $scope.TPMToggle = angular.copy($scope.originalTPMToggle); 267*e368108fSDixsie Wolmers }; 268*e368108fSDixsie Wolmers 269*e368108fSDixsie Wolmers /* 270*e368108fSDixsie Wolmers * Get boot settings 271*e368108fSDixsie Wolmers */ 272*e368108fSDixsie Wolmers const loadBootSettings = function() { 273*e368108fSDixsie Wolmers APIUtils.getBootOptions() 274*e368108fSDixsie Wolmers .then(function(response) { 275*e368108fSDixsie Wolmers const boot = response.Boot; 276*e368108fSDixsie Wolmers const BootSourceOverrideEnabled = 277*e368108fSDixsie Wolmers boot['BootSourceOverrideEnabled']; 278*e368108fSDixsie Wolmers const BootSourceOverrideTarget = boot['BootSourceOverrideTarget']; 279*e368108fSDixsie Wolmers const bootSourceValues = 280*e368108fSDixsie Wolmers boot['BootSourceOverrideTarget@Redfish.AllowableValues']; 281*e368108fSDixsie Wolmers 282*e368108fSDixsie Wolmers $scope.bootSources = bootSourceValues; 283*e368108fSDixsie Wolmers 284*e368108fSDixsie Wolmers $scope.boot = { 285*e368108fSDixsie Wolmers BootSourceOverrideEnabled: BootSourceOverrideEnabled, 286*e368108fSDixsie Wolmers BootSourceOverrideTarget: BootSourceOverrideTarget 287*e368108fSDixsie Wolmers }; 288*e368108fSDixsie Wolmers 289*e368108fSDixsie Wolmers if (BootSourceOverrideEnabled == 'Once') { 290*e368108fSDixsie Wolmers $scope.boot.oneTimeBootEnabled = true; 291*e368108fSDixsie Wolmers } 292*e368108fSDixsie Wolmers 293*e368108fSDixsie Wolmers $scope.originalBoot = angular.copy($scope.boot); 294*e368108fSDixsie Wolmers }) 295*e368108fSDixsie Wolmers .catch(function(error) { 296*e368108fSDixsie Wolmers $scope.bootOverrideError = true; 297*e368108fSDixsie Wolmers toastService.error('Unable to get boot override values.'); 298*e368108fSDixsie Wolmers console.log( 299*e368108fSDixsie Wolmers 'Error loading boot settings:', JSON.stringify(error)); 300*e368108fSDixsie Wolmers }); 301*e368108fSDixsie Wolmers $scope.loading = false; 302*e368108fSDixsie Wolmers }; 303*e368108fSDixsie Wolmers 304*e368108fSDixsie Wolmers /* 305*e368108fSDixsie Wolmers * Get TPM status 306*e368108fSDixsie Wolmers */ 307*e368108fSDixsie Wolmers const loadTPMStatus = function() { 308*e368108fSDixsie Wolmers APIUtils.getTPMStatus() 309*e368108fSDixsie Wolmers .then(function(response) { 310*e368108fSDixsie Wolmers $scope.TPMToggle = response.data; 311*e368108fSDixsie Wolmers $scope.originalTPMToggle = angular.copy($scope.TPMToggle); 312*e368108fSDixsie Wolmers }) 313*e368108fSDixsie Wolmers .catch(function(error) { 314*e368108fSDixsie Wolmers toastService.error('Unable to get TPM policy status.'); 315*e368108fSDixsie Wolmers console.log('Error loading TPM status', JSON.stringify(error)); 316*e368108fSDixsie Wolmers }); 317*e368108fSDixsie Wolmers $scope.loading = false; 318*e368108fSDixsie Wolmers }; 319*e368108fSDixsie Wolmers 320*e368108fSDixsie Wolmers /* 321*e368108fSDixsie Wolmers * Save boot settings 322*e368108fSDixsie Wolmers */ 323*e368108fSDixsie Wolmers $scope.saveBootSettings = function() { 324*e368108fSDixsie Wolmers if ($scope.hostBootSettings.bootSelected.$dirty || 325*e368108fSDixsie Wolmers $scope.hostBootSettings.oneTime.$dirty) { 326*e368108fSDixsie Wolmers const data = {}; 327*e368108fSDixsie Wolmers data.Boot = {}; 328*e368108fSDixsie Wolmers 329*e368108fSDixsie Wolmers let isOneTimeBoot = $scope.boot.oneTimeBootEnabled; 330*e368108fSDixsie Wolmers let overrideTarget = $scope.boot.BootSourceOverrideTarget || 'None'; 331*e368108fSDixsie Wolmers let overrideEnabled = 'Disabled'; 332*e368108fSDixsie Wolmers 333*e368108fSDixsie Wolmers if (isOneTimeBoot) { 334*e368108fSDixsie Wolmers overrideEnabled = 'Once'; 335*e368108fSDixsie Wolmers } else if (overrideTarget !== 'None') { 336*e368108fSDixsie Wolmers overrideEnabled = 'Continuous'; 337*e368108fSDixsie Wolmers } 338*e368108fSDixsie Wolmers 339*e368108fSDixsie Wolmers data.Boot.BootSourceOverrideEnabled = overrideEnabled; 340*e368108fSDixsie Wolmers data.Boot.BootSourceOverrideTarget = overrideTarget; 341*e368108fSDixsie Wolmers 342*e368108fSDixsie Wolmers APIUtils.saveBootSettings(data).then( 343*e368108fSDixsie Wolmers function(response) { 344*e368108fSDixsie Wolmers $scope.originalBoot = angular.copy($scope.boot); 345*e368108fSDixsie Wolmers toastService.success('Successfully updated boot settings.'); 346*e368108fSDixsie Wolmers }, 347*e368108fSDixsie Wolmers function(error) { 348*e368108fSDixsie Wolmers toastService.error('Unable to save boot settings.'); 349*e368108fSDixsie Wolmers console.log(JSON.stringify(error)); 350*e368108fSDixsie Wolmers }); 351*e368108fSDixsie Wolmers } 352*e368108fSDixsie Wolmers }; 353*e368108fSDixsie Wolmers 354*e368108fSDixsie Wolmers /* 355*e368108fSDixsie Wolmers * Save TPM required policy 356*e368108fSDixsie Wolmers */ 357*e368108fSDixsie Wolmers $scope.saveTPMPolicy = function() { 358*e368108fSDixsie Wolmers if ($scope.hostBootSettings.toggle.$dirty) { 359*e368108fSDixsie Wolmers const tpmEnabled = $scope.TPMToggle.TPMEnable; 360*e368108fSDixsie Wolmers 361*e368108fSDixsie Wolmers if (tpmEnabled === undefined) { 362cd789508SIftekharul Islam return; 363cd789508SIftekharul Islam } 364*e368108fSDixsie Wolmers 365*e368108fSDixsie Wolmers APIUtils.saveTPMEnable(tpmEnabled) 366*e368108fSDixsie Wolmers .then( 367*e368108fSDixsie Wolmers function(response) { 368*e368108fSDixsie Wolmers $scope.originalTPMToggle = angular.copy($scope.TPMToggle); 369*e368108fSDixsie Wolmers toastService.success( 370*e368108fSDixsie Wolmers 'Sucessfully updated TPM required policy.'); 371*e368108fSDixsie Wolmers }, 372*e368108fSDixsie Wolmers function(error) { 373*e368108fSDixsie Wolmers toastService.error('Unable to update TPM required policy.'); 374*e368108fSDixsie Wolmers console.log(JSON.stringify(error)); 375*e368108fSDixsie Wolmers }); 376*e368108fSDixsie Wolmers } 377cd789508SIftekharul Islam }; 378*e368108fSDixsie Wolmers 379*e368108fSDixsie Wolmers /* 380*e368108fSDixsie Wolmers * Emitted every time the view is reloaded 381*e368108fSDixsie Wolmers */ 382*e368108fSDixsie Wolmers $scope.$on('$viewContentLoaded', function() { 383*e368108fSDixsie Wolmers APIUtils.getLastPowerTime() 384*e368108fSDixsie Wolmers .then( 385*e368108fSDixsie Wolmers function(data) { 386*e368108fSDixsie Wolmers if (data.data == 0) { 387*e368108fSDixsie Wolmers $scope.powerTime = 'not available'; 388*e368108fSDixsie Wolmers } else { 389*e368108fSDixsie Wolmers $scope.powerTime = data.data; 390*e368108fSDixsie Wolmers } 391*e368108fSDixsie Wolmers }, 392*e368108fSDixsie Wolmers function(error) { 393*e368108fSDixsie Wolmers toastService.error( 394*e368108fSDixsie Wolmers 'Unable to get last power operation time.'); 395*e368108fSDixsie Wolmers console.log(JSON.stringify(error)); 396*e368108fSDixsie Wolmers }) 397*e368108fSDixsie Wolmers .finally(function() { 398*e368108fSDixsie Wolmers $scope.loading = false; 399*e368108fSDixsie Wolmers }); 400*e368108fSDixsie Wolmers 401*e368108fSDixsie Wolmers loadBootSettings(); 402*e368108fSDixsie Wolmers loadTPMStatus(); 403*e368108fSDixsie Wolmers }); 404cd789508SIftekharul Islam } 405ba5e3f34SAndrew Geissler ]); 406cd789508SIftekharul Islam})(angular); 407