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")
return {
restrict: 'E',
scope: {
alerts: '=',
redirectAction: '&',
onCancel: '&?',
isDialog: '@'
......@@ -555,9 +554,8 @@ angular.module("openshiftCommonUI")
$scope.isDialog = $scope.isDialog === 'true';
var showAlert = function(name, alert) {
$scope.alerts[name] = alert;
NotificationsService.addNotification(alert);
var hideErrorNotifications = function() {
NotificationsService.hideNotification('create-project-error');
};
$scope.createProject = function() {
......@@ -581,9 +579,9 @@ angular.module("openshiftCommonUI")
} else {
$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create");
}
showAlert('created-project', {
NotificationsService.addNotification({
type: "success",
message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
});
}, function(result) {
$scope.disableInputs = false;
......@@ -592,7 +590,11 @@ angular.module("openshiftCommonUI")
$scope.nameTaken = true;
} else {
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")
$window.history.back();
}
};
$scope.$on("$destroy", hideErrorNotifications);
},
};
});
......
......@@ -713,7 +713,6 @@ angular.module("openshiftCommonUI")
return {
restrict: 'E',
scope: {
alerts: '=',
redirectAction: '&',
onCancel: '&?',
isDialog: '@'
......@@ -726,9 +725,8 @@ angular.module("openshiftCommonUI")
$scope.isDialog = $scope.isDialog === 'true';
var showAlert = function(name, alert) {
$scope.alerts[name] = alert;
NotificationsService.addNotification(alert);
var hideErrorNotifications = function() {
NotificationsService.hideNotification('create-project-error');
};
$scope.createProject = function() {
......@@ -752,9 +750,9 @@ angular.module("openshiftCommonUI")
} else {
$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create");
}
showAlert('created-project', {
NotificationsService.addNotification({
type: "success",
message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
});
}, function(result) {
$scope.disableInputs = false;
......@@ -763,7 +761,11 @@ angular.module("openshiftCommonUI")
$scope.nameTaken = true;
} else {
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")
$window.history.back();
}
};
$scope.$on("$destroy", hideErrorNotifications);
}],
};
}]);
......
......@@ -158,7 +158,6 @@ return humanizeKind(object.kind);
return {
restrict:"E",
scope:{
alerts:"=",
redirectAction:"&",
onCancel:"&?",
isDialog:"@"
......@@ -166,8 +165,8 @@ isDialog:"@"
templateUrl:"src/components/create-project/createProject.html",
controller:[ "$scope", "$filter", "$location", "DataService", "NotificationsService", "displayNameFilter", function($scope, $filter, $location, DataService, NotificationsService, displayNameFilter) {
$scope.submitButtonLabel || ($scope.submitButtonLabel = "Create"), $scope.isDialog = "true" === $scope.isDialog;
var showAlert = function(name, alert) {
$scope.alerts[name] = alert, NotificationsService.addNotification(alert);
var hideErrorNotifications = function() {
NotificationsService.hideNotification("create-project-error");
};
$scope.createProject = function() {
$scope.disableInputs = !0, $scope.createProjectForm.$valid && DataService.create("projectrequests", null, {
......@@ -180,7 +179,7 @@ displayName:$scope.displayName,
description:$scope.description
}, $scope).then(function(data) {
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",
message:"Project '" + displayNameFilter(data) + "' was successfully created."
});
......@@ -189,7 +188,8 @@ $scope.disableInputs = !1;
var data = result.data || {};
if ("AlreadyExists" === data.reason) $scope.nameTaken = !0; else {
var msg = data.message || "An error occurred creating the project.";
showAlert("error-creating-project", {
NotificationsService.addNotification({
id:"create-project-error",
type:"error",
message:msg
});
......@@ -200,7 +200,7 @@ if ($scope.onCancel) {
var cb = $scope.onCancel();
cb && cb();
} 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) {
......
......@@ -6,7 +6,6 @@ angular.module("openshiftCommonUI")
return {
restrict: 'E',
scope: {
alerts: '=',
redirectAction: '&',
onCancel: '&?',
isDialog: '@'
......@@ -19,9 +18,8 @@ angular.module("openshiftCommonUI")
$scope.isDialog = $scope.isDialog === 'true';
var showAlert = function(name, alert) {
$scope.alerts[name] = alert;
NotificationsService.addNotification(alert);
var hideErrorNotifications = function() {
NotificationsService.hideNotification('create-project-error');
};
$scope.createProject = function() {
......@@ -45,9 +43,9 @@ angular.module("openshiftCommonUI")
} else {
$location.path("project/" + encodeURIComponent(data.metadata.name) + "/create");
}
showAlert('created-project', {
NotificationsService.addNotification({
type: "success",
message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
message: "Project \'" + displayNameFilter(data) + "\' was successfully created."
});
}, function(result) {
$scope.disableInputs = false;
......@@ -56,7 +54,11 @@ angular.module("openshiftCommonUI")
$scope.nameTaken = true;
} else {
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")
$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