From cad69d20b5971f419535c9e30ae52cc166f2d1d9 Mon Sep 17 00:00:00 2001 From: Maihan Nijat Date: Mon, 3 Dec 2018 09:16:44 -0500 Subject: [PATCH 1/2] feat(menu): Add an option to set skipLocationChange true or false for menu item. --- .../components/menu/menu-item.component.html | 1 + .../theme/components/menu/menu.service.ts | 34 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/framework/theme/components/menu/menu-item.component.html b/src/framework/theme/components/menu/menu-item.component.html index 2f26629780..c3bb5f4081 100644 --- a/src/framework/theme/components/menu/menu-item.component.html +++ b/src/framework/theme/components/menu/menu-item.component.html @@ -6,6 +6,7 @@ [routerLink]="menuItem.link" [queryParams]="menuItem.queryParams" [fragment]="menuItem.fragment" + [skipLocationChange]="menuItem.skipLocationChange" [attr.target]="menuItem.target" [attr.title]="menuItem.title" [class.active]="menuItem.selected" diff --git a/src/framework/theme/components/menu/menu.service.ts b/src/framework/theme/components/menu/menu.service.ts index cf602c49e3..146da110bb 100644 --- a/src/framework/theme/components/menu/menu.service.ts +++ b/src/framework/theme/components/menu/menu.service.ts @@ -4,14 +4,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -import { Injectable } from '@angular/core'; -import { Location } from '@angular/common'; -import { Params } from '@angular/router'; -import { Observable, BehaviorSubject, ReplaySubject, Subject } from 'rxjs'; -import { share } from 'rxjs/operators'; -import { isUrlPathContain, isUrlPathEqual } from './url-matching-helpers'; - -export interface NbMenuBag { tag: string; item: NbMenuItem } +import {Injectable} from '@angular/core'; +import {Location} from '@angular/common'; +import {Params} from '@angular/router'; +import {Observable, BehaviorSubject, ReplaySubject, Subject} from 'rxjs'; +import {share} from 'rxjs/operators'; +import {isUrlPathContain, isUrlPathEqual} from './url-matching-helpers'; + +export interface NbMenuBag { + tag: string; + item: NbMenuItem +} const itemClick$ = new Subject(); const addItems$ = new ReplaySubject<{ tag: string; items: NbMenuItem[] }>(1); @@ -83,6 +86,10 @@ export class NbMenuItem { * @type {boolean} */ group?: boolean; + /** Whether the item skipLocationChange is true or false + *@type {boolean} + */ + skipLocationChange?: boolean; /** Map of query parameters *@type {Params} */ @@ -128,7 +135,7 @@ export class NbMenuService { * @param {string} tag */ addItems(items: NbMenuItem[], tag?: string) { - addItems$.next({ tag, items }); + addItems$.next({tag, items}); } /** @@ -136,7 +143,7 @@ export class NbMenuService { * @param {string} tag */ collapseAll(tag?: string) { - collapseAll$.next({ tag }); + collapseAll$.next({tag}); } /** @@ -144,7 +151,7 @@ export class NbMenuService { * @param {string} tag */ navigateHome(tag?: string) { - navigateHome$.next({ tag }); + navigateHome$.next({tag}); } /** @@ -155,7 +162,7 @@ export class NbMenuService { getSelectedItem(tag?: string): Observable { const listener = new BehaviorSubject(null); - getSelectedItem$.next({ tag, listener }); + getSelectedItem$.next({tag, listener}); return listener.asObservable(); } @@ -180,7 +187,8 @@ export class NbMenuService { @Injectable() export class NbMenuInternalService { - constructor(private location: Location) {} + constructor(private location: Location) { + } prepareItems(items: NbMenuItem[]) { const defaultItem = new NbMenuItem(); From 76d480c8d581abffb430e647e9fc0fff5c488ba5 Mon Sep 17 00:00:00 2001 From: Maihan Nijat Date: Thu, 13 Dec 2018 12:11:02 -0500 Subject: [PATCH 2/2] feat(menu): Add an option to set skipLocationChange true or false for menu item. --- .../theme/components/menu/menu.service.ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/framework/theme/components/menu/menu.service.ts b/src/framework/theme/components/menu/menu.service.ts index 146da110bb..263c8af23d 100644 --- a/src/framework/theme/components/menu/menu.service.ts +++ b/src/framework/theme/components/menu/menu.service.ts @@ -4,17 +4,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -import {Injectable} from '@angular/core'; -import {Location} from '@angular/common'; -import {Params} from '@angular/router'; -import {Observable, BehaviorSubject, ReplaySubject, Subject} from 'rxjs'; -import {share} from 'rxjs/operators'; -import {isUrlPathContain, isUrlPathEqual} from './url-matching-helpers'; - -export interface NbMenuBag { - tag: string; - item: NbMenuItem -} +import { Injectable } from '@angular/core'; +import { Location } from '@angular/common'; +import { Params } from '@angular/router'; +import { Observable, BehaviorSubject, ReplaySubject, Subject } from 'rxjs'; +import { share } from 'rxjs/operators'; +import { isUrlPathContain, isUrlPathEqual } from './url-matching-helpers'; + +export interface NbMenuBag { tag: string; item: NbMenuItem } const itemClick$ = new Subject(); const addItems$ = new ReplaySubject<{ tag: string; items: NbMenuItem[] }>(1); @@ -135,7 +132,7 @@ export class NbMenuService { * @param {string} tag */ addItems(items: NbMenuItem[], tag?: string) { - addItems$.next({tag, items}); + addItems$.next({ tag, items }); } /** @@ -143,7 +140,7 @@ export class NbMenuService { * @param {string} tag */ collapseAll(tag?: string) { - collapseAll$.next({tag}); + collapseAll$.next({ tag }); } /** @@ -151,7 +148,7 @@ export class NbMenuService { * @param {string} tag */ navigateHome(tag?: string) { - navigateHome$.next({tag}); + navigateHome$.next({ tag }); } /** @@ -162,7 +159,7 @@ export class NbMenuService { getSelectedItem(tag?: string): Observable { const listener = new BehaviorSubject(null); - getSelectedItem$.next({tag, listener}); + getSelectedItem$.next({ tag, listener }); return listener.asObservable(); } @@ -187,8 +184,7 @@ export class NbMenuService { @Injectable() export class NbMenuInternalService { - constructor(private location: Location) { - } + constructor(private location: Location) {} prepareItems(items: NbMenuItem[]) { const defaultItem = new NbMenuItem();