bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/errors.ts (about) 1 interface IErrorScope extends IBosunScope { 2 errors: any; 3 error: string; 4 loading: boolean; 5 totalLines: () => number; 6 selectedLines: ()=> number; 7 check: (err: any) => void; 8 click: (err: any, event:any) => void; 9 clearAll: () => void; 10 clearSelected: () => void; 11 ruleLink: (line:any, err:any) => string; 12 } 13 14 bosunControllers.controller('ErrorCtrl', ['$scope', '$http', '$location', '$route', function($scope: IErrorScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) { 15 $scope.loading = true 16 $http.get('/api/errors') 17 .success((data: any) => { 18 $scope.errors = []; 19 _(data).forEach((err,name)=>{ 20 err.Name = name; 21 err.Sum = 0; 22 err.Shown = true; 23 _(err.Errors).forEach((line)=>{ 24 err.Sum += line.Count 25 line.FirstTime = moment.utc(line.FirstTime) 26 line.LastTime = moment.utc(line.LastTime) 27 }) 28 $scope.errors.push(err); 29 }) 30 }) 31 .error(function(data) { 32 $scope.error = "Error fetching data: " + data; 33 }) 34 .finally(()=>{$scope.loading=false}) 35 36 37 $scope.click = (err, event) => { 38 event.stopPropagation(); 39 }; 40 41 $scope.totalLines = () => { 42 return $scope.errors.length; 43 }; 44 45 $scope.selectedLines = () => { 46 var t = 0; 47 _($scope.errors).forEach((err) =>{ 48 if (err.checked){ 49 t++; 50 } 51 }) 52 return t; 53 }; 54 55 var getChecked = () => { 56 var keys = []; 57 _($scope.errors).forEach((err) =>{ 58 if (err.checked){ 59 keys.push(err.Name) 60 } 61 }) 62 return keys; 63 } 64 65 var clear = (keys) => { 66 $http.post('/api/errors', keys) 67 .success((data) => { 68 $route.reload(); 69 }) 70 .error(function(data) { 71 $scope.error = "Error Clearing Errors: " + data; 72 }) 73 } 74 75 $scope.clearAll = () =>{ 76 clear(["all"]); 77 } 78 79 $scope.clearSelected = () => { 80 var keys = getChecked(); 81 clear(keys); 82 } 83 84 $scope.ruleLink = (line,err) => { 85 var url = "/config?alert=" + err.Name; 86 var fromDate = moment.utc(line.FirstTime) 87 url += "&fromDate=" + fromDate.format("YYYY-MM-DD"); 88 url += "&fromTime=" + fromDate.format("hh:mm") 89 var toDate = moment.utc(line.LastTime) 90 url += "&toDate=" + toDate.format("YYYY-MM-DD"); 91 url += "&toTime=" + toDate.format("hh:mm") 92 return url; 93 } 94 }]);