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;
|
|
|
|
old_theme: any;
|
2018-07-27 06:45:16 -05:00
|
|
|
teams: any = [];
|
2016-09-08 02:03:29 -05:00
|
|
|
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;
|
2017-03-21 08:34:48 -05:00
|
|
|
readonlyLoginFields = config.disableLoginForm;
|
2017-06-02 07:00:42 -05:00
|
|
|
navModel: any;
|
2016-04-01 19:34:30 -05:00
|
|
|
|
|
|
|
/** @ngInject **/
|
2017-12-21 01:39:31 -06:00
|
|
|
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() {
|
|
|
|
console.log(this.backendSrv.get('/api/teams'));
|
|
|
|
this.backendSrv.get('/api/user').then(teams => {
|
|
|
|
this.user.teams = [
|
|
|
|
{ name: 'Backend', email: 'backend@grafana.com', members: 2 },
|
|
|
|
{ name: 'Frontend', email: 'frontend@grafana.com', members: 2 },
|
|
|
|
{ name: 'Ops', email: 'ops@grafana.com', members: 2 },
|
|
|
|
];
|
|
|
|
this.showTeamsList = this.user.teams.length > 1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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;
|
2016-09-08 02:03:29 -05:00
|
|
|
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() {
|
2017-12-19 09:06:54 -06:00
|
|
|
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.old_theme !== this.user.theme) {
|
|
|
|
window.location.href = config.appSubUrl + this.$location.path();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.controller('ProfileCtrl', ProfileCtrl);
|