Files
grafana/public/app/features/org/profile_ctrl.ts
Torkel Ödegaard 0c86241c5b Webpack (#9391)
* webpack poc, this is not going to work for plugins, dam

* tech: webpack and systemjs for plugins starting to work

* tech: webpack and systemjs combo starting to work

* tech: webpack + karma tests progress

* tech: webpack + karma progress

* tech: working on tests

* tech: webpack

* tech: webpack + karma, all tests pass

* tech: webpack + karma, all tests pass

* tech: webpack all tests pass

* webpack: getting closer

* tech: webpack progress

* webpack: further build refinements

* webpack: ng annotate fixes

* webpack: optimized build fix

* tech: minor fix for elasticsearch

* tech: webpack + ace editor

* tech: restored lodash move mixin compatability

* tech: added enzyme react test and upgraded to react v16

* tech: package version fix

* tech: added testdata to built in bundle

* webpack: sass progress

* tech: prod & dev build is working for the sass

* tech: clean up unused grunt stuff and moved to scripts folder

* tech: added vendor and manifest chunks, updated readme and docs

* tech: webpack finishing touches
2017-10-01 20:02:25 +02:00

54 lines
1.3 KiB
TypeScript

import config from 'app/core/config';
import {coreModule} from 'app/core/core';
export class ProfileCtrl {
user: any;
old_theme: any;
orgs: any = [];
userForm: any;
showOrgsList = false;
readonlyLoginFields = config.disableLoginForm;
navModel: any;
/** @ngInject **/
constructor(private backendSrv, private contextSrv, private $location, navModelSrv) {
this.getUser();
this.getUserOrgs();
this.navModel = navModelSrv.getProfileNav();
}
getUser() {
this.backendSrv.get('/api/user').then(user => {
this.user = user;
this.user.theme = user.theme || 'dark';
});
}
getUserOrgs() {
this.backendSrv.get('/api/user/orgs').then(orgs => {
this.orgs = orgs;
this.showOrgsList = orgs.length > 1;
});
}
setUsingOrg(org) {
this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
window.location.href = config.appSubUrl + '/profile';
});
}
update() {
if (!this.userForm.$valid) { return; }
this.backendSrv.put('/api/user/', this.user).then(() => {
this.contextSrv.user.name = this.user.name || this.user.login;
if (this.old_theme !== this.user.theme) {
window.location.href = config.appSubUrl + this.$location.path();
}
});
}
}
coreModule.controller('ProfileCtrl', ProfileCtrl);