forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditProbe.js
76 lines (66 loc) · 2.23 KB
/
editProbe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";
angular.module('openshiftConsole')
.directive('editProbe', function() {
return {
restrict: 'E',
scope: {
probe: '=',
exposedPorts: '='
},
templateUrl: 'views/directives/_edit-probe.html',
link: function(scope) {
scope.id = _.uniqueId('edit-probe-');
scope.probe = scope.probe || {};
// Map of previous probes by type so switching to a different type and
// back remembers the previous values.
scope.previousProbes = {};
// Only allow selecting TCP ports for HTTP and TCP socket checks.
scope.tcpPorts = _.filter(scope.exposedPorts, { protocol: "TCP" });
var updateSelectedType = function(newType, oldType) {
scope.probe = scope.probe || {};
// Remember the values entered for `oldType`.
scope.previousProbes[oldType] = scope.probe[oldType];
delete scope.probe[oldType];
// Use previous values when switching back to `newType` if found.
scope.probe[newType] = scope.previousProbes[newType];
// If no previous values, set the defaults.
if (!scope.probe[newType]) {
switch (newType) {
case 'httpGet':
case 'tcpSocket':
var firstPort = _.head(scope.tcpPorts);
scope.probe[newType] = {
port: firstPort ? firstPort.containerPort : ''
};
break;
case 'exec':
scope.probe = {
exec: {
command: []
}
};
break;
}
}
};
// Initialize type from existing data.
if (scope.probe.httpGet) {
scope.type = 'httpGet';
} else if (scope.probe.exec) {
scope.type = 'exec';
} else if (scope.probe.tcpSocket) {
scope.type = 'tcpSocket';
} else {
// Set defaults for new probe.
scope.type = 'httpGet';
updateSelectedType('httpGet');
}
scope.$watch('type', function(newType, oldType) {
if (newType === oldType) {
return;
}
updateSelectedType(newType, oldType);
});
}
};
});