Browse Source

update: refactor routes component

pull/22629/head
sumeyye 1 year ago
parent
commit
3065b5d2da
  1. 15
      npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.html
  2. 9
      npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.ts

15
npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.html

@ -3,8 +3,7 @@
<ng-container <ng-container
[ngTemplateOutlet]="isDropdown(route) ? dropdownLink : defaultLink" [ngTemplateOutlet]="isDropdown(route) ? dropdownLink : defaultLink"
[ngTemplateOutletContext]="{ $implicit: route }" [ngTemplateOutletContext]="{ $implicit: route }"
> />
</ng-container>
} }
<ng-template #defaultLink let-route> <ng-template #defaultLink let-route>
@ -13,7 +12,7 @@
@if (route.iconClass) { @if (route.iconClass) {
<i [ngClass]="route.iconClass"></i> <i [ngClass]="route.iconClass"></i>
} }
{{ route.name | abpLocalization }} {{ route.name | abpLazyTranslate | async }}
</a> </a>
</li> </li>
</ng-template> </ng-template>
@ -40,7 +39,7 @@
@if (route.iconClass) { @if (route.iconClass) {
<i [ngClass]="route.iconClass"></i> <i [ngClass]="route.iconClass"></i>
} }
{{ route.name | abpLocalization }} {{ route.name | abpLazyTranslate | async }}
</a> </a>
<div <div
#routeContainer #routeContainer
@ -48,9 +47,7 @@
(click)="$event.preventDefault(); $event.stopPropagation()" (click)="$event.preventDefault(); $event.stopPropagation()"
[class.d-block]="smallScreen && rootDropdownExpand[route.name]" [class.d-block]="smallScreen && rootDropdownExpand[route.name]"
> >
<ng-container <ng-container *ngTemplateOutlet="forTemplate; context: { $implicit: route }" />
*ngTemplateOutlet="forTemplate; context: { $implicit: route }"
></ng-container>
</div> </div>
</li> </li>
} }
@ -61,7 +58,7 @@
<ng-template <ng-template
[ngTemplateOutlet]="child.children?.length ? dropdownChild : defaultChild" [ngTemplateOutlet]="child.children?.length ? dropdownChild : defaultChild"
[ngTemplateOutletContext]="{ $implicit: child }" [ngTemplateOutletContext]="{ $implicit: child }"
></ng-template> />
} }
</ng-template> </ng-template>
@ -105,7 +102,7 @@
class="dropdown-menu dropdown-menu-start border-0 shadow-sm" class="dropdown-menu dropdown-menu-start border-0 shadow-sm"
[class.d-block]="smallScreen && dropdownSubmenu.isOpen()" [class.d-block]="smallScreen && dropdownSubmenu.isOpen()"
> >
<ng-container *ngTemplateOutlet="forTemplate; context: { $implicit: child }"></ng-container> <ng-container *ngTemplateOutlet="forTemplate; context: { $implicit: child }" />
</div> </div>
</div> </div>
</ng-template> </ng-template>

9
npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.ts

@ -2,6 +2,7 @@ import { ABP, RoutesService, TreeNode } from '@abp/ng.core';
import { import {
Component, Component,
ElementRef, ElementRef,
inject,
Input, Input,
QueryList, QueryList,
Renderer2, Renderer2,
@ -15,6 +16,9 @@ import {
templateUrl: 'routes.component.html', templateUrl: 'routes.component.html',
}) })
export class RoutesComponent { export class RoutesComponent {
public readonly routesService = inject(RoutesService);
protected renderer = inject(Renderer2);
@Input() smallScreen?: boolean; @Input() smallScreen?: boolean;
@ViewChildren('childrenContainer') childrenContainers!: QueryList<ElementRef<HTMLDivElement>>; @ViewChildren('childrenContainer') childrenContainers!: QueryList<ElementRef<HTMLDivElement>>;
@ -23,11 +27,6 @@ export class RoutesComponent {
trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name; trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name;
constructor(
public readonly routesService: RoutesService,
protected renderer: Renderer2,
) {}
isDropdown(node: TreeNode<ABP.Route>) { isDropdown(node: TreeNode<ABP.Route>) {
return !node?.isLeaf || this.routesService.hasChildren(node.name); return !node?.isLeaf || this.routesService.hasChildren(node.name);
} }

Loading…
Cancel
Save