context_srv.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. define([
  2. 'angular',
  3. 'lodash',
  4. '../core_module',
  5. 'app/core/store',
  6. 'app/core/config',
  7. ],
  8. function (angular, _, coreModule, store, config) {
  9. 'use strict';
  10. coreModule.default.service('contextSrv', function() {
  11. function User() {
  12. if (config.bootData.user) {
  13. _.extend(this, config.bootData.user);
  14. }
  15. }
  16. this.hasRole = function(role) {
  17. return this.user.orgRole === role;
  18. };
  19. this.setPinnedState = function(val) {
  20. this.pinned = val;
  21. store.set('grafana.sidemenu.pinned', val);
  22. };
  23. this.toggleSideMenu = function() {
  24. this.sidemenu = !this.sidemenu;
  25. if (!this.sidemenu) {
  26. this.setPinnedState(false);
  27. }
  28. };
  29. this.pinned = store.getBool('grafana.sidemenu.pinned', false);
  30. if (this.pinned) {
  31. this.sidemenu = true;
  32. }
  33. this.version = config.buildInfo.version;
  34. this.lightTheme = false;
  35. this.user = new User();
  36. this.isSignedIn = this.user.isSignedIn;
  37. this.isGrafanaAdmin = this.user.isGrafanaAdmin;
  38. this.isEditor = this.hasRole('Editor') || this.hasRole('Admin');
  39. });
  40. });