55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
import { BreadcrumbItem } from './definition/breadcrumb-item';
|
|
import { BreadCrumbResolverService } from './service/breadcrumb.service';
|
|
import { DashboardService } from '../../../core/services/dashboard/dashboard.service';
|
|
import { assertDataInRangeInternal } from '@angular/core/src/render3/util';
|
|
import { url } from 'inspector';
|
|
|
|
@Component({
|
|
selector: 'app-breadcrumb',
|
|
templateUrl: './breadcrumb.component.html',
|
|
styleUrls: ['./breadcrumb.component.scss']
|
|
})
|
|
export class BreadcrumbComponent implements OnInit {
|
|
breadcrumbs$ = this.router.events
|
|
.filter(event => event instanceof NavigationEnd)
|
|
.distinctUntilChanged()
|
|
.flatMap(event => this.buildBreadCrumb(this.activatedRoute.root));
|
|
|
|
|
|
constructor(
|
|
public activatedRoute: ActivatedRoute,
|
|
private router: Router,
|
|
private breadCrumbService: BreadCrumbResolverService
|
|
) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
buildBreadCrumb(route: ActivatedRoute): Observable<BreadcrumbItem[]> {
|
|
if (this.breadCrumbService.resolve(route)) {
|
|
return this.breadCrumbService.resolve(route).map(x => {
|
|
x.unshift({ label: 'HOME', url: '/home', icon: 'dashboard' }); return x;
|
|
});
|
|
}
|
|
return Observable.of([]);
|
|
}
|
|
|
|
navigate(url, params) {
|
|
this.router.navigate([url, params]);
|
|
}
|
|
|
|
currentUrl(breadcrumb) {
|
|
if (breadcrumb.url == this.router.url) {
|
|
return true;
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
}
|