feat(sidemenu): filtering organizations by an input, issue #2609

This commit is contained in:
Othyus 2016-06-22 13:04:38 +02:00
parent 0555525f97
commit e204c308bf
2 changed files with 31 additions and 14 deletions

View File

@ -22,6 +22,13 @@
{{::menuItem.text}}
</a>
</li>
<li><input ng-model="::ctrl.orgFilter" type="text" ng-change="::ctrl.loadOrgsItems();" class="gf-form-input" placeholder="Filter"></li>
<li ng-repeat="orgItem in ctrl.orgItems" ng-class="::orgItem.cssClass">
<a href="{{::orgItem.url}}" ng-show="::orgItem.url" target="{{::orgItem.target}}">
<i class="{{::orgItem.icon}}" ng-show="::orgItem.icon"></i>
{{::orgItem.text}}
</a>
</li>
</ul>
</li>

View File

@ -12,6 +12,9 @@ export class SideMenuCtrl {
mainLinks: any;
orgMenu: any;
appSubUrl: string;
orgFilter: string;
orgItems: any;
orgs: any;
/** @ngInject */
constructor(private $scope, private $location, private contextSrv, private backendSrv, private $element) {
@ -20,6 +23,7 @@ export class SideMenuCtrl {
this.appSubUrl = config.appSubUrl;
this.showSignout = this.contextSrv.isSignedIn && !config['authProxyEnabled'];
this.mainLinks = config.bootData.mainNavLinks;
this.openUserDropdown();
@ -28,7 +32,7 @@ export class SideMenuCtrl {
this.contextSrv.sidemenu = false;
}
});
this.orgFilter = '';
}
getUrl(url) {
@ -49,38 +53,44 @@ export class SideMenuCtrl {
this.orgMenu.push({section: this.user.orgName, cssClass: 'dropdown-menu-title'});
this.orgMenu.push({
text: "Preferences",
url: this.getUrl("/org"),
url: this.getUrl("/org")
});
this.orgMenu.push({
text: "Users",
url: this.getUrl("/org/users"),
url: this.getUrl("/org/users")
});
this.orgMenu.push({
text: "API Keys",
url: this.getUrl("/org/apikeys"),
url: this.getUrl("/org/apikeys")
});
}
this.orgMenu.push({cssClass: "divider"});
this.backendSrv.get('/api/user/orgs').then(orgs => {
orgs.forEach(org => {
if (org.orgId === this.contextSrv.user.orgId) {
return;
}
this.orgs = orgs;
this.loadOrgsItems();
});
}
this.orgMenu.push({
loadOrgsItems(){
this.orgItems = [];
this.orgs.forEach(org => {
if (org.orgId === this.contextSrv.user.orgId) {
return;
}
if (this.orgFilter === '' || org.name.indexOf(this.orgFilter) !== -1){
this.orgItems.push({
text: "Switch to " + org.name,
icon: "fa fa-fw fa-random",
url: this.getUrl('/profile/switch-org/' + org.orgId),
target: '_self'
});
});
if (config.allowOrgCreate) {
this.orgMenu.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
}
});
if (config.allowOrgCreate) {
this.orgItems.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
}
}
}