mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
feat(prefs): moved context srv to typescript
This commit is contained in:
parent
ab1048b7ee
commit
55d95f9009
@ -1,47 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'../core_module',
|
||||
'app/core/store',
|
||||
'app/core/config',
|
||||
],
|
||||
function (angular, _, coreModule, store, config) {
|
||||
'use strict';
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
this.setPinnedState = function(val) {
|
||||
this.pinned = val;
|
||||
store.set('grafana.sidemenu.pinned', val);
|
||||
};
|
||||
|
||||
this.toggleSideMenu = function() {
|
||||
this.sidemenu = !this.sidemenu;
|
||||
if (!this.sidemenu) {
|
||||
this.setPinnedState(false);
|
||||
}
|
||||
};
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
67
public/app/core/services/context_srv.ts
Normal file
67
public/app/core/services/context_srv.ts
Normal file
@ -0,0 +1,67 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import config from 'app/core/config';
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import coreModule from 'app/core/core_module';
|
||||
import store from 'app/core/store';
|
||||
|
||||
export class User {
|
||||
isGrafanaAdmin: any;
|
||||
isSignedIn: any;
|
||||
orgRole: any;
|
||||
|
||||
constructor() {
|
||||
if (config.bootData.user) {
|
||||
_.extend(this, config.bootData.user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ContextSrv {
|
||||
pinned: any;
|
||||
version: any;
|
||||
user: User;
|
||||
isSignedIn: any;
|
||||
isGrafanaAdmin: any;
|
||||
isEditor: any;
|
||||
sidemenu: any;
|
||||
lightTheme: any;
|
||||
|
||||
constructor() {
|
||||
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');
|
||||
}
|
||||
|
||||
hasRole(role) {
|
||||
return this.user.orgRole === role;
|
||||
}
|
||||
|
||||
setPinnedState(val) {
|
||||
this.pinned = val;
|
||||
store.set('grafana.sidemenu.pinned', val);
|
||||
}
|
||||
|
||||
toggleSideMenu() {
|
||||
this.sidemenu = !this.sidemenu;
|
||||
if (!this.sidemenu) {
|
||||
this.setPinnedState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var contextSrv = new ContextSrv();
|
||||
export {contextSrv};
|
||||
|
||||
coreModule.factory('contextSrv', function() {
|
||||
return contextSrv;
|
||||
});
|
Loading…
Reference in New Issue
Block a user