Skip to content

Commit 6e71649

Browse files
committed
feat: enhance enterprise module directive to support dynamic menu names and icons
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent c388e9a commit 6e71649

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

frontend/src/app/app-management/layout/app-management-sidebar/app-management-sidebar.component.html

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,22 @@
125125
</span>
126126
</a>
127127

128-
<a *appHasAnyAuthority="adminAuth"
128+
<ng-container *appHasAnyAuthority="adminAuth">
129+
130+
<a *appIsEnterpriseModule="'AUTH_WITH_PROVIDERS_MODULE', else community; menuName: 'API Keys'; cssIcon: 'icon-key'"
129131
class="list-group-item"
130132
routerLink="/app-management/settings/api-keys"
131133
routerLinkActive="router-link-active">
132134
<span class="font-weight-semibold">
133135
<i class="icon-key font-size-sm"></i>&nbsp;
134136
API Keys
135137
</span>
136-
</a>
138+
</a>
139+
</ng-container>
137140

138141
<ng-container *appHasAnyAuthority="adminAuth">
139142

140-
<a *appIsEnterpriseModule="'AUTH_WITH_PROVIDERS_MODULE', else community"
143+
<a *appIsEnterpriseModule="'AUTH_WITH_PROVIDERS_MODULE', else community; menuName: 'Identity Providers'; cssIcon: 'icon-shield-check'"
141144
class="list-group-item"
142145
routerLink="/app-management/settings/providers"
143146
routerLinkActive="router-link-active">
@@ -147,17 +150,6 @@
147150
</span>
148151
</a>
149152

150-
<ng-template #community>
151-
<a
152-
(click)="modalVersionInfoService.showVersionInfo()"
153-
class="list-group-item">
154-
<span class="font-weight-semibold">
155-
<i class="icon-shield-check font-size-sm"></i>&nbsp;
156-
Identity Providers
157-
</span>
158-
</a>
159-
</ng-template>
160-
161153
</ng-container>
162154

163155

@@ -173,3 +165,20 @@
173165
</a>
174166
</div>
175167
</div>
168+
169+
<ng-template #community let-menuName="menuName" let-cssIcon="cssIcon">
170+
<a (click)="modalVersionInfoService.showVersionInfo()"
171+
class="list-group-item cursor-pointer position-relative">
172+
<div class="d-flex align-items-flex-start justify-content-between">
173+
<div class="d-flex align-items-center">
174+
<i class="icon-lock2 font-size-sm mr-2" aria-hidden="true"></i>
175+
<span class="font-weight-semibold">
176+
{{ menuName }}
177+
</span>
178+
</div>
179+
</div>
180+
</a>
181+
</ng-template>
182+
183+
184+

frontend/src/app/shared/directives/enterprise/enterprise.directive.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import {Directive, Input, OnDestroy, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
1+
import { Directive, Input, OnDestroy, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
22
import { Subject } from 'rxjs';
33
import { takeUntil } from 'rxjs/operators';
4-
import {EnterpriseFeatures, VersionInfoService, VersionType} from 'src/app/shared/services/version/version-info.service';
4+
import { EnterpriseFeatures, VersionInfoService, VersionType } from 'src/app/shared/services/version/version-info.service';
55

66
@Directive({
77
selector: '[appIsEnterpriseModule]'
88
})
99
export class IsEnterpriseModuleDirective implements OnInit, OnDestroy {
1010
@Input('appIsEnterpriseModule') module: string;
1111
@Input('appIsEnterpriseModuleElse') elseTpl: TemplateRef<any> | null = null;
12+
@Input('appIsEnterpriseModuleMenuName') menuName = '';
13+
@Input('appIsEnterpriseModuleCssIcon') cssIcon: string = '';
1214

1315
private destroy$ = new Subject<void>();
1416

@@ -21,15 +23,27 @@ export class IsEnterpriseModuleDirective implements OnInit, OnDestroy {
2123
ngOnInit() {
2224
this.versionTypeService.versionType$
2325
.pipe(takeUntil(this.destroy$))
24-
.subscribe(versionType => {
25-
if (versionType === VersionType.ENTERPRISE && EnterpriseFeatures.includes(this.module)) {
26-
this.vcr.createEmbeddedView(this.tpl);
27-
} else if (this.elseTpl) {
28-
this.vcr.createEmbeddedView(this.elseTpl);
29-
} else {
30-
this.vcr.clear();
31-
}
32-
});
26+
.subscribe(versionType => this.render(versionType));
27+
}
28+
29+
private render(versionType: VersionType) {
30+
this.vcr.clear();
31+
32+
const context = {
33+
$implicit: this.menuName,
34+
menuName: this.menuName,
35+
cssIcon: this.cssIcon
36+
};
37+
38+
if (versionType === VersionType.ENTERPRISE && EnterpriseFeatures.includes(this.module)) {
39+
const viewRef = this.vcr.createEmbeddedView(this.tpl, context);
40+
viewRef.detectChanges();
41+
} else if (this.elseTpl) {
42+
const viewRef = this.vcr.createEmbeddedView(this.elseTpl, context);
43+
viewRef.detectChanges();
44+
} else {
45+
46+
}
3347
}
3448

3549
ngOnDestroy() {

0 commit comments

Comments
 (0)