bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/annotation.ts (about) 1 /// <reference path="0-bosun.ts" /> 2 interface IAnnotationScope extends IBosunScope { 3 id: string; 4 annotation: Annotation; 5 error: string; 6 submitAnnotation: () => void; 7 deleteAnnotation: () => void; 8 owners: string[]; 9 hosts: string[]; 10 categories: string[]; 11 submitSuccess: boolean; 12 deleteSuccess: boolean; 13 } 14 15 bosunControllers.controller('AnnotationCtrl', ['$scope', '$http', '$location', '$route', function ($scope: IAnnotationScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) { 16 var search = $location.search(); 17 $scope.id = search.id; 18 if ($scope.id && $scope.id != "") { 19 $http.get('/api/annotation/' + $scope.id) 20 .success((data: any) => { 21 $scope.annotation = new Annotation(data, true); 22 $scope.error = ""; 23 }) 24 .error((data: any) => { 25 $scope.error = "failed to get annotation with id: " + $scope.id + ", error: " + data; 26 }); 27 } else { 28 $scope.annotation = new Annotation(); 29 $scope.annotation.setTimeUTC(); 30 } 31 $http.get('/api/annotation/values/Owner') 32 .success((data: string[]) => { 33 $scope.owners = data; 34 }); 35 $http.get('/api/annotation/values/Category') 36 .success((data: string[]) => { 37 $scope.categories = data; 38 }); 39 $http.get('/api/annotation/values/Host') 40 .success((data: string[]) => { 41 $scope.hosts = data; 42 }); 43 44 45 $scope.submitAnnotation = () => { 46 $scope.animate(); 47 $scope.annotation.CreationUser = $scope.auth.GetUsername(); 48 $http.post('/api/annotation', $scope.annotation) 49 .success((data: any) => { 50 $scope.annotation = new Annotation(data, true); 51 $scope.error = ""; 52 $scope.submitSuccess = true; 53 $scope.deleteSuccess = false; 54 }) 55 .error((error) => { 56 $scope.error = "failed to create annotation: " + error.error; 57 $scope.submitSuccess = false; 58 }) 59 .finally(() => { 60 $scope.stop(); 61 }); 62 }; 63 64 $scope.deleteAnnotation = () => { 65 $scope.animate(); 66 $http.delete('/api/annotation/' + $scope.annotation.Id) 67 .success((data) => { 68 $scope.error = ""; 69 $scope.deleteSuccess = true; 70 $scope.submitSuccess = false; 71 $scope.annotation = new (Annotation); 72 $scope.annotation.setTimeUTC(); 73 }) 74 .error((error) => { 75 $scope.error = "failed to delete annotation with id: " + $scope.annotation.Id + ", error: " + error.error; 76 $scope.deleteSuccess = false; 77 }) 78 .finally(() => { 79 $scope.stop(); 80 }); 81 } 82 }]);