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