summaryrefslogtreecommitdiffstats
path: root/app/common/directives/log-event.js
blob: e179389bddd44cda1016e9a11da3b6e33e1b3a98 (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
window.angular && (function(angular) {
  'use strict';

  angular.module('app.common.directives').directive('logEvent', [
    'APIUtils',
    function(APIUtils) {
      return {
        'restrict': 'E',
        'template': require('./log-event.html'),
        'scope': {'event': '=', 'tmz': '=', 'multiSelected': '='},
        'controller': [
          '$rootScope', '$scope', 'dataService', '$location', '$timeout',
          function($rootScope, $scope, dataService, $location, $timeout) {
            $scope.dataService = dataService;
            $scope.copySuccess = function(event) {
              event.copied = true;
              $timeout(function() {
                event.copied = false;
              }, 5000);
            };
            $scope.copyFailed = function(err) {
              console.error('Error!', err);
            };
            $scope.resolveEvent = function(event) {
              APIUtils.resolveLogs([{Id: event.Id}])
                  .then(
                      function(data) {
                        event.Resolved = 1;
                      },
                      function(error) {
                        // TODO: Show error to user
                        console.log(JSON.stringify(error));
                      });
            };
            $scope.accept = function() {
              $scope.event.selected = true;
              $timeout(function() {
                $scope.$parent.accept();
              }, 10);
            };

            $scope.getTitle = function(event) {
              var title = event.type;
              if ((event.eventID != 'None') && (event.description != 'None')) {
                title = event.eventID + ': ' + event.description;
              }
              return title;
            };

            $scope.getAdditionalData = function(event) {
              var data = event.additional_data;
              // Stick the type into the additional data if it isn't
              // already in the title.
              if ($scope.getTitle(event).search(event.type) == -1) {
                data += '\nMESSAGE=' + event.type;
              }
              return data;
            };
            $scope.copyText = function(event) {
              return event.description + ' ' + event.additional_data;
            }
          }
        ]
      };
    }
  ]);
})(window.angular);
OpenPOWER on IntegriCloud