2019-01-18 18:03:45 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2018-06-27 12:29:21 +02:00
|
|
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
2018-10-12 17:17:31 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BreadcrumbItem } from './definition/breadcrumb-item';
|
|
|
|
import { BreadCrumbResolverService } from './service/breadcrumb.service';
|
2019-05-23 11:40:24 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-06-27 12:29:21 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-07-23 17:56:09 +02:00
|
|
|
selector: 'app-breadcrumb',
|
|
|
|
templateUrl: './breadcrumb.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./breadcrumb.component.scss']
|
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,
|
2019-05-23 11:40:24 +02:00
|
|
|
private breadCrumbService: BreadCrumbResolverService,
|
|
|
|
private language: TranslateService,
|
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-27 12:29:21 +02:00
|
|
|
|
2018-07-23 17:56:09 +02:00
|
|
|
buildBreadCrumb(route: ActivatedRoute): Observable<BreadcrumbItem[]> {
|
2019-05-16 18:11:41 +02:00
|
|
|
if (this.breadCrumbService.resolve(route)) {
|
|
|
|
return this.breadCrumbService.resolve(route).map(x => {
|
2019-05-23 11:40:24 +02:00
|
|
|
x.unshift({
|
|
|
|
label: this.language.instant('NAV-BAR.HOME'),
|
|
|
|
url: '/home',
|
|
|
|
icon: 'dashboard'
|
|
|
|
}); return x;
|
2019-05-16 18:11:41 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-18 12:21:56 +02:00
|
|
|
return Observable.of([]);
|
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
|
|
|
}
|