From ed20502959df400f5ba38fdd5d4b3ba3cf9389c4 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 7 Nov 2022 16:55:27 +0200 Subject: [PATCH] Helper Functions: Add routerMatcher function in order to add more than one path in route configuration. --- .../sidebar/sideBar.component.ts | 6 +++- utils/HelperFunctions.class.ts | 35 +++++++++++++++++++ .../transition-group.component.ts | 4 ++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/dashboard/sharedComponents/sidebar/sideBar.component.ts b/dashboard/sharedComponents/sidebar/sideBar.component.ts index ef41ba8f..dbc76745 100644 --- a/dashboard/sharedComponents/sidebar/sideBar.component.ts +++ b/dashboard/sharedComponents/sidebar/sideBar.component.ts @@ -23,7 +23,11 @@ export class SideBarComponent implements AfterViewInit { constructor(private route: ActivatedRoute, private router: Router, private sanitizer: DomSanitizer, private layoutService: LayoutService) {} ngAfterViewInit() { - UIkit.nav(this.nav.nativeElement).toggle(this.activeIndex, false); + if(this.nav) { + setTimeout(() => { + UIkit.nav(this.nav.nativeElement).toggle(this.activeIndex, true); + }); + } } get currentRoute() { diff --git a/utils/HelperFunctions.class.ts b/utils/HelperFunctions.class.ts index 1b629fb0..872009ce 100644 --- a/utils/HelperFunctions.class.ts +++ b/utils/HelperFunctions.class.ts @@ -1,3 +1,5 @@ +import {UrlMatcher, UrlSegment} from "@angular/router"; + export class HelperFunctions { public static scroll() { @@ -107,4 +109,37 @@ export class HelperFunctions { public static swap(array: any[], from, to) { array.splice(to, 0, array.splice(from, 1)[0]); } + + public static routingMatcher:((paths: string[]) => UrlMatcher) = (paths: string[]) => { + return (segments) => { + const matchingPathIndex = paths.findIndex((path, index) => { + const pathSegments = path.split("/"); + return segments.every((segment, i) => + pathSegments.length > i && ( + pathSegments[i].startsWith(":") ? true : segment.path.toLowerCase() === pathSegments[i].toLowerCase())); + }); + + if (matchingPathIndex >= 0) { + const matchingPath = paths[matchingPathIndex]; + + const consumed: UrlSegment[] = []; + const params = {}; + + matchingPath.split("/").forEach((path, i) => { + consumed.push(segments[i]); + if (path.startsWith(":")) { + const param = path.substring(1); + params[param] = segments[i]; + } + }); + + return { + consumed: consumed, + posParams: params + }; + } + + return null; + }; + }; } diff --git a/utils/transition-group/transition-group.component.ts b/utils/transition-group/transition-group.component.ts index c2232fd3..53530868 100644 --- a/utils/transition-group/transition-group.component.ts +++ b/utils/transition-group/transition-group.component.ts @@ -3,7 +3,7 @@ import { AfterViewInit, Component, ContentChildren, - ElementRef, + ElementRef, Input, OnDestroy, QueryList, ViewEncapsulation @@ -27,6 +27,8 @@ import {THREE} from "@angular/cdk/keycodes"; }) export class TransitionGroupComponent implements AfterViewInit, OnDestroy { @ContentChildren(TransitionGroupItemDirective) items: QueryList; + @Input() + public id: string; private disabled: boolean = false; private subscription: Subscription;