summaryrefslogtreecommitdiffstats
path: root/app/common/directives/log-filter.js
blob: 1b7939c58549ac6992893ea73daa15269a1299da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
window.angular && (function(angular) {
  'use strict';

  angular.module('app.common.directives').directive('logFilter', [
    'APIUtils',
    function(APIUtils) {
      return {
        'restrict': 'E',
        'template': require('./log-filter.html'),
        'controller': [
          '$rootScope', '$scope', 'dataService', '$location',
          function($rootScope, $scope, dataService, $location) {
            $scope.dataService = dataService;
            $scope.supportsDateInput = true;

            $scope.toggleSeverityAll = function() {
              $scope.selectedSeverity.all = !$scope.selectedSeverity.all;

              if ($scope.selectedSeverity.all) {
                $scope.selectedSeverity.low = false;
                $scope.selectedSeverity.medium = false;
                $scope.selectedSeverity.high = false;
              }
            };

            $scope.toggleSeverity = function(severity) {
              $scope.selectedSeverity[severity] =
                  !$scope.selectedSeverity[severity];

              if (['high', 'medium', 'low'].indexOf(severity) > -1) {
                if ($scope.selectedSeverity[severity] == false &&
                    (!$scope.selectedSeverity.low &&
                     !$scope.selectedSeverity.medium &&
                     !$scope.selectedSeverity.high)) {
                  $scope.selectedSeverity.all = true;
                  return;
                }
              }

              if ($scope.selectedSeverity.low &&
                  $scope.selectedSeverity.medium &&
                  $scope.selectedSeverity.high) {
                $scope.selectedSeverity.all = true;
                $scope.selectedSeverity.low = false;
                $scope.selectedSeverity.medium = false;
                $scope.selectedSeverity.high = false;
              } else {
                $scope.selectedSeverity.all = false;
              }
            };

            /**
             * Handle browsers that don't support the native date input element
             * IE 11 and Safari do not support this native date element and
             * users cannot select a date from a browser generated date picker.
             * This is a test so that we can indicate to the user the proper
             * date format based on date input element support.
             */
            const testDateInputSupport = () => {
              const firstDateInput = document.querySelector('input[type=date]');

              if (firstDateInput && firstDateInput.type == 'text') {
                $scope.supportsDateInput = false;
              }
            };

            testDateInputSupport();
          }
        ]
      };
    }
  ]);
})(window.angular);
OpenPOWER on IntegriCloud