org_api_keys_ctrl.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import angular from 'angular';
  2. export class OrgApiKeysCtrl {
  3. /** @ngInject **/
  4. constructor ($scope, $http, backendSrv, navModelSrv) {
  5. $scope.navModel = navModelSrv.getNav('cfg', 'apikeys');
  6. $scope.roleTypes = ['Viewer', 'Editor', 'Admin'];
  7. $scope.token = { role: 'Viewer' };
  8. $scope.init = function() {
  9. $scope.getTokens();
  10. };
  11. $scope.getTokens = function() {
  12. backendSrv.get('/api/auth/keys').then(function(tokens) {
  13. $scope.tokens = tokens;
  14. });
  15. };
  16. $scope.removeToken = function(id) {
  17. backendSrv.delete('/api/auth/keys/'+id).then($scope.getTokens);
  18. };
  19. $scope.addToken = function() {
  20. backendSrv.post('/api/auth/keys', $scope.token).then(function(result) {
  21. var modalScope = $scope.$new(true);
  22. modalScope.key = result.key;
  23. modalScope.rootPath = window.location.origin + $scope.$root.appSubUrl;
  24. $scope.appEvent('show-modal', {
  25. src: 'public/app/features/org/partials/apikeyModal.html',
  26. scope: modalScope
  27. });
  28. $scope.getTokens();
  29. });
  30. };
  31. $scope.init();
  32. }
  33. }
  34. angular.module('grafana.controllers').controller('OrgApiKeysCtrl', OrgApiKeysCtrl);