Skip to content

Commit 4cb3e01

Browse files
[DURACOM-501] adapt public menu to use decorators
1 parent 482675b commit 4cb3e01

7 files changed

Lines changed: 54 additions & 45 deletions

src/app/shared/dso-page/dso-public-menu/dso-public-expandable-menu-section/dso-public-menu-expandable-section.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
}
1818
</div>
1919
}
20-
<ng-container
21-
*ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;">
22-
</ng-container>
20+
@if (sectionMap().get(subSection.id); as subSectionDTO) {
21+
<ng-container *ngComponentOutlet="subSectionDTO.component; injector: subSectionDTO.injector;"></ng-container>
22+
}
2323
</li>
2424
}
2525
</ul>

src/app/shared/dso-page/dso-public-menu/dso-public-expandable-menu-section/dso-public-menu-expandable-section.component.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { MenuItemType } from '../../../menu/menu-item-type.model';
1616
import { MenuItemModels } from '../../../menu/menu-section.model';
1717
import { MenuServiceStub } from '../../../menu/menu-service.stub';
1818
import { CSSVariableService } from '../../../sass-helper/css-variable.service';
19+
import { getMockThemeService } from '../../../theme-support/test/theme-service.mock';
20+
import { ThemeService } from '../../../theme-support/theme.service';
1921
import { DsoPublicMenuExpandableSectionComponent } from './dso-public-menu-expandable-section.component';
2022

2123
describe('DsoPublicMenuExpandableSectionComponent', () => {
@@ -41,10 +43,10 @@ describe('DsoPublicMenuExpandableSectionComponent', () => {
4143
TestBed.configureTestingModule({
4244
imports: [TranslateModule.forRoot(), DsoPublicMenuExpandableSectionComponent, TestComponent],
4345
providers: [
44-
{ provide: 'sectionDataProvider', useValue: dummySection },
4546
{ provide: MenuService, useValue: menuService },
4647
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
4748
{ provide: Router, useValue: new RouterStub() },
49+
{ provide: ThemeService, useValue: getMockThemeService() },
4850
],
4951
}).compileComponents();
5052
}));
@@ -57,7 +59,9 @@ describe('DsoPublicMenuExpandableSectionComponent', () => {
5759
}]));
5860
fixture = TestBed.createComponent(DsoPublicMenuExpandableSectionComponent);
5961
component = fixture.componentInstance;
60-
spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestComponent);
62+
component.section = dummySection;
63+
component.itemModel = dummySection.model;
64+
spyOn(component, 'getMenuItemComponent').and.returnValue(Promise.resolve(TestComponent));
6165
fixture.detectChanges();
6266
});
6367

@@ -76,10 +80,10 @@ describe('DsoPublicMenuExpandableSectionComponent', () => {
7680
TestBed.configureTestingModule({
7781
imports: [TranslateModule.forRoot(), DsoPublicMenuExpandableSectionComponent, TestComponent],
7882
providers: [
79-
{ provide: 'sectionDataProvider', useValue: dummySection },
8083
{ provide: MenuService, useValue: menuService },
8184
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
8285
{ provide: Router, useValue: new RouterStub() },
86+
{ provide: ThemeService, useValue: getMockThemeService() },
8387
],
8488
}).compileComponents();
8589
}));
@@ -88,7 +92,8 @@ describe('DsoPublicMenuExpandableSectionComponent', () => {
8892
spyOn(menuService, 'getSubSectionsByParentID').and.returnValue(of([]));
8993
fixture = TestBed.createComponent(DsoPublicMenuExpandableSectionComponent);
9094
component = fixture.componentInstance;
91-
spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestComponent);
95+
component.section = dummySection;
96+
spyOn(component, 'getMenuItemComponent').and.returnValue(Promise.resolve(TestComponent));
9297
fixture.detectChanges();
9398
});
9499

src/app/shared/dso-page/dso-public-menu/dso-public-expandable-menu-section/dso-public-menu-expandable-section.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '@angular/common';
1212
import {
1313
Component,
14-
Inject,
1514
Injector,
1615
OnInit,
1716
} from '@angular/core';
@@ -33,6 +32,8 @@ import { AbstractMenuSectionComponent } from 'src/app/shared/menu/menu-section/a
3332

3433
import { BtnDisabledDirective } from '../../../btn-disabled.directive';
3534
import { MenuService } from '../../../menu/menu.service';
35+
import { rendersSectionForMenu } from '../../../menu/menu-section.decorator';
36+
import { ThemeService } from '../../../theme-support/theme.service';
3637

