import { ChangeDetectionStrategy, Component, HostBinding, Inject, Input, OnInit } from '@angular/core'; import { NB_WINDOW, NbMenuItem, NbSidebarService } from '@nebular/theme'; import { Observable } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; import { NgdVersionService, Version } from '../../services'; @Component({ selector: 'ngd-header', styleUrls: ['./header.component.scss'], template: `
{{ version.name }}
`, changeDetection: ChangeDetectionStrategy.OnPush, }) export class NgdHeaderComponent implements OnInit { @Input() showSearch = true; @HostBinding('class.docs-page') @Input() isDocs = false; private window: Window; supportedVersions$: Observable; currentVersion$: Observable; currentVersionName$: Observable; showVersionSelect$: Observable; mainMenu: NbMenuItem[] = [ { title: 'Docs', link: '/docs', }, { title: 'Components', link: '/docs/components/components-overview', }, { title: 'Design System', link: '/docs/design-system/eva-design-system-intro', }, { title: 'Auth', link: '/docs/auth/introduction', }, { title: 'Security', link: '/docs/security/introduction', }, ]; @Input() sidebarTag: string; constructor( @Inject(NB_WINDOW) window, private versionService: NgdVersionService, private sidebarService: NbSidebarService, ) { this.window = window; } ngOnInit() { this.currentVersion$ = this.versionService.getCurrentVersion(); this.currentVersionName$ = this.currentVersion$.pipe(map((version: Version) => version.name)); this.supportedVersions$ = this.versionService.getSupportedVersions(); this.showVersionSelect$ = this.supportedVersions$ .pipe( map((versions: Version[]) => versions.length > 0), startWith(false), ); if (!this.isDocs) { this.mainMenu.push({ title: 'Professional Services', link: '/docs/getting-started/professional-services', }); } } toggleSidebar() { this.sidebarService.toggle(false, this.sidebarTag); } redirectToVersion(version: Version): void { this.window.location.href = version.path; } }