Commit d8934c2e by Jeffrey Phillips

Updates for edit-project and create-project components

No longer used in full pages so remove the btn-lg and input-lg classes
and remove the alerts parameters
parent df4a63c5
...@@ -206,7 +206,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -206,7 +206,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"name\" class=\"required\">Name</label>\n" + " <label for=\"name\" class=\"required\">Name</label>\n" +
" <span ng-class=\"{'has-error': (createProjectForm.name.$error.pattern && createProjectForm.name.$touched) || nameTaken}\">\n" + " <span ng-class=\"{'has-error': (createProjectForm.name.$error.pattern && createProjectForm.name.$touched) || nameTaken}\">\n" +
" <input class=\"form-control input-lg\"\n" + " <input class=\"form-control\"\n" +
" name=\"name\"\n" + " name=\"name\"\n" +
" id=\"name\"\n" + " id=\"name\"\n" +
" placeholder=\"my-project\"\n" + " placeholder=\"my-project\"\n" +
...@@ -252,7 +252,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -252,7 +252,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
"\n" + "\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"displayName\">Display Name</label>\n" + " <label for=\"displayName\">Display Name</label>\n" +
" <input class=\"form-control input-lg\"\n" + " <input class=\"form-control\"\n" +
" name=\"displayName\"\n" + " name=\"displayName\"\n" +
" id=\"displayName\"\n" + " id=\"displayName\"\n" +
" placeholder=\"My Project\"\n" + " placeholder=\"My Project\"\n" +
...@@ -262,7 +262,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -262,7 +262,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
"\n" + "\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"description\">Description</label>\n" + " <label for=\"description\">Description</label>\n" +
" <textarea class=\"form-control input-lg\"\n" + " <textarea class=\"form-control\"\n" +
" name=\"description\"\n" + " name=\"description\"\n" +
" id=\"description\"\n" + " id=\"description\"\n" +
" placeholder=\"A short description.\"\n" + " placeholder=\"A short description.\"\n" +
...@@ -271,7 +271,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -271,7 +271,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
"\n" + "\n" +
" <div class=\"button-group\">\n" + " <div class=\"button-group\">\n" +
" <button type=\"submit\"\n" + " <button type=\"submit\"\n" +
" class=\"btn btn-primary btn-lg\"\n" + " class=\"btn btn-primary\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"createProject()\"\n" + " ng-click=\"createProject()\"\n" +
" ng-disabled=\"createProjectForm.$invalid || nameTaken || disableInputs\"\n" + " ng-disabled=\"createProjectForm.$invalid || nameTaken || disableInputs\"\n" +
...@@ -279,7 +279,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -279,7 +279,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
" Create\n" + " Create\n" +
" </button>\n" + " </button>\n" +
" <button\n" + " <button\n" +
" class=\"btn btn-default btn-lg\"\n" + " class=\"btn btn-default\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"cancelCreateProject()\">\n" + " ng-click=\"cancelCreateProject()\">\n" +
" Cancel\n" + " Cancel\n" +
...@@ -357,7 +357,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -357,7 +357,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
" <fieldset ng-disabled=\"disableInputs\">\n" + " <fieldset ng-disabled=\"disableInputs\">\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"displayName\">Display Name</label>\n" + " <label for=\"displayName\">Display Name</label>\n" +
" <input class=\"form-control input-lg\"\n" + " <input class=\"form-control\"\n" +
" name=\"displayName\"\n" + " name=\"displayName\"\n" +
" id=\"displayName\"\n" + " id=\"displayName\"\n" +
" placeholder=\"My Project\"\n" + " placeholder=\"My Project\"\n" +
...@@ -367,7 +367,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -367,7 +367,7 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
"\n" + "\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"description\">Description</label>\n" + " <label for=\"description\">Description</label>\n" +
" <textarea class=\"form-control input-lg\"\n" + " <textarea class=\"form-control\"\n" +
" name=\"description\"\n" + " name=\"description\"\n" +
" id=\"description\"\n" + " id=\"description\"\n" +
" placeholder=\"A short description.\"\n" + " placeholder=\"A short description.\"\n" +
...@@ -376,13 +376,13 @@ hawtioPluginLoader.addModule('openshiftCommonUI'); ...@@ -376,13 +376,13 @@ hawtioPluginLoader.addModule('openshiftCommonUI');
"\n" + "\n" +
" <div class=\"button-group\">\n" + " <div class=\"button-group\">\n" +
" <button type=\"submit\"\n" + " <button type=\"submit\"\n" +
" class=\"btn btn-primary btn-lg\"\n" + " class=\"btn btn-primary\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"update()\"\n" + " ng-click=\"update()\"\n" +
" ng-disabled=\"editProjectForm.$invalid || disableInputs\"\n" + " ng-disabled=\"editProjectForm.$invalid || disableInputs\"\n" +
" value=\"\">{{submitButtonLabel}}</button>\n" + " value=\"\">{{submitButtonLabel}}</button>\n" +
" <button\n" + " <button\n" +
" class=\"btn btn-default btn-lg\"\n" + " class=\"btn btn-default\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"cancelEditProject()\">\n" + " ng-click=\"cancelEditProject()\">\n" +
" Cancel\n" + " Cancel\n" +
...@@ -561,7 +561,7 @@ angular.module("openshiftCommonUI") ...@@ -561,7 +561,7 @@ angular.module("openshiftCommonUI")
isDialog: '@' isDialog: '@'
}, },
templateUrl: 'src/components/create-project/createProject.html', templateUrl: 'src/components/create-project/createProject.html',
controller: function($scope, $location, ProjectsService, NotificationsService, displayNameFilter) { controller: function($scope, $location, ProjectsService, NotificationsService, displayNameFilter, Logger) {
if(!($scope.submitButtonLabel)) { if(!($scope.submitButtonLabel)) {
$scope.submitButtonLabel = 'Create'; $scope.submitButtonLabel = 'Create';
} }
...@@ -575,6 +575,8 @@ angular.module("openshiftCommonUI") ...@@ -575,6 +575,8 @@ angular.module("openshiftCommonUI")
$scope.createProject = function() { $scope.createProject = function() {
$scope.disableInputs = true; $scope.disableInputs = true;
if ($scope.createProjectForm.$valid) { if ($scope.createProjectForm.$valid) {
var displayName = $scope.displayName || $scope.name;
ProjectsService.create($scope.name, $scope.displayName, $scope.description) ProjectsService.create($scope.name, $scope.displayName, $scope.description)
.then(function(project) { .then(function(project) {
// angular is actually wrapping the redirect action // angular is actually wrapping the redirect action
...@@ -594,12 +596,12 @@ angular.module("openshiftCommonUI") ...@@ -594,12 +596,12 @@ angular.module("openshiftCommonUI")
if (data.reason === 'AlreadyExists') { if (data.reason === 'AlreadyExists') {
$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 project \'" + displayName + "\'.";
NotificationsService.addNotification({ NotificationsService.addNotification({
id: 'create-project-error',
type: 'error', type: 'error',
message: msg message: msg
}); });
Logger.error("Project \'" + displayName + "\' could not be created.", result);
} }
}); });
} }
...@@ -656,10 +658,6 @@ angular.module("openshiftCommonUI") ...@@ -656,10 +658,6 @@ angular.module("openshiftCommonUI")
// Replace so ".dropdown-menu > li > a" styles are applied. // Replace so ".dropdown-menu > li > a" styles are applied.
replace: true, replace: true,
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
var showAlert = function(alert) {
NotificationsService.addNotification(alert.data);
};
var navigateToList = function() { var navigateToList = function() {
if (scope.stayOnCurrentPage) { if (scope.stayOnCurrentPage) {
return; return;
...@@ -695,19 +693,16 @@ angular.module("openshiftCommonUI") ...@@ -695,19 +693,16 @@ angular.module("openshiftCommonUI")
modalInstance.result.then(function() { modalInstance.result.then(function() {
// upon clicking delete button, delete resource and send alert // upon clicking delete button, delete resource and send alert
var projectName = scope.projectName; var projectName = scope.projectName;
var formattedResource = "Project \'" + scope.displayName + "\'"; var formattedResource = "Project \'" + (scope.displayName || projectName) + "\'";
var context = {}; var context = {};
DataService.delete({ DataService.delete({
resource: APIService.kindToResource("Project") resource: APIService.kindToResource("Project")
}, projectName, context) }, projectName, context)
.then(function() { .then(function() {
showAlert({ NotificationsService.addNotification({
name: projectName, type: "success",
data: { message: formattedResource + " was marked for deletion."
type: "success",
message: formattedResource + " was marked for deletion."
}
}); });
if (scope.success) { if (scope.success) {
...@@ -718,12 +713,11 @@ angular.module("openshiftCommonUI") ...@@ -718,12 +713,11 @@ angular.module("openshiftCommonUI")
}) })
.catch(function(err) { .catch(function(err) {
// called if failure to delete // called if failure to delete
var alert = { NotificationsService.addNotification({
type: "error", type: "error",
message: formattedResource + " could not be deleted.", message: formattedResource + " could not be deleted.",
details: $filter('getErrorDetails')(err) details: $filter('getErrorDetails')(err)
}; });
NotificationsService.addNotification(alert);
Logger.error(formattedResource + " could not be deleted.", err); Logger.error(formattedResource + " could not be deleted.", err);
}); });
}); });
...@@ -758,14 +752,13 @@ angular.module("openshiftCommonUI") ...@@ -758,14 +752,13 @@ angular.module("openshiftCommonUI")
restrict: 'E', restrict: 'E',
scope: { scope: {
project: '=', project: '=',
alerts: '=',
submitButtonLabel: '@', submitButtonLabel: '@',
redirectAction: '&', redirectAction: '&',
onCancel: '&', onCancel: '&',
isDialog: '@' isDialog: '@'
}, },
templateUrl: 'src/components/edit-project/editProject.html', templateUrl: 'src/components/edit-project/editProject.html',
controller: function($scope, $filter, $location, DataService, NotificationsService, annotationNameFilter, displayNameFilter) { controller: function($scope, $filter, $location, DataService, NotificationsService, annotationNameFilter, displayNameFilter, Logger) {
if(!($scope.submitButtonLabel)) { if(!($scope.submitButtonLabel)) {
$scope.submitButtonLabel = 'Save'; $scope.submitButtonLabel = 'Save';
} }
...@@ -802,11 +795,6 @@ angular.module("openshiftCommonUI") ...@@ -802,11 +795,6 @@ angular.module("openshiftCommonUI")
return resource; return resource;
}; };
var showAlert = function(alert) {
$scope.alerts["update"] = alert;
NotificationsService.addNotification(alert);
};
$scope.editableFields = editableFields($scope.project); $scope.editableFields = editableFields($scope.project);
$scope.update = function() { $scope.update = function() {
...@@ -826,18 +814,19 @@ angular.module("openshiftCommonUI") ...@@ -826,18 +814,19 @@ angular.module("openshiftCommonUI")
cb(encodeURIComponent($scope.project.metadata.name)); cb(encodeURIComponent($scope.project.metadata.name));
} }
showAlert({ NotificationsService.addNotification({
type: "success", type: 'success',
message: "Project \'" + displayNameFilter(project) + "\' was successfully updated." message: "Project \'" + displayNameFilter(project) + "\' was successfully updated."
}); });
}, function(result) { }, function(result) {
$scope.disableInputs = false; $scope.disableInputs = false;
$scope.editableFields = editableFields($scope.project); $scope.editableFields = editableFields($scope.project);
showAlert({ NotificationsService.addNotification({
type: "error", type: 'error',
message: "An error occurred while updating the project", message: "An error occurred while updating project \'" + displayNameFilter($scope.project) + "\'." ,
details: $filter('getErrorDetails')(result) details: $filter('getErrorDetails')(result)
}); });
Logger.error("Project \'" + displayNameFilter($scope.project) + "\' could not be updated.", result);
}); });
} }
}; };
......
...@@ -177,7 +177,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -177,7 +177,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"name\" class=\"required\">Name</label>\n" + " <label for=\"name\" class=\"required\">Name</label>\n" +
" <span ng-class=\"{'has-error': (createProjectForm.name.$error.pattern && createProjectForm.name.$touched) || nameTaken}\">\n" + " <span ng-class=\"{'has-error': (createProjectForm.name.$error.pattern && createProjectForm.name.$touched) || nameTaken}\">\n" +
" <input class=\"form-control input-lg\"\n" + " <input class=\"form-control\"\n" +
" name=\"name\"\n" + " name=\"name\"\n" +
" id=\"name\"\n" + " id=\"name\"\n" +
" placeholder=\"my-project\"\n" + " placeholder=\"my-project\"\n" +
...@@ -223,7 +223,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -223,7 +223,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
"\n" + "\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"displayName\">Display Name</label>\n" + " <label for=\"displayName\">Display Name</label>\n" +
" <input class=\"form-control input-lg\"\n" + " <input class=\"form-control\"\n" +
" name=\"displayName\"\n" + " name=\"displayName\"\n" +
" id=\"displayName\"\n" + " id=\"displayName\"\n" +
" placeholder=\"My Project\"\n" + " placeholder=\"My Project\"\n" +
...@@ -233,7 +233,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -233,7 +233,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
"\n" + "\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"description\">Description</label>\n" + " <label for=\"description\">Description</label>\n" +
" <textarea class=\"form-control input-lg\"\n" + " <textarea class=\"form-control\"\n" +
" name=\"description\"\n" + " name=\"description\"\n" +
" id=\"description\"\n" + " id=\"description\"\n" +
" placeholder=\"A short description.\"\n" + " placeholder=\"A short description.\"\n" +
...@@ -242,7 +242,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -242,7 +242,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
"\n" + "\n" +
" <div class=\"button-group\">\n" + " <div class=\"button-group\">\n" +
" <button type=\"submit\"\n" + " <button type=\"submit\"\n" +
" class=\"btn btn-primary btn-lg\"\n" + " class=\"btn btn-primary\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"createProject()\"\n" + " ng-click=\"createProject()\"\n" +
" ng-disabled=\"createProjectForm.$invalid || nameTaken || disableInputs\"\n" + " ng-disabled=\"createProjectForm.$invalid || nameTaken || disableInputs\"\n" +
...@@ -250,7 +250,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -250,7 +250,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
" Create\n" + " Create\n" +
" </button>\n" + " </button>\n" +
" <button\n" + " <button\n" +
" class=\"btn btn-default btn-lg\"\n" + " class=\"btn btn-default\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"cancelCreateProject()\">\n" + " ng-click=\"cancelCreateProject()\">\n" +
" Cancel\n" + " Cancel\n" +
...@@ -328,7 +328,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -328,7 +328,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
" <fieldset ng-disabled=\"disableInputs\">\n" + " <fieldset ng-disabled=\"disableInputs\">\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"displayName\">Display Name</label>\n" + " <label for=\"displayName\">Display Name</label>\n" +
" <input class=\"form-control input-lg\"\n" + " <input class=\"form-control\"\n" +
" name=\"displayName\"\n" + " name=\"displayName\"\n" +
" id=\"displayName\"\n" + " id=\"displayName\"\n" +
" placeholder=\"My Project\"\n" + " placeholder=\"My Project\"\n" +
...@@ -338,7 +338,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -338,7 +338,7 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
"\n" + "\n" +
" <div class=\"form-group\">\n" + " <div class=\"form-group\">\n" +
" <label for=\"description\">Description</label>\n" + " <label for=\"description\">Description</label>\n" +
" <textarea class=\"form-control input-lg\"\n" + " <textarea class=\"form-control\"\n" +
" name=\"description\"\n" + " name=\"description\"\n" +
" id=\"description\"\n" + " id=\"description\"\n" +
" placeholder=\"A short description.\"\n" + " placeholder=\"A short description.\"\n" +
...@@ -347,13 +347,13 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac ...@@ -347,13 +347,13 @@ angular.module('openshiftCommonUI').run(['$templateCache', function($templateCac
"\n" + "\n" +
" <div class=\"button-group\">\n" + " <div class=\"button-group\">\n" +
" <button type=\"submit\"\n" + " <button type=\"submit\"\n" +
" class=\"btn btn-primary btn-lg\"\n" + " class=\"btn btn-primary\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"update()\"\n" + " ng-click=\"update()\"\n" +
" ng-disabled=\"editProjectForm.$invalid || disableInputs\"\n" + " ng-disabled=\"editProjectForm.$invalid || disableInputs\"\n" +
" value=\"\">{{submitButtonLabel}}</button>\n" + " value=\"\">{{submitButtonLabel}}</button>\n" +
" <button\n" + " <button\n" +
" class=\"btn btn-default btn-lg\"\n" + " class=\"btn btn-default\"\n" +
" ng-class=\"{'dialog-btn': isDialog}\"\n" + " ng-class=\"{'dialog-btn': isDialog}\"\n" +
" ng-click=\"cancelEditProject()\">\n" + " ng-click=\"cancelEditProject()\">\n" +
" Cancel\n" + " Cancel\n" +
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="form-group"> <div class="form-group">
<label for="name" class="required">Name</label> <label for="name" class="required">Name</label>
<span ng-class="{'has-error': (createProjectForm.name.$error.pattern && createProjectForm.name.$touched) || nameTaken}"> <span ng-class="{'has-error': (createProjectForm.name.$error.pattern && createProjectForm.name.$touched) || nameTaken}">
<input class="form-control input-lg" <input class="form-control"
name="name" name="name"
id="name" id="name"
placeholder="my-project" placeholder="my-project"
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
<div class="form-group"> <div class="form-group">
<label for="displayName">Display Name</label> <label for="displayName">Display Name</label>
<input class="form-control input-lg" <input class="form-control"
name="displayName" name="displayName"
id="displayName" id="displayName"
placeholder="My Project" placeholder="My Project"
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
<div class="form-group"> <div class="form-group">
<label for="description">Description</label> <label for="description">Description</label>
<textarea class="form-control input-lg" <textarea class="form-control"
name="description" name="description"
id="description" id="description"
placeholder="A short description." placeholder="A short description."
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
<div class="button-group"> <div class="button-group">
<button type="submit" <button type="submit"
class="btn btn-primary btn-lg" class="btn btn-primary"
ng-class="{'dialog-btn': isDialog}" ng-class="{'dialog-btn': isDialog}"
ng-click="createProject()" ng-click="createProject()"
ng-disabled="createProjectForm.$invalid || nameTaken || disableInputs" ng-disabled="createProjectForm.$invalid || nameTaken || disableInputs"
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
Create Create
</button> </button>
<button <button
class="btn btn-default btn-lg" class="btn btn-default"
ng-class="{'dialog-btn': isDialog}" ng-class="{'dialog-btn': isDialog}"
ng-click="cancelCreateProject()"> ng-click="cancelCreateProject()">
Cancel Cancel
......
...@@ -11,7 +11,7 @@ angular.module("openshiftCommonUI") ...@@ -11,7 +11,7 @@ angular.module("openshiftCommonUI")
isDialog: '@' isDialog: '@'
}, },
templateUrl: 'src/components/create-project/createProject.html', templateUrl: 'src/components/create-project/createProject.html',
controller: function($scope, $location, ProjectsService, NotificationsService, displayNameFilter) { controller: function($scope, $location, ProjectsService, NotificationsService, displayNameFilter, Logger) {
if(!($scope.submitButtonLabel)) { if(!($scope.submitButtonLabel)) {
$scope.submitButtonLabel = 'Create'; $scope.submitButtonLabel = 'Create';
} }
...@@ -25,6 +25,8 @@ angular.module("openshiftCommonUI") ...@@ -25,6 +25,8 @@ angular.module("openshiftCommonUI")
$scope.createProject = function() { $scope.createProject = function() {
$scope.disableInputs = true; $scope.disableInputs = true;
if ($scope.createProjectForm.$valid) { if ($scope.createProjectForm.$valid) {
var displayName = $scope.displayName || $scope.name;
ProjectsService.create($scope.name, $scope.displayName, $scope.description) ProjectsService.create($scope.name, $scope.displayName, $scope.description)
.then(function(project) { .then(function(project) {
// angular is actually wrapping the redirect action // angular is actually wrapping the redirect action
...@@ -44,12 +46,12 @@ angular.module("openshiftCommonUI") ...@@ -44,12 +46,12 @@ angular.module("openshiftCommonUI")
if (data.reason === 'AlreadyExists') { if (data.reason === 'AlreadyExists') {
$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 project \'" + displayName + "\'.";
NotificationsService.addNotification({ NotificationsService.addNotification({
id: 'create-project-error',
type: 'error', type: 'error',
message: msg message: msg
}); });
Logger.error("Project \'" + displayName + "\' could not be created.", result);
} }
}); });
} }
......
...@@ -34,10 +34,6 @@ angular.module("openshiftCommonUI") ...@@ -34,10 +34,6 @@ angular.module("openshiftCommonUI")
// Replace so ".dropdown-menu > li > a" styles are applied. // Replace so ".dropdown-menu > li > a" styles are applied.
replace: true, replace: true,
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
var showAlert = function(alert) {
NotificationsService.addNotification(alert.data);
};
var navigateToList = function() { var navigateToList = function() {
if (scope.stayOnCurrentPage) { if (scope.stayOnCurrentPage) {
return; return;
...@@ -73,19 +69,16 @@ angular.module("openshiftCommonUI") ...@@ -73,19 +69,16 @@ angular.module("openshiftCommonUI")
modalInstance.result.then(function() { modalInstance.result.then(function() {
// upon clicking delete button, delete resource and send alert // upon clicking delete button, delete resource and send alert
var projectName = scope.projectName; var projectName = scope.projectName;
var formattedResource = "Project \'" + scope.displayName + "\'"; var formattedResource = "Project \'" + (scope.displayName || projectName) + "\'";
var context = {}; var context = {};
DataService.delete({ DataService.delete({
resource: APIService.kindToResource("Project") resource: APIService.kindToResource("Project")
}, projectName, context) }, projectName, context)
.then(function() { .then(function() {
showAlert({ NotificationsService.addNotification({
name: projectName, type: "success",
data: { message: formattedResource + " was marked for deletion."
type: "success",
message: formattedResource + " was marked for deletion."
}
}); });
if (scope.success) { if (scope.success) {
...@@ -96,12 +89,11 @@ angular.module("openshiftCommonUI") ...@@ -96,12 +89,11 @@ angular.module("openshiftCommonUI")
}) })
.catch(function(err) { .catch(function(err) {
// called if failure to delete // called if failure to delete
var alert = { NotificationsService.addNotification({
type: "error", type: "error",
message: formattedResource + " could not be deleted.", message: formattedResource + " could not be deleted.",
details: $filter('getErrorDetails')(err) details: $filter('getErrorDetails')(err)
}; });
NotificationsService.addNotification(alert);
Logger.error(formattedResource + " could not be deleted.", err); Logger.error(formattedResource + " could not be deleted.", err);
}); });
}); });
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<fieldset ng-disabled="disableInputs"> <fieldset ng-disabled="disableInputs">
<div class="form-group"> <div class="form-group">
<label for="displayName">Display Name</label> <label for="displayName">Display Name</label>
<input class="form-control input-lg" <input class="form-control"
name="displayName" name="displayName"
id="displayName" id="displayName"
placeholder="My Project" placeholder="My Project"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<div class="form-group"> <div class="form-group">
<label for="description">Description</label> <label for="description">Description</label>
<textarea class="form-control input-lg" <textarea class="form-control"
name="description" name="description"
id="description" id="description"
placeholder="A short description." placeholder="A short description."
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
<div class="button-group"> <div class="button-group">
<button type="submit" <button type="submit"
class="btn btn-primary btn-lg" class="btn btn-primary"
ng-class="{'dialog-btn': isDialog}" ng-class="{'dialog-btn': isDialog}"
ng-click="update()" ng-click="update()"
ng-disabled="editProjectForm.$invalid || disableInputs" ng-disabled="editProjectForm.$invalid || disableInputs"
value="">{{submitButtonLabel}}</button> value="">{{submitButtonLabel}}</button>
<button <button
class="btn btn-default btn-lg" class="btn btn-default"
ng-class="{'dialog-btn': isDialog}" ng-class="{'dialog-btn': isDialog}"
ng-click="cancelEditProject()"> ng-click="cancelEditProject()">
Cancel Cancel
......
...@@ -7,14 +7,13 @@ angular.module("openshiftCommonUI") ...@@ -7,14 +7,13 @@ angular.module("openshiftCommonUI")
restrict: 'E', restrict: 'E',
scope: { scope: {
project: '=', project: '=',
alerts: '=',
submitButtonLabel: '@', submitButtonLabel: '@',
redirectAction: '&', redirectAction: '&',
onCancel: '&', onCancel: '&',
isDialog: '@' isDialog: '@'
}, },
templateUrl: 'src/components/edit-project/editProject.html', templateUrl: 'src/components/edit-project/editProject.html',
controller: function($scope, $filter, $location, DataService, NotificationsService, annotationNameFilter, displayNameFilter) { controller: function($scope, $filter, $location, DataService, NotificationsService, annotationNameFilter, displayNameFilter, Logger) {
if(!($scope.submitButtonLabel)) { if(!($scope.submitButtonLabel)) {
$scope.submitButtonLabel = 'Save'; $scope.submitButtonLabel = 'Save';
} }
...@@ -51,11 +50,6 @@ angular.module("openshiftCommonUI") ...@@ -51,11 +50,6 @@ angular.module("openshiftCommonUI")
return resource; return resource;
}; };
var showAlert = function(alert) {
$scope.alerts["update"] = alert;
NotificationsService.addNotification(alert);
};
$scope.editableFields = editableFields($scope.project); $scope.editableFields = editableFields($scope.project);
$scope.update = function() { $scope.update = function() {
...@@ -75,18 +69,19 @@ angular.module("openshiftCommonUI") ...@@ -75,18 +69,19 @@ angular.module("openshiftCommonUI")
cb(encodeURIComponent($scope.project.metadata.name)); cb(encodeURIComponent($scope.project.metadata.name));
} }
showAlert({ NotificationsService.addNotification({
type: "success", type: 'success',
message: "Project \'" + displayNameFilter(project) + "\' was successfully updated." message: "Project \'" + displayNameFilter(project) + "\' was successfully updated."
}); });
}, function(result) { }, function(result) {
$scope.disableInputs = false; $scope.disableInputs = false;
$scope.editableFields = editableFields($scope.project); $scope.editableFields = editableFields($scope.project);
showAlert({ NotificationsService.addNotification({
type: "error", type: 'error',
message: "An error occurred while updating the project", message: "An error occurred while updating project \'" + displayNameFilter($scope.project) + "\'." ,
details: $filter('getErrorDetails')(result) details: $filter('getErrorDetails')(result)
}); });
Logger.error("Project \'" + displayNameFilter($scope.project) + "\' could not be updated.", result);
}); });
} }
}; };
......
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