14129f402SGunnar Mills/** 24129f402SGunnar Mills * Controller for server LED 34129f402SGunnar Mills * 44129f402SGunnar Mills * @module app/serverControl 54129f402SGunnar Mills * @exports serverLEDController 64129f402SGunnar Mills * @name serverLEDController 74129f402SGunnar Mills */ 84129f402SGunnar Mills 94129f402SGunnar Millswindow.angular && (function(angular) { 104129f402SGunnar Mills 'use strict'; 114129f402SGunnar Mills 124129f402SGunnar Mills angular.module('app.serverControl').controller('serverLEDController', [ 13*27ce84d2Sbeccabroek '$scope', '$window', '$route', 'APIUtils', 'dataService', 'toastService', 14*27ce84d2Sbeccabroek function($scope, $window, $route, APIUtils, dataService, toastService) { 154129f402SGunnar Mills $scope.dataService = dataService; 164129f402SGunnar Mills 174129f402SGunnar Mills APIUtils.getLEDState().then(function(state) { 184129f402SGunnar Mills $scope.displayLEDState(state); 194129f402SGunnar Mills }); 204129f402SGunnar Mills 214129f402SGunnar Mills $scope.displayLEDState = function(state) { 224129f402SGunnar Mills if (state == APIUtils.LED_STATE.on) { 234129f402SGunnar Mills dataService.LED_state = APIUtils.LED_STATE_TEXT.on; 244129f402SGunnar Mills } else { 254129f402SGunnar Mills dataService.LED_state = APIUtils.LED_STATE_TEXT.off; 264129f402SGunnar Mills } 274129f402SGunnar Mills }; 284129f402SGunnar Mills 294129f402SGunnar Mills $scope.toggleLED = function() { 304129f402SGunnar Mills var toggleState = 314129f402SGunnar Mills (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 324129f402SGunnar Mills APIUtils.LED_STATE.off : 334129f402SGunnar Mills APIUtils.LED_STATE.on; 344129f402SGunnar Mills dataService.LED_state = 354129f402SGunnar Mills (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 364129f402SGunnar Mills APIUtils.LED_STATE_TEXT.off : 374129f402SGunnar Mills APIUtils.LED_STATE_TEXT.on; 38b7f0ee19Sbeccabroek APIUtils.setLEDState(toggleState) 39b7f0ee19Sbeccabroek .then( 40b7f0ee19Sbeccabroek function(response) {}, 41b7f0ee19Sbeccabroek function(errors) { 42*27ce84d2Sbeccabroek toastService.error( 43b7f0ee19Sbeccabroek 'Failed to turn LED light ' + 44b7f0ee19Sbeccabroek (toggleState ? 'on' : 'off')); 45b7f0ee19Sbeccabroek console.log(JSON.stringify(errors)); 46b7f0ee19Sbeccabroek // Reload to get correct current LED state 47b7f0ee19Sbeccabroek $route.reload(); 48b7f0ee19Sbeccabroek }) 494129f402SGunnar Mills }; 504129f402SGunnar Mills } 514129f402SGunnar Mills ]); 524129f402SGunnar Mills})(angular); 53