2016-04-03 07:27:35 -05:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import store from 'app/core/store';
|
|
|
|
|
|
|
|
export class User {
|
|
|
|
isGrafanaAdmin: any;
|
|
|
|
isSignedIn: any;
|
|
|
|
orgRole: any;
|
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;
|
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;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.pinned = store.getBool('grafana.sidemenu.pinned', false);
|
|
|
|
if (this.pinned) {
|
|
|
|
this.sidemenu = true;
|
|
|
|
}
|
|
|
|
|
2016-04-03 09:12:43 -05:00
|
|
|
if (!config.buildInfo) {
|
|
|
|
config.buildInfo = {};
|
|
|
|
}
|
|
|
|
if (!config.bootData) {
|
|
|
|
config.bootData = {user: {}, settings: {}};
|
|
|
|
}
|
|
|
|
|
2016-04-03 07:27:35 -05:00
|
|
|
this.version = config.buildInfo.version;
|
|
|
|
this.user = new User();
|
|
|
|
this.isSignedIn = this.user.isSignedIn;
|
|
|
|
this.isGrafanaAdmin = this.user.isGrafanaAdmin;
|
|
|
|
this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
|
|
|
|
}
|
|
|
|
|
|
|
|
hasRole(role) {
|
|
|
|
return this.user.orgRole === role;
|
|
|
|
}
|
|
|
|
|
|
|
|
setPinnedState(val) {
|
|
|
|
this.pinned = val;
|
|
|
|
store.set('grafana.sidemenu.pinned', val);
|
|
|
|
}
|
|
|
|
|
2017-01-11 12:46:34 -06:00
|
|
|
isGrafanaVisible() {
|
|
|
|
return !!(document.visibilityState === undefined || document.visibilityState === 'visible');
|
|
|
|
}
|
|
|
|
|
2016-04-03 07:27:35 -05:00
|
|
|
toggleSideMenu() {
|
|
|
|
this.sidemenu = !this.sidemenu;
|
2017-06-12 14:11:22 -05:00
|
|
|
this.setPinnedState(this.sidemenu);
|
2016-04-03 07:27:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var contextSrv = new ContextSrv();
|
|
|
|
export {contextSrv};
|
|
|
|
|
|
|
|
coreModule.factory('contextSrv', function() {
|
|
|
|
return contextSrv;
|
|
|
|
});
|