mirror of https://github.com/abpframework/abp.git
2 changed files with 17 additions and 49 deletions
@ -1,37 +1,14 @@ |
|||||
import { ABP, ConfigState } from '@abp/ng.core'; |
import { ABP, RoutesService, TreeNode } from '@abp/ng.core'; |
||||
import { Component, Input, Renderer2, TrackByFunction } from '@angular/core'; |
import { Component, Input, TrackByFunction } from '@angular/core'; |
||||
import { Select } from '@ngxs/store'; |
|
||||
import { Observable } from 'rxjs'; |
|
||||
import { map } from 'rxjs/operators'; |
|
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-routes', |
selector: 'abp-routes', |
||||
templateUrl: 'routes.component.html', |
templateUrl: 'routes.component.html', |
||||
}) |
}) |
||||
export class RoutesComponent { |
export class RoutesComponent { |
||||
@Select(ConfigState.getOne('routes')) |
@Input() smallScreen: boolean; |
||||
routes$: Observable<ABP.FullRoute[]>; |
|
||||
|
|
||||
@Input() |
trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name; |
||||
smallScreen: boolean; |
|
||||
|
|
||||
get visibleRoutes$(): Observable<ABP.FullRoute[]> { |
constructor(public readonly routes: RoutesService) {} |
||||
return this.routes$.pipe(map(routes => getVisibleRoutes(routes))); |
|
||||
} |
|
||||
|
|
||||
trackByFn: TrackByFunction<ABP.FullRoute> = (_, item) => item.name; |
|
||||
|
|
||||
constructor(private renderer: Renderer2) {} |
|
||||
} |
|
||||
|
|
||||
function getVisibleRoutes(routes: ABP.FullRoute[]) { |
|
||||
return routes.reduce((acc, val) => { |
|
||||
if (val.invisible) return acc; |
|
||||
|
|
||||
if (val.children && val.children.length) { |
|
||||
val.children = getVisibleRoutes(val.children); |
|
||||
} |
|
||||
|
|
||||
return [...acc, val]; |
|
||||
}, []); |
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue