2016-01-16 23:26:29 +01:00
|
|
|
///<reference path="../../../headers/common.d.ts" />
|
2016-01-15 11:13:02 +01:00
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import $ from 'jquery';
|
2016-01-16 23:26:29 +01:00
|
|
|
import coreModule from '../../core_module';
|
2016-01-15 11:13:02 +01:00
|
|
|
|
2016-01-16 23:26:29 +01:00
|
|
|
export class SideMenuCtrl {
|
2016-01-15 11:13:02 +01:00
|
|
|
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-02-09 14:06:23 +01:00
|
|
|
constructor(private $scope, private $location, private contextSrv, private backendSrv, private $element) {
|
2016-01-15 11:13:02 +01:00
|
|
|
this.isSignedIn = contextSrv.isSignedIn;
|
|
|
|
|
this.user = contextSrv.user;
|
|
|
|
|
this.appSubUrl = config.appSubUrl;
|
|
|
|
|
this.showSignout = this.contextSrv.isSignedIn && !config['authProxyEnabled'];
|
|
|
|
|
this.updateMenu();
|
2016-01-29 15:12:56 -05:00
|
|
|
|
2016-01-15 13:20:32 +01:00
|
|
|
this.$scope.$on('$routeChangeSuccess', () => {
|
2016-01-29 16:52:30 -05:00
|
|
|
this.updateMenu();
|
2016-01-29 15:12:56 -05:00
|
|
|
if (!this.contextSrv.pinned) {
|
|
|
|
|
this.contextSrv.sidemenu = false;
|
|
|
|
|
}
|
2016-01-15 13:20:32 +01:00
|
|
|
});
|
2016-02-09 14:06:23 +01:00
|
|
|
|
2016-01-15 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getUrl(url) {
|
|
|
|
|
return config.appSubUrl + url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupMainNav() {
|
2016-02-09 14:06:23 +01:00
|
|
|
this.mainLinks = config.bootData.mainNavLinks;
|
2016-01-15 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openUserDropdown() {
|
|
|
|
|
this.orgMenu = [
|
|
|
|
|
{section: 'You', cssClass: 'dropdown-menu-title'},
|
2016-01-15 12:51:55 +01:00
|
|
|
{text: 'Preferences', url: this.getUrl('/profile')},
|
2016-01-17 20:32:37 +01:00
|
|
|
{text: 'Profile', 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({
|
2016-01-16 19:16:49 +01:00
|
|
|
text: "Preferences",
|
2016-01-15 11:13:02 +01:00
|
|
|
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
|
|
|
});
|
2016-01-29 16:52:30 -05: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
|
|
|
});
|
|
|
|
|
|
2016-01-21 01:48:29 -08:00
|
|
|
this.mainLinks.push({
|
2016-01-29 16:52:30 -05:00
|
|
|
text: "Stats",
|
2016-01-21 01:48:29 -08:00
|
|
|
icon: "fa fa-fw fa-bar-chart",
|
|
|
|
|
url: this.getUrl("/admin/stats"),
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-15 11:13:02 +01:00
|
|
|
this.mainLinks.push({
|
2016-01-29 16:52:30 -05:00
|
|
|
text: "Users",
|
2016-01-15 11:13:02 +01:00
|
|
|
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({
|
2016-01-29 16:52:30 -05:00
|
|
|
text: "Organizations",
|
2016-01-15 11:13:02 +01:00
|
|
|
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
|
|
|
});
|
2016-01-21 01:48:29 -08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 23:26:29 +01:00
|
|
|
export function sideMenuDirective() {
|
2016-01-15 11:13:02 +01:00
|
|
|
return {
|
|
|
|
|
restrict: 'E',
|
2016-02-01 18:19:02 +01:00
|
|
|
templateUrl: 'public/app/core/components/sidemenu/sidemenu.html',
|
2016-01-15 11:13:02 +01:00
|
|
|
controller: SideMenuCtrl,
|
|
|
|
|
bindToController: true,
|
|
|
|
|
controllerAs: 'ctrl',
|
|
|
|
|
scope: {},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 23:26:29 +01:00
|
|
|
coreModule.directive('sidemenu', sideMenuDirective);
|