@@ -19,7 +19,6 @@ angular.module("openshiftConsole")
19
19
restrict : 'E' ,
20
20
scope : {
21
21
project : '=' ,
22
- context : '=' ,
23
22
isDialog : '='
24
23
} ,
25
24
templateUrl : 'views/directives/deploy-image.html' ,
@@ -28,6 +27,10 @@ angular.module("openshiftConsole")
28
27
$scope . forms = { } ;
29
28
} ,
30
29
link : function ( $scope ) {
30
+ $scope . input = {
31
+ selectedProject : $scope . project
32
+ } ;
33
+
31
34
// Pick from an image stream tag or Docker image name.
32
35
$scope . mode = "istag" ; // "istag" or "dockerImage"
33
36
@@ -40,7 +43,6 @@ angular.module("openshiftConsole")
40
43
name : 'app' ,
41
44
value : ''
42
45
} ] ;
43
- $scope . pullSecrets = [ { name : '' } ] ;
44
46
45
47
var orderByDisplayName = $filter ( 'orderByDisplayName' ) ;
46
48
var getErrorDetails = $filter ( 'getErrorDetails' ) ;
@@ -56,48 +58,18 @@ angular.module("openshiftConsole")
56
58
} ) ;
57
59
} ;
58
60
59
- var configMapDataOrdered = [ ] ;
60
- var secretDataOrdered = [ ] ;
61
- var context = { namespace : $scope . project . metadata . name } ;
62
- $scope . valueFromObjects = [ ] ;
63
-
64
- DataService . list ( "configmaps" , context , null , { errorNotification : false } ) . then ( function ( configMapData ) {
65
- configMapDataOrdered = orderByDisplayName ( configMapData . by ( "metadata.name" ) ) ;
66
- $scope . valueFromObjects = configMapDataOrdered . concat ( secretDataOrdered ) ;
67
- } , function ( e ) {
68
- if ( e . code === 403 ) {
69
- return ;
70
- }
61
+ $scope . valueFromNamespace = { } ;
71
62
72
- NotificationsService . addAlert ( {
73
- id : "deploy-image-list-config-maps-error" ,
74
- type : "error" ,
75
- message : "Could not load config maps." ,
76
- details : getErrorDetails ( e )
77
- } ) ;
78
- } ) ;
79
-
80
- DataService . list ( "secrets" , context , null , { errorNotification : false } ) . then ( function ( secretData ) {
81
- secretDataOrdered = orderByDisplayName ( secretData . by ( "metadata.name" ) ) ;
82
- $scope . valueFromObjects = secretDataOrdered . concat ( configMapDataOrdered ) ;
83
- var secretsByType = SecretsService . groupSecretsByType ( secretData ) ;
84
- var secretNamesByType = _ . mapValues ( secretsByType , function ( secretData ) { return _ . map ( secretData , 'metadata.name' ) ; } ) ;
85
- // Add empty option to the image/source secrets
86
- $scope . secretsByType = _ . each ( secretNamesByType , function ( secretsArray ) {
87
- secretsArray . unshift ( "" ) ;
88
- } ) ;
89
- } , function ( e ) {
90
- if ( e . code === 403 ) {
91
- return ;
63
+ var createProjectIfNecessary = function ( ) {
64
+ if ( _ . has ( $scope . input . selectedProject , 'metadata.uid' ) ) {
65
+ return $q . when ( $scope . input . selectedProject ) ;
92
66
}
93
67
94
- NotificationsService . addAlert ( {
95
- id : "deploy-image-list-secrets-error" ,
96
- type : "error" ,
97
- message : "Could not load secrets." ,
98
- details : getErrorDetails ( e )
99
- } ) ;
100
- } ) ;
68
+ var newProjName = $scope . input . selectedProject . metadata . name ;
69
+ var newProjDisplayName = $scope . input . selectedProject . metadata . annotations [ 'new-display-name' ] ;
70
+ var newProjDesc = $filter ( 'description' ) ( $scope . input . selectedProject ) ;
71
+ return ProjectsService . create ( newProjName , newProjDisplayName , newProjDesc ) ;
72
+ } ;
101
73
102
74
var stripTag = $filter ( 'stripTag' ) ;
103
75
var stripSHA = $filter ( 'stripSHA' ) ;
@@ -135,14 +107,13 @@ angular.module("openshiftConsole")
135
107
ports : $scope . ports ,
136
108
volumes : $scope . volumes ,
137
109
env : keyValueEditorUtils . compactEntries ( $scope . env ) ,
138
- labels : labels ,
139
- pullSecrets : $scope . pullSecrets
110
+ labels : labels
140
111
} ) ;
141
112
}
142
113
143
114
$scope . findImage = function ( ) {
144
115
$scope . loading = true ;
145
- ImagesService . findImage ( $scope . imageName , $scope . context )
116
+ ImagesService . findImage ( $scope . imageName , { namespace : $scope . input . selectedProject . metadata . name } )
146
117
. then (
147
118
// success
148
119
function ( response ) {
@@ -242,18 +213,68 @@ angular.module("openshiftConsole")
242
213
} ) ;
243
214
} , true ) ;
244
215
216
+ $scope . $watch ( 'input.selectedProject' , function ( project ) {
217
+ // clear any existing valueFrom env to avoid invalid data
218
+ $scope . env = _ . reject ( $scope . env , 'valueFrom' ) ;
219
+
220
+ // if the project doesn't have metadata.uid, that means project creation is occurring
221
+ if ( ! ( _ . get ( project , 'metadata.uid' ) ) ) {
222
+ // image search requires a project, so ensure $scope.mode is set to 'istag'
223
+ $scope . mode = "istag" ;
224
+ return ;
225
+ }
226
+ if ( $scope . valueFromNamespace [ project . metadata . name ] ) {
227
+ // if we already have the data, return early
228
+ return ;
229
+ }
230
+ var configMapDataOrdered = [ ] ;
231
+ var secretDataOrdered = [ ] ;
232
+
233
+ DataService . list ( "configmaps" , { namespace : $scope . input . selectedProject . metadata . name } , null , { errorNotification : false } ) . then ( function ( configMapData ) {
234
+ configMapDataOrdered = orderByDisplayName ( configMapData . by ( "metadata.name" ) ) ;
235
+ $scope . valueFromNamespace [ project . metadata . name ] = configMapDataOrdered . concat ( secretDataOrdered ) ;
236
+ } , function ( e ) {
237
+ if ( e . code === 403 ) {
238
+ return ;
239
+ }
240
+
241
+ NotificationsService . addNotification ( {
242
+ id : "deploy-image-list-config-maps-error" ,
243
+ type : "error" ,
244
+ message : "Could not load config maps." ,
245
+ details : getErrorDetails ( e )
246
+ } ) ;
247
+ } ) ;
248
+
249
+ DataService . list ( "secrets" , { namespace : $scope . input . selectedProject . metadata . name } , null , { errorNotification : false } ) . then ( function ( secretData ) {
250
+ secretDataOrdered = orderByDisplayName ( secretData . by ( "metadata.name" ) ) ;
251
+ $scope . valueFromNamespace [ project . metadata . name ] = secretDataOrdered . concat ( configMapDataOrdered ) ;
252
+ } , function ( e ) {
253
+ if ( e . code === 403 ) {
254
+ return ;
255
+ }
256
+
257
+ NotificationsService . addNotification ( {
258
+ id : "deploy-image-list-secrets-error" ,
259
+ type : "error" ,
260
+ message : "Could not load secrets." ,
261
+ details : getErrorDetails ( e )
262
+ } ) ;
263
+ } ) ;
264
+ } ) ;
265
+
245
266
var displayName = $filter ( 'displayName' ) ;
246
267
var generatedResources ;
247
268
var createResources = function ( ) {
248
269
var titles = {
249
- started : "Deploying image " + $scope . app . name + " to project " + displayName ( $scope . project ) ,
250
- success : "Deployed image " + $scope . app . name + " to project " + displayName ( $scope . project ) ,
251
- failure : "Failed to deploy image " + $scope . app . name + " to project " + displayName ( $scope . project )
270
+ started : "Deploying image " + $scope . app . name + " to project " + displayName ( $scope . input . selectedProject ) ,
271
+ success : "Deployed image " + $scope . app . name + " to project " + displayName ( $scope . input . selectedProject ) ,
272
+ failure : "Failed to deploy image " + $scope . app . name + " to project " + displayName ( $scope . input . selectedProject )
252
273
} ;
253
274
TaskList . clear ( ) ;
254
- TaskList . add ( titles , { } , $scope . project . metadata . name , function ( ) {
275
+ TaskList . add ( titles , { } , $scope . input . selectedProject . metadata . name , function ( ) {
255
276
var d = $q . defer ( ) ;
256
- DataService . batch ( generatedResources , $scope . context ) . then ( function ( result ) {
277
+ DataService . batch ( generatedResources , { namespace : $scope . input . selectedProject . metadata . name } ) . then ( function ( result ) {
257
278
var alerts , hasErrors = ! _ . isEmpty ( result . failure ) ;
258
279
if ( hasErrors ) {
259
280
// Show failure alerts.
@@ -286,11 +307,11 @@ angular.module("openshiftConsole")
286
307
287
308
if ( $scope . isDialog ) {
288
309
$scope . $emit ( 'deployImageNewAppCreated' , {
289
- project : $scope . project ,
310
+ project : $scope . input . selectedProject ,
290
311
appName : $scope . app . name
291
312
} ) ;
292
313
} else {
293
- Navigate . toNextSteps ( $scope . app . name , $scope . project . metadata . name ) ;
314
+ Navigate . toNextSteps ( $scope . app . name , $scope . input . selectedProject . metadata . name ) ;
294
315
}
295
316
} ;
296
317
@@ -338,17 +359,28 @@ angular.module("openshiftConsole")
338
359
$scope . create = function ( ) {
339
360
$scope . disableInputs = true ;
340
361
hideErrorNotifications ( ) ;
341
- generatedResources = getResources ( ) ;
342
-
343
- var nameTakenPromise = ApplicationGenerator . ifResourcesDontExist ( generatedResources , $scope . project . metadata . name ) ;
344
- var checkQuotaPromise = QuotaService . getLatestQuotaAlerts ( generatedResources , $scope . context ) ;
345
- // Don't want to wait for the name checks to finish before making the calls to quota
346
- // so kick off the requests above and then chain the promises here
347
- var setNameTaken = function ( result ) {
348
- $scope . nameTaken = result . nameTaken ;
349
- return checkQuotaPromise ;
350
- } ;
351
- nameTakenPromise . then ( setNameTaken , setNameTaken ) . then ( showWarningsOrCreate , showWarningsOrCreate ) ;
362
+ createProjectIfNecessary ( ) . then ( function ( project ) {
363
+ $scope . input . selectedProject = project ;
364
+ generatedResources = getResources ( ) ;
365
+
366
+ var nameTakenPromise = ApplicationGenerator . ifResourcesDontExist ( generatedResources , $scope . input . selectedProject . metadata . name ) ;
367
+ var checkQuotaPromise = QuotaService . getLatestQuotaAlerts ( generatedResources , { namespace : $scope . input . selectedProject . metadata . name } ) ;
368
+ // Don't want to wait for the name checks to finish before making the calls to quota
369
+ // so kick off the requests above and then chain the promises here
370
+ var setNameTaken = function ( result ) {
371
+ $scope . nameTaken = result . nameTaken ;
372
+ return checkQuotaPromise ;
373
+ } ;
374
+ nameTakenPromise . then ( setNameTaken , setNameTaken ) . then ( showWarningsOrCreate , showWarningsOrCreate ) ;
375
+ } , function ( e ) {
376
+ NotificationsService . addNotification ( {
377
+ id : "deploy-image-create-project-error" ,
378
+ type : "error" ,
379
+ message : "An error occurred creating project" ,
380
+ details : getErrorDetails ( e )
381
+ } ) ;
382
+ $scope . disableInputs = false ;
383
+ } ) ;
352
384
} ;
353
385
354
386
// When the deploy-image component is displayed in a dialog, the create
0 commit comments