-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathotherResources.js
176 lines (162 loc) · 5.69 KB
/
otherResources.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
'use strict';
angular.module('openshiftConsole')
.controller('OtherResourcesController', function (
$routeParams,
$location,
$scope,
AuthorizationService,
DataService,
ProjectsService,
$filter,
LabelFilter,
Logger,
APIService) {
$scope.projectName = $routeParams.project;
$scope.labelSuggestions = {};
$scope.kindSelector = {disabled: true};
$scope.kinds = _.filter(APIService.availableKinds(), function(kind) {
switch (kind.kind) {
case "AppliedClusterResourceQuota":
case "Build":
case "BuildConfig":
case "ConfigMap":
case "Deployment":
case "DeploymentConfig":
case "Event":
case "ImageStream":
case "ImageStreamImage":
case "ImageStreamImport":
case "ImageStreamMapping":
case "ImageStreamTag":
case "LimitRange":
case "PersistentVolumeClaim":
case "Pod":
case "ReplicaSet":
case "ReplicationController":
case "ResourceQuota":
case "Route":
case "Secret":
case "Service":
case "ServiceInstance":
case "StatefulSet":
return false;
default:
return true;
}
});
$scope.clearFilter = function () {
LabelFilter.clear();
};
var isListable = function(kind) {
if(!kind) {
return;
}
var rgv = APIService.kindToResourceGroupVersion(kind);
var apiInfo = APIService.apiInfo(rgv);
return apiInfo && apiInfo.verbs ?
_.includes(apiInfo.verbs, 'list') :
// if we don't have apiInfo, default to show the item
// this can happen if the api server is not current
true;
};
$scope.getReturnURL = function() {
var kind = _.get($scope, 'kindSelector.selected.kind');
if (!kind) {
return '';
}
return URI.expand("project/{projectName}/browse/other?kind={kind}&group={group}", {
projectName: $routeParams.project,
kind: kind,
group: _.get($scope, 'kindSelector.selected.group', '')
}).toString();
};
var counts;
$scope.isDuplicateKind = function(kind) {
if(!counts) {
counts = _.countBy($scope.kinds, 'kind');
}
return counts[kind] > 1;
};
var kindExists = function(kind, group) {
return _.some($scope.kinds, function(next) {
if (next.kind !== kind) {
return false;
}
if (!next.group && !group) {
return true;
}
return next.group === group;
});
};
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.kinds = _.filter($scope.kinds, function(kind){
var resourceAndGroup = {
resource: APIService.kindToResource(kind.kind),
group: kind.group || ''
};
if(!isListable(kind)) {
return false;
}
// exclude 'projectrequests', subresources, and REVIEW_RESOURCES from the list
if (AuthorizationService.checkResource(resourceAndGroup.resource)) {
return AuthorizationService.canI(resourceAndGroup, "list", $scope.projectName);
} else {
return false;
}
});
$scope.project = project;
$scope.context = context;
$scope.kindSelector.disabled = false;
// Optional query param to preselect a kind.
if ($routeParams.kind && kindExists($routeParams.kind, $routeParams.group)) {
_.set($scope, 'kindSelector.selected.kind', $routeParams.kind);
_.set($scope, 'kindSelector.selected.group', $routeParams.group || '');
}
}));
function updateFilterMessage() {
$scope.filterWithZeroResults = !LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.resources) && !_.isEmpty($scope.unfilteredResources);
}
function loadKind() {
var selected = $scope.kindSelector.selected;
if (!selected) {
return;
}
var search = $location.search();
search.kind = selected.kind;
search.group = selected.group || '';
$location.replace().search(search);
$scope.selectedResource = {resource: APIService.kindToResource(selected.kind), group: (selected.group || '')};
// TODO - We can't watch because some of these resources do not support it (roles and rolebindings)
DataService.list({
group: selected.group,
resource: APIService.kindToResource(selected.kind)
}, $scope.context).then(function(resources) {
$scope.unfilteredResources = resources.by("metadata.name");
// Clear the suggestions since they'll be different for each resource type
$scope.labelSuggestions = {};
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredResources, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
$scope.resources = LabelFilter.getLabelSelector().select($scope.unfilteredResources);
$scope.resourceName = APIService.kindToResource(selected.kind, true);
updateFilterMessage();
});
}
$scope.loadKind = loadKind;
$scope.$watch("kindSelector.selected", function() {
LabelFilter.clear();
loadKind();
});
var humanizeKind = $filter("humanizeKind");
$scope.matchKind = function(kind, search) {
return humanizeKind(kind).toLowerCase().indexOf(search.toLowerCase()) !== -1;
};
LabelFilter.onActiveFiltersChanged(function(labelSelector) {
// trigger a digest loop
$scope.$evalAsync(function() {
$scope.resources = labelSelector.select($scope.unfilteredResources);
updateFilterMessage();
});
});
});