2017-12-20 05:33:33 -06:00
|
|
|
import config from 'app/core/config';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import store from 'app/core/store';
|
2016-04-03 07:27:35 -05:00
|
|
|
|
|
|
|
export class User {
|
|
|
|
isGrafanaAdmin: any;
|
|
|
|
isSignedIn: any;
|
|
|
|
orgRole: any;
|
2017-08-16 08:37:13 -05:00
|
|
|
orgId: number;
|
2016-09-19 04:34:08 -05:00
|
|
|
timezone: string;
|
2016-11-09 03:41:39 -06:00
|
|
|
helpFlags1: number;
|
2017-03-31 10:12:50 -05:00
|
|
|
lightTheme: boolean;
|
2018-04-30 08:38:46 -05:00
|
|
|
hasEditPermissionInFolders: boolean;
|
2016-04-03 07:27:35 -05:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
if (config.bootData.user) {
|
|
|
|
_.extend(this, config.bootData.user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ContextSrv {
|
|
|
|
pinned: any;
|
|
|
|
version: any;
|
|
|
|
user: User;
|
|
|
|
isSignedIn: any;
|
|
|
|
isGrafanaAdmin: any;
|
|
|
|
isEditor: any;
|
|
|
|
sidemenu: any;
|
2017-12-04 05:37:00 -06:00
|
|
|
sidemenuSmallBreakpoint = false;
|
2018-04-30 08:38:46 -05:00
|
|
|
hasEditPermissionInFolders: boolean;
|
2016-04-03 07:27:35 -05:00
|
|
|
|
|
|
|
constructor() {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.sidemenu = store.getBool('grafana.sidemenu', true);
|
2016-04-03 07:27:35 -05:00
|
|
|
|
2016-04-03 09:12:43 -05:00
|
|
|
if (!config.bootData) {
|
2017-12-19 09:06:54 -06:00
|
|
|
config.bootData = { user: {}, settings: {} };
|
2016-04-03 09:12:43 -05:00
|
|
|
}
|
|
|
|
|
2016-04-03 07:27:35 -05:00
|
|
|
this.user = new User();
|
|
|
|
this.isSignedIn = this.user.isSignedIn;
|
|
|
|
this.isGrafanaAdmin = this.user.isGrafanaAdmin;
|
2017-12-20 05:33:33 -06:00
|
|
|
this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
|
2018-04-30 08:38:46 -05:00
|
|
|
this.hasEditPermissionInFolders = this.user.hasEditPermissionInFolders;
|
2016-04-03 07:27:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
hasRole(role) {
|
|
|
|
return this.user.orgRole === role;
|
|
|
|
}
|
|
|
|
|
2017-01-11 12:46:34 -06:00
|
|
|
isGrafanaVisible() {
|
2017-12-21 01:39:31 -06:00
|
|
|
return !!(document.visibilityState === undefined || document.visibilityState === 'visible');
|
2017-01-11 12:46:34 -06:00
|
|
|
}
|
|
|
|
|
2016-04-03 07:27:35 -05:00
|
|
|
toggleSideMenu() {
|
|
|
|
this.sidemenu = !this.sidemenu;
|
2017-12-20 05:33:33 -06:00
|
|
|
store.set('grafana.sidemenu', this.sidemenu);
|
2017-12-04 05:37:00 -06:00
|
|
|
}
|
2016-04-03 07:27:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var contextSrv = new ContextSrv();
|
2017-12-19 09:06:54 -06:00
|
|
|
export { contextSrv };
|
2016-04-03 07:27:35 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.factory('contextSrv', function() {
|
2016-04-03 07:27:35 -05:00
|
|
|
return contextSrv;
|
|
|
|
});
|