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

     1  interface IIncidentScope extends ng.IScope {
     2  	error: string;
     3  	incident: IncidentState;
     4  	events: any;
     5  	actions: any;
     6  	body: any;
     7  	shown: any;
     8  	collapse: any;
     9  	loadTimelinePanel: any;
    10  	config_text: any;
    11  	lastNonUnknownAbnormalIdx: any;
    12  	state: any;
    13  	action: any;
    14  	configLink: string;
    15  	isActive: boolean;
    16  	silence: any;
    17  	silenceId: string;
    18  	editSilenceLink: string;
    19  	time: (v: any) => string;
    20  }
    21  
    22  bosunControllers.controller('IncidentCtrl', ['$scope', '$http', '$location', '$route', '$sce', 'linkService', function ($scope: IIncidentScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService, $sce: ng.ISCEService, linkService: ILinkService) {
    23  	var search = $location.search();
    24  	var id = search.id;
    25  	if (!id) {
    26  		$scope.error = "must supply incident id as query parameter"
    27  		return
    28  	}
    29  	$http.get('/api/config')
    30  		.success((data: any) => {
    31  			$scope.config_text = data;
    32  		});
    33  	$scope.action = (type: string) => {
    34  		var key = encodeURIComponent($scope.state.AlertKey);
    35  		return '/action?type=' + type + '&key=' + key;
    36  	};
    37  	$scope.getEditSilenceLink = () => {
    38  		return linkService.GetEditSilenceLink($scope.silence, $scope.silenceId);
    39  	};
    40  	$scope.loadTimelinePanel = (v: any, i: any) => {
    41  		if (v.doneLoading && !v.error) { return; }
    42  		v.error = null;
    43  		v.doneLoading = false;
    44  		if (i == $scope.lastNonUnknownAbnormalIdx && $scope.body) {
    45  			v.subject = $scope.incident.Subject;
    46  			v.body = $scope.body;
    47  			v.doneLoading = true;
    48  			return;
    49  		}
    50  		var ak = $scope.incident.AlertKey;
    51  		var url = ruleUrl(ak, moment(v.Time));
    52  		$http.post(url, $scope.config_text)
    53  			.success((data: any) => {
    54  				v.subject = data.Subject;
    55  				v.body = $sce.trustAsHtml(data.Body);
    56  			})
    57  			.error((error) => {
    58  				v.error = error;
    59  			})
    60  			.finally(() => {
    61  				v.doneLoading = true;
    62  			});
    63  	};
    64  	$scope.shown = {};
    65  	$scope.collapse = (i: any, v: any) => {
    66  		$scope.shown[i] = !$scope.shown[i];
    67  		if ($scope.loadTimelinePanel && $scope.shown[i]) {
    68  			$scope.loadTimelinePanel(v, i);
    69  		}
    70  	};
    71  	$scope.time = (v: any) => {
    72  		var m = moment(v).utc();
    73  		return m.format();
    74  	};
    75  	$http.get('/api/incidents/events?id=' + id)
    76  		.success((data: any) => {
    77  			$scope.incident = data;
    78  			$scope.state = $scope.incident;
    79  			$scope.actions = data.Actions;
    80  			$scope.body = $sce.trustAsHtml(data.Body);
    81  			$scope.events = data.Events.reverse();
    82  			$scope.configLink = configUrl($scope.incident.AlertKey, moment.unix($scope.incident.LastAbnormalTime));
    83  			$scope.isActive = data.IsActive;
    84  			$scope.silence = data.Silence;
    85  			$scope.silenceId = data.SilenceId;
    86  			$scope.editSilenceLink = linkService.GetEditSilenceLink($scope.silence, $scope.silenceId);
    87  			for (var i = 0; i < $scope.events.length; i++) {
    88  				var e = $scope.events[i];
    89  				if (e.Status != 'normal' && e.Status != 'unknown' && $scope.body) {
    90  					$scope.lastNonUnknownAbnormalIdx = i;
    91  					$scope.collapse(i, e); // Expand the panel of the current body
    92  					break;
    93  				}
    94  			}
    95  			$scope.collapse;
    96  		})
    97  		.error(err => {
    98  			$scope.error = err;
    99  		});
   100  }]);