mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ActivatedRoute, ActivatedRouteSnapshot, Data, Params, RouterStateSnapshot } from '@angular/router';
|
|
|
|
export function allData(value: ActivatedRouteSnapshot | ActivatedRoute): Data {
|
|
let snapshot: ActivatedRouteSnapshot | null = value['snapshot'] || value;
|
|
|
|
const result: { [key: string]: any } = {};
|
|
|
|
while (snapshot) {
|
|
for (const [key, value] of Object.entries(snapshot.data)) {
|
|
if (!result[key]) {
|
|
result[key] = value;
|
|
}
|
|
}
|
|
|
|
snapshot = snapshot.parent;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
export function allParams(value: ActivatedRouteSnapshot | ActivatedRoute): Params {
|
|
let snapshot: ActivatedRouteSnapshot | null = value['snapshot'] || value;
|
|
|
|
const result: { [key: string]: any } = {};
|
|
|
|
while (snapshot) {
|
|
for (const [key, value] of Object.entries(snapshot.params)) {
|
|
if (!result[key]) {
|
|
result[key] = value;
|
|
}
|
|
}
|
|
|
|
snapshot = snapshot.parent;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export function childComponent(value: RouterStateSnapshot) {
|
|
let current = value.root;
|
|
|
|
while (current) {
|
|
if (current.firstChild) {
|
|
current = current.firstChild;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return current.component;
|
|
}
|
|
|