This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/repository-tokens-table.js
2015-04-20 17:42:33 -04:00

62 lines
No EOL
1.9 KiB
JavaScript

/**
* 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.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;
});