forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceInstances.js
98 lines (83 loc) · 3.7 KB
/
serviceInstances.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
'use strict';
angular.module('openshiftConsole')
.controller('ServiceInstancesController', function ($scope,
$filter,
$routeParams,
APIService,
BindingService,
Constants,
DataService,
LabelFilter,
Logger,
ProjectsService) {
$scope.alerts = {};
$scope.bindingsByInstanceRef = {};
$scope.emptyMessage = "Loading...";
$scope.labelSuggestions = {};
$scope.projectName = $routeParams.project;
$scope.serviceClasses = {};
$scope.serviceInstances = {};
$scope.unfilteredServiceInstances = {};
var watches = [];
var updateFilter = function() {
$scope.serviceInstances = LabelFilter.getLabelSelector().select($scope.unfilteredServiceInstances);
};
var sortServiceInstances = function() {
$scope.unfilteredServiceInstances = BindingService.sortServiceInstances($scope.unfilteredServiceInstances, $scope.serviceClasses);
};
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
$scope.projectContext = context;
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstancecredentials'
}, context, function(bindings) {
var bindingsByName = bindings.by('metadata.name');
$scope.bindingsByInstanceRef = _.groupBy(bindingsByName, 'spec.instanceRef.name');
}));
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'serviceinstances'
}, context, function(serviceInstances) {
$scope.emptyMessage = "No provisioned services to show";
$scope.unfilteredServiceInstances = serviceInstances.by('metadata.name');
sortServiceInstances();
updateFilter();
updateFilterWarning();
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredServiceInstances, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
Logger.log("provisioned services (subscribe)", $scope.unfilteredServiceInstances);
}));
DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, {}, function(serviceClasses) {
$scope.serviceClasses = serviceClasses.by('metadata.name');
sortServiceInstances();
updateFilter();
});
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.serviceInstances) && !_.isEmpty($scope.unfilteredServiceInstances)) {
$scope.alerts["all-instances-filtered"] = {
type: "warning",
details: "The active filters are hiding all provisioned services."
};
}
else {
delete $scope.alerts["all-instances-filtered"];
}
}
LabelFilter.onActiveFiltersChanged(function(labelSelector) {
// trigger a digest loop
$scope.$evalAsync(function() {
$scope.serviceInstances = labelSelector.select($scope.unfilteredServiceInstances);
updateFilterWarning();
});
});
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});