New create entity dialogs (team and robot)

Fixes https://github.com/coreos-inc/design/issues/230
This commit is contained in:
Joseph Schorr 2016-05-12 17:59:49 -04:00
parent 2274d6ff84
commit 4a543be7a7
31 changed files with 687 additions and 232 deletions

View file

@ -1,61 +0,0 @@
/**
* Service which exposes various methods for creating entities on the backend.
*/
angular.module('quay').factory('CreateService', ['ApiService', 'UserService', function(ApiService, UserService) {
var createService = {};
createService.createRobotAccount = function(ApiService, is_org, orgname, name, callback) {
ApiService.createRobot(is_org ? orgname : null, null, {'robot_shortname': name})
.then(callback, ApiService.errorDisplay('Cannot create robot account'));
};
createService.createOrganizationTeam = function(ApiService, orgname, teamname, callback) {
var data = {
'name': teamname,
'role': 'member'
};
var params = {
'orgname': orgname,
'teamname': teamname
};
ApiService.updateOrganizationTeam(data, params)
.then(callback, ApiService.errorDisplay('Cannot create team'));
};
createService.askCreateRobot = function(namespace, callback) {
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
var isorg = UserService.isOrganization(namespace);
bootbox.prompt('Enter the name of the new robot account', function(robotname) {
if (!robotname) { return; }
var regex = new RegExp(ROBOT_PATTERN);
if (!regex.test(robotname)) {
bootbox.alert('Invalid robot account name');
return;
}
createService.createRobotAccount(ApiService, isorg, namespace, robotname, callback);
});
};
createService.askCreateTeam = function(namespace, callback) {
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
bootbox.prompt('Enter the name of the new team', function(teamname) {
if (!teamname) { return; }
var regex = new RegExp(TEAM_PATTERN);
if (!regex.test(teamname)) {
bootbox.alert('Invalid team name');
return;
}
createService.createOrganizationTeam(ApiService, namespace, teamname, callback);
});
};
return createService;
}]);

View file

@ -1,20 +1,57 @@
/**
* Service which defines the various role groups.
*/
angular.module('quay').factory('RolesService', [function() {
angular.module('quay').factory('RolesService', ['UtilService', 'Restangular', 'ApiService', function(UtilService, Restangular, ApiService) {
var roleService = {};
roleService.repoRoles = [
roleService.repoRolesOrNone = [
{ 'id': 'none', 'title': 'None', 'kind': 'default', 'description': 'No permissions on the repository' },
{ 'id': 'read', 'title': 'Read', 'kind': 'success', 'description': 'Can view and pull from the repository' },
{ 'id': 'write', 'title': 'Write', 'kind': 'success', 'description': 'Can view, pull and push to the repository' },
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary', 'description': 'Full admin access, pull and push on the repository' }
];
roleService.repoRoles = roleService.repoRolesOrNone.slice(1);
roleService.teamRoles = [
{ 'id': 'member', 'title': 'Member', 'kind': 'default', 'description': 'Inherits all permissions of the team' },
{ 'id': 'creator', 'title': 'Creator', 'kind': 'success', 'description': 'Member and can create new repositories' },
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary', 'description': 'Full admin access to the organization' }
];
var getPermissionEndpoint = function(repository, entityName, kind) {
var namespace = repository.namespace;
var name = repository.name;
var url = UtilService.getRestUrl('repository', namespace, name, 'permissions', kind, entityName);
return Restangular.one(url);
};
roleService.deleteRepositoryRole = function(repository, entityKind, entityName, callback) {
var errorDisplay = ApiService.errorDisplay('Cannot change permission', function(resp) {
callback(false);
});
var endpoint = getPermissionEndpoint(repository, entityName, kind);
endpoint.customDELETE().then(function() {
callback(true);
}, errorHandler);
};
roleService.setRepositoryRole = function(repository, role, entityKind, entityName, callback) {
var errorDisplay = ApiService.errorDisplay('Cannot change permission', function(resp) {
callback(false);
});
var permission = {
'role': role
};
var endpoint = getPermissionEndpoint(repository, entityName, entityKind);
endpoint.customPUT(permission).then(function(resp) {
callback(true, resp);
}, errorDisplay);
};
return roleService;
}]);

View file

@ -22,6 +22,14 @@ angular.module('quay').factory('TableService', ['AngularViewArray', function(Ang
options.predicate = predicate;
};
tableService.getReversedTimestamp = function(datetime) {
if (!datetime) {
return -Number.MAX_VALUE;
}
return (new Date(datetime)).valueOf() * (-1);
};
tableService.buildOrderedItems = function(items, options, filterFields, numericFields, opt_extrafilter) {
var orderedItems = AngularViewArray.create();

View file

@ -82,7 +82,7 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
CheckStateController.prototype.rebuildCheckedList_ = function() {
var that = this;
this.checked = [];
this.items.forEach(function(item) {
this.allItems_.forEach(function(item) {
if (that.allCheckedMap_[item[that.itemKey_]]) {
that.checked.push(item);
}

View file

@ -122,6 +122,19 @@ function(ApiService, CookieService, $rootScope, Config) {
return !!org;
};
userService.getNamespace = function(namespace) {
var org = userService.getOrganization(namespace);
if (org) {
return org;
}
if (namespace == userResponse.username) {
return userResponse;
}
return null;
};
userService.currentUser = function() {
return userResponse;
};