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