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';
|
2018-10-12 17:17:31 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2018-06-27 12:29:21 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-07-23 17:56:09 +02:00
|
|
|
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 {
|
2018-07-23 17:56:09 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
2018-07-23 17:56:09 +02:00
|
|
|
constructor(
|
|
|
|
public activatedRoute: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private breadCrumbService: BreadCrumbResolverService
|
|
|
|
) {
|
2018-06-28 11:28:16 +02:00
|
|
|
|
2018-07-23 17:56:09 +02:00
|
|
|
}
|
2018-06-27 12:29:21 +02:00
|
|
|
|
2018-07-23 17:56:09 +02:00
|
|
|
ngOnInit() {
|
2018-06-28 11:28:16 +02:00
|
|
|
|
2018-07-23 17:56:09 +02:00
|
|
|
}
|
2018-06-27 12:29:21 +02:00
|
|
|
|
2018-07-23 17:56:09 +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-07-23 17:56:09 +02:00
|
|
|
}
|
2018-06-27 12:29:21 +02:00
|
|
|
|
2018-07-23 17:56:09 +02:00
|
|
|
navigate(url, params) {
|
|
|
|
this.router.navigate([url, params]);
|
|
|
|
}
|
2018-06-27 12:29:21 +02:00
|
|
|
}
|