contextSrv.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // events
  18. $rootScope.$on('toggle-sidemenu', function() {
  19. self.toggleSideMenu();
  20. });
  21. this.hasRole = function(role) {
  22. return this.user.orgRole === role;
  23. };
  24. this.setSideMenuState = function(state) {
  25. this.sidemenu = state;
  26. store.set('grafana.sidemenu', state);
  27. };
  28. this.toggleSideMenu = function() {
  29. this.setSideMenuState(!this.sidemenu);
  30. $timeout(function() {
  31. $rootScope.$broadcast("render");
  32. }, 50);
  33. };
  34. this.version = config.buildInfo.version;
  35. this.lightTheme = false;
  36. this.user = new User();
  37. this.isSignedIn = this.user.isSignedIn;
  38. this.isGrafanaAdmin = this.user.isGrafanaAdmin;
  39. this.sidemenu = store.getBool('grafana.sidemenu');
  40. this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
  41. });
  42. });