contextSrv.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'store',
  5. 'config',
  6. ],
  7. function (angular, _, store, config) {
  8. 'use strict';
  9. var module = angular.module('grafana.services');
  10. module.service('contextSrv', function($rootScope, $timeout) {
  11. var self = this;
  12. function User() {
  13. if (window.grafanaBootData.user) {
  14. _.extend(this, window.grafanaBootData.user);
  15. }
  16. }
  17. this.version = config.buildInfo.version;
  18. this.lightTheme = false;
  19. this.user = new User();
  20. this.isSignedIn = this.user.isSignedIn;
  21. this.isGrafanaAdmin = this.user.isGrafanaAdmin;
  22. this.sidemenu = store.getBool('grafana.sidemenu');
  23. // events
  24. $rootScope.$on('toggle-sidemenu', function() {
  25. self.toggleSideMenu();
  26. });
  27. this.hasRole = function(role) {
  28. return this.user.orgRole === role;
  29. };
  30. this.setSideMenuState = function(state) {
  31. this.sidemenu = state;
  32. store.set('grafana.sidemenu', state);
  33. };
  34. this.toggleSideMenu = function() {
  35. this.setSideMenuState(!this.sidemenu);
  36. $timeout(function() {
  37. $rootScope.$broadcast("render");
  38. }, 50);
  39. };
  40. });
  41. });