orgApiKeysCtrl.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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, navModelSrv) {
  8. $scope.navModel = navModelSrv.getOrgNav(0);
  9. $scope.roleTypes = ['Viewer', 'Editor', 'Admin'];
  10. $scope.token = { role: 'Viewer' };
  11. $scope.init = function() {
  12. $scope.getTokens();
  13. };
  14. $scope.getTokens = function() {
  15. backendSrv.get('/api/auth/keys').then(function(tokens) {
  16. $scope.tokens = tokens;
  17. });
  18. };
  19. $scope.removeToken = function(id) {
  20. backendSrv.delete('/api/auth/keys/'+id).then($scope.getTokens);
  21. };
  22. $scope.addToken = function() {
  23. backendSrv.post('/api/auth/keys', $scope.token).then(function(result) {
  24. var modalScope = $scope.$new(true);
  25. modalScope.key = result.key;
  26. modalScope.rootPath = window.location.origin + $scope.$root.appSubUrl;
  27. $scope.appEvent('show-modal', {
  28. src: 'public/app/features/org/partials/apikeyModal.html',
  29. scope: modalScope
  30. });
  31. $scope.getTokens();
  32. });
  33. };
  34. $scope.init();
  35. });
  36. });