diff options
author | beccabroek <beccabroek@gmail.com> | 2019-01-10 11:15:58 -0600 |
---|---|---|
committer | beccabroek <beccabroek@gmail.com> | 2019-01-21 09:51:27 -0600 |
commit | b7f0ee19eb0ee728eb4075646821898e7d29c7bc (patch) | |
tree | c0f9c7c1fd8475a164698a4a1f0fd6ae5f1b0c19 | |
parent | 92d13b62f56fa302a8231690e7371c6ae04f50ba (diff) | |
download | phosphor-webui-b7f0ee19eb0ee728eb4075646821898e7d29c7bc.tar.gz phosphor-webui-b7f0ee19eb0ee728eb4075646821898e7d29c7bc.zip |
Add toast to LED page
Toast error notification alerts user if LED light switch was
not successful.
Change-Id: I4f7af80276b6fefa93c8d0f0f50f8b28a06bced3
Signed-off-by: beccabroek <beccabroek@gmail.com>
-rw-r--r-- | app/common/services/api-utils.js | 19 | ||||
-rw-r--r-- | app/server-control/controllers/server-led-controller.js | 16 |
2 files changed, 15 insertions, 20 deletions
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js index 9e458aa..0de6b1f 100644 --- a/app/common/services/api-utils.js +++ b/app/common/services/api-utils.js @@ -838,29 +838,14 @@ window.angular && (function(angular) { }); return deferred.promise; }, - setLEDState: function(state, callback) { - $http({ + setLEDState: function(state) { + return $http({ method: 'PUT', url: DataService.getHost() + '/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted', withCredentials: true, data: JSON.stringify({'data': state}) }) - .then( - function(response) { - var json = JSON.stringify(response.data); - var content = JSON.parse(json); - if (callback) { - return callback(content.status); - } - }, - function(error) { - if (callback) { - callback(error); - } else { - console.log(error); - } - }); }, bmcReboot: function(callback) { $http({ diff --git a/app/server-control/controllers/server-led-controller.js b/app/server-control/controllers/server-led-controller.js index e30f3b3..96ea064 100644 --- a/app/server-control/controllers/server-led-controller.js +++ b/app/server-control/controllers/server-led-controller.js @@ -10,8 +10,8 @@ window.angular && (function(angular) { 'use strict'; angular.module('app.serverControl').controller('serverLEDController', [ - '$scope', '$window', 'APIUtils', 'dataService', - function($scope, $window, APIUtils, dataService) { + '$scope', '$window', '$route', 'APIUtils', 'dataService', 'ngToast', + function($scope, $window, $route, APIUtils, dataService, ngToast) { $scope.dataService = dataService; APIUtils.getLEDState().then(function(state) { @@ -35,7 +35,17 @@ window.angular && (function(angular) { (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; - APIUtils.setLEDState(toggleState, function(status) {}); + APIUtils.setLEDState(toggleState) + .then( + function(response) {}, + function(errors) { + ngToast.danger( + 'Failed to turn LED light ' + + (toggleState ? 'on' : 'off')); + console.log(JSON.stringify(errors)); + // Reload to get correct current LED state + $route.reload(); + }) }; } ]); |