Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 1 | window.angular && (function(angular) { |
| 2 | 'use strict'; |
Iftekharul Islam | 8b4828a | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 3 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 4 | angular.module('app.common.directives').directive('logEvent', [ |
| 5 | 'APIUtils', |
| 6 | function(APIUtils) { |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 7 | return { |
| 8 | 'restrict': 'E', |
| 9 | 'template': require('./log-event.html'), |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 10 | 'scope': {'event': '=', 'tmz': '=', 'multiSelected': '='}, |
| 11 | 'controller': [ |
| 12 | '$rootScope', '$scope', 'dataService', '$location', '$timeout', |
| 13 | function($rootScope, $scope, dataService, $location, $timeout) { |
| 14 | $scope.dataService = dataService; |
| 15 | $scope.copySuccess = function(event) { |
| 16 | event.copied = true; |
| 17 | $timeout(function() { |
| 18 | event.copied = false; |
| 19 | }, 5000); |
| 20 | }; |
| 21 | $scope.copyFailed = function(err) { |
| 22 | console.error('Error!', err); |
| 23 | }; |
| 24 | $scope.resolveEvent = function(event) { |
Gunnar Mills | 7e48d08 | 2019-01-23 16:02:03 -0600 | [diff] [blame] | 25 | APIUtils.resolveLogs([{Id: event.Id}]) |
| 26 | .then( |
| 27 | function(data) { |
| 28 | event.Resolved = 1; |
| 29 | }, |
| 30 | function(error) { |
| 31 | // TODO: Show error to user |
| 32 | console.log(JSON.stringify(error)); |
| 33 | }); |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 34 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 35 | $scope.accept = function() { |
| 36 | $scope.event.selected = true; |
| 37 | $timeout(function() { |
| 38 | $scope.$parent.accept(); |
| 39 | }, 10); |
| 40 | }; |
Matt Spinler | 845acdc | 2018-05-01 16:41:28 -0500 | [diff] [blame] | 41 | |
| 42 | $scope.getTitle = function(event) { |
| 43 | var title = event.type; |
| 44 | if ((event.eventID != 'None') && (event.description != 'None')) { |
| 45 | title = event.eventID + ': ' + event.description; |
| 46 | } |
| 47 | return title; |
| 48 | }; |
| 49 | |
| 50 | $scope.getAdditionalData = function(event) { |
| 51 | var data = event.additional_data; |
| 52 | // Stick the type into the additional data if it isn't |
| 53 | // already in the title. |
| 54 | if ($scope.getTitle(event).search(event.type) == -1) { |
| 55 | data += '\nMESSAGE=' + event.type; |
| 56 | } |
| 57 | return data; |
| 58 | }; |
beccabroek | c93b03c | 2018-07-27 10:07:51 -0500 | [diff] [blame] | 59 | $scope.copyText = function(event) { |
| 60 | return event.description + ' ' + event.additional_data; |
| 61 | } |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 62 | } |
| 63 | ] |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 64 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 65 | } |
| 66 | ]); |
Iftekharul Islam | 8b4828a | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 67 | })(window.angular); |