2017-12-15 02:33:32 -05:00
|
|
|
import { Component } from "@angular/core";
|
2021-09-01 19:01:01 -04:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
NavigationEnd,
|
|
|
|
PRIMARY_OUTLET,
|
|
|
|
Router,
|
|
|
|
} from "@angular/router";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2021-08-11 17:41:29 -04:00
|
|
|
import { filter } from "rxjs/operators";
|
2017-12-14 23:25:15 -05:00
|
|
|
|
|
|
|
@Component({
|
2021-09-01 19:01:01 -04:00
|
|
|
selector: "app-page-header",
|
2017-12-14 23:25:15 -05:00
|
|
|
templateUrl: "./page-header.component.html",
|
|
|
|
styleUrls: ["./page-header.component.scss"],
|
|
|
|
})
|
|
|
|
export class PageHeaderComponent {
|
2017-12-15 02:33:32 -05:00
|
|
|
public pageName: string;
|
|
|
|
|
2021-09-01 19:01:01 -04:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private activatedRoute: ActivatedRoute,
|
|
|
|
public translate: TranslateService
|
|
|
|
) {
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate = translate;
|
2021-09-01 19:01:01 -04:00
|
|
|
this.router.events
|
|
|
|
.pipe(filter((ev) => ev instanceof NavigationEnd))
|
|
|
|
.subscribe((ev) => {
|
|
|
|
let currentRoute = this.activatedRoute.root;
|
|
|
|
let url = "";
|
|
|
|
const event = ev as NavigationEnd;
|
2017-12-15 02:33:32 -05:00
|
|
|
|
2021-09-01 19:01:01 -04:00
|
|
|
while (currentRoute.children.length > 0) {
|
|
|
|
const children = currentRoute.children;
|
|
|
|
children.forEach((route) => {
|
|
|
|
if (route.snapshot.data["breadcrumb"]) {
|
|
|
|
this.translate
|
|
|
|
.get(route.snapshot.data["breadcrumb"])
|
|
|
|
.subscribe((res: string) => {
|
|
|
|
route.snapshot.data["breadcrumb"] = res;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
currentRoute = route;
|
|
|
|
url += "/" + route.snapshot.url.map((s) => s.path).join("/");
|
|
|
|
if (route.outlet !== PRIMARY_OUTLET) return;
|
|
|
|
if (!route.routeConfig || !route.routeConfig.data) return;
|
|
|
|
if (url === event.urlAfterRedirects.split("?")[0])
|
|
|
|
this.pageName = route.snapshot.data.name;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-12-15 02:33:32 -05:00
|
|
|
}
|
2017-12-14 23:25:15 -05:00
|
|
|
}
|