UI: Breadcrumb component improvements
This commit is contained in:
parent
a43d3f2fd2
commit
81aa229ba7
@ -61,8 +61,19 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private lastChild(route: ActivatedRouteSnapshot) {
|
||||||
|
let child = route;
|
||||||
|
while (child.firstChild !== null) {
|
||||||
|
child = child.firstChild;
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
buildBreadCrumbs(route: ActivatedRouteSnapshot, breadcrumbs: Array<BreadCrumb> = []): Array<BreadCrumb> {
|
buildBreadCrumbs(route: ActivatedRouteSnapshot, breadcrumbs: Array<BreadCrumb> = [],
|
||||||
|
lastChild?: ActivatedRouteSnapshot): Array<BreadCrumb> {
|
||||||
|
if (!lastChild) {
|
||||||
|
lastChild = this.lastChild(route);
|
||||||
|
}
|
||||||
let newBreadcrumbs = breadcrumbs;
|
let newBreadcrumbs = breadcrumbs;
|
||||||
if (route.routeConfig && route.routeConfig.data) {
|
if (route.routeConfig && route.routeConfig.data) {
|
||||||
const breadcrumbConfig = route.routeConfig.data.breadcrumb as BreadCrumbConfig<any>;
|
const breadcrumbConfig = route.routeConfig.data.breadcrumb as BreadCrumbConfig<any>;
|
||||||
@ -72,7 +83,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
|
|||||||
let ignoreTranslate;
|
let ignoreTranslate;
|
||||||
if (breadcrumbConfig.labelFunction) {
|
if (breadcrumbConfig.labelFunction) {
|
||||||
labelFunction = () => {
|
labelFunction = () => {
|
||||||
return breadcrumbConfig.labelFunction(route, this.translate, this.activeComponentValue);
|
return breadcrumbConfig.labelFunction(route, this.translate, this.activeComponentValue, lastChild.data);
|
||||||
};
|
};
|
||||||
ignoreTranslate = true;
|
ignoreTranslate = true;
|
||||||
} else {
|
} else {
|
||||||
@ -96,7 +107,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (route.firstChild) {
|
if (route.firstChild) {
|
||||||
return this.buildBreadCrumbs(route.firstChild, newBreadcrumbs);
|
return this.buildBreadCrumbs(route.firstChild, newBreadcrumbs, lastChild);
|
||||||
}
|
}
|
||||||
return newBreadcrumbs;
|
return newBreadcrumbs;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export interface BreadCrumb {
|
|||||||
queryParams: Params;
|
queryParams: Params;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BreadCrumbLabelFunction<C> = (route: ActivatedRouteSnapshot, translate: TranslateService, component: C) => string;
|
export type BreadCrumbLabelFunction<C> = (route: ActivatedRouteSnapshot, translate: TranslateService, component: C, data?: any) => string;
|
||||||
|
|
||||||
export interface BreadCrumbConfig<C> {
|
export interface BreadCrumbConfig<C> {
|
||||||
labelFunction: BreadCrumbLabelFunction<C>;
|
labelFunction: BreadCrumbLabelFunction<C>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user