@@ -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,29 @@ 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
+ var cb = ctrl . onProjectSelected ( ) ;
198
+ if ( cb ) {
199
+ cb ( project ) ;
200
+ }
201
+ } ) ;
202
+
195
203
var processedResources ;
196
204
var createResources = function ( ) {
197
205
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
206
+ started : "Creating " + ctrl . templateDisplayName + " in project " + displayName ( ctrl . selectedProject ) ,
207
+ success : "Created " + ctrl . templateDisplayName + " in project " + displayName ( ctrl . selectedProject ) ,
208
+ failure : "Failed to create " + ctrl . templateDisplayName + " in project " + displayName ( ctrl . selectedProject )
201
209
} ;
202
210
var helpLinks = getHelpLinks ( ctrl . template ) ;
203
211
TaskList . clear ( ) ;
204
- TaskList . add ( titles , helpLinks , ctrl . project . metadata . name , function ( ) {
212
+ TaskList . add ( titles , helpLinks , ctrl . selectedProject . metadata . name , function ( ) {
205
213
var d = $q . defer ( ) ;
206
214
DataService . batch ( processedResources , context ) . then (
207
215
function ( result ) {
@@ -235,7 +243,15 @@ function ProcessTemplate($filter,
235
243
) ;
236
244
return d . promise ;
237
245
} ) ;
238
- Navigate . toNextSteps ( ctrl . templateDisplayName , ctrl . project . metadata . name ) ;
246
+
247
+ if ( ctrl . isDialog ) {
248
+ $scope . $emit ( 'templateInstantiated' , {
249
+ project : ctrl . selectedProject ,
250
+ template : ctrl . template
251
+ } ) ;
252
+ } else {
253
+ Navigate . toNextSteps ( ctrl . templateDisplayName , ctrl . selectedProject . metadata . name ) ;
254
+ }
239
255
} ;
240
256
241
257
var launchConfirmationDialog = function ( alerts ) {
@@ -260,7 +276,7 @@ function ProcessTemplate($filter,
260
276
} ;
261
277
262
278
var showWarningsOrCreate = function ( result ) {
263
- var alerts = SecurityCheckService . getSecurityAlerts ( processedResources , ctrl . project . metadata . name ) ;
279
+ var alerts = SecurityCheckService . getSecurityAlerts ( processedResources , ctrl . selectedProject . metadata . name ) ;
264
280
265
281
// Now that all checks are completed, show any Alerts if we need to
266
282
var quotaAlerts = result . quotaAlerts || [ ] ;
@@ -279,36 +295,77 @@ function ProcessTemplate($filter,
279
295
}
280
296
} ;
281
297
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 ;
298
+ var createProjectIfNecessary = function ( ) {
299
+ if ( _ . has ( ctrl . selectedProject , 'metadata.uid' ) ) {
300
+ return $q . when ( ) ;
301
+ }
293
302
294
- QuotaService . getLatestQuotaAlerts ( processedResources , context ) . then ( showWarningsOrCreate ) ;
303
+ var newProjName = ctrl . selectedProject . metadata . name ;
304
+ var newProjDisplayName = ctrl . selectedProject . metadata . annotations [ 'new-display-name' ] ;
305
+ var newProjDesc = $filter ( 'description' ) ( ctrl . selectedProject ) ;
306
+ var projReqObj = {
307
+ apiVersion : "v1" ,
308
+ kind : "ProjectRequest" ,
309
+ metadata : {
310
+ name : newProjName
295
311
} ,
296
- function ( result ) { // failure
297
- ctrl . disableInputs = false ;
298
- var details ;
299
- if ( result . data && result . data . message ) {
300
- details = result . data . message ;
312
+ displayName : newProjDisplayName ,
313
+ description : newProjDesc
314
+ } ;
315
+ return DataService . create ( 'projectrequests' , null , projReqObj , $scope ) ;
316
+ } ;
317
+
318
+ ctrl . createFromTemplate = function ( ) {
319
+ ctrl . disableInputs = true ;
320
+ createProjectIfNecessary ( ) . then ( function ( ) {
321
+ context = {
322
+ namespace : ctrl . selectedProject . metadata . name
323
+ } ;
324
+ var userLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( ctrl . labels ) ) ;
325
+ var systemLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( ctrl . systemLabels ) ) ;
326
+ ctrl . template . labels = _ . extend ( systemLabels , userLabels ) ;
327
+
328
+ DataService . create ( "processedtemplates" , null , ctrl . template , context ) . then (
329
+ function ( config ) { // success
330
+ // Cache template parameters and message so they can be displayed in the nexSteps page
331
+ ProcessedTemplateService . setTemplateData ( config . parameters , ctrl . template . parameters , config . message ) ;
332
+ processedResources = config . objects ;
333
+
334
+ QuotaService . getLatestQuotaAlerts ( processedResources , context ) . then ( showWarningsOrCreate ) ;
335
+ } ,
336
+ function ( result ) { // failure
337
+ ctrl . disableInputs = false ;
338
+ var details ;
339
+ if ( result . data && result . data . message ) {
340
+ details = result . data . message ;
341
+ }
342
+ ctrl . alerts [ "process" ] =
343
+ {
344
+ type : "error" ,
345
+ message : "An error occurred processing the template." ,
346
+ details : details
347
+ } ;
301
348
}
302
- ctrl . alerts [ "process" ] =
303
- {
304
- type : "error" ,
305
- message : "An error occurred processing the template." ,
306
- details : details
307
- } ;
349
+ ) ;
350
+ } , function ( result ) {
351
+ ctrl . disableInputs = false ;
352
+ var details ;
353
+ if ( result . data && result . data . message ) {
354
+ details = result . data . message ;
308
355
}
309
- ) ;
356
+ ctrl . alerts [ "create-project" ] = {
357
+ type : "error" ,
358
+ message : "An error occurred creating the project." ,
359
+ details : details
360
+ } ;
361
+ } ) ;
310
362
} ;
311
363
364
+ // When the process-template component is displayed in a dialog, the create
365
+ // button is outside the component since it is in the wizard footer. Listen
366
+ // for an event for when the button is clicked.
367
+ $scope . $on ( 'instantiateTemplate' , ctrl . createFromTemplate ) ;
368
+
312
369
var shouldAddAppLabel = function ( ) {
313
370
// If the template defines its own app label, we don't need to add one at all
314
371
if ( _ . get ( ctrl . template , 'labels.app' ) ) {
0 commit comments