/
unbindService.js
115 lines (100 loc) · 3.03 KB
/
unbindService.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
(function() {
angular.module('openshiftConsole').component('unbindService', {
controller: [
'$scope',
'$filter',
'DataService',
UnbindService
],
controllerAs: 'ctrl',
bindings: {
target: '<',
bindings: '<',
applicationsByBinding: '<',
onClose: '<'
},
templateUrl: 'views/directives/unbind-service.html'
});
function UnbindService($scope, $filter, DataService) {
var ctrl = this;
var validityWatcher;
var context;
var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');
var unbindService = function() {
var bindingName = ctrl.selectedBinding.metadata.name;
// Make sure to get the unbound apps now. Otherwise they don't appear on
// the result page since deleting the binding will remove them from the
// map that is passed in.
ctrl.unboundApps = ctrl.appsForBinding(bindingName);
DataService.delete({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstancecredentials'
},
bindingName,
context,
{ propagationPolicy: null })
.then(_.noop, function(err) {
ctrl.error = err;
});
};
var setupValidator = function() {
var firstStep = _.head(ctrl.steps);
firstStep.valid = false;
// TODO: auto-select if one option is kludgy. will follow-on a fix
// if(_.size(ctrl.bindings) === 1) {
// firstStep.valid = true;
// ctrl.selectedBinding = _.head(ctrl.bindings);
// } else {
validityWatcher = $scope.$watch("ctrl.selectedBinding", function(selectedBinding) {
firstStep.valid = !!selectedBinding;
});
// }
};
var tearDownValidator = function() {
if(validityWatcher) {
validityWatcher();
validityWatcher = undefined;
}
};
var showDeleteForm = function() {
ctrl.nextTitle = 'Delete';
setupValidator();
};
var showResults = function() {
ctrl.nextTitle = 'Close';
ctrl.wizardComplete = true;
unbindService();
tearDownValidator();
};
ctrl.$onInit = function() {
var formStepLabel = (ctrl.target.kind === 'ServiceInstance') ? 'Applications' : 'Services';
ctrl.displayName = serviceInstanceDisplayName(ctrl.target);
ctrl.steps = [{
id: 'deleteForm',
label: formStepLabel,
view: 'views/directives/bind-service/delete-binding-select-form.html',
onShow: showDeleteForm
}, {
id: 'results',
label: 'Results',
view: 'views/directives/bind-service/delete-binding-result.html',
onShow: showResults
}];
context = {
namespace: _.get(ctrl.target, 'metadata.namespace')
};
};
ctrl.appsForBinding = function(bindingName) {
return _.get(ctrl.applicationsByBinding, bindingName);
};
ctrl.closeWizard = function() {
if (_.isFunction(ctrl.onClose)) {
ctrl.onClose();
}
};
ctrl.$onDestroy = function() {
tearDownValidator();
};
}
})();