Commit | Line | Data |
---|---|---|
4d8e3559 NM |
1 | (function(angular, $, _) { |
2 | ||
3 | // controller | |
4 | ||
5 | angular.module('statuspage').controller('statuspageStatusPage', | |
6 | function($scope, $location, crmApi, crmStatus, crmUiHelp, statuses, crmNavigator, preferences) { | |
7 | // The ts() and hs() functions help load strings for this module. | |
8 | var ts = $scope.ts = CRM.ts('statuspage'); | |
9 | var hs = $scope.hs = crmUiHelp({file: 'CRM/statuspage/StatusPage'}); // See: templates/CRM/statuspage/StatusPage.hlp | |
10 | ||
11 | $scope.path = $location.path(); | |
12 | $scope.navigator = crmNavigator; | |
13 | $scope.statuses = statuses; | |
4d8e3559 NM |
14 | $scope.preferences = preferences; |
15 | ||
16 | // will "hush" a status - gets the severity level of the status that is being hushed, and hushes all alerts for that check at and below the level of the current check | |
17 | $scope.hush = function(name, severity) { | |
18 | return crmStatus( | |
19 | { start: ts('Saving Status Preference...') , success: ts('Preference Saved') }, | |
20 | crmApi('StatusPreference', 'create', { | |
21 | "sequential": 1, | |
22 | "name": name, | |
23 | "ignore_severity": severity, | |
24 | "hush_until": "" | |
25 | }) | |
26 | .then(function(){rmStatus($scope, name);}) | |
27 | ); | |
28 | }; | |
29 | ||
30 | // will reset ignore_severity to 0 to unhush the status alert. | |
31 | $scope.unhush = function(name, severity) { | |
32 | return crmStatus( | |
33 | { start: ts('Saving Status Preference...') , success: ts('Preference Saved') }, | |
34 | crmApi('StatusPreference', 'create', { | |
35 | "sequential": 1, | |
36 | "name": name, | |
37 | "ignore_severity": 0, | |
38 | "hush_until": "" | |
39 | }) | |
40 | .then(function(){rmStatus($scope, name);}) | |
41 | ); | |
42 | }; | |
43 | ||
44 | // will 'snooze' a status - will not show alerts at that level for that check + alerts below that level for that check until the specified date | |
45 | $scope.snooze = function(status) { | |
46 | $scope.showSnoozeOptions(status); | |
47 | return crmStatus( | |
48 | { status: ts('Saving Status Preference...') , success: ts('Preference Saved') }, | |
49 | crmApi('StatusPreference', 'create', { | |
50 | "sequential": 1, | |
51 | "name": status.name, | |
52 | "ignore_severity": status.snoozeOptions.severity, | |
53 | "hush_until": status.snoozeOptions.until | |
54 | }) .then(function(){rmStatus($scope, status.name);}) | |
55 | ); | |
56 | }; | |
57 | $scope.showSnoozeOptions = function(status) { | |
58 | status.snoozeOptions.show = !status.snoozeOptions.show; | |
59 | }; | |
60 | }); | |
61 | ||
62 | ||
63 | /** | |
64 | * remove a status after it has been hushed/snoozed | |
65 | * @param {type} $scope | |
66 | * @param {type} statusName | |
67 | * @returns void | |
68 | */ | |
69 | function rmStatus($scope, statusName) { | |
70 | $scope.statuses.values = _.reject($scope.statuses.values, | |
71 | function(status) { | |
72 | return status.name === statusName; | |
73 | }); | |
74 | } | |
75 | ||
76 | })(angular, CRM.$, CRM._); |