1
1
"use strict" ;
2
2
3
3
angular . module ( "openshiftConsole" )
4
- . controller ( "CreateFromImageController" , function ( $scope ,
5
- Logger ,
6
- $q ,
7
- $routeParams ,
8
- APIService ,
9
- DataService ,
10
- ProjectsService ,
11
- Navigate ,
12
- ApplicationGenerator ,
13
- LimitRangesService ,
14
- MetricsService ,
15
- HPAService ,
16
- QuotaService ,
17
- SecretsService ,
18
- ImagesService ,
19
- TaskList ,
20
- failureObjectNameFilter ,
21
- $filter ,
22
- $parse ,
23
- $uibModal ,
24
- SOURCE_URL_PATTERN ,
25
- keyValueEditorUtils
26
- ) {
4
+ . controller ( "CreateFromImageController" ,
5
+ function ( $scope ,
6
+ $filter ,
7
+ $parse ,
8
+ $q ,
9
+ $routeParams ,
10
+ $uibModal ,
11
+ APIService ,
12
+ ApplicationGenerator ,
13
+ DataService ,
14
+ HPAService ,
15
+ ImagesService ,
16
+ LimitRangesService ,
17
+ Logger ,
18
+ MetricsService ,
19
+ Navigate ,
20
+ NotificationsService ,
21
+ ProjectsService ,
22
+ QuotaService ,
23
+ SOURCE_URL_PATTERN ,
24
+ SecretsService ,
25
+ TaskList ,
26
+ failureObjectNameFilter ,
27
+ keyValueEditorUtils ) {
27
28
var displayNameFilter = $filter ( 'displayName' ) ;
28
29
var humanize = $filter ( 'humanize' ) ;
29
30
@@ -60,20 +61,21 @@ angular.module("openshiftConsole")
60
61
title : breadcrumbTitle
61
62
}
62
63
] ;
63
- $scope . alerts = { } ;
64
- $scope . quotaAlerts = { } ;
65
64
66
65
var appLabel = { name : 'app' , value : '' } ;
67
66
68
67
var orderByDisplayName = $filter ( 'orderByDisplayName' ) ;
69
68
var getErrorDetails = $filter ( 'getErrorDetails' ) ;
70
69
71
- var displayError = function ( errorMessage , errorDetails ) {
72
- $scope . alerts [ 'from-value-objects' ] = {
73
- type : "error" ,
74
- message : errorMessage ,
75
- details : errorDetails
76
- } ;
70
+ var quotaAlerts = { } ;
71
+ var hideErrorNotifications = function ( ) {
72
+ NotificationsService . hideNotification ( "create-builder-list-config-maps-error" ) ;
73
+ NotificationsService . hideNotification ( "create-builder-list-secrets-error" ) ;
74
+ _ . each ( quotaAlerts , function ( alert ) {
75
+ if ( alert . id && ( alert . type === 'error' || alert . type === 'warning' ) ) {
76
+ NotificationsService . hideNotification ( alert . id ) ;
77
+ }
78
+ } ) ;
77
79
} ;
78
80
79
81
ProjectsService
@@ -174,7 +176,12 @@ angular.module("openshiftConsole")
174
176
return ;
175
177
}
176
178
177
- displayError ( 'Could not load config maps' , getErrorDetails ( e ) ) ;
179
+ NotificationsService . addNotification ( {
180
+ id : "create-builder-list-config-maps-error" ,
181
+ type : "error" ,
182
+ message : "Could not load config maps." ,
183
+ details : getErrorDetails ( e )
184
+ } ) ;
178
185
} ) ;
179
186
180
187
DataService . list ( "secrets" , context , null , { errorNotification : false } ) . then ( function ( secretData ) {
@@ -191,7 +198,12 @@ angular.module("openshiftConsole")
191
198
return ;
192
199
}
193
200
194
- displayError ( 'Could not load secrets' , getErrorDetails ( e ) ) ;
201
+ NotificationsService . addNotification ( {
202
+ id : "create-builder-list-secrets-error" ,
203
+ type : "error" ,
204
+ message : "Could not load secrets." ,
205
+ details : getErrorDetails ( e )
206
+ } ) ;
195
207
} ) ;
196
208
197
209
DataService . get ( "imagestreams" , scope . imageName , { namespace : ( scope . namespace || $routeParams . project ) } ) . then ( function ( imageStream ) {
@@ -279,7 +291,7 @@ angular.module("openshiftConsole")
279
291
var helpLinks = { } ;
280
292
281
293
TaskList . clear ( ) ;
282
- TaskList . add ( titles , helpLinks , $routeParams . project , function ( ) {
294
+ TaskList . add ( titles , helpLinks , $routeParams . project , function ( ) {
283
295
var d = $q . defer ( ) ;
284
296
DataService . batch ( generatedResources , context )
285
297
//refactor these helpers to be common for 'newfromtemplate'
@@ -313,16 +325,7 @@ angular.module("openshiftConsole")
313
325
}
314
326
) ;
315
327
return d . promise ;
316
- } ,
317
- function ( result ) { // failure
318
- $scope . alerts [ "create" ] =
319
- {
320
- type : "error" ,
321
- message : "An error occurred creating the application." ,
322
- details : "Status: " + result . status + ". " + result . data
323
- } ;
324
- }
325
- ) ;
328
+ } ) ;
326
329
Navigate . toNextSteps ( $scope . name , $scope . projectName , {
327
330
usingSampleRepo : $scope . usingSampleRepo ( ) ,
328
331
breadcrumbTitle : breadcrumbTitle
@@ -351,12 +354,16 @@ angular.module("openshiftConsole")
351
354
} ;
352
355
353
356
var showWarningsOrCreate = function ( result ) {
357
+ // Hide any previous notifications.
358
+ hideErrorNotifications ( ) ;
354
359
// Now that all checks are completed, show any Alerts if we need to
355
- var quotaAlerts = result . quotaAlerts || [ ] ;
356
- var errorAlerts = _ . filter ( quotaAlerts , { type : 'error' } ) ;
357
- if ( $scope . nameTaken || ! _ . isEmpty ( errorAlerts ) ) {
360
+ quotaAlerts = result . quotaAlerts || [ ] ;
361
+ if ( $scope . nameTaken || _ . some ( quotaAlerts , { type : 'error' } ) ) {
358
362
$scope . disableInputs = false ;
359
- $scope . quotaAlerts = quotaAlerts ;
363
+ _ . each ( quotaAlerts , function ( alert ) {
364
+ alert . id = _ . uniqueId ( 'create-builder-alert-' ) ;
365
+ NotificationsService . addNotification ( alert ) ;
366
+ } ) ;
360
367
}
361
368
else if ( ! _ . isEmpty ( quotaAlerts ) ) {
362
369
launchConfirmationDialog ( quotaAlerts ) ;
@@ -373,7 +380,7 @@ angular.module("openshiftConsole")
373
380
374
381
$scope . createApp = function ( ) {
375
382
$scope . disableInputs = true ;
376
- $scope . alerts = { } ;
383
+ hideErrorNotifications ( ) ;
377
384
$scope . buildConfig . envVars = keyValueEditorUtils . compactEntries ( $scope . buildConfigEnvVars ) ;
378
385
$scope . deploymentConfig . envVars = keyValueEditorUtils . compactEntries ( $scope . DCEnvVarsFromUser ) ;
379
386
var userLabels = keyValueEditorUtils . mapEntries ( keyValueEditorUtils . compactEntries ( $scope . userDefinedLabels ) ) ;
@@ -401,4 +408,9 @@ angular.module("openshiftConsole")
401
408
nameTakenPromise . then ( setNameTaken , setNameTaken ) . then ( showWarningsOrCreate , showWarningsOrCreate ) ;
402
409
} ;
403
410
} ) ) ;
411
+
412
+ $scope . cancel = function ( ) {
413
+ hideErrorNotifications ( ) ;
414
+ Navigate . toProjectOverview ( $scope . projectName ) ;
415
+ } ;
404
416
} ) ;
0 commit comments