bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/history.ts (about)

     1  interface IHistoryScope extends IBosunScope {
     2  	ak: string;
     3  	alert_history: any;
     4  	error: string;
     5  }
     6  
     7  bosunApp.directive('tsAlertHistory', () => {
     8  	return {
     9  		templateUrl: '/partials/alerthistory.html',
    10  	};
    11  });
    12  
    13  bosunControllers.controller('HistoryCtrl', ['$scope', '$http', '$location', '$route', function($scope: IHistoryScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) {
    14  	var search = $location.search();
    15  	var keys: any = {};
    16  	if (angular.isArray(search.key)) {
    17  		angular.forEach(search.key, function(v) {
    18  			keys[v] = true;
    19  		});
    20  	} else {
    21  		keys[search.key] = true;
    22  	}
    23  	var params = Object.keys(keys).map((v: any) => { return 'ak=' + encodeURIComponent(v); }).join('&');
    24  	$http.get('/api/status?' + params + "&all=1")
    25  		.success((data) => {
    26  			console.log(data);
    27  			var selected_alerts: any = {};
    28  			angular.forEach(data, function(v, ak) {
    29  				if (!keys[ak]) {
    30  					return;
    31  				}
    32  				v.Events.map((h: any) => { h.Time = moment.utc(h.Time); });
    33  				angular.forEach(v.Events, function(h: any, i: number) {
    34  					if (i + 1 < v.Events.length) {
    35  						h.EndTime = v.Events[i + 1].Time;
    36  					} else {
    37  						h.EndTime = moment.utc();
    38  					}
    39  				});
    40  				selected_alerts[ak] = {
    41  					History: v.Events.reverse(),
    42  				};
    43  			});
    44  			if (Object.keys(selected_alerts).length > 0) {
    45  				$scope.alert_history = selected_alerts;
    46  			} else {
    47  				$scope.error = 'No Matching Alerts Found';
    48  			}
    49  		})
    50  		.error(err => {
    51  			$scope.error = err;
    52  		});
    53  }]);