1window.angular && (function(angular) {
2  'use strict';
3
4  angular.module('app.common.directives').directive('logFilter', [
5    'APIUtils',
6    function(APIUtils) {
7      return {
8        'restrict': 'E',
9        'template': require('./log-filter.html'),
10        'controller': [
11          '$rootScope', '$scope', 'dataService', '$location',
12          function($rootScope, $scope, dataService, $location) {
13            $scope.dataService = dataService;
14            $scope.toggleSeverityAll = function() {
15              $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
16
17              if ($scope.selectedSeverity.all) {
18                $scope.selectedSeverity.low = false;
19                $scope.selectedSeverity.medium = false;
20                $scope.selectedSeverity.high = false;
21              }
22            };
23
24            $scope.toggleSeverity = function(severity) {
25              $scope.selectedSeverity[severity] =
26                  !$scope.selectedSeverity[severity];
27
28              if (['high', 'medium', 'low'].indexOf(severity) > -1) {
29                if ($scope.selectedSeverity[severity] == false &&
30                    (!$scope.selectedSeverity.low &&
31                     !$scope.selectedSeverity.medium &&
32                     !$scope.selectedSeverity.high)) {
33                  $scope.selectedSeverity.all = true;
34                  return;
35                }
36              }
37
38              if ($scope.selectedSeverity.low &&
39                  $scope.selectedSeverity.medium &&
40                  $scope.selectedSeverity.high) {
41                $scope.selectedSeverity.all = true;
42                $scope.selectedSeverity.low = false;
43                $scope.selectedSeverity.medium = false;
44                $scope.selectedSeverity.high = false;
45              } else {
46                $scope.selectedSeverity.all = false;
47              }
48            };
49          }
50        ]
51      };
52    }
53  ]);
54})(window.angular);
55