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;
|
|
|
|
|
appSubUrl: string;
|
2016-07-06 10:09:53 +02:00
|
|
|
loginUrl: string;
|
2016-06-22 13:04:38 +02:00
|
|
|
orgFilter: string;
|
|
|
|
|
orgItems: any;
|
|
|
|
|
orgs: any;
|
2016-06-28 08:11:37 +02:00
|
|
|
maxShownOrgs: number;
|
2016-01-15 11:13:02 +01:00
|
|
|
|
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;
|
2017-03-29 11:33:28 +02:00
|
|
|
this.showSignout = this.contextSrv.isSignedIn && !config['disableSignoutMenu'];
|
2016-06-28 08:11:37 +02:00
|
|
|
this.maxShownOrgs = 10;
|
2016-02-14 17:37:05 +01:00
|
|
|
|
|
|
|
|
this.mainLinks = config.bootData.mainNavLinks;
|
2016-02-12 11:21:42 +01:00
|
|
|
this.openUserDropdown();
|
2016-07-07 14:48:22 +02:00
|
|
|
this.loginUrl = 'login?redirect=' + encodeURIComponent(this.$location.path());
|
2016-01-29 15:12:56 -05:00
|
|
|
|
2016-01-15 13:20:32 +01:00
|
|
|
this.$scope.$on('$routeChangeSuccess', () => {
|
2016-01-29 15:12:56 -05:00
|
|
|
if (!this.contextSrv.pinned) {
|
|
|
|
|
this.contextSrv.sidemenu = false;
|
|
|
|
|
}
|
2016-07-07 14:48:22 +02:00
|
|
|
this.loginUrl = 'login?redirect=' + encodeURIComponent(this.$location.path());
|
2016-01-15 13:20:32 +01:00
|
|
|
});
|
2016-08-18 15:48:01 +02:00
|
|
|
|
2016-06-22 13:04:38 +02:00
|
|
|
this.orgFilter = '';
|
2016-01-15 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getUrl(url) {
|
|
|
|
|
return config.appSubUrl + url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openUserDropdown() {
|
|
|
|
|
this.orgMenu = [
|
|
|
|
|
{section: 'You', cssClass: 'dropdown-menu-title'},
|
2016-01-17 20:32:37 +01:00
|
|
|
{text: 'Profile', url: this.getUrl('/profile')},
|
2016-01-15 11:13:02 +01:00
|
|
|
];
|
|
|
|
|
|
2017-01-26 13:10:33 -05:00
|
|
|
if (this.showSignout) {
|
2016-01-15 12:51:55 +01:00
|
|
|
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-06-22 13:04:38 +02:00
|
|
|
url: this.getUrl("/org")
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
|
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "Users",
|
2016-06-22 13:04:38 +02:00
|
|
|
url: this.getUrl("/org/users")
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
2017-04-10 01:24:16 +02:00
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "User Groups",
|
|
|
|
|
url: this.getUrl("/org/user-groups")
|
|
|
|
|
});
|
2016-01-15 11:13:02 +01:00
|
|
|
this.orgMenu.push({
|
|
|
|
|
text: "API Keys",
|
2016-06-22 13:04:38 +02:00
|
|
|
url: this.getUrl("/org/apikeys")
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.orgMenu.push({cssClass: "divider"});
|
|
|
|
|
this.backendSrv.get('/api/user/orgs').then(orgs => {
|
2016-06-22 13:04:38 +02:00
|
|
|
this.orgs = orgs;
|
|
|
|
|
this.loadOrgsItems();
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-01-15 11:13:02 +01:00
|
|
|
|
2016-06-22 13:04:38 +02:00
|
|
|
loadOrgsItems(){
|
|
|
|
|
this.orgItems = [];
|
|
|
|
|
this.orgs.forEach(org => {
|
|
|
|
|
if (org.orgId === this.contextSrv.user.orgId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 12:30:19 +02:00
|
|
|
if (this.orgItems.length === this.maxShownOrgs) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.orgFilter === '' || (org.name.toLowerCase().indexOf(this.orgFilter.toLowerCase()) !== -1)) {
|
2016-06-22 13:04:38 +02:00
|
|
|
this.orgItems.push({
|
2016-01-15 11:13:02 +01:00
|
|
|
text: "Switch to " + org.name,
|
|
|
|
|
icon: "fa fa-fw fa-random",
|
2016-04-09 13:27:06 -04:00
|
|
|
url: this.getUrl('/profile/switch-org/' + org.orgId),
|
|
|
|
|
target: '_self'
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
2016-01-29 16:52:30 -05:00
|
|
|
}
|
2016-01-15 11:13:02 +01:00
|
|
|
});
|
2016-06-22 13:04:38 +02:00
|
|
|
if (config.allowOrgCreate) {
|
|
|
|
|
this.orgItems.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
|
|
|
|
|
}
|
2016-01-15 11:13:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-02-26 10:22:06 +01:00
|
|
|
link: function(scope, elem) {
|
|
|
|
|
// hack to hide dropdown menu
|
|
|
|
|
elem.on('click.dropdown', '.dropdown-menu a', function(evt) {
|
|
|
|
|
var menu = $(evt.target).parents('.dropdown-menu');
|
|
|
|
|
var parent = menu.parent();
|
|
|
|
|
menu.detach();
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
parent.append(menu);
|
|
|
|
|
}, 100);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
scope.$on("$destory", function() {
|
|
|
|
|
elem.off('click.dropdown');
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-01-15 11:13:02 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 23:26:29 +01:00
|
|
|
coreModule.directive('sidemenu', sideMenuDirective);
|