charting, routing and stats
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<ul class="layout-menu">
|
||||
<ng-container *ngFor="let item of model; let i = index;">
|
||||
<ng-container *ngFor="let item of model$ | async; let i = index;">
|
||||
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||
</ng-container>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';
|
||||
import { filter, map, mergeMap, Observable, startWith } from 'rxjs';
|
||||
|
||||
import { LayoutService } from './service/app.layout.service';
|
||||
|
||||
@@ -8,19 +10,62 @@ import { LayoutService } from './service/app.layout.service';
|
||||
})
|
||||
export class AppMenuComponent implements OnInit {
|
||||
|
||||
model: any[] = [];
|
||||
private params$!: Observable<any>;
|
||||
public model$!: Observable<any[]>;
|
||||
|
||||
constructor(public layoutService: LayoutService) { }
|
||||
constructor(public layoutService: LayoutService, private router: Router, private activatedRoute: ActivatedRoute) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.model = [
|
||||
{
|
||||
label: 'Home',
|
||||
items: [
|
||||
{ label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: ['/'] }
|
||||
]
|
||||
},
|
||||
|
||||
];
|
||||
const rootRoute = this.activatedRoute.root;
|
||||
const initialParams = this.extractRouteParams(rootRoute.snapshot);
|
||||
|
||||
this.params$ = this.router.events
|
||||
.pipe(
|
||||
filter((event) => event instanceof NavigationEnd),
|
||||
map(() => this.activatedRoute),
|
||||
map((route) => {
|
||||
while (route.firstChild) {
|
||||
route = route.firstChild;
|
||||
}
|
||||
return route;
|
||||
}),
|
||||
filter((route) => route.outlet === 'primary'), // Adjust the outlet name if necessary
|
||||
mergeMap((route) => route.params),
|
||||
startWith(initialParams)
|
||||
);
|
||||
|
||||
this.model$ = this.params$.pipe(map(params => {
|
||||
|
||||
return [
|
||||
{
|
||||
label: 'Home',
|
||||
items: [
|
||||
{ label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: [params.address] }
|
||||
]
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
}))
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extractRouteParams(routeSnapshot: ActivatedRouteSnapshot): any {
|
||||
let route = routeSnapshot;
|
||||
let params = {};
|
||||
|
||||
while (route.firstChild) {
|
||||
route = route.firstChild;
|
||||
}
|
||||
|
||||
if (route && route.params) {
|
||||
params = route.params;
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user