Add a unified error display method to make the code cleaner. Also fixes a UI issue in create org

This commit is contained in:
Joseph Schorr 2014-08-18 18:21:53 -04:00
parent 1460879169
commit c4a27b2c7a
4 changed files with 86 additions and 279 deletions

View file

@ -59,18 +59,8 @@ function getFirstTextLine(commentString) {
} }
function createRobotAccount(ApiService, is_org, orgname, name, callback) { function createRobotAccount(ApiService, is_org, orgname, name, callback) {
ApiService.createRobot(is_org ? orgname : null, null, {'robot_shortname': name}).then(callback, function(resp) { ApiService.createRobot(is_org ? orgname : null, null, {'robot_shortname': name})
bootbox.dialog({ .then(callback, ApiService.errorDisplay('Cannot create robot account'));
"message": resp.data ? resp.data['message'] : 'The robot account could not be created',
"title": "Cannot create robot account",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
} }
function createOrganizationTeam(ApiService, orgname, teamname, callback) { function createOrganizationTeam(ApiService, orgname, teamname, callback) {
@ -84,18 +74,8 @@ function createOrganizationTeam(ApiService, orgname, teamname, callback) {
'teamname': teamname 'teamname': teamname
}; };
ApiService.updateOrganizationTeam(data, params).then(callback, function(resp) { ApiService.updateOrganizationTeam(data, params)
bootbox.dialog({ .then(callback, ApiService.errorDisplay('Cannot create team'));
"message": resp.data ? resp.data : 'The team could not be created',
"title": "Cannot create team",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
} }
function getMarkedDown(string) { function getMarkedDown(string) {
@ -847,6 +827,38 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
buildMethodsForEndpointResource(endpointResource, resourceMap); buildMethodsForEndpointResource(endpointResource, resourceMap);
} }
apiService.getErrorMessage = function(resp, defaultMessage) {
var message = defaultMessage;
if (resp['data']) {
message = resp['data']['error_message'] || resp['data']['message'] || resp['data']['error_description'] || message;
}
return message;
};
apiService.errorDisplay = function(defaultMessage, opt_handler) {
return function(resp) {
var message = apiService.getErrorMessage(resp, defaultMessage);
if (opt_handler) {
var handlerMessage = opt_handler(resp);
if (handlerMessage) {
message = handlerMessage;
}
}
bootbox.dialog({
"message": message,
"title": defaultMessage,
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
};
};
return apiService; return apiService;
}]); }]);
@ -2013,18 +2025,7 @@ quayApp.directive('applicationReference', function () {
template: '/static/directives/application-reference-dialog.html', template: '/static/directives/application-reference-dialog.html',
show: true show: true
}); });
}, function() { }, ApiService.errorDisplay('Application could not be found'));
bootbox.dialog({
"message": 'The application could not be found; it might have been deleted.',
"title": "Cannot find application",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
} }
}; };
@ -2793,18 +2794,7 @@ quayApp.directive('applicationManager', function () {
ApiService.createOrganizationApplication(data, params).then(function(resp) { ApiService.createOrganizationApplication(data, params).then(function(resp) {
$scope.applications.push(resp); $scope.applications.push(resp);
}, function(resp) { }, ApiService.errorDisplay('Cannot create application'));
bootbox.dialog({
"message": resp['message'] || 'The application could not be created',
"title": "Cannot create application",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
var update = function() { var update = function() {
@ -2889,18 +2879,7 @@ quayApp.directive('robotsManager', function () {
if (index >= 0) { if (index >= 0) {
$scope.robots.splice(index, 1); $scope.robots.splice(index, 1);
} }
}, function() { }, ApiService.errorDisplay('Cannot delete robot account'));
bootbox.dialog({
"message": 'The selected robot account could not be deleted',
"title": "Cannot delete robot account",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
var update = function() { var update = function() {
@ -2965,18 +2944,7 @@ quayApp.directive('prototypeManager', function () {
ApiService.updateOrganizationPrototypePermission(data, params).then(function(resp) { ApiService.updateOrganizationPrototypePermission(data, params).then(function(resp) {
prototype.role = role; prototype.role = role;
}, function(resp) { }, ApiService.errorDisplay('Cannot modify permission'));
bootbox.dialog({
"message": resp.data ? resp.data : 'The permission could not be modified',
"title": "Cannot modify permission",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.comparePrototypes = function(p) { $scope.comparePrototypes = function(p) {
@ -3016,23 +2984,16 @@ quayApp.directive('prototypeManager', function () {
data['activating_user'] = $scope.activatingForNew; data['activating_user'] = $scope.activatingForNew;
} }
var errorHandler = ApiService.errorDisplay('Cannot create permission',
function(resp) {
$('#addPermissionDialogModal').modal('hide');
});
ApiService.createOrganizationPrototypePermission(data, params).then(function(resp) { ApiService.createOrganizationPrototypePermission(data, params).then(function(resp) {
$scope.prototypes.push(resp); $scope.prototypes.push(resp);
$scope.loading = false; $scope.loading = false;
$('#addPermissionDialogModal').modal('hide'); $('#addPermissionDialogModal').modal('hide');
}, function(resp) { }, errorHandler);
$('#addPermissionDialogModal').modal('hide');
bootbox.dialog({
"message": resp.data ? resp.data : 'The permission could not be created',
"title": "Cannot create permission",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.deletePrototype = function(prototype) { $scope.deletePrototype = function(prototype) {
@ -3046,18 +3007,7 @@ quayApp.directive('prototypeManager', function () {
ApiService.deleteOrganizationPrototypePermission(null, params).then(function(resp) { ApiService.deleteOrganizationPrototypePermission(null, params).then(function(resp) {
$scope.prototypes.splice($scope.prototypes.indexOf(prototype), 1); $scope.prototypes.splice($scope.prototypes.indexOf(prototype), 1);
$scope.loading = false; $scope.loading = false;
}, function(resp) { }, ApiService.errorDisplay('Cannot delete permission'));
bootbox.dialog({
"message": resp.data ? resp.data : 'The permission could not be deleted',
"title": "Cannot delete permission",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
var update = function() { var update = function() {
@ -4377,26 +4327,17 @@ quayApp.directive('setupTriggerDialog', function () {
$scope.activating = true; $scope.activating = true;
var errorHandler = ApiService.errorDisplay('Cannot activate build trigger', function(resp) {
$scope.hide();
$scope.canceled({'trigger': $scope.trigger});
});
ApiService.activateBuildTrigger(data, params).then(function(resp) { ApiService.activateBuildTrigger(data, params).then(function(resp) {
$scope.hide(); $scope.hide();
$scope.trigger['is_active'] = true; $scope.trigger['is_active'] = true;
$scope.trigger['pull_robot'] = resp['pull_robot']; $scope.trigger['pull_robot'] = resp['pull_robot'];
$scope.activated({'trigger': $scope.trigger}); $scope.activated({'trigger': $scope.trigger});
}, function(resp) { }, errorHandler);
$scope.hide();
$scope.canceled({'trigger': $scope.trigger});
bootbox.dialog({
"message": resp['data']['message'] || 'The build trigger setup could not be completed',
"title": "Could not activate build trigger",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
var check = function() { var check = function() {

View file

@ -532,23 +532,15 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
'image': image.id 'image': image.id
}; };
var errorHandler = ApiService.errorDisplay('Cannot create or move tag', function(resp) {
$('#addTagModal').modal('hide');
});
ApiService.changeTagImage(data, params).then(function(resp) { ApiService.changeTagImage(data, params).then(function(resp) {
$scope.creatingTag = false; $scope.creatingTag = false;
loadViewInfo(); loadViewInfo();
$('#addTagModal').modal('hide'); $('#addTagModal').modal('hide');
}, function(resp) { }, errorHandler);
$('#addTagModal').modal('hide');
bootbox.dialog({
"message": resp.data ? resp.data : 'Could not create or move tag',
"title": "Cannot create or move tag",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.deleteTag = function(tagName) { $scope.deleteTag = function(tagName) {
@ -562,18 +554,7 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
ApiService.deleteFullTag(null, params).then(function() { ApiService.deleteFullTag(null, params).then(function() {
loadViewInfo(); loadViewInfo();
}, function(resp) { }, ApiService.errorDisplay('Cannot delete tag'));
bootbox.dialog({
"message": resp.data ? resp.data : 'Could not delete tag',
"title": "Cannot delete tag",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.getImagesForTagBySize = function(tag) { $scope.getImagesForTagBySize = function(tag) {
@ -1362,17 +1343,16 @@ function RepoAdminCtrl($scope, Restangular, ApiService, KeyService, $routeParams
}; };
$scope.deleteRole = function(entityName, kind) { $scope.deleteRole = function(entityName, kind) {
var errorHandler = ApiService.errorDisplay('Cannot change permission', function(resp) {
if (resp.status == 409) {
return 'Cannot change permission as you do not have the authority';
}
});
var permissionDelete = Restangular.one(getRestUrl('repository', namespace, name, 'permissions', kind, entityName)); var permissionDelete = Restangular.one(getRestUrl('repository', namespace, name, 'permissions', kind, entityName));
permissionDelete.customDELETE().then(function() { permissionDelete.customDELETE().then(function() {
delete $scope.permissions[kind][entityName]; delete $scope.permissions[kind][entityName];
}, function(resp) { }, errorHandler);
if (resp.status == 409) {
$scope.changePermError = resp.data || '';
$('#channgechangepermModal').modal({});
} else {
$('#cannotchangeModal').modal({});
}
});
}; };
$scope.addRole = function(entityName, role, kind) { $scope.addRole = function(entityName, role, kind) {
@ -1383,9 +1363,7 @@ function RepoAdminCtrl($scope, Restangular, ApiService, KeyService, $routeParams
var permissionPost = Restangular.one(getRestUrl('repository', namespace, name, 'permissions', kind, entityName)); var permissionPost = Restangular.one(getRestUrl('repository', namespace, name, 'permissions', kind, entityName));
permissionPost.customPUT(permission).then(function(result) { permissionPost.customPUT(permission).then(function(result) {
$scope.permissions[kind][entityName] = result; $scope.permissions[kind][entityName] = result;
}, function(result) { }, ApiService.errorDisplay('Cannot change permission'));
$('#cannotchangeModal').modal({});
});
}; };
$scope.roles = [ $scope.roles = [
@ -1600,18 +1578,7 @@ function RepoAdminCtrl($scope, Restangular, ApiService, KeyService, $routeParams
window.console.log(resp); window.console.log(resp);
var url = '/repository/' + namespace + '/' + name + '/build?current=' + resp['id']; var url = '/repository/' + namespace + '/' + name + '/build?current=' + resp['id'];
document.location = url; document.location = url;
}, function(resp) { }, ApiService.errorDisplay('Could not start build'));
bootbox.dialog({
"message": resp['message'] || 'The build could not be started',
"title": "Could not start build",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.deleteTrigger = function(trigger) { $scope.deleteTrigger = function(trigger) {
@ -1739,18 +1706,7 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use
ApiService.deleteUserAuthorization(null, params).then(function(resp) { ApiService.deleteUserAuthorization(null, params).then(function(resp) {
$scope.authorizedApps.splice($scope.authorizedApps.indexOf(accessTokenInfo), 1); $scope.authorizedApps.splice($scope.authorizedApps.indexOf(accessTokenInfo), 1);
}, function(resp) { }, ApiService.errorDisplay('Could not revoke authorization'));
bootbox.dialog({
"message": resp.message || 'Could not revoke authorization',
"title": "Cannot revoke authorization",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.loadLogs = function() { $scope.loadLogs = function() {
@ -2215,13 +2171,14 @@ function OrgViewCtrl($rootScope, $scope, ApiService, $routeParams) {
'teamname': teamname 'teamname': teamname
}; };
var errorHandler = ApiService.errorDisplay('Cannot delete team', function() {
$scope.currentDeleteTeam = null;
});
ApiService.deleteOrganizationTeam(null, params).then(function() { ApiService.deleteOrganizationTeam(null, params).then(function() {
delete $scope.organization.teams[teamname]; delete $scope.organization.teams[teamname];
$scope.currentDeleteTeam = null; $scope.currentDeleteTeam = null;
}, function() { }, errorHandler);
$('#cannotchangeModal').modal({});
$scope.currentDeleteTeam = null;
});
}; };
var loadOrganization = function() { var loadOrganization = function() {
@ -2515,9 +2472,9 @@ function NewOrgCtrl($scope, $routeParams, $timeout, $location, UserService, Plan
}; };
PlanService.changePlan($scope, org.name, $scope.holder.currentPlan.stripeId, callbacks); PlanService.changePlan($scope, org.name, $scope.holder.currentPlan.stripeId, callbacks);
}, function(result) { }, function(resp) {
$scope.creating = false; $scope.creating = false;
$scope.createError = result.data.error_description || result.data; $scope.createError = ApiService.getErrorMessage(resp);
$timeout(function() { $timeout(function() {
$('#orgName').popover('show'); $('#orgName').popover('show');
}); });
@ -2594,18 +2551,7 @@ function ManageApplicationCtrl($scope, $routeParams, $rootScope, $location, $tim
$timeout(function() { $timeout(function() {
$location.path('/organization/' + orgname + '/admin'); $location.path('/organization/' + orgname + '/admin');
}, 500); }, 500);
}, function(resp) { }, ApiService.errorDisplay('Could not delete application'));
bootbox.dialog({
"message": resp.message || 'Could not delete application',
"title": "Cannot delete application",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.updateApplication = function() { $scope.updateApplication = function() {
@ -2623,22 +2569,13 @@ function ManageApplicationCtrl($scope, $routeParams, $rootScope, $location, $tim
delete $scope.application['gravatar_email']; delete $scope.application['gravatar_email'];
} }
var errorHandler = ApiService.errorDisplay('Could not update application', function(resp) {
$scope.updating = false;
});
ApiService.updateOrganizationApplication($scope.application, params).then(function(resp) { ApiService.updateOrganizationApplication($scope.application, params).then(function(resp) {
$scope.application = resp; $scope.application = resp;
$scope.updating = false; }, errorHandler);
}, function(resp) {
$scope.updating = false;
bootbox.dialog({
"message": resp.message || 'Could not update application',
"title": "Cannot update application",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.resetClientSecret = function() { $scope.resetClientSecret = function() {
@ -2651,18 +2588,7 @@ function ManageApplicationCtrl($scope, $routeParams, $rootScope, $location, $tim
ApiService.resetOrganizationApplicationClientSecret(null, params).then(function(resp) { ApiService.resetOrganizationApplicationClientSecret(null, params).then(function(resp) {
$scope.application = resp; $scope.application = resp;
}, function(resp) { }, ApiService.errorDisplay('Could not reset client secret'));
bootbox.dialog({
"message": resp.message || 'Could not reset client secret',
"title": "Cannot reset client secret",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
var loadOrganization = function() { var loadOrganization = function() {
@ -2758,18 +2684,7 @@ function SuperUserAdminCtrl($scope, ApiService, Features, UserService) {
ApiService.changeInstallUser(data, params).then(function(resp) { ApiService.changeInstallUser(data, params).then(function(resp) {
$scope.loadUsersInternal(); $scope.loadUsersInternal();
}, function(resp) { }, ApiService.errorDisplay('Could not change user'));
bootbox.dialog({
"message": resp.data ? resp.data.message : 'Could not change user',
"title": "Cannot change user",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
$scope.deleteUser = function(user) { $scope.deleteUser = function(user) {
@ -2781,18 +2696,7 @@ function SuperUserAdminCtrl($scope, ApiService, Features, UserService) {
ApiService.deleteInstallUser(null, params).then(function(resp) { ApiService.deleteInstallUser(null, params).then(function(resp) {
$scope.loadUsersInternal(); $scope.loadUsersInternal();
}, function(resp) { }, ApiService.errorDisplay('Cannot delete user'));
bootbox.dialog({
"message": resp.data ? resp.data.message : 'Could not delete user',
"title": "Cannot delete user",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
}; };
var seatUsageLoaded = function(usage) { var seatUsageLoaded = function(usage) {

View file

@ -53,7 +53,7 @@
<label for="orgName">Organization Name</label> <label for="orgName">Organization Name</label>
<input id="orgName" name="orgName" type="text" class="form-control" placeholder="Organization Name" <input id="orgName" name="orgName" type="text" class="form-control" placeholder="Organization Name"
ng-model="org.name" required autofocus data-trigger="manual" data-content="{{ createError }}" ng-model="org.name" required autofocus data-trigger="manual" data-content="{{ createError }}"
data-placement="right" data-container="body" ng-pattern="/^[a-z0-9_]{4,30}$/"> data-placement="bottom" data-container="body" ng-pattern="/^[a-z0-9_]{4,30}$/">
<span class="description">This will also be the namespace for your repositories</span> <span class="description">This will also be the namespace for your repositories</span>
</div> </div>

View file

@ -377,24 +377,6 @@
counter="showNewNotificationCounter" counter="showNewNotificationCounter"
notification-created="handleNotificationCreated(notification)"></div> notification-created="handleNotificationCreated(notification)"></div>
<!-- Modal message dialog -->
<div class="modal fade" id="cannotchangeModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Cannot change</h4>
</div>
<div class="modal-body">
The selected action could not be performed because you do not have that authority.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Modal message dialog --> <!-- Modal message dialog -->
<div class="modal fade" id="makepublicModal"> <div class="modal fade" id="makepublicModal">
<div class="modal-dialog"> <div class="modal-dialog">
@ -441,26 +423,6 @@
</div><!-- /.modal --> </div><!-- /.modal -->
<!-- Modal message dialog -->
<div class="modal fade" id="channgechangepermModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Cannot change permissions</h4>
</div>
<div class="modal-body">
<span ng-show="!changePermError">You do not have permission to change the permissions on the repository.</span>
<span ng-show="changePermError">{{ changePermError }}</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Modal message dialog --> <!-- Modal message dialog -->
<div class="modal fade" id="confirmdeleteModal"> <div class="modal fade" id="confirmdeleteModal">
<div class="modal-dialog"> <div class="modal-dialog">