forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.js
115 lines (99 loc) · 3.53 KB
/
route.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';
/**
* @ngdoc function
* @name openshiftConsole.controller:ServiceController
* @description
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('RouteController',
function($scope,
$filter,
$routeParams,
AlertMessageService,
DataService,
ProjectsService,
RoutesService) {
$scope.projectName = $routeParams.project;
$scope.route = null;
$scope.alerts = {};
$scope.renderOptions = $scope.renderOptions || {};
$scope.renderOptions.hideFilterWidget = true;
$scope.breadcrumbs = [
{
title: "Routes",
link: "project/" + $routeParams.project + "/browse/routes"
},
{
title: $routeParams.route
}
];
AlertMessageService.getAlerts().forEach(function(alert) {
$scope.alerts[alert.name] = alert.data;
});
AlertMessageService.clearAlerts();
var watches = [];
var isCustomHost;
var routeResolved = function(route, action) {
$scope.loaded = true;
$scope.route = route;
isCustomHost = RoutesService.isCustomHost(route);
if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
message: "This route has been deleted."
};
}
};
// Use an alert key that has the route UID, route host, and router
// hostname. This will handle cases where the route is admitted by
// multiple routers and we have more than one alert.
var routerHostnameAlertKey = function(ingress) {
var uid = _.get($scope, 'route.metadata.uid');
return 'router-host-' + uid + '-' + ingress.host + '-' + ingress.routerCanonicalHostname;
};
// Show the alert for admitted routes that have a custom host if
// routerCanonicalHostname is set.
$scope.showRouterHostnameAlert = function(ingress, admittedCondition) {
if (!isCustomHost) {
return false;
}
if (!ingress || !ingress.host || !ingress.routerCanonicalHostname) {
return false;
}
if (!admittedCondition || admittedCondition.status !== 'True') {
return false;
}
var alertKey = routerHostnameAlertKey(ingress);
return !AlertMessageService.isAlertPermanentlyHidden(alertKey, $scope.projectName);
};
$scope.hideRouterHostnameAlert = function(ingress) {
var alertKey = routerHostnameAlertKey(ingress);
AlertMessageService.permanentlyHideAlert(alertKey, $scope.projectName);
};
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
DataService
.get("routes", $routeParams.route, context)
.then(function(route) {
routeResolved(route);
watches.push(DataService.watchObject("routes", $routeParams.route, context, routeResolved));
}, function(e) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The route details could not be loaded.",
details: "Reason: " + $filter('getErrorDetails')(e)
};
});
// Watch services to display route warnings.
watches.push(DataService.watch("services", context, function(services) {
$scope.services = services.by("metadata.name");
}));
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});