3738
/**
3839
* Represents an expandable section in the dso public menus
@@ -50,18 +51,14 @@ import { MenuService } from '../../../menu/menu.service';
5051
TranslateModule,
5152
],
5253
})
54+
@rendersSectionForMenu(MenuID.DSO_PUBLIC, true)
5355
export class DsoPublicMenuExpandableSectionComponent extends AbstractMenuSectionComponent implements OnInit {
5456

5557
/**
5658
* This section resides in the DSO public menu
5759
*/
5860
menuID: MenuID = MenuID.DSO_PUBLIC;
5961

60-
/**
61-
* The MenuItemModel of the top section
62-
*/
63-
itemModel;
64-
6562
/**
6663
* Emits whether one of the subsections contains an icon
6764
*/
@@ -73,13 +70,16 @@ export class DsoPublicMenuExpandableSectionComponent extends AbstractMenuSection
7370
hasSubSections$: Observable<boolean>;
7471

7572
constructor(
76-
@Inject('sectionDataProvider') protected section: MenuSection,
7773
protected menuService: MenuService,
7874
protected injector: Injector,
75+
protected themeService: ThemeService,
7976
protected router: Router,
8077
) {
81-
super(menuService, injector);
82-
this.itemModel = section.model;
78+
super(
79+
menuService,
80+
injector,
81+
themeService,
82+
);
8383
}
8484

