forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigate.js
308 lines (280 loc) · 10.2 KB
/
navigate.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
"use strict";
angular.module("openshiftConsole")
.service("Navigate", function($location,
$window,
$timeout,
annotationFilter,
LabelFilter,
$filter,
APIService){
var annotation = $filter('annotation');
var buildConfigForBuild = $filter('buildConfigForBuild');
var isPipeline = $filter('isJenkinsPipelineStrategy');
// Get the type segment for build URLs. `resource` can be a build or build config.
var getBuildURLType = function(resource, opts) {
if (_.get(opts, 'isPipeline')) {
return "pipelines";
}
if (_.isObject(resource) && isPipeline(resource)) {
// Use "pipelines" instead of "builds" in the URL so the right nav item is highlighted
// for pipeline builds.
return "pipelines";
}
return "builds";
};
return {
/**
* Navigate and display the error page.
*
* @param {type} message The message to display to the user
* @param {type} errorCode An optional error code to display
* @returns {undefined}
*/
toErrorPage: function(message, errorCode, reload) {
var redirect = URI('error').query({
error_description: message,
error: errorCode
}).toString();
if (!reload) {
// Use replace() to avoid breaking the browser back button.
$location.url(redirect).replace();
}
else {
$window.location.href = redirect;
}
},
/**
* Navigate and display the project overview page.
*
* @param {type} projectName the project name
* @returns {undefined}
*/
toProjectOverview: function(projectName){
$location.path(this.projectOverviewURL(projectName));
},
/**
* Return the URL for the project overview
*
* @param {type} projectName
* @returns {String} a URL string for the project overview
*/
projectOverviewURL: function(projectName){
return "project/" + encodeURIComponent(projectName) + "/overview";
},
/**
* Return the URL for the fromTemplate page for the picked template
*
* @param {String} projectName Project name
* @param {String} name Template name
* @param {String} namespace Namespace from which the Template should be loaded
* @returns {String} a URL string for the fromTemplate page. If the namespace is not set
* read the template from TemplateService.
*/
fromTemplateURL: function(projectName, name, namespace){
namespace = namespace || "";
return "project/" + encodeURIComponent(projectName) + "/create/fromtemplate?name=" + name + "&namespace=" + namespace;
},
/**
* Navigate and display the next steps after creation page.
*
* @param {type} projectName the project name
* @returns {undefined}
*/
toNextSteps: function(name, projectName, searchPart){
var search = $location.search();
search.name = name;
if (_.isObject(searchPart)) {
_.extend(search, searchPart);
}
$location.path("project/" + encodeURIComponent(projectName) + "/create/next").search(search);
},
toPodsForDeployment: function(deployment) {
$location.url("/project/" + deployment.metadata.namespace + "/browse/pods");
$timeout(function() {
LabelFilter.setLabelSelector(new LabelSelector(deployment.spec.selector, true));
}, 1);
},
// Resource is either a resource object, or a name. If resource is a name, kind and namespace must be specified
// Note that builds and deployments can only have their URL built correctly (including their config in the URL)
// if resource is an object, otherwise they will fall back to the non-nested URL.
//
// `opts` is for additional options. Currently only `opts.isPipeline` is supported for building URLs with a
// pipeline path segment.
resourceURL: function(resource, kind, namespace, action, opts) {
action = action || "browse";
if (!resource || (!resource.metadata && (!kind || !namespace))) {
return null;
}
// normalize based on the kind of args we got
if (!kind) {
kind = resource.kind;
}
if (!namespace) {
namespace = resource.metadata.namespace;
}
var name = resource;
if (resource.metadata) {
name = resource.metadata.name;
}
var url = URI("")
.segment("project")
.segmentCoded(namespace)
.segment(action);
switch(kind) {
case "Build":
var buildConfigName = $filter('buildConfigForBuild')(resource);
var typeSegment = getBuildURLType(resource, opts);
if (buildConfigName) {
url.segment(typeSegment)
.segmentCoded(buildConfigName)
.segmentCoded(name);
}
else {
url.segment(typeSegment + "-noconfig")
.segmentCoded(name);
}
break;
case "BuildConfig":
url.segment(getBuildURLType(resource, opts))
.segmentCoded(name);
break;
case "ConfigMap":
url.segment('config-maps')
.segmentCoded(name);
break;
case "Deployment":
url.segment("deployment")
.segmentCoded(name);
break;
case "DeploymentConfig":
url.segment("dc")
.segmentCoded(name);
break;
case "ReplicaSet":
url.segment("rs")
.segmentCoded(name);
break;
case "ReplicationController":
url.segment("rc")
.segmentCoded(name);
break;
case "ImageStream":
url.segment("images")
.segmentCoded(name);
break;
case "PersistentVolumeClaim":
case "Pod":
case "Route":
case "Secret":
case "Service":
url.segment(APIService.kindToResource(kind))
.segmentCoded(name);
break;
default:
var rgv;
if (resource.metadata) {
rgv = APIService.objectToResourceGroupVersion(resource);
}
else if (_.get(opts, "apiVersion")) {
var r = APIService.kindToResource(kind);
var gv = APIService.parseGroupVersion(opts.apiVersion);
gv.resource = r;
rgv = APIService.toResourceGroupVersion(gv);
}
else {
rgv = APIService.toResourceGroupVersion(APIService.kindToResource(kind));
}
var apiInfo = APIService.apiInfo(rgv);
if (!apiInfo) {
// This is not an API object we know about from discovery
// We won't be able to navigate to it in Other Resources
return null;
}
url.segment("other")
.search({
kind: kind,
group: rgv.group
});
}
return url.toString();
},
// Returns the build config URL for a build or the deployment config URL for a deployment.
configURLForResource: function(resource, /* optional */ action) {
var bc, dc,
kind = _.get(resource, 'kind'),
namespace = _.get(resource, 'metadata.namespace');
if (!kind || !namespace) {
return null;
}
switch (kind) {
case 'Build':
bc = buildConfigForBuild(resource);
if (!bc) {
return null;
}
return this.resourceURL(bc, 'BuildConfig', namespace, action, {
isPipeline: isPipeline(resource)
});
case 'ReplicationController':
dc = annotation(resource, 'deploymentConfig');
if (!dc) {
return null;
}
return this.resourceURL(dc, 'DeploymentConfig', namespace, action);
}
return null;
},
resourceListURL: function(resource, projectName) {
var routeMap = {
'builds': 'builds',
'buildconfigs': 'builds',
'configmaps': 'config-maps',
'deployments': 'deployments',
'deploymentconfigs': 'deployments',
'imagestreams': 'images',
'pods': 'pods',
'replicasets': 'deployments',
'replicationcontrollers': 'deployments',
'routes': 'routes',
'secrets': 'secrets',
'services': 'services',
'persistentvolumeclaims': 'storage'
};
return URI.expand("project/{projectName}/browse/{browsePath}", {
projectName: projectName,
browsePath: routeMap[resource]
}).toString();
},
/**
* Navigate to a list view for a resource type
*
* @param {String} resource the resource (e.g., builds or replicationcontrollers)
* @param {String} projectName the project name
* @returns {undefined}
*/
toResourceList: function(resource, projectName) {
$location.url(this.resourceListURL(resource, projectName));
},
yamlURL: function(object, returnURL) {
if (!object) {
return '';
}
var groupVersion = APIService.parseGroupVersion(object.apiVersion);
return URI.expand("project/{projectName}/edit/yaml?kind={kind}&name={name}&group={group}&returnURL={returnURL}", {
projectName: object.metadata.namespace,
kind: object.kind,
name: object.metadata.name,
group: groupVersion.group || '',
returnURL: returnURL || ''
}).toString();
},
healthCheckURL: function(projectName, kind, name, group) {
return URI.expand("project/{projectName}/edit/health-checks?kind={kind}&name={name}&group={group}", {
projectName: projectName,
kind: kind,
name: name,
group: group || ''
}).toString();
}
};
});