argos/dmp-frontend/src/app/shared/components/breadcrumb/breadcrumb.component.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-06-27 12:29:21 +02:00
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { BreadCrumbResolverService } from '../../../services/breadcrumb/breadcrumb-resolver.service';
import { BreadcrumbItem } from './definition/breadcrumb-item';
import { Observable } from 'rxjs';
2018-06-27 12:29:21 +02:00
@Component({
selector: 'app-breadcrumb',
templateUrl: './breadcrumb.component.html',
styleUrls: ['./breadcrumb.component.scss'],
encapsulation: ViewEncapsulation.None
2018-06-27 12:29:21 +02:00
})
export class BreadcrumbComponent implements OnInit {
breadcrumbs$ = this.router.events
.filter(event => event instanceof NavigationEnd)
.distinctUntilChanged()
.flatMap(event => this.buildBreadCrumb(this.activatedRoute.root));
2018-06-27 12:29:21 +02:00
constructor(
public activatedRoute: ActivatedRoute,
private router: Router,
private breadCrumbService: BreadCrumbResolverService
) {
2018-06-28 11:28:16 +02:00
}
2018-06-27 12:29:21 +02:00
ngOnInit() {
2018-06-28 11:28:16 +02:00
}
2018-06-27 12:29:21 +02:00
buildBreadCrumb(route: ActivatedRoute): Observable<BreadcrumbItem[]> {
2018-09-18 14:41:24 +02:00
return this.breadCrumbService.resolve(route).map(x => { x.unshift({ label: 'Dashboard', url: '/welcome' }); return x; });
}
2018-06-27 12:29:21 +02:00
navigate(url, params) {
this.router.navigate([url, params]);
}
2018-06-27 12:29:21 +02:00
}