8585
ngOnInit(): void {

src/app/shared/dso-page/dso-public-menu/dso-public-menu-section/dso-public-menu-section.component.spec.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ import { MenuService } from '../../../menu/menu.service';
2020
import { OnClickMenuItemModel } from '../../../menu/menu-item/models/onclick.model';
2121
import { MenuServiceStub } from '../../../menu/menu-service.stub';
2222
import { CSSVariableService } from '../../../sass-helper/css-variable.service';
23+
import { getMockThemeService } from '../../../theme-support/test/theme-service.mock';
24+
import { ThemeService } from '../../../theme-support/theme.service';
2325
import { DsoPublicMenuSectionComponent } from './dso-public-menu-section.component';
2426

25-
function initAsync(dummySectionText: {
26-
visible: boolean;
27-
icon: string;
28-
active: boolean;
29-
model: { disabled: boolean; text: string; type: MenuItemType };
30-
id: string
31-
}, menuService: MenuServiceStub) {
27+
function initAsync(menuService: MenuServiceStub) {
3228
beforeEach(waitForAsync(() => {
3329
TestBed.configureTestingModule({
3430
imports: [
@@ -37,11 +33,11 @@ function initAsync(dummySectionText: {
3733
TestComponent,
3834
],
3935
providers: [
40-
{ provide: 'sectionDataProvider', useValue: dummySectionText },
4136
{ provide: MenuService, useValue: menuService },
4237
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
4338
{ provide: Router, useValue: new RouterStub() },
4439
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
40+
{ provide: ThemeService, useValue: getMockThemeService() },
4541
],
4642
}).compileComponents();
4743
}));
@@ -90,13 +86,15 @@ describe('DsoPublicMenuSectionComponent', () => {
9086
};
9187

9288
describe('text model', () => {
93-
initAsync(dummySectionText, menuService);
89+
initAsync(menuService);
9490

9591
beforeEach(() => {
9692
spyOn(menuService, 'getSubSectionsByParentID').and.returnValue(of([]));
9793
fixture = TestBed.createComponent(DsoPublicMenuSectionComponent);
9894
component = fixture.componentInstance;
99-
spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestComponent);
95+
component.section = dummySectionText;
96+
component.itemModel = component.section.model;
97+
spyOn(component, 'getMenuItemComponent').and.returnValue(Promise.resolve(TestComponent));
10098
fixture.detectChanges();
10199
});
102100

@@ -117,12 +115,14 @@ describe('DsoPublicMenuSectionComponent', () => {
117115
});
118116
});
119117
describe('on click model', () => {
120-
initAsync(dummySectionClick, menuService);
118+
initAsync(menuService);
121119
beforeEach(() => {
122120
spyOn(menuService, 'getSubSectionsByParentID').and.returnValue(of([]));
123121
fixture = TestBed.createComponent(DsoPublicMenuSectionComponent);
124122
component = fixture.componentInstance;
125-
spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestComponent);
123+
component.section = dummySectionClick;
124+
component.itemModel = component.section.model;
125+
spyOn(component, 'getMenuItemComponent').and.returnValue(Promise.resolve(TestComponent));
126126
fixture.detectChanges();
127127
});
128128

@@ -160,12 +160,14 @@ describe('DsoPublicMenuSectionComponent', () => {
160160
});
161161

162162
describe('when the section model in a non disabled link', () => {
163-
initAsync(dummySectionLink, menuService);
163+
initAsync(menuService);
164164
beforeEach(() => {
165165
spyOn(menuService, 'getSubSectionsByParentID').and.returnValue(of([]));
166166
fixture = TestBed.createComponent(DsoPublicMenuSectionComponent);
167167
component = fixture.componentInstance;
168-
spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestComponent);
168+
component.section = dummySectionLink;
169+
component.itemModel = component.section.model;
170+
spyOn(component, 'getMenuItemComponent').and.returnValue(Promise.resolve(TestComponent));
169171
fixture.detectChanges();
170172
});
171173

src/app/shared/dso-page/dso-public-menu/dso-public-menu-section/dso-public-menu-section.component.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
import {
99
Component,
10-
Inject,
1110
Injector,
1211
OnInit,
1312
} from '@angular/core';
@@ -20,7 +19,8 @@ import { AbstractMenuSectionComponent } from 'src/app/shared/menu/menu-section/a
2019
import { BtnDisabledDirective } from '../../../btn-disabled.directive';
2120
import { MenuService } from '../../../menu/menu.service';
2221
import { MenuID } from '../../../menu/menu-id.model';
23-
import { MenuSection } from '../../../menu/menu-section.model';
22+
import { rendersSectionForMenu } from '../../../menu/menu-section.decorator';
23+
import { ThemeService } from '../../../theme-support/theme.service';
2424

2525
/**
2626
* Represents a non-expandable section in the dso public menus
@@ -36,20 +36,23 @@ import { MenuSection } from '../../../menu/menu-section.model';
3636
TranslateModule,
3737
],
3838
})
39+
@rendersSectionForMenu(MenuID.DSO_PUBLIC, false)
3940
export class DsoPublicMenuSectionComponent extends AbstractMenuSectionComponent implements OnInit {
4041

4142
menuID: MenuID = MenuID.DSO_PUBLIC;
42-
itemModel;
4343
hasLink: boolean;
4444
canActivate: boolean;
4545

4646
constructor(
47-
@Inject('sectionDataProvider') protected section: MenuSection,
4847
protected menuService: MenuService,
4948
protected injector: Injector,
49+
protected themeService: ThemeService,
5050
) {
51-
super(menuService, injector);
52-
this.itemModel = section.model;
51+
super(
52+
menuService,
53+
injector,
54+
themeService,
55+
);
5356
}
5457

5558
ngOnInit(): void {
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<div class="dso-public-menu d-flex"
22
[attr.role]="(menuVisibleWithSections$ | async) ? 'menubar' : null"
33
[attr.aria-hidden]="(menuVisibleWithSections$ | async) === false ? 'true' : null">
4-
@for (section of (sections | async); track section) {
4+
@for (sectionDTO of (sectionDTOs$ | async); track sectionDTO) {
55
<div class="ms-1">
6-
<ng-container
7-
*ngComponentOutlet="(sectionMap$ | async).get(section.id)?.component; injector: (sectionMap$ | async).get(section.id)?.injector;">
8-
</ng-container>
6+
<ds-menu-component-loader [menuID]="menuID"
7+
[expandable]="sectionDTO.hasSubSections || sectionDTO.menuSection.alwaysRenderExpandable"
8+
[section]="sectionDTO.menuSection">
9+
</ds-menu-component-loader>
910
</div>
1011
}
1112
</div>

src/app/shared/dso-page/dso-public-menu/dso-public-menu.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
*
66
* http://www.dspace.org/license/
77
*/
8-
import {
9-
AsyncPipe,
10-
NgComponentOutlet,
11-
} from '@angular/common';
8+
import { AsyncPipe } from '@angular/common';
129
import {
1310
Component,
1411
Injector,
@@ -27,6 +24,7 @@ import {
2724

2825
import { MenuComponent } from '../../menu/menu.component';
2926
import { MenuService } from '../../menu/menu.service';
27+
import { MenuComponentLoaderComponent } from '../../menu/menu-component-loader/menu-component-loader.component';
3028
import { MenuID } from '../../menu/menu-id.model';
3129
import { ThemeService } from '../../theme-support/theme.service';
3230

@@ -40,7 +38,7 @@ import { ThemeService } from '../../theme-support/theme.service';
4038
templateUrl: './dso-public-menu.component.html',
4139
imports: [
4240
AsyncPipe,
43-
NgComponentOutlet,
41+
MenuComponentLoaderComponent,
4442
],
4543
})
4644
export class DsoPublicMenuComponent extends MenuComponent {

0 commit comments

Comments
 (0)