bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/action.ts (about) 1 2 /// <reference path="expr.ts" /> 3 4 interface IActionScope extends IBosunScope { 5 type: string; 6 user: string; 7 message: string; 8 notify: boolean; 9 keys: string[]; 10 submit: () => void; 11 validateMsg: () => void; 12 msgValid: boolean; 13 activeIncidents: boolean; 14 duration: string; 15 durationValid: boolean; 16 } 17 18 bosunControllers.controller('ActionCtrl', ['$scope', '$http', '$location', '$route', function ($scope: IActionScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) { 19 var search = $location.search(); 20 $scope.type = search.type; 21 $scope.activeIncidents = search.active == "true"; 22 $scope.notify = true; 23 $scope.msgValid = true; 24 $scope.message = ""; 25 $scope.duration = ""; 26 $scope.validateMsg = () => { 27 $scope.msgValid = (!$scope.notify) || ($scope.message != ""); 28 } 29 $scope.durationValid = true; 30 $scope.validateDuration = () => { 31 $scope.durationValid = $scope.duration == "" || parseDuration($scope.duration).asMilliseconds() != 0; 32 } 33 34 if (search.key) { 35 var keys = search.key; 36 if (!angular.isArray(search.key)) { 37 keys = [search.key]; 38 } 39 $location.search('key', null); 40 $scope.setKey('action-keys', keys); 41 } else { 42 $scope.keys = $scope.getKey('action-keys'); 43 } 44 $scope.submit = () => { 45 $scope.validateMsg(); 46 $scope.validateDuration(); 47 if (!$scope.msgValid || ($scope.user == "") || !$scope.durationValid) { 48 return; 49 } 50 var data = { 51 Type: $scope.type, 52 Message: $scope.message, 53 Keys: $scope.keys, 54 Notify: $scope.notify, 55 }; 56 if ($scope.duration != "") { 57 data['Time'] = moment.utc().add(parseDuration($scope.duration)); 58 } 59 $http.post('/api/action', data) 60 .success((data) => { 61 $location.url('/'); 62 }) 63 .error((error) => { 64 alert(error); 65 }); 66 }; 67 }]);