Skip to content

Show toast notifications in create from builder flow #1681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 61 additions & 49 deletions app/scripts/controllers/create/createFromImage.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
"use strict";

angular.module("openshiftConsole")
.controller("CreateFromImageController", function ($scope,
Logger,
$q,
$routeParams,
APIService,
DataService,
ProjectsService,
Navigate,
ApplicationGenerator,
LimitRangesService,
MetricsService,
HPAService,
QuotaService,
SecretsService,
ImagesService,
TaskList,
failureObjectNameFilter,
$filter,
$parse,
$uibModal,
SOURCE_URL_PATTERN,
keyValueEditorUtils
){
.controller("CreateFromImageController",
function($scope,
$filter,
$parse,
$q,
$routeParams,
$uibModal,
APIService,
ApplicationGenerator,
DataService,
HPAService,
ImagesService,
LimitRangesService,
Logger,
MetricsService,
Navigate,
NotificationsService,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only change to dependencies is NotificationsService. But I sorted and reformatted the list.

ProjectsService,
QuotaService,
SOURCE_URL_PATTERN,
SecretsService,
TaskList,
failureObjectNameFilter,
keyValueEditorUtils) {
var displayNameFilter = $filter('displayName');
var humanize = $filter('humanize');

Expand Down Expand Up @@ -60,20 +61,21 @@ angular.module("openshiftConsole")
title: breadcrumbTitle
}
];
$scope.alerts = {};
$scope.quotaAlerts = {};

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

var orderByDisplayName = $filter('orderByDisplayName');
var getErrorDetails = $filter('getErrorDetails');

var displayError = function(errorMessage, errorDetails) {
$scope.alerts['from-value-objects'] = {
type: "error",
message: errorMessage,
details: errorDetails
};
var quotaAlerts = {};
var hideErrorNotifications = function() {
NotificationsService.hideNotification("create-builder-list-config-maps-error");
NotificationsService.hideNotification("create-builder-list-secrets-error");
_.each(quotaAlerts, function(alert) {
if (alert.id && (alert.type === 'error' || alert.type === 'warning')) {
NotificationsService.hideNotification(alert.id);
}
});
};

ProjectsService
Expand Down Expand Up @@ -174,7 +176,12 @@ angular.module("openshiftConsole")
return;
}

displayError('Could not load config maps', getErrorDetails(e));
NotificationsService.addNotification({
id: "create-builder-list-config-maps-error",
type: "error",
message: "Could not load config maps.",
details: getErrorDetails(e)
});
});

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

displayError('Could not load secrets', getErrorDetails(e));
NotificationsService.addNotification({
id: "create-builder-list-secrets-error",
type: "error",
message: "Could not load secrets.",
details: getErrorDetails(e)
});
});

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

TaskList.clear();
TaskList.add(titles, helpLinks, $routeParams.project, function(){
TaskList.add(titles, helpLinks, $routeParams.project, function() {
var d = $q.defer();
DataService.batch(generatedResources, context)
//refactor these helpers to be common for 'newfromtemplate'
Expand Down Expand Up @@ -313,16 +325,7 @@ angular.module("openshiftConsole")
}
);
return d.promise;
},
function(result) { // failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assume DataService.batch was never resulting in a rejected promise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were passing an extra argument to TaskList.add that it doesn't take :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yep didnt have my curly braces matched up right, got it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation and nesting makes it really hard to follow in this file :(

$scope.alerts["create"] =
{
type: "error",
message: "An error occurred creating the application.",
details: "Status: " + result.status + ". " + result.data
};
}
);
});
Navigate.toNextSteps($scope.name, $scope.projectName, {
usingSampleRepo: $scope.usingSampleRepo(),
breadcrumbTitle: breadcrumbTitle
Expand Down Expand Up @@ -351,12 +354,16 @@ angular.module("openshiftConsole")
};

var showWarningsOrCreate = function(result){
// Hide any previous notifications.
hideErrorNotifications();
// Now that all checks are completed, show any Alerts if we need to
var quotaAlerts = result.quotaAlerts || [];
var errorAlerts = _.filter(quotaAlerts, {type: 'error'});
if ($scope.nameTaken || !_.isEmpty(errorAlerts)) {
quotaAlerts = result.quotaAlerts || [];
if ($scope.nameTaken || _.some(quotaAlerts, { type: 'error' })) {
$scope.disableInputs = false;
$scope.quotaAlerts = quotaAlerts;
_.each(quotaAlerts, function(alert) {
alert.id = _.uniqueId('create-builder-alert-');
NotificationsService.addNotification(alert);
});
}
else if (!_.isEmpty(quotaAlerts)) {
launchConfirmationDialog(quotaAlerts);
Expand All @@ -373,7 +380,7 @@ angular.module("openshiftConsole")

$scope.createApp = function(){
$scope.disableInputs = true;
$scope.alerts = {};
hideErrorNotifications();
$scope.buildConfig.envVars = keyValueEditorUtils.compactEntries($scope.buildConfigEnvVars);
$scope.deploymentConfig.envVars = keyValueEditorUtils.compactEntries($scope.DCEnvVarsFromUser);
var userLabels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.userDefinedLabels));
Expand Down Expand Up @@ -401,4 +408,9 @@ angular.module("openshiftConsole")
nameTakenPromise.then(setNameTaken, setNameTaken).then(showWarningsOrCreate, showWarningsOrCreate);
};
}));

$scope.cancel = function() {
hideErrorNotifications();
Navigate.toProjectOverview($scope.projectName);
};
});
3 changes: 1 addition & 2 deletions app/views/create/fromimage.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,13 @@ <h3>Environment Variables <span class="appended-icon">(Runtime only) <span class
<a href="" ng-click="advancedOptions = !advancedOptions" role="button">advanced options</a>
for source, routes, builds, and deployments.
</div>
<alerts alerts="quotaAlerts"></alerts>
<div class="buttons gutter-bottom" ng-class="{'gutter-top': !alerts.length}">
<!-- unable to use form.valid. need to fix validators in labels and key values directive -->
<button type="submit"
class="btn btn-primary btn-lg"
ng-disabled="form.$invalid || nameTaken || cpuProblems.length || memoryProblems.length || disableInputs"
>Create</button>
<a class="btn btn-default btn-lg" ng-href="{{projectName | projectOverviewURL}}">Cancel</a>
<a class="btn btn-default btn-lg" href="" ng-click="cancel()" role="button">Cancel</a>
</div>
</form>
</fieldset>
Expand Down
Loading