From b38d168867b308d10d39662745d299c047ddeada Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Wed, 2 Mar 2022 17:07:09 +0300 Subject: [PATCH 1/2] navBar collapse added when route is changed --- .../application-layout.component.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts index 42da273fbb..de906894a4 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts @@ -1,7 +1,8 @@ -import { eLayoutType, SubscriptionService } from '@abp/ng.core'; +import {eLayoutType, RouterEvents, SubscriptionService} from '@abp/ng.core'; import { collapseWithMargin, slideFromBottom } from '@abp/ng.theme.shared'; -import { AfterViewInit, Component } from '@angular/core'; +import {AfterViewInit, Component, OnDestroy} from '@angular/core'; import { LayoutService } from '../../services/layout.service'; +import {Subscription} from "rxjs"; @Component({ selector: 'abp-layout-application', @@ -9,13 +10,23 @@ import { LayoutService } from '../../services/layout.service'; animations: [slideFromBottom, collapseWithMargin], providers: [LayoutService, SubscriptionService], }) -export class ApplicationLayoutComponent implements AfterViewInit { +export class ApplicationLayoutComponent implements AfterViewInit , OnDestroy{ // required for dynamic component static type = eLayoutType.application; - - constructor(public service: LayoutService) {} + navigationEndSubscription:Subscription + constructor(public service: LayoutService, + routerEvents:RouterEvents, + ) { + this.navigationEndSubscription = routerEvents.getNavigationEvents('End').subscribe(() => { + service.isCollapsed = true; + }) + } ngAfterViewInit() { this.service.subscribeWindowSize(); } + + ngOnDestroy(): void { + this.navigationEndSubscription.unsubscribe() + } } From 5bc9c9d47e220e03c147b2296b79d47b19d34d68 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Thu, 3 Mar 2022 09:39:56 +0300 Subject: [PATCH 2/2] logic moved to LayoutService from Component --- .../application-layout.component.ts | 22 +++++-------------- .../src/lib/services/layout.service.ts | 10 +++++++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts index de906894a4..32dd47bad6 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts @@ -1,8 +1,8 @@ -import {eLayoutType, RouterEvents, SubscriptionService} from '@abp/ng.core'; +import {eLayoutType, SubscriptionService} from '@abp/ng.core'; import { collapseWithMargin, slideFromBottom } from '@abp/ng.theme.shared'; -import {AfterViewInit, Component, OnDestroy} from '@angular/core'; +import {AfterViewInit, Component} from '@angular/core'; import { LayoutService } from '../../services/layout.service'; -import {Subscription} from "rxjs"; + @Component({ selector: 'abp-layout-application', @@ -10,23 +10,13 @@ import {Subscription} from "rxjs"; animations: [slideFromBottom, collapseWithMargin], providers: [LayoutService, SubscriptionService], }) -export class ApplicationLayoutComponent implements AfterViewInit , OnDestroy{ +export class ApplicationLayoutComponent implements AfterViewInit { // required for dynamic component static type = eLayoutType.application; - navigationEndSubscription:Subscription - constructor(public service: LayoutService, - routerEvents:RouterEvents, - ) { - this.navigationEndSubscription = routerEvents.getNavigationEvents('End').subscribe(() => { - service.isCollapsed = true; - }) - } + + constructor(public service: LayoutService) {} ngAfterViewInit() { this.service.subscribeWindowSize(); } - - ngOnDestroy(): void { - this.navigationEndSubscription.unsubscribe() - } } diff --git a/npm/ng-packs/packages/theme-basic/src/lib/services/layout.service.ts b/npm/ng-packs/packages/theme-basic/src/lib/services/layout.service.ts index 860f499d55..a990173218 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/services/layout.service.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/services/layout.service.ts @@ -1,4 +1,4 @@ -import { SubscriptionService } from '@abp/ng.core'; +import {RouterEvents, SubscriptionService} from '@abp/ng.core'; import { ChangeDetectorRef, Injectable } from '@angular/core'; import { fromEvent } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; @@ -16,7 +16,13 @@ export class LayoutService { navItemsComponentKey = eThemeBasicComponents.NavItems; - constructor(private subscription: SubscriptionService, private cdRef: ChangeDetectorRef) {} + constructor(private subscription: SubscriptionService, + private cdRef: ChangeDetectorRef, + routerEvents:RouterEvents) { + subscription.addOne(routerEvents.getNavigationEvents("End"),() => { + this.isCollapsed = true; + }) + } private checkWindowWidth() { const isSmallScreen = window.innerWidth < 992;