forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc.js
137 lines (123 loc) · 5.68 KB
/
dc.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
'use strict';
angular.module('openshiftConsole')
.directive('overviewDeploymentConfig',
function($filter,
$uibModal,
BuildsService,
DeploymentsService,
Navigate) {
return {
restrict: 'E',
// Inherit scope from OverviewController. This directive is only used for the overview.
// We want to do all of the grouping of resources once in the overview controller watch callbacks.
scope: true,
templateUrl: 'views/overview/_dc.html',
link: function($scope) {
var orderByDate = $filter('orderObjectsByDate');
var deploymentIsInProgress = $filter('deploymentIsInProgress');
$scope.$watch('scalableReplicationControllerByDC', function() {
var dcName = _.get($scope, 'deploymentConfig.metadata.name');
$scope.activeReplicationController = _.get($scope, ['scalableReplicationControllerByDC', dcName]);
});
$scope.$watch('visibleRCByDC', function(visibleRCByDC) {
var dcName = _.get($scope, 'deploymentConfig.metadata.name');
var replicationControllers = _.get(visibleRCByDC, [dcName], []);
$scope.orderedReplicationControllers = orderByDate(replicationControllers, true);
$scope.inProgressDeployment = _.find($scope.orderedReplicationControllers, deploymentIsInProgress);
});
$scope.$watch('deploymentConfig', function(deploymentConfig) {
var triggers = _.get(deploymentConfig, 'spec.triggers', []);
$scope.imageChangeTriggers = _.filter(triggers, function(trigger) {
return trigger.type === 'ImageChange' && _.get(trigger, 'imageChangeParams.automatic');
});
});
$scope.urlForImageChangeTrigger = function(imageChangeTrigger) {
var name = $filter('stripTag')(_.get(imageChangeTrigger, 'imageChangeParams.from.name'));
var namespace = _.get(imageChangeTrigger, 'imageChangeParams.from.namespace', $scope.deploymentConfig.metadata.namespace);
return Navigate.resourceURL(name, 'ImageStream', namespace);
};
$scope.startPipeline = function(pipeline) {
BuildsService
.startBuild(pipeline.metadata.name, { namespace: pipeline.metadata.namespace })
.then(_.noop, function(result) {
$scope.alerts["start-pipeline"] = {
type: "error",
message: "An error occurred while starting the pipeline.",
details: $filter('getErrorDetails')(result)
};
});
};
$scope.startDeployment = function() {
DeploymentsService.startLatestDeployment($scope.deploymentConfig, {
namespace: $scope.deploymentConfig.metadata.namespace
}, $scope);
};
var resumePending;
$scope.$watch('deploymentConfig.spec.paused', function() {
resumePending = false;
});
$scope.resumeDeployment = function() {
// Guard against double clicks.
if (resumePending) {
return;
}
resumePending = true;
DeploymentsService.setPaused($scope.deploymentConfig, false, {
namespace: $scope.deploymentConfig.metadata.namespace
}).then(_.noop, function(e) {
resumePending = false;
$scope.alerts["resume-deployment"] = {
type: "error",
message: "An error occurred resuming the deployment.",
details: $filter('getErrorDetails')(e)
};
});
};
$scope.cancelDeployment = function() {
var replicationController = $scope.inProgressDeployment;
if (!replicationController) {
return;
}
var rcName = replicationController.metadata.name;
var latestVersion = _.get($scope, 'deploymentConfig.status.latestVersion');
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/modals/confirm.html',
controller: 'ConfirmModalController',
resolve: {
modalConfig: function() {
return {
message: "Cancel deployment " + rcName + "?",
details: latestVersion ? ("This will attempt to stop the in-progress deployment and rollback to the previous deployment, #" + latestVersion + ". It may take some time to complete.") :
"This will attempt to stop the in-progress deployment and may take some time to complete.",
okButtonText: "Yes, cancel",
okButtonClass: "btn-danger",
cancelButtonText: "No, don't cancel"
};
}
}
});
modalInstance.result.then(function() {
// Make sure we have the latest resource version of the deployment.
var replicationController = _.get($scope, ['replicationControllersByName', rcName]);
if (!replicationController) {
$scope.alerts["cancel-deployment"] = {
type: "error",
message: "Deployment " + rcName + " no longer exists."
};
return;
}
// Make sure it's still running.
if (!deploymentIsInProgress(replicationController)) {
$scope.alerts["cancel-deployment"] = {
type: "error",
message: "Deployment " + rcName + " is no longer in progress."
};
return;
}
DeploymentsService.cancelRunningDeployment(replicationController, $scope.projectContext, $scope);
});
};
}
};
});