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;
|
2018-09-03 04:00:46 -05:00
|
|
|
oldTheme: 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
|
|
|
|
2018-08-31 09:40:43 -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() {
|
2018-08-08 03:50:27 -05:00
|
|
|
this.backendSrv.get('/api/user/teams').then(teams => {
|
|
|
|
this.teams = teams;
|
2018-08-13 08:07:29 -05:00
|
|
|
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;
|
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;
|
2018-09-03 04:00:46 -05:00
|
|
|
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);
|