profileCtrl.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. define([
  2. 'angular',
  3. 'app/core/config',
  4. ],
  5. function (angular, config) {
  6. 'use strict';
  7. var module = angular.module('grafana.controllers');
  8. module.controller('ProfileCtrl', function($scope, backendSrv, contextSrv, $location) {
  9. $scope.init = function() {
  10. $scope.getUser();
  11. $scope.getUserOrgs();
  12. };
  13. $scope.getUser = function() {
  14. backendSrv.get('/api/user').then(function(user) {
  15. $scope.user = user;
  16. $scope.user.theme = user.theme || 'dark';
  17. $scope.old_theme = $scope.user.theme;
  18. });
  19. };
  20. $scope.getUserOrgs = function() {
  21. backendSrv.get('/api/user/orgs').then(function(orgs) {
  22. $scope.orgs = orgs;
  23. });
  24. };
  25. $scope.setUsingOrg = function(org) {
  26. backendSrv.post('/api/user/using/' + org.orgId).then(function() {
  27. window.location.href = config.appSubUrl + '/profile';
  28. });
  29. };
  30. $scope.update = function() {
  31. if (!$scope.userForm.$valid) { return; }
  32. backendSrv.put('/api/user/', $scope.user).then(function() {
  33. contextSrv.user.name = $scope.user.name || $scope.user.login;
  34. if ($scope.old_theme !== $scope.user.theme) {
  35. window.location.href = config.appSubUrl + $location.path();
  36. }
  37. });
  38. };
  39. $scope.init();
  40. });
  41. });