Removed the id from the navigation as there might be multiple navigations

Fixed: getFlatNavigation doesn't correctly get the 'collapsable' items because of the item.type change
Closes #71: getFlatNavigation method not correctly working when its called multiple times
This commit is contained in:
Sercan Yemen 2018-07-02 13:15:49 +03:00
parent 224bbf479a
commit 64e0451dc6
2 changed files with 14 additions and 23 deletions

View File

@ -1,5 +1,4 @@
<div id="main-navigation" class="nav"
[ngClass]="{'horizontal':layout === 'horizontal', 'vertical':layout === 'vertical'}">
<div class="nav" [ngClass]="{'horizontal':layout === 'horizontal', 'vertical':layout === 'vertical'}">
<!-- Vertical Navigation Layout -->
<ng-container *ngIf="layout === 'vertical'">
@ -21,7 +20,8 @@
<ng-container *ngFor="let item of navigation">
<fuse-nav-horizontal-collapsable *ngIf="item.type=='group'" [item]="item"></fuse-nav-horizontal-collapsable>
<fuse-nav-horizontal-collapsable *ngIf="item.type=='collapse'" [item]="item"></fuse-nav-horizontal-collapsable>
<fuse-nav-horizontal-collapsable *ngIf="item.type=='collapse'"
[item]="item"></fuse-nav-horizontal-collapsable>
<fuse-nav-horizontal-item *ngIf="item.type=='item'" [item]="item"></fuse-nav-horizontal-item>
</ng-container>

View File

@ -1,11 +1,11 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { FuseNavigationItem } from '@fuse/types';
@Injectable()
export class FuseNavigationService
{
flatNavigation: any[] = [];
onItemCollapsed: Subject<any>;
onItemCollapseToggled: Subject<any>;
@ -138,39 +138,30 @@ export class FuseNavigationService
* Get flattened navigation array
*
* @param navigation
* @param flatNavigation
* @returns {any[]}
*/
getFlatNavigation(navigation): any
getFlatNavigation(navigation, flatNavigation: FuseNavigationItem[] = []): any
{
for ( const navItem of navigation )
for ( const item of navigation )
{
if ( navItem.type === 'item' )
if ( item.type === 'item' )
{
this.flatNavigation.push({
id : navItem.id || null,
title : navItem.title || null,
translate : navItem.translate || null,
type : navItem.type,
icon : navItem.icon || null,
url : navItem.url || null,
function : navItem.function || null,
exactMatch: navItem.exactMatch || false,
badge : navItem.badge || null
});
flatNavigation.push(item);
continue;
}
if ( navItem.type === 'collapse' || navItem.type === 'group' )
if ( item.type === 'collapsable' || item.type === 'group' )
{
if ( navItem.children )
if ( item.children )
{
this.getFlatNavigation(navItem.children);
this.getFlatNavigation(item.children, flatNavigation);
}
}
}
return this.flatNavigation;
return flatNavigation;
}
/**