Skip to content

Commit 6d60d12

Browse files
committed
Merge branch 'Othyus-filter_orgs'
2 parents 998ed09 + e3bbf96 commit 6d60d12

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
{{::menuItem.text}}
2323
</a>
2424
</li>
25+
<li ng-show="ctrl.orgs.length > ctrl.maxShownOrgs" style="margin-left: 10px;width: 90%">
26+
<span class="sidemenu-item-text">Max shown : {{::ctrl.maxShownOrgs}}</span>
27+
<input ng-model="::ctrl.orgFilter" style="padding-left: 5px" type="text" ng-change="::ctrl.loadOrgsItems();" class="gf-input-small width-12" placeholder="Filter">
28+
</li>
29+
<li ng-repeat="orgItem in ctrl.orgItems" ng-class="::orgItem.cssClass">
30+
<a href="{{::orgItem.url}}" ng-show="::orgItem.url" target="{{::orgItem.target}}">
31+
<i class="{{::orgItem.icon}}" ng-show="::orgItem.icon"></i>
32+
{{::orgItem.text}}
33+
</a>
34+
</li>
2535
</ul>
2636
</li>
2737

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ export class SideMenuCtrl {
1313
orgMenu: any;
1414
appSubUrl: string;
1515
loginUrl: string;
16+
orgFilter: string;
17+
orgItems: any;
18+
orgs: any;
19+
maxShownOrgs: number;
1620

1721
/** @ngInject */
1822
constructor(private $scope, private $location, private contextSrv, private backendSrv, private $element) {
1923
this.isSignedIn = contextSrv.isSignedIn;
2024
this.user = contextSrv.user;
2125
this.appSubUrl = config.appSubUrl;
2226
this.showSignout = this.contextSrv.isSignedIn && !config['authProxyEnabled'];
27+
this.maxShownOrgs = 10;
2328

2429
this.mainLinks = config.bootData.mainNavLinks;
2530
this.openUserDropdown();
@@ -31,6 +36,8 @@ export class SideMenuCtrl {
3136
}
3237
this.loginUrl = 'login?redirect=' + encodeURIComponent(this.$location.path());
3338
});
39+
40+
this.orgFilter = '';
3441
}
3542

3643
getUrl(url) {
@@ -51,38 +58,44 @@ export class SideMenuCtrl {
5158
this.orgMenu.push({section: this.user.orgName, cssClass: 'dropdown-menu-title'});
5259
this.orgMenu.push({
5360
text: "Preferences",
54-
url: this.getUrl("/org"),
61+
url: this.getUrl("/org")
5562
});
5663
this.orgMenu.push({
5764
text: "Users",
58-
url: this.getUrl("/org/users"),
65+
url: this.getUrl("/org/users")
5966
});
6067
this.orgMenu.push({
6168
text: "API Keys",
62-
url: this.getUrl("/org/apikeys"),
69+
url: this.getUrl("/org/apikeys")
6370
});
6471
}
6572

6673
this.orgMenu.push({cssClass: "divider"});
67-
6874
this.backendSrv.get('/api/user/orgs').then(orgs => {
69-
orgs.forEach(org => {
70-
if (org.orgId === this.contextSrv.user.orgId) {
71-
return;
72-
}
75+
this.orgs = orgs;
76+
this.loadOrgsItems();
77+
});
78+
}
7379

74-
this.orgMenu.push({
80+
loadOrgsItems(){
81+
this.orgItems = [];
82+
this.orgs.forEach(org => {
83+
if (org.orgId === this.contextSrv.user.orgId) {
84+
return;
85+
}
86+
87+
if (this.orgItems.length < this.maxShownOrgs && (this.orgFilter === '' || org.name.indexOf(this.orgFilter) !== -1)){
88+
this.orgItems.push({
7589
text: "Switch to " + org.name,
7690
icon: "fa fa-fw fa-random",
7791
url: this.getUrl('/profile/switch-org/' + org.orgId),
7892
target: '_self'
7993
});
80-
});
81-
82-
if (config.allowOrgCreate) {
83-
this.orgMenu.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
8494
}
8595
});
96+
if (config.allowOrgCreate) {
97+
this.orgItems.push({text: "New organization", icon: "fa fa-fw fa-plus", url: this.getUrl('/org/new')});
98+
}
8699
}
87100
}
88101

0 commit comments

Comments
 (0)