argos/dmp-frontend/src/app/ui/misc/breadcrumb/breadcrumb.component.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-09-23 10:17:03 +02:00
import {of as observableOf, Observable } from 'rxjs';
import {filter, mergeMap, distinctUntilChanged, map} from 'rxjs/operators';
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';
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({
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 {
2019-09-23 10:17:03 +02:00
breadcrumbs$ = this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
distinctUntilChanged(),
mergeMap(event => this.buildBreadCrumb(this.activatedRoute.root)),);
2018-06-27 12:29:21 +02:00
constructor(
public activatedRoute: ActivatedRoute,
private router: Router,
2019-05-23 11:40:24 +02:00
private breadCrumbService: BreadCrumbResolverService,
private language: TranslateService,
) {
}
2018-06-27 12:29:21 +02:00
ngOnInit() {
}
2018-06-27 12:29:21 +02:00
buildBreadCrumb(route: ActivatedRoute): Observable<BreadcrumbItem[]> {
2019-05-16 18:11:41 +02:00
if (this.breadCrumbService.resolve(route)) {
2019-09-23 10:17:03 +02:00
return this.breadCrumbService.resolve(route).pipe(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-09-23 10:17:03 +02:00
}));
2019-05-16 18:11:41 +02:00
}
2019-09-23 10:17:03 +02:00
return observableOf([]);
}
2018-06-27 12:29:21 +02:00
navigate(url, params) {
this.router.navigate([url, params]);
}
2018-06-27 12:29:21 +02:00
}