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