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