Skip to content

Commit e204c30

Browse files
committed
feat(sidemenu): filtering organizations by an input, issue grafana#2609
1 parent 0555525 commit e204c30

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

public/app/core/components/sidemenu/sidemenu.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
{{::menuItem.text}}
2323
</a>
2424
</li>
25+
<li><input ng-model="::ctrl.orgFilter" type="text" ng-change="::ctrl.loadOrgsItems();" class="gf-form-input" placeholder="Filter"></li>
26+
<li ng-repeat="orgItem in ctrl.orgItems" ng-class="::orgItem.cssClass">
27+
<a href="{{::orgItem.url}}" ng-show="::orgItem.url" target="{{::orgItem.target}}">
28+
<i class="{{::orgItem.icon}}" ng-show="::orgItem.icon"></i>
29+
{{::orgItem.text}}
30+
</a>
31+
</li>
2532
</ul>
2633
</li>
2734

public/app/core/components/sidemenu/sidemenu.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export class SideMenuCtrl {
1212
mainLinks: any;
1313
orgMenu: any;
1414
appSubUrl: string;
15+
orgFilter: string;
16+
orgItems: any;
17+
orgs: any;
1518

1619
/** @ngInject */
1720
constructor(private $scope, private $location, private contextSrv, private backendSrv, private $element) {
@@ -20,6 +23,7 @@ export class SideMenuCtrl {
2023
this.appSubUrl = config.appSubUrl;
2124
this.showSignout = this.contextSrv.isSignedIn && !config['authProxyEnabled'];
2225

26+
2327
this.mainLinks = config.bootData.mainNavLinks;
2428
this.openUserDropdown();
2529

@@ -28,7 +32,7 @@ export class SideMenuCtrl {
2832
this.contextSrv.sidemenu = false;
2933
}
3034
});
31-
35+
this.orgFilter = '';
3236
}
3337

3438
getUrl(url) {
@@ -49,38 +53,44 @@ export class SideMenuCtrl {
4953
this.orgMenu.push({section: this.user.orgName, cssClass: 'dropdown-menu-title'});
5054
this.orgMenu.push({
5155
text: "Preferences",
52-
url: this.getUrl("/org"),
56+
url: this.getUrl("/org")
5357
});
5458
this.orgMenu.push({
5559
text: "Users",
56-
url: this.getUrl("/org/users"),
60+
url: this.getUrl("/org/users")
5761
});
5862
this.orgMenu.push({
5963
text: "API Keys",
60-
url: this.getUrl("/org/apikeys"),
64+
url: this.getUrl("/org/apikeys")
6165
});
6266
}
6367

6468
this.orgMenu.push({cssClass: "divider"});
65-
6669
this.backendSrv.get('/api/user/orgs').then(orgs => {
67-
orgs.forEach(org => {
68-
if (org.orgId === this.contextSrv.user.orgId) {
69-
return;
70-
}
70+
this.orgs = orgs;
71+
this.loadOrgsItems();
72+
});
73+
}
7174

72-
this.orgMenu.push({
75+
loadOrgsItems(){
76+
this.orgItems = [];
77+
this.orgs.forEach(org => {
78+
if (org.orgId === this.contextSrv.user.orgId) {
79+
return;
80+
}
81+
82+
if (this.orgFilter === '' || org.name.indexOf(this.orgFilter) !== -1){
83+
this.orgItems.push({
7384
text: "Switch to " + org.name,
7485
icon: "fa fa-fw fa-random",
7586
url: this.getUrl('/profile/switch-org/' + org.orgId),
7687
target: '_self'
7788
});
78-
});
79-
80-
if (config.allowOrgCreate) {
81-
this.orgMenu.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
8289
}
8390
});
91+
if (config.allowOrgCreate) {
92+
this.orgItems.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
93+
}
8494
}
8595
}
8696

0 commit comments

Comments
 (0)