Skip to content

Commit

Permalink
Merge pull request #1678 from spadgett/process-template-toasts
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Jun 12, 2017
2 parents cdf2198 + def2450 commit a33749d
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 107 deletions.
21 changes: 7 additions & 14 deletions app/scripts/controllers/newfromtemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ angular.module('openshiftConsole')
$parse,
$routeParams,
$scope,
AlertMessageService,
CachedTemplateService,
DataService,
Navigate,
NotificationsService,
ProjectsService) {
var name = $routeParams.template;

Expand All @@ -34,9 +34,6 @@ angular.module('openshiftConsole')
return;
}

$scope.alerts = {};
$scope.precheckAlerts = {};

$scope.breadcrumbs = [
{
title: $routeParams.project,
Expand All @@ -55,25 +52,21 @@ angular.module('openshiftConsole')
}
];

$scope.alerts = $scope.alerts || {};
AlertMessageService.getAlerts().forEach(function(alert) {
$scope.alerts[alert.name] = alert.data;
});
AlertMessageService.clearAlerts();

var displayName = $filter('displayName');
var getValidTemplateParamsMap = function() {
try {
return JSON.parse($routeParams.templateParamsMap);
} catch (e) {
$scope.alerts.invalidTemplateParams = {
NotificationsService.addNotification({
id: "template-params-invalid-json",
type: "error",
message: "The templateParamsMap is not valid JSON. " + e
};
message: "Could not prefill parameter values.",
details: "The `templateParamsMap` URL parameter is not valid JSON. " + e
});
}
};

if($routeParams.templateParamsMap) {
if ($routeParams.templateParamsMap) {
$scope.prefillParameters = getValidTemplateParamsMap();
}

Expand Down
47 changes: 36 additions & 11 deletions app/scripts/directives/processTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ angular.module('openshiftConsole').component('processTemplate', {
'$uibModal',
'DataService',
'Navigate',
'NotificationsService',
'ProcessedTemplateService',
'QuotaService',
'SecurityCheckService',
Expand All @@ -19,7 +20,6 @@ angular.module('openshiftConsole').component('processTemplate', {
bindings: {
template: '<',
project: '<',
alerts: '<',
prefillParameters: '<',
isDialog: '<'
},
Expand All @@ -32,6 +32,7 @@ function ProcessTemplate($filter,
$uibModal,
DataService,
Navigate,
NotificationsService,
ProcessedTemplateService,
QuotaService,
SecurityCheckService,
Expand Down Expand Up @@ -152,16 +153,32 @@ function ProcessTemplate($filter,
modalInstance.result.then(createResources);
};

var alerts = {};
var hideNotificationErrors = function() {
NotificationsService.hideNotification("process-template-error");
_.each(alerts, function(alert) {
if (alert.id && (alert.type === 'error' || alert.type === 'warning')) {
NotificationsService.hideNotification(alert.id);
}
});
};

var showWarningsOrCreate = function(result) {
var alerts = SecurityCheckService.getSecurityAlerts(processedResources, ctrl.selectedProject.metadata.name);
// Hide any previous notifications when form is resubmitted.
hideNotificationErrors();

alerts = SecurityCheckService.getSecurityAlerts(processedResources, ctrl.selectedProject.metadata.name);

// Now that all checks are completed, show any Alerts if we need to
var quotaAlerts = result.quotaAlerts || [];
alerts = alerts.concat(quotaAlerts);
var errorAlerts = _.filter(alerts, {type: 'error'});
if (errorAlerts.length) {
ctrl.disableInputs = false;
ctrl.precheckAlerts = alerts;
_.each(alerts, function(alert) {
alert.id = _.uniqueId('process-template-alert-');
NotificationsService.addNotification(alert);
});
}
else if (alerts.length) {
launchConfirmationDialog(alerts);
Expand Down Expand Up @@ -217,12 +234,12 @@ function ProcessTemplate($filter,
if (result.data && result.data.message) {
details = result.data.message;
}
ctrl.alerts["process"] =
{
type: "error",
message: "An error occurred processing the template.",
details: details
};
NotificationsService.addNotification({
id: "process-template-error",
type: "error",
message: "An error occurred processing the template.",
details: details
});
}
);
}, function(result) {
Expand All @@ -231,18 +248,26 @@ function ProcessTemplate($filter,
if (result.data && result.data.message) {
details = result.data.message;
}
ctrl.alerts["create-project"] = {
NotificationsService.addNotification({
id: "process-template-error",
type: "error",
message: "An error occurred creating the project.",
details: details
};
});
});
};

// Only called when not in a dialog.
ctrl.cancel = function() {
hideNotificationErrors();
Navigate.toProjectOverview(ctrl.project.metadata.name);
};

// When the process-template component is displayed in a dialog, the create
// button is outside the component since it is in the wizard footer. Listen
// for an event for when the button is clicked.
$scope.$on('instantiateTemplate', ctrl.createFromTemplate);
$scope.$on('hideTemplateNotificationErrors', hideNotificationErrors);

var shouldAddAppLabel = function() {
// If the template defines its own app label, we don't need to add one at all
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/directives/processTemplateDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@


ctrl.$onInit = function() {
ctrl.alerts = {};
ctrl.loginBaseUrl = DataService.openshiftAPIBaseUrl();
};

Expand Down Expand Up @@ -80,6 +79,8 @@
};

ctrl.close = function() {
$scope.$broadcast('hideTemplateNotificationErrors');

var cb = ctrl.onDialogClosed();
if (_.isFunction(cb)) {
cb();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div class="osc-form">
<alerts alerts="$ctrl.alerts"></alerts>
<form name="$ctrl.form">
<process-template template="$ctrl.template" alerts="$ctrl.alerts" is-dialog="true"></process-template>
<process-template template="$ctrl.template" is-dialog="true"></process-template>
</form>
</div>
3 changes: 1 addition & 2 deletions app/views/directives/process-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
can-toggle="false"
help-text="Each label is applied to each created resource.">
</label-editor>
<alerts alerts="$ctrl.precheckAlerts"></alerts>
<div ng-if="!$ctrl.isDialog" class="buttons gutter-top-bottom">
<button class="btn btn-primary btn-lg" ng-click="$ctrl.createFromTemplate()" ng-disabled="$ctrl.templateForm.$invalid || $ctrl.disableInputs">Create</button>
<a class="btn btn-default btn-lg" ng-href="{{$ctrl.project | projectOverviewURL}}">Cancel</a>
<a class="btn btn-default btn-lg" href="" ng-click="$ctrl.cancel()" role="button">Cancel</a>
</div>
</ng-form>
</fieldset>
2 changes: 0 additions & 2 deletions app/views/newfromtemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Loading...
</div>
<div ng-if="template" class="row osc-form">
<alerts alerts="alerts"></alerts>
<div class="col-md-2 icon hidden-sm hidden-xs">
<custom-icon resource="template" kind="template"></custom-icon>
</div>
Expand All @@ -43,7 +42,6 @@ <h2>Images</h2>
<process-template
project="project"
template="template"
alerts="alerts"
prefill-parameters="prefillParameters">
</process-template>
</div>
Expand Down
Loading

0 comments on commit a33749d

Please sign in to comment.