Commit 1a256eb3 by Jessica Forrester Committed by GitHub

Merge pull request #108 from spadgett/create-project-toasts

Don't show both a toast and in-page alert for create project
parents 672591da 65721be3
...@@ -542,7 +542,6 @@ angular.module("openshiftCommonUI") ...@@ -542,7 +542,6 @@ angular.module("openshiftCommonUI")
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: {
alerts: '=',
redirectAction: '&', redirectAction: '&',
onCancel: '&?', onCancel: '&?',
isDialog: '@' isDialog: '@'
...@@ -555,9 +554,8 @@ angular.module("openshiftCommonUI") ...@@ -555,9 +554,8 @@ angular.module("openshiftCommonUI")
$scope.isDialog = $scope.isDialog === 'true'; $scope.isDialog = $scope.isDialog === 'true';
var showAlert = function(name, alert) { var hideErrorNotifications = function() {
$scope.alerts[name] = alert; NotificationsService.hideNotification('create-project-error');
NotificationsService.addNotification(alert);
}; };
$scope.createProject = function() { $scope.createProject = function() {
...@@ -581,7 +579,7 @@ angular.module("openshiftCommonUI") ...@@ -581,7 +579,7 @@ angular.module("openshiftCommonUI")
} else { } else {
$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create"); $location.path("project/" + encodeURIComponent(data.metadata.name) + "/create");
} }
showAlert('created-project', { NotificationsService.addNotification({
type: "success", type: "success",
message: "Project \'" + displayNameFilter(data) + "\' was successfully created." message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
}); });
...@@ -592,7 +590,11 @@ angular.module("openshiftCommonUI") ...@@ -592,7 +590,11 @@ angular.module("openshiftCommonUI")
$scope.nameTaken = true; $scope.nameTaken = true;
} else { } else {
var msg = data.message || 'An error occurred creating the project.'; var msg = data.message || 'An error occurred creating the project.';
showAlert('error-creating-project', {type: 'error', message: msg}); NotificationsService.addNotification({
id: 'create-project-error',
type: 'error',
message: msg
});
} }
}); });
} }
...@@ -608,6 +610,8 @@ angular.module("openshiftCommonUI") ...@@ -608,6 +610,8 @@ angular.module("openshiftCommonUI")
$window.history.back(); $window.history.back();
} }
}; };
$scope.$on("$destroy", hideErrorNotifications);
}, },
}; };
}); });
......
...@@ -713,7 +713,6 @@ angular.module("openshiftCommonUI") ...@@ -713,7 +713,6 @@ angular.module("openshiftCommonUI")
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: {
alerts: '=',
redirectAction: '&', redirectAction: '&',
onCancel: '&?', onCancel: '&?',
isDialog: '@' isDialog: '@'
...@@ -726,9 +725,8 @@ angular.module("openshiftCommonUI") ...@@ -726,9 +725,8 @@ angular.module("openshiftCommonUI")
$scope.isDialog = $scope.isDialog === 'true'; $scope.isDialog = $scope.isDialog === 'true';
var showAlert = function(name, alert) { var hideErrorNotifications = function() {
$scope.alerts[name] = alert; NotificationsService.hideNotification('create-project-error');
NotificationsService.addNotification(alert);
}; };
$scope.createProject = function() { $scope.createProject = function() {
...@@ -752,7 +750,7 @@ angular.module("openshiftCommonUI") ...@@ -752,7 +750,7 @@ angular.module("openshiftCommonUI")
} else { } else {
$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create"); $location.path("project/" + encodeURIComponent(data.metadata.name) + "/create");
} }
showAlert('created-project', { NotificationsService.addNotification({
type: "success", type: "success",
message: "Project \'" + displayNameFilter(data) + "\' was successfully created." message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
}); });
...@@ -763,7 +761,11 @@ angular.module("openshiftCommonUI") ...@@ -763,7 +761,11 @@ angular.module("openshiftCommonUI")
$scope.nameTaken = true; $scope.nameTaken = true;
} else { } else {
var msg = data.message || 'An error occurred creating the project.'; var msg = data.message || 'An error occurred creating the project.';
showAlert('error-creating-project', {type: 'error', message: msg}); NotificationsService.addNotification({
id: 'create-project-error',
type: 'error',
message: msg
});
} }
}); });
} }
...@@ -779,6 +781,8 @@ angular.module("openshiftCommonUI") ...@@ -779,6 +781,8 @@ angular.module("openshiftCommonUI")
$window.history.back(); $window.history.back();
} }
}; };
$scope.$on("$destroy", hideErrorNotifications);
}], }],
}; };
}]); }]);
......
...@@ -158,7 +158,6 @@ return humanizeKind(object.kind); ...@@ -158,7 +158,6 @@ return humanizeKind(object.kind);
return { return {
restrict:"E", restrict:"E",
scope:{ scope:{
alerts:"=",
redirectAction:"&", redirectAction:"&",
onCancel:"&?", onCancel:"&?",
isDialog:"@" isDialog:"@"
...@@ -166,8 +165,8 @@ isDialog:"@" ...@@ -166,8 +165,8 @@ isDialog:"@"
templateUrl:"src/components/create-project/createProject.html", templateUrl:"src/components/create-project/createProject.html",
controller:[ "$scope", "$filter", "$location", "DataService", "NotificationsService", "displayNameFilter", function($scope, $filter, $location, DataService, NotificationsService, displayNameFilter) { controller:[ "$scope", "$filter", "$location", "DataService", "NotificationsService", "displayNameFilter", function($scope, $filter, $location, DataService, NotificationsService, displayNameFilter) {
$scope.submitButtonLabel || ($scope.submitButtonLabel = "Create"), $scope.isDialog = "true" === $scope.isDialog; $scope.submitButtonLabel || ($scope.submitButtonLabel = "Create"), $scope.isDialog = "true" === $scope.isDialog;
var showAlert = function(name, alert) { var hideErrorNotifications = function() {
$scope.alerts[name] = alert, NotificationsService.addNotification(alert); NotificationsService.hideNotification("create-project-error");
}; };
$scope.createProject = function() { $scope.createProject = function() {
$scope.disableInputs = !0, $scope.createProjectForm.$valid && DataService.create("projectrequests", null, { $scope.disableInputs = !0, $scope.createProjectForm.$valid && DataService.create("projectrequests", null, {
...@@ -180,7 +179,7 @@ displayName:$scope.displayName, ...@@ -180,7 +179,7 @@ displayName:$scope.displayName,
description:$scope.description description:$scope.description
}, $scope).then(function(data) { }, $scope).then(function(data) {
var cb = $scope.redirectAction(); var cb = $scope.redirectAction();
cb ? cb(encodeURIComponent(data.metadata.name)) :$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create"), showAlert("created-project", { cb ? cb(encodeURIComponent(data.metadata.name)) :$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create"), NotificationsService.addNotification({
type:"success", type:"success",
message:"Project '" + displayNameFilter(data) + "' was successfully created." message:"Project '" + displayNameFilter(data) + "' was successfully created."
}); });
...@@ -189,7 +188,8 @@ $scope.disableInputs = !1; ...@@ -189,7 +188,8 @@ $scope.disableInputs = !1;
var data = result.data || {}; var data = result.data || {};
if ("AlreadyExists" === data.reason) $scope.nameTaken = !0; else { if ("AlreadyExists" === data.reason) $scope.nameTaken = !0; else {
var msg = data.message || "An error occurred creating the project."; var msg = data.message || "An error occurred creating the project.";
showAlert("error-creating-project", { NotificationsService.addNotification({
id:"create-project-error",
type:"error", type:"error",
message:msg message:msg
}); });
...@@ -200,7 +200,7 @@ if ($scope.onCancel) { ...@@ -200,7 +200,7 @@ if ($scope.onCancel) {
var cb = $scope.onCancel(); var cb = $scope.onCancel();
cb && cb(); cb && cb();
} else $window.history.back(); } else $window.history.back();
}; }, $scope.$on("$destroy", hideErrorNotifications);
} ] } ]
}; };
} ]), angular.module("openshiftCommonUI").directive("deleteProject", [ "$uibModal", "$location", "$filter", "$q", "hashSizeFilter", "APIService", "DataService", "NotificationsService", "Logger", function($uibModal, $location, $filter, $q, hashSizeFilter, APIService, DataService, NotificationsService, Logger) { } ]), angular.module("openshiftCommonUI").directive("deleteProject", [ "$uibModal", "$location", "$filter", "$q", "hashSizeFilter", "APIService", "DataService", "NotificationsService", "Logger", function($uibModal, $location, $filter, $q, hashSizeFilter, APIService, DataService, NotificationsService, Logger) {
......
...@@ -6,7 +6,6 @@ angular.module("openshiftCommonUI") ...@@ -6,7 +6,6 @@ angular.module("openshiftCommonUI")
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: {
alerts: '=',
redirectAction: '&', redirectAction: '&',
onCancel: '&?', onCancel: '&?',
isDialog: '@' isDialog: '@'
...@@ -19,9 +18,8 @@ angular.module("openshiftCommonUI") ...@@ -19,9 +18,8 @@ angular.module("openshiftCommonUI")
$scope.isDialog = $scope.isDialog === 'true'; $scope.isDialog = $scope.isDialog === 'true';
var showAlert = function(name, alert) { var hideErrorNotifications = function() {
$scope.alerts[name] = alert; NotificationsService.hideNotification('create-project-error');
NotificationsService.addNotification(alert);
}; };
$scope.createProject = function() { $scope.createProject = function() {
...@@ -45,7 +43,7 @@ angular.module("openshiftCommonUI") ...@@ -45,7 +43,7 @@ angular.module("openshiftCommonUI")
} else { } else {
$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create"); $location.path("project/" + encodeURIComponent(data.metadata.name) + "/create");
} }
showAlert('created-project', { NotificationsService.addNotification({
type: "success", type: "success",
message: "Project \'" + displayNameFilter(data) + "\' was successfully created." message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
}); });
...@@ -56,7 +54,11 @@ angular.module("openshiftCommonUI") ...@@ -56,7 +54,11 @@ angular.module("openshiftCommonUI")
$scope.nameTaken = true; $scope.nameTaken = true;
} else { } else {
var msg = data.message || 'An error occurred creating the project.'; var msg = data.message || 'An error occurred creating the project.';
showAlert('error-creating-project', {type: 'error', message: msg}); NotificationsService.addNotification({
id: 'create-project-error',
type: 'error',
message: msg
});
} }
}); });
} }
...@@ -72,6 +74,8 @@ angular.module("openshiftCommonUI") ...@@ -72,6 +74,8 @@ angular.module("openshiftCommonUI")
$window.history.back(); $window.history.back();
} }
}; };
$scope.$on("$destroy", hideErrorNotifications);
}, },
}; };
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment