finished dynamic menus

This commit is contained in:
lotte
2018-12-06 15:50:12 +01:00
parent c17b395ba0
commit 07c9927b6a
39 changed files with 720 additions and 379 deletions

View File

@@ -1,9 +1,9 @@
import { Component, Injector, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Injector, OnInit } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { MenuService } from '../../shared/menu/menu.service';
import { MenuID } from '../../shared/menu/initial-menus-state';
import { MenuSection } from '../../shared/menu/menu.reducer';
import { map, tap } from 'rxjs/operators';
import { first, map } from 'rxjs/operators';
import { getComponentForMenu } from './menu.decorator';
import { GenericConstructor } from '../../core/shared/generic-constructor';
import { MenuSectionComponent } from './menu-section/menu-section.component';
@@ -15,14 +15,25 @@ import { MenuSectionComponent } from './menu-section/menu-section.component';
export class MenuComponent implements OnInit {
menuID: MenuID;
menuCollapsed: Observable<boolean>;
menuVisible: Observable<boolean>;
sections: Observable<MenuSection[]>;
sectionInjectors: Map<string, Injector> = new Map<string, Injector>();
sectionComponents: Map<string, GenericConstructor<MenuSectionComponent>> = new Map<string, GenericConstructor<MenuSectionComponent>>();
changeDetection: ChangeDetectionStrategy.OnPush;
constructor(protected menuService: MenuService, protected injector: Injector) {
}
ngOnInit(): void {
this.menuCollapsed = this.menuService.isMenuCollapsed(this.menuID);
this.sections = this.menuService.getMenuTopSections(this.menuID);
this.menuVisible = this.menuService.isMenuVisible(this.menuID);
this.sections = this.menuService.getMenuTopSections(this.menuID).pipe(first());
this.sections.subscribe((sections: MenuSection[]) => {
sections.forEach((section: MenuSection) => {
this.sectionInjectors.set(section.id, this.getSectionDataInjector(section));
this.getSectionComponent(section).pipe(first()).subscribe((constr) => this.sectionComponents.set(section.id, constr));
})
})
}
toggle(event: Event) {