@@ -13,13 +13,18 @@ export class SideMenuCtrl {
13
13
orgMenu : any ;
14
14
appSubUrl : string ;
15
15
loginUrl : string ;
16
+ orgFilter : string ;
17
+ orgItems : any ;
18
+ orgs : any ;
19
+ maxShownOrgs : number ;
16
20
17
21
/** @ngInject */
18
22
constructor ( private $scope , private $location , private contextSrv , private backendSrv , private $element ) {
19
23
this . isSignedIn = contextSrv . isSignedIn ;
20
24
this . user = contextSrv . user ;
21
25
this . appSubUrl = config . appSubUrl ;
22
26
this . showSignout = this . contextSrv . isSignedIn && ! config [ 'authProxyEnabled' ] ;
27
+ this . maxShownOrgs = 10 ;
23
28
24
29
this . mainLinks = config . bootData . mainNavLinks ;
25
30
this . openUserDropdown ( ) ;
@@ -31,6 +36,8 @@ export class SideMenuCtrl {
31
36
}
32
37
this . loginUrl = 'login?redirect=' + encodeURIComponent ( this . $location . path ( ) ) ;
33
38
} ) ;
39
+
40
+ this . orgFilter = '' ;
34
41
}
35
42
36
43
getUrl ( url ) {
@@ -51,38 +58,44 @@ export class SideMenuCtrl {
51
58
this . orgMenu . push ( { section : this . user . orgName , cssClass : 'dropdown-menu-title' } ) ;
52
59
this . orgMenu . push ( {
53
60
text : "Preferences" ,
54
- url : this . getUrl ( "/org" ) ,
61
+ url : this . getUrl ( "/org" )
55
62
} ) ;
56
63
this . orgMenu . push ( {
57
64
text : "Users" ,
58
- url : this . getUrl ( "/org/users" ) ,
65
+ url : this . getUrl ( "/org/users" )
59
66
} ) ;
60
67
this . orgMenu . push ( {
61
68
text : "API Keys" ,
62
- url : this . getUrl ( "/org/apikeys" ) ,
69
+ url : this . getUrl ( "/org/apikeys" )
63
70
} ) ;
64
71
}
65
72
66
73
this . orgMenu . push ( { cssClass : "divider" } ) ;
67
-
68
74
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
+ }
73
79
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 ( {
75
89
text : "Switch to " + org . name ,
76
90
icon : "fa fa-fw fa-random" ,
77
91
url : this . getUrl ( '/profile/switch-org/' + org . orgId ) ,
78
92
target : '_self'
79
93
} ) ;
80
- } ) ;
81
-
82
- if ( config . allowOrgCreate ) {
83
- this . orgMenu . push ( { text : "New organization" , icon : "fa fa-fw fa-plus" , url : this . getUrl ( '/org/new' ) } ) ;
84
94
}
85
95
} ) ;
96
+ if ( config . allowOrgCreate ) {
97
+ this . orgItems . push ( { text : "New organization" , icon : "fa fa-fw fa-plus" , url : this . getUrl ( '/org/new' ) } ) ;
98
+ }
86
99
}
87
100
}
88
101
0 commit comments