select_org_ctrl.ts 877 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import angular from 'angular';
  2. import config from 'app/core/config';
  3. export class SelectOrgCtrl {
  4. /** @ngInject **/
  5. constructor($scope, backendSrv, contextSrv) {
  6. contextSrv.sidemenu = false;
  7. $scope.navModel = {
  8. main: {
  9. icon: 'gicon gicon-branding',
  10. subTitle: 'Preferences',
  11. text: 'Select active organization',
  12. },
  13. };
  14. $scope.init = function() {
  15. $scope.getUserOrgs();
  16. };
  17. $scope.getUserOrgs = function() {
  18. backendSrv.get('/api/user/orgs').then(function(orgs) {
  19. $scope.orgs = orgs;
  20. });
  21. };
  22. $scope.setUsingOrg = function(org) {
  23. backendSrv.post('/api/user/using/' + org.orgId).then(function() {
  24. window.location.href = config.appSubUrl + '/';
  25. });
  26. };
  27. $scope.init();
  28. }
  29. }
  30. angular.module('grafana.controllers').controller('SelectOrgCtrl', SelectOrgCtrl);