orgApiKeysCtrl.js 1.1 KB

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