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-16 18:11:41 +02:00
|
|
|
import { DashboardService } from '../../../core/services/dashboard/dashboard.service';
|
|
|
|
import { assertDataInRangeInternal } from '@angular/core/src/render3/util';
|
|
|
|
import { url } from 'inspector';
|
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,
|
|
|
|
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[]> {
|
2019-05-16 18:11:41 +02:00
|
|
|
if (this.breadCrumbService.resolve(route)) {
|
|
|
|
return this.breadCrumbService.resolve(route).map(x => {
|
|
|
|
x.unshift({ label: 'HOME', url: '/home', icon: 'dashboard' }); return x;
|
|
|
|
});
|
|
|
|
}
|
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]);
|
|
|
|
}
|
2019-05-16 18:11:41 +02:00
|
|
|
|
|
|
|
currentUrl(breadcrumb) {
|
|
|
|
if (breadcrumb.url == this.router.url) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 12:29:21 +02:00
|
|
|
}
|