-
Notifications
You must be signed in to change notification settings - Fork 231
/
app.js
636 lines (626 loc) · 23.7 KB
/
app.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
'use strict';
/* jshint unused: false */
/**
* @ngdoc overview
* @name openshiftConsole
* @description
* # openshiftConsole
*
* Main module of the application.
*/
angular
.module('openshiftConsole', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'kubernetesUI',
'registryUI.images',
'ui.bootstrap',
'patternfly.charts',
'patternfly.navigation',
'patternfly.sort',
'patternfly.notification',
'openshiftConsoleTemplates',
'ui.ace',
'extension-registry',
'as.sortable',
'ui.select',
'angular-inview',
'angularMoment',
'ab-base64',
'openshiftCommonServices',
'openshiftCommonUI',
'webCatalog'
])
.config(function ($routeProvider, $uibModalProvider, HomePagePreferenceServiceProvider) {
var landingPageRoute;
var projectsPageRoute = {
templateUrl: 'views/projects.html',
controller: 'ProjectsController'
};
if (_.get(window, 'OPENSHIFT_CONSTANTS.DISABLE_SERVICE_CATALOG_LANDING_PAGE')) {
landingPageRoute = projectsPageRoute;
$routeProvider.when('/projects', {
redirectTo: '/'
});
} else {
landingPageRoute = {
templateUrl: 'views/landing-page.html',
controller: 'LandingPageController',
reloadOnSearch: false
};
$routeProvider.when('/projects', projectsPageRoute);
}
$routeProvider
.when('/', {
redirectTo: function() {
return HomePagePreferenceServiceProvider.$get().getHomePagePath();
}
})
.when('/catalog', landingPageRoute)
.when('/create-project', {
templateUrl: 'views/create-project.html',
controller: 'CreateProjectController'
})
.when('/project/:project/catalog', {
templateUrl: 'views/project-browse-catalog.html',
controller: 'ProjectBrowseCatalogController'
})
.when('/project/:project', {
redirectTo: function(params) {
return '/project/' + encodeURIComponent(params.project) + "/overview";
}
})
.when('/project/:project/overview', {
templateUrl: 'views/overview.html',
controller: 'OverviewController',
controllerAs: 'overview',
reloadOnSearch: false
})
.when('/project/:project/quota', {
templateUrl: 'views/quota.html',
controller: 'QuotaController'
})
.when('/project/:project/monitoring', {
templateUrl: 'views/monitoring.html',
controller: 'MonitoringController',
reloadOnSearch: false
})
.when('/project/:project/membership', {
templateUrl: 'views/membership.html',
controller: 'MembershipController',
reloadOnSearch: false
})
.when('/project/:project/browse', {
redirectTo: function(params) {
return '/project/' + encodeURIComponent(params.project) + "/browse/pods"; // TODO decide what subtab to default to here
}
})
.when('/project/:project/browse/builds', {
templateUrl: 'views/builds.html',
controller: 'BuildsController',
reloadOnSearch: false
})
.when('/project/:project/browse/pipelines', {
templateUrl: 'views/pipelines.html',
controller: 'PipelinesController'
})
.when('/project/:project/browse/builds/:buildconfig', {
templateUrl: 'views/browse/build-config.html',
controller: 'BuildConfigController',
reloadOnSearch: false
})
.when('/project/:project/browse/pipelines/:buildconfig', {
templateUrl: 'views/browse/build-config.html',
controller: 'BuildConfigController',
resolve: {
isPipeline: function ($route) {
$route.current.params.isPipeline = true;
}
},
reloadOnSearch: false
})
.when('/project/:project/edit/yaml', {
templateUrl: 'views/edit/yaml.html',
controller: 'EditYAMLController'
})
.when('/project/:project/edit/builds/:buildconfig', {
templateUrl: 'views/edit/build-config.html',
controller: 'EditBuildConfigController'
})
.when('/project/:project/edit/pipelines/:buildconfig', {
templateUrl: 'views/edit/build-config.html',
controller: 'EditBuildConfigController',
resolve: {
isPipeline: function ($route) {
$route.current.params.isPipeline = true;
}
},
reloadOnSearch: false
})
.when('/project/:project/browse/builds/:buildconfig/:build', {
templateUrl: function(params) {
if (params.view === 'chromeless') {
return 'views/logs/chromeless-build-log.html';
}
return 'views/browse/build.html';
},
controller: 'BuildController',
reloadOnSearch: false
})
.when('/project/:project/browse/pipelines/:buildconfig/:build', {
templateUrl: 'views/browse/build.html',
controller: 'BuildController',
resolve: {
isPipeline: function ($route) {
$route.current.params.isPipeline = true;
}
},
reloadOnSearch: false
})
// For when a build is missing a buildconfig label
// Needs to still be prefixed with browse/builds so the secondary nav active state is correct
.when('/project/:project/browse/builds-noconfig/:build', {
templateUrl: 'views/browse/build.html',
controller: 'BuildController',
reloadOnSearch: false
})
.when('/project/:project/browse/pipelines-noconfig/:build', {
templateUrl: 'views/browse/build.html',
controller: 'BuildController',
resolve: {
isPipeline: function ($route) {
$route.current.params.isPipeline = true;
}
},
reloadOnSearch: false
})
.when('/project/:project/browse/deployments', {
templateUrl: 'views/deployments.html',
controller: 'DeploymentsController',
reloadOnSearch: false
})
// Can't be /deployments/ (plural) because we used that previously for deployment config URLs. See redirect below.
.when('/project/:project/browse/deployment/:deployment', {
templateUrl: 'views/browse/deployment.html',
controller: 'DeploymentController',
reloadOnSearch: false
})
.when('/project/:project/browse/dc/:deploymentconfig', {
templateUrl: 'views/browse/deployment-config.html',
controller: 'DeploymentConfigController',
reloadOnSearch: false
})
.when('/project/:project/edit/dc/:deploymentconfig', {
templateUrl: 'views/edit/deployment-config.html',
controller: 'EditDeploymentConfigController'
})
.when('/project/:project/browse/stateful-sets/', {
templateUrl: 'views/browse/stateful-sets.html',
controller: 'StatefulSetsController',
reloadOnSearch: false
})
.when('/project/:project/browse/stateful-sets/:statefulset', {
templateUrl: 'views/browse/stateful-set.html',
controller: 'StatefulSetController',
reloadOnSearch: false
})
.when('/project/:project/browse/rs/:replicaSet', {
templateUrl: 'views/browse/replica-set.html',
resolve: {
// The ReplicaSetController handles both ReplicaSet and ReplicationController.
kind: function () {
return 'ReplicaSet';
}
},
controller: 'ReplicaSetController',
reloadOnSearch: false
})
.when('/project/:project/browse/rc/:replicaSet', {
templateUrl: function(params) {
if (params.view === 'chromeless') {
return 'views/logs/chromeless-deployment-log.html';
}
return 'views/browse/replica-set.html';
},
resolve: {
// The ReplicaSetController handles both ReplicaSet and ReplicationController.
kind: function () {
return 'ReplicationController';
}
},
controller: 'ReplicaSetController',
reloadOnSearch: false
})
.when('/project/:project/browse/events', {
templateUrl: 'views/events.html',
controller: 'EventsController'
})
.when('/project/:project/browse/images', {
templateUrl: 'views/images.html',
controller: 'ImagesController',
reloadOnSearch: false
})
.when('/project/:project/browse/images/:imagestream', {
templateUrl: 'views/browse/imagestream.html',
controller: 'ImageStreamController'
})
.when('/project/:project/browse/images/:imagestream/:tag', {
templateUrl: 'views/browse/image.html',
controller: 'ImageController',
reloadOnSearch: false
})
.when('/project/:project/browse/pods', {
templateUrl: 'views/pods.html',
controller: 'PodsController',
reloadOnSearch: false
})
.when('/project/:project/browse/pods/:pod', {
templateUrl: function(params) {
if (params.view === 'chromeless') {
return 'views/logs/chromeless-pod-log.html';
}
return 'views/browse/pod.html';
},
controller: 'PodController',
reloadOnSearch: false
})
.when('/project/:project/browse/services', {
templateUrl: 'views/services.html',
controller: 'ServicesController',
reloadOnSearch: false
})
.when('/project/:project/browse/services/:service', {
templateUrl: 'views/browse/service.html',
controller: 'ServiceController',
reloadOnSearch: false
})
.when('/project/:project/browse/service-instances', {
templateUrl: 'views/service-instances.html',
controller: 'ServiceInstancesController',
reloadOnSearch: false
})
.when('/project/:project/browse/service-instances/:instance', {
templateUrl: 'views/browse/service-instance.html',
controller: 'ServiceInstanceController',
reloadOnSearch: false
})
.when('/project/:project/browse/storage', {
templateUrl: 'views/storage.html',
controller: 'StorageController',
reloadOnSearch: false
})
.when('/project/:project/browse/secrets/:secret', {
templateUrl: 'views/browse/secret.html',
controller: 'SecretController',
reloadOnSearch: false
})
.when('/project/:project/browse/secrets', {
templateUrl: 'views/secrets.html',
controller: 'SecretsController',
reloadOnSearch: false
})
.when('/project/:project/create-secret', {
templateUrl: 'views/create-secret.html',
controller: 'CreateSecretController'
})
.when('/project/:project/browse/config-maps', {
templateUrl: 'views/browse/config-maps.html',
controller: 'ConfigMapsController',
reloadOnSearch: false
})
.when('/project/:project/browse/config-maps/:configMap', {
templateUrl: 'views/browse/config-map.html',
controller: 'ConfigMapController'
})
.when('/project/:project/create-config-map', {
templateUrl: 'views/create-config-map.html',
controller: 'CreateConfigMapController'
})
.when('/project/:project/edit/config-maps/:configMap', {
templateUrl: 'views/edit/config-map.html',
controller: 'EditConfigMapController'
})
.when('/project/:project/browse/other', {
templateUrl: 'views/other-resources.html',
controller: 'OtherResourcesController',
reloadOnSearch: false
})
.when('/project/:project/browse/persistentvolumeclaims/:pvc', {
templateUrl: 'views/browse/persistent-volume-claim.html',
controller: 'PersistentVolumeClaimController'
})
.when('/project/:project/browse/routes', {
templateUrl: 'views/browse/routes.html',
controller: 'RoutesController',
reloadOnSearch: false
})
.when('/project/:project/edit/routes/:route', {
templateUrl: 'views/edit/route.html',
controller: 'EditRouteController'
})
.when('/project/:project/browse/routes/:route', {
templateUrl: 'views/browse/route.html',
controller: 'RouteController'
})
.when('/project/:project/create-route', {
templateUrl: 'views/create-route.html',
controller: 'CreateRouteController'
})
.when('/project/:project/edit', {
templateUrl: 'views/edit/project.html',
controller: 'EditProjectController'
})
.when('/project/:project/create-pvc', {
templateUrl: 'views/create-persistent-volume-claim.html',
controller: 'CreatePersistentVolumeClaimController'
})
.when('/project/:project/attach-pvc', {
templateUrl: 'views/attach-pvc.html',
controller: 'AttachPVCController'
})
.when('/project/:project/add-config-volume', {
templateUrl: 'views/add-config-volume.html',
controller: 'AddConfigVolumeController'
})
.when('/project/:project/create', {
templateUrl: 'views/create.html',
controller: 'CreateController',
reloadOnSearch: false
})
.when('/project/:project/create/category/:category', {
templateUrl: 'views/create/category.html',
controller: 'BrowseCategoryController'
})
.when('/project/:project/create/category/:category/:subcategory', {
templateUrl: 'views/create/category.html',
controller: 'BrowseCategoryController'
})
.when('/project/:project/create/fromtemplate', {
templateUrl: 'views/newfromtemplate.html',
controller: 'NewFromTemplateController'
})
.when('/project/:project/create/fromimage', {
templateUrl: 'views/create/fromimage.html',
controller: 'CreateFromImageController'
})
.when('/project/:project/create/next', {
templateUrl: 'views/create/next-steps.html',
controller: 'NextStepsController'
})
.when('/project/:project/set-limits', {
templateUrl: 'views/set-limits.html',
controller: 'SetLimitsController'
})
.when('/project/:project/edit/autoscaler', {
templateUrl: 'views/edit/autoscaler.html',
controller: 'EditAutoscalerController'
})
.when('/project/:project/edit/health-checks', {
templateUrl: 'views/edit/health-checks.html',
controller: 'EditHealthChecksController'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutController'
})
.when('/command-line', {
templateUrl: 'views/command-line.html',
controller: 'CommandLineController'
})
.when('/oauth', {
templateUrl: 'views/util/oauth.html',
controller: 'OAuthController'
})
.when('/error', {
templateUrl: 'views/util/error.html',
controller: 'ErrorController'
})
.when('/logout', {
templateUrl: 'views/util/logout.html',
controller: 'LogoutController'
})
.when('/create', {
templateUrl: 'views/create-from-url.html',
controller: 'CreateFromURLController'
})
// legacy redirects
.when('/createProject', {
redirectTo: '/create-project'
})
.when('/project/:project/createRoute', {
redirectTo: '/project/:project/create-route'
})
.when('/project/:project/attachPVC', {
redirectTo: '/project/:project/attach-pvc'
})
.when('/project/:project/browse/deployments/:deploymentconfig', {
redirectTo: '/project/:project/browse/dc/:deploymentconfig'
})
.when('/project/:project/browse/deployments/:deploymentconfig/:rc', {
redirectTo: '/project/:project/browse/rc/:rc'
})
.when('/project/:project/browse/deployments-replicationcontrollers/:rc', {
redirectTo: '/project/:project/browse/rc/:rc'
})
.otherwise({
redirectTo: '/'
});
$uibModalProvider.options = {
animation: true,
backdrop: 'static' // do not allow close of modal by clicking backdrop
};
})
.constant("LOGGING_URL", _.get(window.OPENSHIFT_CONFIG, "loggingURL"))
.constant("METRICS_URL", _.get(window.OPENSHIFT_CONFIG, "metricsURL"))
// A (very) basic regex to determine if a URL is an absolute URL, enough to
// warn the user the Git URL probably won't work. This should only be used
// as a sanity test and shouldn't block submitting the form. Rely on the API
// server for any additional validation.
.constant('SOURCE_URL_PATTERN', /^[a-z][a-z0-9+.-@]*:(\/\/)?[0-9a-z_-]+/i)
// RELATIVE_PATH_PATTERN matches any paths not starting with `/` or
// containing `..` as path elements. Use negative lookaheads to assert that
// the value does not match those patterns.
//
// (?!\/) do not match strings starting with `/`
// (?!\.\.(\/|$)) do not match strings starting with `../` or exactly `..`
// (?!.*\/\.\.(\/|$)) do not match strings containing `/../` or ending in `/..`
.constant('RELATIVE_PATH_PATTERN', /^(?!\/)(?!\.\.(\/|$))(?!.*\/\.\.(\/|$)).*$/)
// http://stackoverflow.com/questions/5899783/detect-safari-using-jquery
.constant('IS_SAFARI', /Version\/[\d\.]+.*Safari/.test(navigator.userAgent))
.constant('amTimeAgoConfig', {
// Set the title attribute to a localized time format like "September 4 1986 8:30 PM"
// See http://momentjs.com/docs/#/displaying/format/
titleFormat: 'LLL'
})
.config(function(kubernetesContainerSocketProvider) {
// Configure the container terminal
kubernetesContainerSocketProvider.WebSocketFactory = "ContainerWebSocket";
})
.config(function($compileProvider){
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|git):/i);
})
.run(function($rootScope, LabelFilter){
// assume we always want filterState persisted, pages that dont can turn it off
LabelFilter.persistFilterState(true);
$rootScope.$on('$routeChangeSuccess', function() {
LabelFilter.readPersistedState();
});
})
.run(function($location, $uibModal, AuthService) {
var INACTIVITY_TIMEOUT_MINUTES = window.OPENSHIFT_CONFIG.inactivityTimeoutMinutes;
if (!INACTIVITY_TIMEOUT_MINUTES) {
return;
}
var lastInteractionKey = 'origin-web-console-last-interaction-timestamp';
var inactivityLogoutKey = 'origin-web-console-inactivity-logout';
var isLocalLogoutModalShown = false;
var checkInteractionInterval;
var modalInstance;
// Interval that will check for user inactivity every minute.
// In case the last interaction is higher than INACTIVITY_TIMEOUT_MINUTES a logout modal will be shown.
// Also check for 'origin-web-console-inactivity-logout' object in the local storage, that indicates that the
// user has been already logged out, in case of multiple opened console tabs.
var startInteractionIntervalCheck = function () {
checkInteractionInterval = setInterval(function(){
if (!AuthService.isLoggedIn()) {
return;
}
var lastInteraction = Date.parse(localStorage.getItem(lastInteractionKey));
if (isNaN(lastInteraction)) {
Logger.warn("Last interaction timestamp has been corrupted. The logout timeout will be restarted.");
lastInteraction = new Date();
}
var currentTime = new Date();
// Since the INACTIVITY_TIMEOUT_MINUTES is set in minutes it needs to be converted into milliseconds.
if (currentTime - lastInteraction > INACTIVITY_TIMEOUT_MINUTES * 60000) {
showLogoutModal();
}
}, 60000);
};
// In case of multiple opened tabs the interval needs to be restarted everytime there is any activity in any tab,
// so all intervals are synced, and they start the counting at the same time.
var restartCheckInteractionInterval = function() {
// Handles cases of user activity during the opened modal, where user clicks inside the modal but not on the buttons.
if (modalInstance) {
modalInstance.dismiss("User activity");
modalInstance = null;
}
clearInterval(checkInteractionInterval);
startInteractionIntervalCheck();
};
// Updates lastInteraction date and restarts interval
// restartCheckInteractionInterval() has to be called, cause because the listener on the `storage` event
// is not fired in the tab where the event happened.
var updateLastInteraction = function() {
restartCheckInteractionInterval();
localStorage.setItem(lastInteractionKey, new Date().toString());
};
// Updates Local Storage variable that indicates if all opened tabs should log out current user.
var logoutAllTabs = function(bool) {
localStorage.setItem(inactivityLogoutKey, bool.toString());
};
// Logout with passing reason.
var logout = function() {
var logoutURI = URI.expand("/logout{?cause*}", {
cause: 'timeout'
});
$location.url(logoutURI.toString());
};
// Show inactivity logout modal.
// Before the the modal is shown the handler for checking the changes in local storage is detached.
// After the the modal is closed or dismissed the handler will be attached again. This is because of
// the fact that the handler is attached
function showLogoutModal() {
if (isLocalLogoutModalShown) {
return false;
}
isLocalLogoutModalShown = true;
modalInstance = $uibModal.open({
templateUrl: 'views/modals/logout.html',
controller: 'LogoutModalController',
backdrop: true
});
modalInstance.result.then(function(event) {
if (event === 'logout') {
logoutAllTabs(true);
logout();
} else if (event === 'cancel') {
// In case of multiple tabs, when the logoutModal would be canceled, the timer has to be restarted.
updateLastInteraction();
isLocalLogoutModalShown = false;
}
}, function () {
updateLastInteraction();
isLocalLogoutModalShown = false;
});
}
// Need to check for changes in last interaction so the interval can be restarted.
$(window).on('storage', function (event) {
if (event.originalEvent.key === lastInteractionKey) {
restartCheckInteractionInterval();
} else if (event.originalEvent.key === inactivityLogoutKey) {
logout();
}
});
// Reset 'origin-web-console-inactivity-logout' key on login.
AuthService.onUserChanged(function() {
logoutAllTabs(false);
});
updateLastInteraction();
// Bind to click and keydown events so the in last interaction timestamp is updated.
$(document).bind("click keydown", _.throttle(updateLastInteraction, 500));
})
.run(function(durationFilter, timeOnlyDurationFromTimestampsFilter, countdownToTimestampFilter) {
// Use setInterval instead of $interval because we're directly manipulating the DOM and don't want scope.$apply overhead
setInterval(function() {
// Set by duration-until-now directive.
$('.duration[data-timestamp]').text(function(i, existing) {
var timestamp = $(this).data("timestamp");
var omitSingle = $(this).data("omit-single");
var precision = $(this).data("precision");
var timeOnly = $(this).data("time-only");
if (timeOnly) {
return timeOnlyDurationFromTimestampsFilter(timestamp, null) || existing;
}
else {
return durationFilter(timestamp, null, omitSingle, precision) || existing;
}
});
$('.countdown[data-timestamp]').text(function(i, existing) {
var endTimestamp = $(this).data("timestamp");
return countdownToTimestampFilter(endTimestamp);
});
}, 1000);
})
.run(function(IS_IOS) {
if (IS_IOS) {
// Add a class for iOS devices. This lets us disable some hover effects
// since iOS will treat the first tap as a hover if it changes the DOM
// content (e.g. using :before pseudo-elements).
$('body').addClass('ios');
}
});
hawtioPluginLoader.addModule('openshiftConsole');