Skip to content

Commit 8bde33d

Browse files
committed
Show toast notifications in create from builder flow
1 parent a33749d commit 8bde33d

File tree

4 files changed

+153
-138
lines changed

4 files changed

+153
-138
lines changed

app/scripts/controllers/create/createFromImage.js

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
"use strict";
22

33
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) {
2728
var displayNameFilter = $filter('displayName');
2829
var humanize = $filter('humanize');
2930

@@ -60,20 +61,21 @@ angular.module("openshiftConsole")
6061
title: breadcrumbTitle
6162
}
6263
];
63-
$scope.alerts = {};
64-
$scope.quotaAlerts = {};
6564

6665
var appLabel = {name: 'app', value: ''};
6766

6867
var orderByDisplayName = $filter('orderByDisplayName');
6968
var getErrorDetails = $filter('getErrorDetails');
7069

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+
});
7779
};
7880

7981
ProjectsService
@@ -174,7 +176,12 @@ angular.module("openshiftConsole")
174176
return;
175177
}
176178

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+
});
178185
});
179186

180187
DataService.list("secrets", context, null, { errorNotification: false }).then(function(secretData) {
@@ -191,7 +198,12 @@ angular.module("openshiftConsole")
191198
return;
192199
}
193200

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+
});
195207
});
196208

197209
DataService.get("imagestreams", scope.imageName, {namespace: (scope.namespace || $routeParams.project)}).then(function(imageStream){
@@ -279,7 +291,7 @@ angular.module("openshiftConsole")
279291
var helpLinks = {};
280292

281293
TaskList.clear();
282-
TaskList.add(titles, helpLinks, $routeParams.project, function(){
294+
TaskList.add(titles, helpLinks, $routeParams.project, function() {
283295
var d = $q.defer();
284296
DataService.batch(generatedResources, context)
285297
//refactor these helpers to be common for 'newfromtemplate'
@@ -313,16 +325,7 @@ angular.module("openshiftConsole")
313325
}
314326
);
315327
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+
});
326329
Navigate.toNextSteps($scope.name, $scope.projectName, {
327330
usingSampleRepo: $scope.usingSampleRepo(),
328331
breadcrumbTitle: breadcrumbTitle
@@ -351,12 +354,16 @@ angular.module("openshiftConsole")
351354
};
352355

353356
var showWarningsOrCreate = function(result){
357+
// Hide any previous notifications.
358+
hideErrorNotifications();
354359
// 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' })) {
358362
$scope.disableInputs = false;
359-
$scope.quotaAlerts = quotaAlerts;
363+
_.each(quotaAlerts, function(alert) {
364+
alert.id = _.uniqueId('create-builder-alert-');
365+
NotificationsService.addNotification(alert);
366+
});
360367
}
361368
else if (!_.isEmpty(quotaAlerts)) {
362369
launchConfirmationDialog(quotaAlerts);
@@ -373,7 +380,7 @@ angular.module("openshiftConsole")
373380

374381
$scope.createApp = function(){
375382
$scope.disableInputs = true;
376-
$scope.alerts = {};
383+
hideErrorNotifications();
377384
$scope.buildConfig.envVars = keyValueEditorUtils.compactEntries($scope.buildConfigEnvVars);
378385
$scope.deploymentConfig.envVars = keyValueEditorUtils.compactEntries($scope.DCEnvVarsFromUser);
379386
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.userDefinedLabels));
@@ -401,4 +408,9 @@ angular.module("openshiftConsole")
401408
nameTakenPromise.then(setNameTaken, setNameTaken).then(showWarningsOrCreate, showWarningsOrCreate);
402409
};
403410
}));
411+
412+
$scope.cancel = function() {
413+
hideErrorNotifications();
414+
Navigate.toProjectOverview($scope.projectName);
415+
};
404416
});

app/views/create/fromimage.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,13 @@ <h3>Environment Variables <span class="appended-icon">(Runtime only) <span class
411411
<a href="" ng-click="advancedOptions = !advancedOptions" role="button">advanced options</a>
412412
for source, routes, builds, and deployments.
413413
</div>
414-
<alerts alerts="quotaAlerts"></alerts>
415414
<div class="buttons gutter-bottom" ng-class="{'gutter-top': !alerts.length}">
416415
<!-- unable to use form.valid. need to fix validators in labels and key values directive -->
417416
<button type="submit"
418417
class="btn btn-primary btn-lg"
419418
ng-disabled="form.$invalid || nameTaken || cpuProblems.length || memoryProblems.length || disableInputs"
420419
>Create</button>
421-
<a class="btn btn-default btn-lg" ng-href="{{projectName | projectOverviewURL}}">Cancel</a>
420+
<a class="btn btn-default btn-lg" href="" ng-click="cancel()" role="button">Cancel</a>
422421
</div>
423422
</form>
424423
</fieldset>

0 commit comments

Comments
 (0)