1/**
2 * Controller for server LED
3 *
4 * @module app/serverControl
5 * @exports serverLEDController
6 * @name serverLEDController
7 */
8
9window.angular && (function(angular) {
10  'use strict';
11
12  angular.module('app.serverControl').controller('serverLEDController', [
13    '$scope', '$window', 'APIUtils', 'dataService',
14    function($scope, $window, APIUtils, dataService) {
15      $scope.dataService = dataService;
16
17      APIUtils.getLEDState().then(function(state) {
18        $scope.displayLEDState(state);
19      });
20
21      $scope.displayLEDState = function(state) {
22        if (state == APIUtils.LED_STATE.on) {
23          dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
24        } else {
25          dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
26        }
27      };
28
29      $scope.toggleLED = function() {
30        var toggleState =
31            (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
32            APIUtils.LED_STATE.off :
33            APIUtils.LED_STATE.on;
34        dataService.LED_state =
35            (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
36            APIUtils.LED_STATE_TEXT.off :
37            APIUtils.LED_STATE_TEXT.on;
38        APIUtils.setLEDState(toggleState, function(status) {});
39      };
40    }
41  ]);
42})(angular);
43