profile_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import {coreModule} from 'app/core/core';
  4. import _ from 'lodash';
  5. export class ProfileCtrl {
  6. user: any;
  7. old_theme: any;
  8. orgs: any;
  9. userForm: any;
  10. /** @ngInject **/
  11. constructor(private backendSrv, private contextSrv, private $location) {
  12. this.getUser();
  13. this.getUserOrgs();
  14. }
  15. getUser() {
  16. this.backendSrv.get('/api/user').then(user => {
  17. this.user = user;
  18. this.user.theme = user.theme || 'dark';
  19. });
  20. }
  21. getUserOrgs() {
  22. this.backendSrv.get('/api/user/orgs').then(orgs => {
  23. this.orgs = orgs;
  24. });
  25. }
  26. setUsingOrg(org) {
  27. this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
  28. window.location.href = config.appSubUrl + '/profile';
  29. });
  30. }
  31. update() {
  32. if (!this.userForm.$valid) { return; }
  33. this.backendSrv.put('/api/user/', this.user).then(() => {
  34. this.contextSrv.user.name = this.user.name || this.user.login;
  35. if (this.old_theme !== this.user.theme) {
  36. window.location.href = config.appSubUrl + this.$location.path();
  37. }
  38. });
  39. }
  40. }
  41. coreModule.controller('ProfileCtrl', ProfileCtrl);