profile_ctrl.ts 1.3 KB

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