@@ -21,7 +21,9 @@ angular.module('openshiftConsole').component('processTemplate', {
21
21
template : '<' ,
22
22
project : '<' ,
23
23
alerts : '<' ,
24
- prefillParameters : '<'
24
+ prefillParameters : '<' ,
25
+ isDialog : '<' ,
26
+ onProjectSelected : '&'
25
27
} ,
26
28
templateUrl : 'views/directives/process-template.html'
27
29
} ) ;
@@ -41,7 +43,6 @@ function ProcessTemplate($filter,
41
43
var ctrl = this ;
42
44
43
45
var context ;
44
- var projectDisplayName ;
45
46
46
47
var dcContainers = $parse ( 'spec.template.spec.containers' ) ;
47
48
var builderImage = $parse ( 'spec.strategy.sourceStrategy.from || spec.strategy.dockerStrategy.from || spec.strategy.customStrategy.from' ) ;
@@ -129,16 +130,17 @@ function ProcessTemplate($filter,
129
130
images = [ ] ;
130
131
var dcImages = [ ] ;
131
132
var outputImages = { } ;
133
+ var namespace = _ . get ( ctrl , 'selectedProject.metadata.name' ) ;
132
134
angular . forEach ( data . objects , function ( item ) {
133
135
if ( item . kind === "BuildConfig" ) {
134
- var builder = imageObjectRef ( builderImage ( item ) , ctrl . project . metadata . name ) ;
136
+ var builder = imageObjectRef ( builderImage ( item ) , namespace ) ;
135
137
if ( builder ) {
136
138
images . push ( {
137
139
name : builder ,
138
140
usesParameters : getParametersInImage ( builder )
139
141
} ) ;
140
142
}
141
- var output = imageObjectRef ( outputImage ( item ) , ctrl . project . metadata . name ) ;
143
+ var output = imageObjectRef ( outputImage ( item ) , namespace ) ;
142
144
if ( output ) {
143
145
outputImages [ output ] = true ;
144
146
}
@@ -185,23 +187,26 @@ function ProcessTemplate($filter,
185
187
ctrl . $onInit = function ( ) {
186
188
ctrl . labels = [ ] ;
187
189
ctrl . templateDisplayName = displayName ( ctrl . template ) ;
188
- context = {
189
- namespace : ctrl . project . metadata . name
190
- } ;
191
- projectDisplayName = displayName ( ctrl . project ) ;
190
+ ctrl . selectedProject = ctrl . project ;
192
191
setTemplateParams ( ) ;
193
192
} ;
194
193
194
+ $scope . $watch ( function ( ) {
195
+ return ctrl . selectedProject ;
196
+ } , function ( project ) {
197
+ ctrl . onProjectSelected ( { project : project } ) ;
198
+ } ) ;
199
+
195
200
var processedResources ;
196
201
var createResources = function ( ) {
197
202
var titles = {
198
- started : "Creating " + ctrl . templateDisplayName + " in project " + projectDisplayName ,
199
- success : "Created " + ctrl . templateDisplayName + " in project " + projectDisplayName ,
200
- failure : "Failed to create " + ctrl . templateDisplayName + " in project " + projectDisplayName
203
+ started : "Creating " + ctrl . templateDisplayName + " in project " + displayName ( ctrl . selectedProject ) ,
204
+ success : "Created " + ctrl . templateDisplayName + " in project " + displayName ( ctrl . selectedProject ) ,
205
+ failure : "Failed to create " + ctrl . templateDisplayName + " in project " + displayName ( ctrl . selectedProject )
201
206
} ;
202
207
var helpLinks = getHelpLinks ( ctrl . template ) ;
203
208
TaskList . clear ( ) ;
204
- TaskList . add ( titles , helpLinks , ctrl . project . metadata . name , function ( ) {
209
+ TaskList . add ( titles , helpLinks , ctrl . selectedProject . metadata . name , function ( ) {
205
210
var d = $q . defer ( ) ;
206
211
DataService . batch ( processedResources , context ) . then (
207
212
function ( result ) {
@@ -235,7 +240,9 @@ function ProcessTemplate($filter,
235
240
) ;
236
241
return d . promise ;
237
242
} ) ;
238
- Navigate . toNextSteps ( ctrl . templateDisplayName , ctrl . project . metadata . name ) ;
243
+ if ( ! ctrl . isDialog ) {
244
+ Navigate . toNextSteps ( ctrl . templateDisplayName , ctrl . selectedProject . metadata . name ) ;
245
+ }
239
246
} ;
240
247
241
248
var launchConfirmationDialog = function ( alerts ) {
@@ -260,7 +267,7 @@ function ProcessTemplate($filter,
260
267
} ;
261
268
262
269
var showWarningsOrCreate = function ( result ) {
263
- var alerts = SecurityCheckService . getSecurityAlerts ( processedResources , ctrl . project . metadata . name ) ;
270
+ var alerts = SecurityCheckService . getSecurityAlerts ( processedResources , ctrl . selectedProject . metadata . name ) ;
264
271
265
272
// Now that all checks are completed, show any Alerts if we need to
266
273
var quotaAlerts = result . quotaAlerts || [ ] ;
@@ -279,36 +286,77 @@ function ProcessTemplate($filter,
279
286
}
280
287
} ;
281
288
282
- ctrl . createFromTemplate = function ( ) {
283
- ctrl . disableInputs = true ;
284
- var userLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( ctrl . labels ) ) ;
285
- var systemLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( ctrl . systemLabels ) ) ;
286
- ctrl . template . labels = _ . extend ( systemLabels , userLabels ) ;
287
-
288
- DataService . create ( "processedtemplates" , null , ctrl . template , context ) . then (
289
- function ( config ) { // success
290
- // Cache template parameters and message so they can be displayed in the nexSteps page
291
- ProcessedTemplateService . setTemplateData ( config . parameters , ctrl . template . parameters , config . message ) ;
292
- processedResources = config . objects ;
289
+ var createProjectIfNecessary = function ( ) {
290
+ if ( _ . has ( ctrl . selectedProject , 'metadata.uid' ) ) {
291
+ return $q . when ( ) ;
292
+ }
293
293
294
- QuotaService . getLatestQuotaAlerts ( processedResources , context ) . then ( showWarningsOrCreate ) ;
294
+ var newProjName = ctrl . selectedProject . metadata . name ;
295
+ var newProjDisplayName = ctrl . selectedProject . metadata . annotations [ 'new-display-name' ] ;
296
+ var newProjDesc = $filter ( 'description' ) ( ctrl . selectedProject ) ;
297
+ var projReqObj = {
298
+ apiVersion : "v1" ,
299
+ kind : "ProjectRequest" ,
300
+ metadata : {
301
+ name : newProjName
295
302
} ,
296
- function ( result ) { // failure
297
- ctrl . disableInputs = false ;
298
- var details ;
299
- if ( result . data && result . data . message ) {
300
- details = result . data . message ;
303
+ displayName : newProjDisplayName ,
304
+ description : newProjDesc
305
+ } ;
306
+ return DataService . create ( 'projectrequests' , null , projReqObj , $scope ) ;
307
+ } ;
308
+
309
+ ctrl . createFromTemplate = function ( ) {
310
+ ctrl . disableInputs = true ;
311
+ createProjectIfNecessary ( ) . then ( function ( ) {
312
+ context = {
313
+ namespace : ctrl . selectedProject . metadata . name
314
+ } ;
315
+ var userLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( ctrl . labels ) ) ;
316
+ var systemLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( ctrl . systemLabels ) ) ;
317
+ ctrl . template . labels = _ . extend ( systemLabels , userLabels ) ;
318
+
319
+ DataService . create ( "processedtemplates" , null , ctrl . template , context ) . then (
320
+ function ( config ) { // success
321
+ // Cache template parameters and message so they can be displayed in the nexSteps page
322
+ ProcessedTemplateService . setTemplateData ( config . parameters , ctrl . template . parameters , config . message ) ;
323
+ processedResources = config . objects ;
324
+
325
+ QuotaService . getLatestQuotaAlerts ( processedResources , context ) . then ( showWarningsOrCreate ) ;
326
+ } ,
327
+ function ( result ) { // failure
328
+ ctrl . disableInputs = false ;
329
+ var details ;
330
+ if ( result . data && result . data . message ) {
331
+ details = result . data . message ;
332
+ }
333
+ ctrl . alerts [ "process" ] =
334
+ {
335
+ type : "error" ,
336
+ message : "An error occurred processing the template." ,
337
+ details : details
338
+ } ;
301
339
}
302
- ctrl . alerts [ "process" ] =
303
- {
304
- type : "error" ,
305
- message : "An error occurred processing the template." ,
306
- details : details
307
- } ;
340
+ ) ;
341
+ } , function ( result ) {
342
+ ctrl . disableInputs = false ;
343
+ var details ;
344
+ if ( result . data && result . data . message ) {
345
+ details = result . data . message ;
308
346
}
309
- ) ;
347
+ ctrl . alerts [ "create-project" ] = {
348
+ type : "error" ,
349
+ message : "An error occurred creating the project." ,
350
+ details : details
351
+ } ;
352
+ } ) ;
310
353
} ;
311
354
355
+ // When the process-template component is displayed in a dialog, the create
356
+ // button is outside the component since it is in the wizard footer. Listen
357
+ // for an event for when the button is clicked.
358
+ $scope . $on ( 'instantiateTemplate' , ctrl . createFromTemplate ) ;
359
+
312
360
var shouldAddAppLabel = function ( ) {
313
361
// If the template defines its own app label, we don't need to add one at all
314
362
if ( _ . get ( ctrl . template , 'labels.app' ) ) {
0 commit comments