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',
14e368108fSDixsie Wolmers    'toastService', '$uibModal',
15d27bb135SAndrew Geissler    function(
16e368108fSDixsie Wolmers        $scope, APIUtils, dataService, Constants, $interval, $q, toastService,
17e368108fSDixsie Wolmers        $uibModal) {
18cd789508SIftekharul Islam      $scope.dataService = dataService;
196add8325SGunnar Mills      $scope.loading = true;
20e368108fSDixsie Wolmers      $scope.oneTimeBootEnabled = false;
21e368108fSDixsie Wolmers      $scope.bootOverrideError = false;
22e368108fSDixsie Wolmers      $scope.bootSources = [];
23e368108fSDixsie Wolmers      $scope.boot = {};
24e368108fSDixsie Wolmers      $scope.defaultRebootSetting = 'warm-reboot';
25e368108fSDixsie Wolmers      $scope.defaultShutdownSetting = 'warm-shutdown';
26e368108fSDixsie Wolmers
27e368108fSDixsie 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
35e368108fSDixsie Wolmers      const modalTemplate = require('./power-operations-modal.html');
36e368108fSDixsie Wolmers
37e368108fSDixsie Wolmers      const powerOperations =
38e368108fSDixsie Wolmers          {WARM_REBOOT: 0, COLD_REBOOT: 1, WARM_SHUTDOWN: 2, COLD_SHUTDOWN: 3};
39e368108fSDixsie 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       */
49e368108fSDixsie 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       */
72e368108fSDixsie 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            })
88e368108fSDixsie 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;
95e368108fSDixsie Wolmers            });
96cd789508SIftekharul Islam      };
97cd789508SIftekharul Islam
985ff98780SYoshie Muranaka      /**
995ff98780SYoshie Muranaka       * Initiate Immediate reboot
1005ff98780SYoshie Muranaka       * Does not attempt to stop all software
1015ff98780SYoshie Muranaka       */
102e368108fSDixsie 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            })
122e368108fSDixsie 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;
129e368108fSDixsie Wolmers            });
130cd789508SIftekharul Islam      };
131cd789508SIftekharul Islam
1325ff98780SYoshie Muranaka      /**
1335ff98780SYoshie Muranaka       * Initiate Orderly shutdown
1345ff98780SYoshie Muranaka       * Attempts to stop all software
1355ff98780SYoshie Muranaka       */
136e368108fSDixsie 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            })
146e368108fSDixsie 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;
153e368108fSDixsie Wolmers            });
154cd789508SIftekharul Islam      };
155cd789508SIftekharul Islam
1565ff98780SYoshie Muranaka      /**
1575ff98780SYoshie Muranaka       * Initiate Immediate shutdown
1585ff98780SYoshie Muranaka       * Does not attempt to stop all software
1595ff98780SYoshie Muranaka       */
160e368108fSDixsie 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            })
174e368108fSDixsie 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;
181e368108fSDixsie Wolmers            });
182cd789508SIftekharul Islam      };
1835ff98780SYoshie Muranaka
184e368108fSDixsie Wolmers      /**
185e368108fSDixsie Wolmers       * Initiate Power on
186e368108fSDixsie Wolmers       */
187e368108fSDixsie Wolmers      $scope.powerOn = () => {
188e368108fSDixsie Wolmers        $scope.operationPending = true;
189e368108fSDixsie Wolmers        dataService.setUnreachableState();
190e368108fSDixsie Wolmers        APIUtils.hostPowerOn()
191e368108fSDixsie Wolmers            .then(() => {
192e368108fSDixsie Wolmers              // Check for on state
193e368108fSDixsie Wolmers              return checkHostStatus(
194e368108fSDixsie Wolmers                  Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON,
195e368108fSDixsie Wolmers                  Constants.MESSAGES.POLL.HOST_ON_TIMEOUT);
196e368108fSDixsie Wolmers            })
197e368108fSDixsie Wolmers            .catch(error => {
198e368108fSDixsie Wolmers              console.log(error);
199e368108fSDixsie Wolmers              toastService.error(Constants.MESSAGES.POWER_OP.POWER_ON_FAILED);
200e368108fSDixsie Wolmers            })
201e368108fSDixsie Wolmers            .finally(() => {
202e368108fSDixsie Wolmers              $scope.operationPending = false;
203e368108fSDixsie Wolmers            });
204e368108fSDixsie Wolmers      };
205e368108fSDixsie Wolmers
206e368108fSDixsie Wolmers      /*
207e368108fSDixsie Wolmers       *  Power operations modal
208e368108fSDixsie Wolmers       */
209e368108fSDixsie Wolmers      const initPowerOperation = function(powerOperation) {
210e368108fSDixsie Wolmers        switch (powerOperation) {
211e368108fSDixsie Wolmers          case powerOperations.WARM_REBOOT:
212e368108fSDixsie Wolmers            warmReboot();
213e368108fSDixsie Wolmers            break;
214e368108fSDixsie Wolmers          case powerOperations.COLD_REBOOT:
215e368108fSDixsie Wolmers            coldReboot();
216e368108fSDixsie Wolmers            break;
217e368108fSDixsie Wolmers          case powerOperations.WARM_SHUTDOWN:
218e368108fSDixsie Wolmers            orderlyShutdown();
219e368108fSDixsie Wolmers            break;
220e368108fSDixsie Wolmers          case powerOperations.COLD_SHUTDOWN:
221e368108fSDixsie Wolmers            immediateShutdown();
222e368108fSDixsie Wolmers            break;
223e368108fSDixsie Wolmers          default:
224e368108fSDixsie Wolmers            // do nothing
225e368108fSDixsie Wolmers        }
226e368108fSDixsie Wolmers      };
227e368108fSDixsie Wolmers
228e368108fSDixsie Wolmers      const powerOperationModal = function() {
229e368108fSDixsie Wolmers        $uibModal
230e368108fSDixsie Wolmers            .open({
231e368108fSDixsie Wolmers              template: modalTemplate,
232e368108fSDixsie Wolmers              windowTopClass: 'uib-modal',
233e368108fSDixsie Wolmers              scope: $scope,
234e368108fSDixsie Wolmers              ariaLabelledBy: 'modal-operation'
235e368108fSDixsie Wolmers            })
236e368108fSDixsie Wolmers            .result
237e368108fSDixsie Wolmers            .then(function(activeModal) {
238e368108fSDixsie Wolmers              initPowerOperation(activeModal);
239e368108fSDixsie Wolmers            })
240e368108fSDixsie Wolmers            .finally(function() {
241e368108fSDixsie Wolmers              $scope.activeModal = undefined;
242e368108fSDixsie Wolmers            });
243e368108fSDixsie Wolmers      };
244e368108fSDixsie Wolmers
245e368108fSDixsie Wolmers      $scope.rebootConfirmModal = function() {
246e368108fSDixsie Wolmers        if ($scope.rebootForm.radioReboot.$modelValue == 'warm-reboot') {
247e368108fSDixsie Wolmers          $scope.activeModal = powerOperations.WARM_REBOOT;
248e368108fSDixsie Wolmers        } else if ($scope.rebootForm.radioReboot.$modelValue == 'cold-reboot') {
249e368108fSDixsie Wolmers          $scope.activeModal = powerOperations.COLD_REBOOT;
250e368108fSDixsie Wolmers        }
251e368108fSDixsie Wolmers        powerOperationModal();
252e368108fSDixsie Wolmers      };
253e368108fSDixsie Wolmers
254e368108fSDixsie Wolmers      $scope.shutdownConfirmModal = function() {
255e368108fSDixsie Wolmers        if ($scope.shutdownForm.radioShutdown.$modelValue == 'warm-shutdown') {
256e368108fSDixsie Wolmers          $scope.activeModal = powerOperations.WARM_SHUTDOWN;
257e368108fSDixsie Wolmers        } else if (
258e368108fSDixsie Wolmers            $scope.shutdownForm.radioShutdown.$modelValue == 'cold-shutdown') {
259e368108fSDixsie Wolmers          $scope.activeModal = powerOperations.COLD_SHUTDOWN;
260e368108fSDixsie Wolmers        }
261e368108fSDixsie Wolmers        powerOperationModal();
262e368108fSDixsie Wolmers      };
263e368108fSDixsie Wolmers
264e368108fSDixsie Wolmers      $scope.resetForm = function() {
265e368108fSDixsie Wolmers        $scope.boot = angular.copy($scope.originalBoot);
266e368108fSDixsie Wolmers        $scope.TPMToggle = angular.copy($scope.originalTPMToggle);
267e368108fSDixsie Wolmers      };
268e368108fSDixsie Wolmers
269e368108fSDixsie Wolmers      /*
270e368108fSDixsie Wolmers       *   Get boot settings
271e368108fSDixsie Wolmers       */
272e368108fSDixsie Wolmers      const loadBootSettings = function() {
273e368108fSDixsie Wolmers        APIUtils.getBootOptions()
274e368108fSDixsie Wolmers            .then(function(response) {
275e368108fSDixsie Wolmers              const boot = response.Boot;
276e368108fSDixsie Wolmers              const BootSourceOverrideEnabled =
277e368108fSDixsie Wolmers                  boot['BootSourceOverrideEnabled'];
278e368108fSDixsie Wolmers              const BootSourceOverrideTarget = boot['BootSourceOverrideTarget'];
279e368108fSDixsie Wolmers              const bootSourceValues =
280e368108fSDixsie Wolmers                  boot['BootSourceOverrideTarget@Redfish.AllowableValues'];
281e368108fSDixsie Wolmers
282e368108fSDixsie Wolmers              $scope.bootSources = bootSourceValues;
283e368108fSDixsie Wolmers
284e368108fSDixsie Wolmers              $scope.boot = {
285e368108fSDixsie Wolmers                BootSourceOverrideEnabled: BootSourceOverrideEnabled,
286e368108fSDixsie Wolmers                BootSourceOverrideTarget: BootSourceOverrideTarget
287e368108fSDixsie Wolmers              };
288e368108fSDixsie Wolmers
289e368108fSDixsie Wolmers              if (BootSourceOverrideEnabled == 'Once') {
290e368108fSDixsie Wolmers                $scope.boot.oneTimeBootEnabled = true;
291e368108fSDixsie Wolmers              }
292e368108fSDixsie Wolmers
293e368108fSDixsie Wolmers              $scope.originalBoot = angular.copy($scope.boot);
294e368108fSDixsie Wolmers            })
295e368108fSDixsie Wolmers            .catch(function(error) {
296e368108fSDixsie Wolmers              $scope.bootOverrideError = true;
297e368108fSDixsie Wolmers              toastService.error('Unable to get boot override values.');
298e368108fSDixsie Wolmers              console.log(
299e368108fSDixsie Wolmers                  'Error loading boot settings:', JSON.stringify(error));
300e368108fSDixsie Wolmers            });
301e368108fSDixsie Wolmers        $scope.loading = false;
302e368108fSDixsie Wolmers      };
303e368108fSDixsie Wolmers
304e368108fSDixsie Wolmers      /*
305e368108fSDixsie Wolmers       *   Get TPM status
306e368108fSDixsie Wolmers       */
307e368108fSDixsie Wolmers      const loadTPMStatus = function() {
308e368108fSDixsie Wolmers        APIUtils.getTPMStatus()
309e368108fSDixsie Wolmers            .then(function(response) {
310e368108fSDixsie Wolmers              $scope.TPMToggle = response.data;
311e368108fSDixsie Wolmers              $scope.originalTPMToggle = angular.copy($scope.TPMToggle);
312e368108fSDixsie Wolmers            })
313e368108fSDixsie Wolmers            .catch(function(error) {
314e368108fSDixsie Wolmers              toastService.error('Unable to get TPM policy status.');
315e368108fSDixsie Wolmers              console.log('Error loading TPM status', JSON.stringify(error));
316e368108fSDixsie Wolmers            });
317e368108fSDixsie Wolmers        $scope.loading = false;
318e368108fSDixsie Wolmers      };
319e368108fSDixsie Wolmers
320e368108fSDixsie Wolmers      /*
321e368108fSDixsie Wolmers       *   Save boot settings
322e368108fSDixsie Wolmers       */
323e368108fSDixsie Wolmers      $scope.saveBootSettings = function() {
324e368108fSDixsie Wolmers        if ($scope.hostBootSettings.bootSelected.$dirty ||
325e368108fSDixsie Wolmers            $scope.hostBootSettings.oneTime.$dirty) {
326e368108fSDixsie Wolmers          const data = {};
327e368108fSDixsie Wolmers          data.Boot = {};
328e368108fSDixsie Wolmers
329e368108fSDixsie Wolmers          let isOneTimeBoot = $scope.boot.oneTimeBootEnabled;
330e368108fSDixsie Wolmers          let overrideTarget = $scope.boot.BootSourceOverrideTarget || 'None';
331e368108fSDixsie Wolmers          let overrideEnabled = 'Disabled';
332e368108fSDixsie Wolmers
333e368108fSDixsie Wolmers          if (isOneTimeBoot) {
334e368108fSDixsie Wolmers            overrideEnabled = 'Once';
335e368108fSDixsie Wolmers          } else if (overrideTarget !== 'None') {
336e368108fSDixsie Wolmers            overrideEnabled = 'Continuous';
337e368108fSDixsie Wolmers          }
338e368108fSDixsie Wolmers
339e368108fSDixsie Wolmers          data.Boot.BootSourceOverrideEnabled = overrideEnabled;
340e368108fSDixsie Wolmers          data.Boot.BootSourceOverrideTarget = overrideTarget;
341e368108fSDixsie Wolmers
342e368108fSDixsie Wolmers          APIUtils.saveBootSettings(data).then(
343e368108fSDixsie Wolmers              function(response) {
344e368108fSDixsie Wolmers                $scope.originalBoot = angular.copy($scope.boot);
345e368108fSDixsie Wolmers                toastService.success('Successfully updated boot settings.');
346e368108fSDixsie Wolmers              },
347e368108fSDixsie Wolmers              function(error) {
348e368108fSDixsie Wolmers                toastService.error('Unable to save boot settings.');
349e368108fSDixsie Wolmers                console.log(JSON.stringify(error));
350e368108fSDixsie Wolmers              });
351e368108fSDixsie Wolmers        }
352e368108fSDixsie Wolmers      };
353e368108fSDixsie Wolmers
354e368108fSDixsie Wolmers      /*
355e368108fSDixsie Wolmers       *   Save TPM required policy
356e368108fSDixsie Wolmers       */
357e368108fSDixsie Wolmers      $scope.saveTPMPolicy = function() {
358e368108fSDixsie Wolmers        if ($scope.hostBootSettings.toggle.$dirty) {
359e368108fSDixsie Wolmers          const tpmEnabled = $scope.TPMToggle.TPMEnable;
360e368108fSDixsie Wolmers
361e368108fSDixsie Wolmers          if (tpmEnabled === undefined) {
362cd789508SIftekharul Islam            return;
363cd789508SIftekharul Islam          }
364e368108fSDixsie Wolmers
365e368108fSDixsie Wolmers          APIUtils.saveTPMEnable(tpmEnabled)
366e368108fSDixsie Wolmers              .then(
367e368108fSDixsie Wolmers                  function(response) {
368e368108fSDixsie Wolmers                    $scope.originalTPMToggle = angular.copy($scope.TPMToggle);
369e368108fSDixsie Wolmers                    toastService.success(
370e368108fSDixsie Wolmers                        'Sucessfully updated TPM required policy.');
371e368108fSDixsie Wolmers                  },
372e368108fSDixsie Wolmers                  function(error) {
373e368108fSDixsie Wolmers                    toastService.error('Unable to update TPM required policy.');
374e368108fSDixsie Wolmers                    console.log(JSON.stringify(error));
375e368108fSDixsie Wolmers                  });
376e368108fSDixsie Wolmers        }
377cd789508SIftekharul Islam      };
378e368108fSDixsie Wolmers
379*5dac9e15SYoshie Muranaka      /**
380*5dac9e15SYoshie Muranaka       * Callback when boot setting option changed
381*5dac9e15SYoshie Muranaka       */
382*5dac9e15SYoshie Muranaka      $scope.onChangeBootSetting = function() {
383*5dac9e15SYoshie Muranaka        const bootSetting = $scope.hostBootSettings.bootSelected.$viewValue;
384*5dac9e15SYoshie Muranaka        if (bootSetting === 'None') {
385*5dac9e15SYoshie Muranaka          $scope.boot.oneTimeBootEnabled = false;
386*5dac9e15SYoshie Muranaka        }
387*5dac9e15SYoshie Muranaka      };
388*5dac9e15SYoshie Muranaka
389e368108fSDixsie Wolmers      /*
390e368108fSDixsie Wolmers       *   Emitted every time the view is reloaded
391e368108fSDixsie Wolmers       */
392e368108fSDixsie Wolmers      $scope.$on('$viewContentLoaded', function() {
393e368108fSDixsie Wolmers        APIUtils.getLastPowerTime()
394e368108fSDixsie Wolmers            .then(
395e368108fSDixsie Wolmers                function(data) {
396e368108fSDixsie Wolmers                  if (data.data == 0) {
397e368108fSDixsie Wolmers                    $scope.powerTime = 'not available';
398e368108fSDixsie Wolmers                  } else {
399e368108fSDixsie Wolmers                    $scope.powerTime = data.data;
400e368108fSDixsie Wolmers                  }
401e368108fSDixsie Wolmers                },
402e368108fSDixsie Wolmers                function(error) {
403e368108fSDixsie Wolmers                  toastService.error(
404e368108fSDixsie Wolmers                      'Unable to get last power operation time.');
405e368108fSDixsie Wolmers                  console.log(JSON.stringify(error));
406e368108fSDixsie Wolmers                })
407e368108fSDixsie Wolmers            .finally(function() {
408e368108fSDixsie Wolmers              $scope.loading = false;
409e368108fSDixsie Wolmers            });
410e368108fSDixsie Wolmers
411e368108fSDixsie Wolmers        loadBootSettings();
412e368108fSDixsie Wolmers        loadTPMStatus();
413e368108fSDixsie Wolmers      });
414cd789508SIftekharul Islam    }
415ba5e3f34SAndrew Geissler  ]);
416cd789508SIftekharul Islam})(angular);
417