grafana/public/app/features/profile/ProfileCtrl.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import config from 'app/core/config';
import { coreModule } from 'app/core/core';
2016-04-01 19:34:30 -05:00
export class ProfileCtrl {
user: any;
oldTheme: any;
2018-07-27 06:45:16 -05:00
teams: any = [];
orgs: any = [];
2016-04-01 19:34:30 -05:00
userForm: any;
2018-07-27 06:45:16 -05:00
showTeamsList = false;
2017-01-30 08:04:55 -06:00
showOrgsList = false;
readonlyLoginFields = config.disableLoginForm;
navModel: any;
2016-04-01 19:34:30 -05:00
/** @ngInject */
constructor(private backendSrv, private contextSrv, private $location, navModelSrv) {
2016-04-01 19:34:30 -05:00
this.getUser();
2018-07-27 06:45:16 -05:00
this.getUserTeams();
2016-04-01 19:34:30 -05:00
this.getUserOrgs();
2017-12-20 05:33:33 -06:00
this.navModel = navModelSrv.getNav('profile', 'profile-settings', 0);
2016-04-01 19:34:30 -05:00
}
getUser() {
2017-12-20 05:33:33 -06:00
this.backendSrv.get('/api/user').then(user => {
2016-04-01 19:34:30 -05:00
this.user = user;
2017-12-20 05:33:33 -06:00
this.user.theme = user.theme || 'dark';
2016-04-01 19:34:30 -05:00
});
}
2018-07-27 06:45:16 -05:00
getUserTeams() {
this.backendSrv.get('/api/user/teams').then(teams => {
this.teams = teams;
this.showTeamsList = this.teams.length > 0;
2018-07-27 06:45:16 -05:00
});
}
2016-04-01 19:34:30 -05:00
getUserOrgs() {
2017-12-20 05:33:33 -06:00
this.backendSrv.get('/api/user/orgs').then(orgs => {
2016-04-01 19:34:30 -05:00
this.orgs = orgs;
this.showOrgsList = orgs.length > 1;
2016-04-01 19:34:30 -05:00
});
}
setUsingOrg(org) {
2017-12-20 05:33:33 -06:00
this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
window.location.href = config.appSubUrl + '/profile';
2016-04-01 19:34:30 -05:00
});
}
update() {
if (!this.userForm.$valid) {
return;
}
2016-04-01 19:34:30 -05:00
2017-12-20 05:33:33 -06:00
this.backendSrv.put('/api/user/', this.user).then(() => {
2016-04-01 19:34:30 -05:00
this.contextSrv.user.name = this.user.name || this.user.login;
if (this.oldTheme !== this.user.theme) {
2016-04-01 19:34:30 -05:00
window.location.href = config.appSubUrl + this.$location.path();
}
});
}
}
2017-12-20 05:33:33 -06:00
coreModule.controller('ProfileCtrl', ProfileCtrl);