2016-01-15 11:13:02 +01:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
|
|
|
import store from 'app/core/store';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import angular from 'angular';
|
|
|
|
|
import $ from 'jquery';
|
|
|
|
|
|
|
|
|
|
class SideMenuCtrl {
|
|
|
|
|
isSignedIn: boolean;
|
|
|
|
|
showSignout: boolean;
|
|
|
|
|
user: any;
|
|
|
|
|
mainLinks: any;
|
|
|
|
|
orgMenu: any;
|
|
|
|
|
systemSection: any;
|
|
|
|
|
grafanaVersion: any;
|
|
|
|
|
appSubUrl: string;
|
|
|
|
|
|
2016-01-16 16:17:29 +01:00
|
|
|
/** @ngInject */
|
2016-01-15 11:13:02 +01:00
|
|
|
constructor(private $scope, private $location, private contextSrv, private backendSrv) {
|
|
|
|
|
this.isSignedIn = contextSrv.isSignedIn;
|
|
|
|
|
this.user = contextSrv.user;
|
|
|
|
|
this.appSubUrl = config.appSubUrl;
|
|
|
|
|
this.showSignout = this.contextSrv.isSignedIn && !config['authProxyEnabled'];
|
|
|
|
|
this.updateMenu();
|
2016-01-15 13:20:32 +01:00
|
|
|
this.$scope.$on('$routeChangeSuccess', () => {
|
|
|
|
|
this.contextSrv.sidemenu = false;
|
|
|
|
|
});
|
2016-01-15 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getUrl(url) {
|
|
|
|
|
return config.appSubUrl + url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupMainNav() {
|
|
|
|
|
this.mainLinks = config.bootData.mainNavLinks.map(item => {
|
|
|
|
|
return {text: item.text, icon: item.icon, img: item.img, url: this.getUrl(item.url)};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openUserDropdown() {
|
|
|
|
|
this.orgMenu = [
|
|
|
|
|
{section: 'You', cssClass: 'dropdown-menu-title'},
|
2016-01-15 12:51:55 +01:00
|
|
|
{text: 'Preferences', url: this.getUrl('/profile')},
|
|
|
|
|
{text: 'Account', url: this.getUrl('/profile')},
|
2016-01-15 11:13:02 +01:00
|
|
|
];
|
|
|
|
|
|
2016-01-15 12:51:55 +01:00
|
|
|
if (this.isSignedIn) {
|
|
|
|
|
this.orgMenu.push({text: "Sign out", url: this.getUrl("/logout"), target: "_self"});
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 11:13:02 +01:00
|
|
|
if (this.contextSrv.hasRole('Admin')) {
|
|
|
|
|
this.orgMenu.push({section: this.user.orgName, cssClass: 'dropdown-menu-title'});
|
|
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "Settings",
|
|
|
|
|
url: this.getUrl("/org"),
|
|
|
|
|
});
|
|
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "Users",
|
|
|
|
|
url: this.getUrl("/org/users"),
|
|
|
|
|
});
|
|
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "API Keys",
|
|
|
|
|
url: this.getUrl("/org/apikeys"),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.orgMenu.push({cssClass: "divider"});
|
|
|
|
|
|
2016-01-15 13:20:32 +01:00
|
|
|
if (this.contextSrv.isGrafanaAdmin) {
|
|
|
|
|
this.orgMenu.push({text: "Grafana adminstration", icon: "fa fa-fw fa-cogs", url: this.getUrl("/admin/settings")});
|
2016-01-15 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.backendSrv.get('/api/user/orgs').then(orgs => {
|
|
|
|
|
orgs.forEach(org => {
|
|
|
|
|
if (org.orgId === this.contextSrv.user.orgId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "Switch to " + org.name,
|
|
|
|
|
icon: "fa fa-fw fa-random",
|
|
|
|
|
click: () => {
|
|
|
|
|
this.switchOrg(org.orgId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-15 13:20:32 +01:00
|
|
|
if (config.allowOrgCreate) {
|
|
|
|
|
this.orgMenu.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switchOrg(orgId) {
|
|
|
|
|
this.backendSrv.post('/api/user/using/' + orgId).then(() => {
|
|
|
|
|
window.location.href = window.location.href;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setupAdminNav() {
|
|
|
|
|
this.systemSection = true;
|
|
|
|
|
this.grafanaVersion = config.buildInfo.version;
|
|
|
|
|
|
|
|
|
|
this.mainLinks.push({
|
|
|
|
|
text: "System info",
|
|
|
|
|
icon: "fa fa-fw fa-info",
|
2016-01-15 13:20:32 +01:00
|
|
|
url: this.getUrl("/admin/settings"),
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.mainLinks.push({
|
|
|
|
|
text: "Global Users",
|
|
|
|
|
icon: "fa fa-fw fa-user",
|
2016-01-15 13:20:32 +01:00
|
|
|
url: this.getUrl("/admin/users"),
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.mainLinks.push({
|
|
|
|
|
text: "Global Orgs",
|
|
|
|
|
icon: "fa fa-fw fa-users",
|
2016-01-15 13:20:32 +01:00
|
|
|
url: this.getUrl("/admin/orgs"),
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMenu() {
|
|
|
|
|
this.systemSection = false;
|
|
|
|
|
this.mainLinks = [];
|
|
|
|
|
this.orgMenu = [];
|
|
|
|
|
|
|
|
|
|
var currentPath = this.$location.path();
|
|
|
|
|
if (currentPath.indexOf('/admin') === 0) {
|
|
|
|
|
this.setupAdminNav();
|
|
|
|
|
} else {
|
|
|
|
|
this.setupMainNav();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sideMenuDirective() {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'E',
|
|
|
|
|
templateUrl: 'app/features/sidemenu/sidemenu.html',
|
|
|
|
|
controller: SideMenuCtrl,
|
|
|
|
|
bindToController: true,
|
|
|
|
|
controllerAs: 'ctrl',
|
|
|
|
|
scope: {},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
angular.module('grafana.directives').directive('sidemenu', sideMenuDirective);
|