Get the remainder of the repo settings panel working
This commit is contained in:
parent
32956b6713
commit
31480de8c1
12 changed files with 480 additions and 30 deletions
68
static/js/directives/ui/repository-tokens-table.js
Normal file
68
static/js/directives/ui/repository-tokens-table.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* An element which displays a table of tokens on a repository and allows them to be
|
||||
* edited.
|
||||
*/
|
||||
angular.module('quay').directive('repositoryTokensTable', function () {
|
||||
var directiveDefinitionObject = {
|
||||
priority: 0,
|
||||
templateUrl: '/static/directives/repository-tokens-table.html',
|
||||
replace: false,
|
||||
transclude: true,
|
||||
restrict: 'C',
|
||||
scope: {
|
||||
'repository': '=repository',
|
||||
'hasTokens': '=hasTokens'
|
||||
},
|
||||
controller: function($scope, $element, ApiService, Restangular, UtilService) {
|
||||
$scope.roles = [
|
||||
{ 'id': 'read', 'title': 'Read', 'kind': 'success' },
|
||||
{ 'id': 'write', 'title': 'Write', 'kind': 'success' },
|
||||
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary' }
|
||||
];
|
||||
|
||||
$scope.hasTokens = false;
|
||||
|
||||
var loadTokens = function() {
|
||||
if (!$scope.repository || $scope.tokensResource) { return; }
|
||||
var params = {
|
||||
'repository': $scope.repository.namespace + '/' + $scope.repository.name
|
||||
};
|
||||
|
||||
$scope.tokensResource = ApiService.listRepoTokensAsResource(params).get(function(resp) {
|
||||
$scope.tokens = resp.tokens;
|
||||
$scope.hasTokens = Object.keys($scope.tokens).length >= 1;
|
||||
}, ApiService.errorDisplay('Could not load access tokens'));
|
||||
};
|
||||
|
||||
$scope.$watch('repository', loadTokens);
|
||||
loadTokens();
|
||||
|
||||
$scope.deleteToken = function(tokenCode) {
|
||||
var params = {
|
||||
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
||||
'code': tokenCode
|
||||
};
|
||||
|
||||
ApiService.deleteToken(null, params).then(function() {
|
||||
delete $scope.tokens[tokenCode];
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeTokenAccess = function(tokenCode, newAccess) {
|
||||
var role = {
|
||||
'role': newAccess
|
||||
};
|
||||
|
||||
var params = {
|
||||
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
||||
'code': tokenCode
|
||||
};
|
||||
|
||||
ApiService.changeToken(role, params).then(function(updated) {
|
||||
$scope.tokens[updated.code] = updated;
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
return directiveDefinitionObject;
|
||||
});
|
Reference in a new issue