Add a dropdown next to the entity search which shows all the user’s teams and robot accounts, and lets them create new ones on the fly
This commit is contained in:
parent
ecabcc3fc6
commit
9197a20a77
11 changed files with 223 additions and 53 deletions
152
static/js/app.js
152
static/js/app.js
|
@ -1,3 +1,6 @@
|
|||
var TEAM_PATTERN = '^[a-zA-Z][a-zA-Z0-9]+$';
|
||||
var ROBOT_PATTERN = '^[a-zA-Z][a-zA-Z0-9]+$';
|
||||
|
||||
function getFirstTextLine(commentString) {
|
||||
if (!commentString) { return ''; }
|
||||
|
||||
|
@ -31,6 +34,45 @@ function getFirstTextLine(commentString) {
|
|||
return '';
|
||||
}
|
||||
|
||||
function createRobotAccount(Restangular, is_org, orgname, name, callback) {
|
||||
var url = is_org ? getRestUrl('organization', orgname, 'robots', name) :
|
||||
getRestUrl('user/robots', name);
|
||||
var createRobot = Restangular.one(url);
|
||||
createRobot.customPUT().then(callback, function(resp) {
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The robot account could not be created',
|
||||
"title": "Cannot create robot account",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createOrganizationTeam(Restangular, orgname, teamname, callback) {
|
||||
var createTeam = Restangular.one(getRestUrl('organization', orgname, 'team', teamname));
|
||||
var data = {
|
||||
'name': teamname,
|
||||
'role': 'member'
|
||||
};
|
||||
|
||||
createTeam.customPOST(data).then(callback, function() {
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The team could not be created',
|
||||
"title": "Cannot create team",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getRestUrl(args) {
|
||||
var url = '';
|
||||
for (var i = 0; i < arguments.length; ++i) {
|
||||
|
@ -474,7 +516,8 @@ quayApp.directive('entityReference', function () {
|
|||
'name': '=name',
|
||||
'orgname': '=orgname',
|
||||
'team': '=team',
|
||||
'isrobot': '=isrobot'
|
||||
'isrobot': '=isrobot',
|
||||
'isorgadmin': '=isorgadmin'
|
||||
},
|
||||
controller: function($scope, $element) {
|
||||
$scope.getPrefix = function(name) {
|
||||
|
@ -905,6 +948,7 @@ quayApp.directive('robotsManager', function () {
|
|||
'user': '=user'
|
||||
},
|
||||
controller: function($scope, $element, Restangular) {
|
||||
$scope.ROBOT_PATTERN = ROBOT_PATTERN;
|
||||
$scope.robots = null;
|
||||
$scope.loading = false;
|
||||
$scope.shownRobot = null;
|
||||
|
@ -928,23 +972,10 @@ quayApp.directive('robotsManager', function () {
|
|||
$scope.createRobot = function(name) {
|
||||
if (!name) { return; }
|
||||
|
||||
var url = $scope.organization ? getRestUrl('organization', $scope.organization.name, 'robots', name) :
|
||||
getRestUrl('user/robots', name);
|
||||
var createRobot = Restangular.one(url);
|
||||
createRobot.customPUT().then(function(resp) {
|
||||
$scope.robots.push(resp);
|
||||
}, function(resp) {
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The robot account could not be created',
|
||||
"title": "Cannot create robot account",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
createRobotAccount(Restangular, !!$scope.organization, $scope.organization ? $scope.organization.name : '', name,
|
||||
function(created) {
|
||||
$scope.robots.push(created);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteRobot = function(info) {
|
||||
|
@ -1218,14 +1249,89 @@ quayApp.directive('entitySearch', function () {
|
|||
'namespace': '=namespace',
|
||||
'inputTitle': '=inputTitle',
|
||||
'entitySelected': '=entitySelected',
|
||||
'includeTeams': '=includeTeams'
|
||||
'includeTeams': '=includeTeams',
|
||||
'isOrganization': '=isOrganization'
|
||||
},
|
||||
controller: function($scope, $element) {
|
||||
controller: function($scope, $element, Restangular) {
|
||||
$scope.lazyLoading = true;
|
||||
$scope.isAdmin = false;
|
||||
|
||||
$scope.lazyLoad = function() {
|
||||
if (!$scope.namespace || !$scope.lazyLoading) { return; }
|
||||
|
||||
if ($scope.isOrganization && $scope.includeTeams) {
|
||||
var url = getRestUrl('organization', $scope.namespace);
|
||||
var getOrganization = Restangular.one(url);
|
||||
getOrganization.customGET().then(function(resp) {
|
||||
$scope.teams = resp.teams;
|
||||
});
|
||||
}
|
||||
|
||||
var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots';
|
||||
var getRobots = Restangular.one(url);
|
||||
getRobots.customGET().then(function(resp) {
|
||||
$scope.robots = resp.robots;
|
||||
$scope.isAdmin = true;
|
||||
$scope.lazyLoading = false;
|
||||
}, function() {
|
||||
$scope.isAdmin = false;
|
||||
$scope.lazyLoading = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createTeam = function() {
|
||||
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;
|
||||
}
|
||||
|
||||
createOrganizationTeam(Restangular, $scope.namespace, teamname, function(created) {
|
||||
$scope.setEntity(created.name, 'team', false);
|
||||
$scope.teams[teamname] = created;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createRobot = function() {
|
||||
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;
|
||||
}
|
||||
|
||||
createRobotAccount(Restangular, $scope.isOrganization, $scope.namespace, robotname, function(created) {
|
||||
$scope.setEntity(created.name, 'user', true);
|
||||
$scope.robots.push(created);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.setEntity = function(name, kind, is_robot) {
|
||||
var entity = {
|
||||
'name': name,
|
||||
'kind': kind,
|
||||
'is_robot': is_robot
|
||||
};
|
||||
|
||||
if ($scope.is_organization) {
|
||||
entity['is_org_member'] = true;
|
||||
}
|
||||
|
||||
$scope.entitySelected(entity);
|
||||
};
|
||||
|
||||
if (!$scope.entitySelected) { return; }
|
||||
|
||||
number++;
|
||||
|
||||
var input = $element[0].firstChild;
|
||||
var input = $element[0].firstChild.firstChild;
|
||||
$scope.namespace = $scope.namespace || '';
|
||||
$(input).typeahead({
|
||||
name: 'entities' + number,
|
||||
|
@ -1274,7 +1380,9 @@ quayApp.directive('entitySearch', function () {
|
|||
|
||||
$(input).on('typeahead:selected', function(e, datum) {
|
||||
$(input).typeahead('setQuery', '');
|
||||
$scope.entitySelected(datum.entity);
|
||||
$scope.$apply(function() {
|
||||
$scope.entitySelected(datum.entity);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$watch('inputTitle', function(title) {
|
||||
|
|
Reference in a new issue