contextSrv.js 1.1 KB

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