forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildConfig.js
274 lines (252 loc) · 10.8 KB
/
buildConfig.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
'use strict';
/**
* @ngdoc function
* @name openshiftConsole.controller:BuildConfigController
* @description
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('BuildConfigController', function ($scope,
$filter,
$routeParams,
AlertMessageService,
APIService,
BuildsService,
ImagesService,
DataService,
LabelFilter,
ProjectsService,
keyValueEditorUtils) {
$scope.projectName = $routeParams.project;
$scope.buildConfigName = $routeParams.buildconfig;
$scope.buildConfig = null;
$scope.labelSuggestions = {};
$scope.alerts = {};
$scope.breadcrumbs = [];
$scope.forms = {};
$scope.expand = {imageEnv: false};
if ($routeParams.isPipeline) {
$scope.breadcrumbs.push({
title: "Pipelines",
link: "project/" + $routeParams.project + "/browse/pipelines"
});
} else {
$scope.breadcrumbs.push({
title: "Builds",
link: "project/" + $routeParams.project + "/browse/builds"
});
}
$scope.breadcrumbs.push({
title: $routeParams.buildconfig
});
$scope.emptyMessage = "Loading...";
AlertMessageService.getAlerts().forEach(function(alert) {
$scope.alerts[alert.name] = alert.data;
});
AlertMessageService.clearAlerts();
$scope.aceLoaded = function(editor) {
var session = editor.getSession();
session.setOption('tabSize', 2);
session.setOption('useSoftTabs', true);
editor.$blockScrolling = Infinity;
};
var orderByDate = $filter('orderObjectsByDate');
var buildConfigForBuild = $filter('buildConfigForBuild');
var buildStrategy = $filter('buildStrategy');
var watches = [];
var requestContext;
// copy buildConfig and ensure it has env so that we can edit env vars using key-value-editor
var copyBuildConfigAndEnsureEnv = function(buildConfig) {
$scope.updatedBuildConfig = angular.copy(buildConfig);
$scope.envVars = buildStrategy($scope.updatedBuildConfig).env || [];
// check valueFrom attribs and set an alt text for display if present
_.each($scope.envVars, function(env) {
$filter('altTextForValueFrom')(env);
});
};
$scope.saveEnvVars = function() {
$scope.envVars = _.filter($scope.envVars, 'name');
buildStrategy($scope.updatedBuildConfig).env = keyValueEditorUtils.compactEntries(angular.copy($scope.envVars));
DataService
.update("buildconfigs", $routeParams.buildconfig, $scope.updatedBuildConfig, requestContext)
.then(function success(){
// TODO: de-duplicate success and error messages.
// as it stands, multiple messages appear based on how edit
// is made.
$scope.alerts['saveBCEnvVarsSuccess'] = {
type: "success",
// TODO: improve success alert
message: $scope.buildConfigName + " was updated."
};
$scope.forms.bcEnvVars.$setPristine();
}, function error(e){
$scope.alerts['saveBCEnvVarsError'] = {
type: "error",
message: $scope.buildConfigName + " was not updated.",
details: "Reason: " + $filter('getErrorDetails')(e)
};
});
};
$scope.clearEnvVarUpdates = function() {
copyBuildConfigAndEnsureEnv($scope.buildConfig);
$scope.forms.bcEnvVars.$setPristine();
};
var lastLoadedBuildFromImageKey;
var buildConfigResolved = function(buildConfig, action) {
$scope.loaded = true;
$scope.buildConfig = buildConfig;
$scope.buildConfigPaused = BuildsService.isPaused($scope.buildConfig);
if ($scope.buildConfig.spec.source.images) {
$scope.imageSources = $scope.buildConfig.spec.source.images;
$scope.imageSourcesPaths = [];
$scope.imageSources.forEach(function(imageSource) {
$scope.imageSourcesPaths.push($filter('destinationSourcePair')(imageSource.paths));
});
}
var buildFrom = _.get(buildStrategy(buildConfig), 'from', {});
// We don't want to reload the image every time the BC updates, only load again if the from changes
var buildFromImageKey = buildFrom.kind + "/" + buildFrom.name + "/" + (buildFrom.namespace || $scope.projectName);
if (lastLoadedBuildFromImageKey !== buildFromImageKey) {
if (_.includes(["ImageStreamTag", "ImageStreamImage"], buildFrom.kind)) {
lastLoadedBuildFromImageKey = buildFromImageKey;
DataService.get(APIService.kindToResource(buildFrom.kind), buildFrom.name, {namespace: buildFrom.namespace || $scope.projectName}, {errorNotification: false}).then(function(imageStreamImage){
$scope.BCEnvVarsFromImage = ImagesService.getEnvironment(imageStreamImage);
}, function() {
// We may not be able to fetch the image info as the end user, don't reveal any errors
$scope.BCEnvVarsFromImage = [];
});
}
else {
$scope.BCEnvVarsFromImage = [];
}
}
copyBuildConfigAndEnsureEnv(buildConfig);
if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
message: "This build configuration has been deleted."
};
$scope.buildConfigDeleted = true;
}
if (!$scope.forms.bcEnvVars || $scope.forms.bcEnvVars.$pristine) {
copyBuildConfigAndEnsureEnv(buildConfig);
} else {
$scope.alerts["background_update"] = {
type: "warning",
message: "This build configuration has been updated in the background. Saving your changes may create a conflict or cause loss of data.",
links: [
{
label: 'Reload environment variables',
onClick: function() {
$scope.clearEnvVarUpdates();
return true;
}
}
]
};
}
$scope.paused = BuildsService.isPaused($scope.buildConfig);
};
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
requestContext = context;
DataService
.get("buildconfigs", $routeParams.buildconfig, context)
.then(function(buildConfig) {
buildConfigResolved(buildConfig);
// If we found the item successfully, watch for changes on it
watches.push(DataService.watchObject("buildconfigs", $routeParams.buildconfig, context, buildConfigResolved));
},
// failure
function(e) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: e.status === 404 ? "This build configuration can not be found, it may have been deleted." : "The build configuration details could not be loaded.",
details: e.status === 404 ? "Any remaining build history for this build will be shown." : "Reason: " + $filter('getErrorDetails')(e)
};
}
);
watches.push(DataService.watch("builds", context, function(builds, action, build) {
$scope.emptyMessage = "No builds to show";
if (!action) {
$scope.unfilteredBuilds = BuildsService.validatedBuildsForBuildConfig($routeParams.buildconfig, builds.by('metadata.name'));
} else {
var buildConfigName = buildConfigForBuild(build);
if (buildConfigName === $routeParams.buildconfig) {
var buildName = build.metadata.name;
switch (action) {
case 'ADDED':
case 'MODIFIED':
$scope.unfilteredBuilds[buildName] = build;
break;
case 'DELETED':
delete $scope.unfilteredBuilds[buildName];
break;
}
}
}
$scope.builds = LabelFilter.getLabelSelector().select($scope.unfilteredBuilds);
updateFilterWarning();
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredBuilds, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
// Sort now to avoid sorting on every digest loop.
$scope.orderedBuilds = orderByDate($scope.builds, true);
$scope.latestBuild = $scope.orderedBuilds.length ? $scope.orderedBuilds[0] : null;
},
// params object for filtering
{
// http is passed to underlying $http calls
http: {
params: {
// because build config names can be > 63 chars but label values can't
// and we can't do a fieldSelector on annotations. Plus old builds dont have the annotation.
labelSelector: $filter('labelName')('buildConfig') + '=' + _.trunc($scope.buildConfigName, {length: 63, omission: ''})
}
}
}));
function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.builds) && !$.isEmptyObject($scope.unfilteredBuilds)) {
$scope.alerts["builds"] = {
type: "warning",
details: "The active filters are hiding all builds."
};
}
else {
delete $scope.alerts["builds"];
}
}
LabelFilter.onActiveFiltersChanged(function(labelSelector) {
// trigger a digest loop
$scope.$apply(function() {
$scope.builds = labelSelector.select($scope.unfilteredBuilds);
$scope.orderedBuilds = orderByDate($scope.builds, true);
$scope.latestBuild = $scope.orderedBuilds.length ? $scope.orderedBuilds[0] : null;
updateFilterWarning();
});
});
$scope.startBuild = function() {
BuildsService
.startBuild($scope.buildConfig.metadata.name, context)
.then(function resolve(build) {
// TODO: common alerts service to eliminate duplication
$scope.alerts["create"] = {
type: "success",
message: "Build " + build.metadata.name + " has started."
};
}, function reject(result) {
// TODO: common alerts service to eliminate duplication
$scope.alerts["create"] = {
type: "error",
message: "An error occurred while starting the build.",
details: $filter('getErrorDetails')(result)
};
});
};
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});