grafana/public/app/core/services/context_srv.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

define([
'angular',
'lodash',
'../core_module',
2015-10-30 08:19:02 -05:00
'app/core/store',
'app/core/config',
],
function (angular, _, coreModule, store, config) {
'use strict';
2016-01-15 07:42:59 -06:00
coreModule.default.service('contextSrv', function() {
function User() {
if (config.bootData.user) {
_.extend(this, config.bootData.user);
}
}
this.hasRole = function(role) {
return this.user.orgRole === role;
};
2016-01-29 14:12:56 -06:00
this.setPinnedState = function(val) {
this.pinned = val;
store.set('grafana.sidemenu.pinned', val);
};
this.toggleSideMenu = function() {
this.sidemenu = !this.sidemenu;
2016-01-29 14:12:56 -06:00
if (!this.sidemenu) {
this.setPinnedState(false);
}
2015-05-05 13:59:21 -05:00
};
2016-01-29 14:12:56 -06:00
this.pinned = store.getBool('grafana.sidemenu.pinned', false);
if (this.pinned) {
this.sidemenu = true;
}
this.version = config.buildInfo.version;
this.lightTheme = false;
this.user = new User();
this.isSignedIn = this.user.isSignedIn;
this.isGrafanaAdmin = this.user.isGrafanaAdmin;
this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
});
});