Skip to content

Commit

Permalink
fix(sidebar): performance issues #74,#75
Browse files Browse the repository at this point in the history
  • Loading branch information
xidedix committed Aug 2, 2019
1 parent 5631d43 commit 53f28f8
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AppSidebarNavBadgePipe } from './app-sidebar-nav-badge.pipe';

describe('AppSidebarNavBadgePipe', () => {
it('create an instance', () => {
const pipe = new AppSidebarNavBadgePipe();
expect(pipe).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'appSidebarNavBadge'
})
export class AppSidebarNavBadgePipe implements PipeTransform {

transform(item: any, args?: any): any {
const classes = {
'badge': true
};
const variant = `badge-${item.badge.variant}`;
classes[variant] = !!item.badge.variant;
return classes;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AppSidebarNavIconPipe } from './app-sidebar-nav-icon.pipe';

describe('AppSidebarNavIconPipe', () => {
it('create an instance', () => {
const pipe = new AppSidebarNavIconPipe();
expect(pipe).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'appSidebarNavIcon'
})
export class AppSidebarNavIconPipe implements PipeTransform {

transform(item: any, args?: any): any {
const classes = {
'nav-icon': true
};
const icon = item.icon;
classes[icon] = !!item.icon;
return classes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
[appHtmlAttr]="item.attributes">
<i *ngIf="helper.hasIcon(item)" [ngClass]="getLabelIconClass()"></i>
<ng-container>{{item.name}}</ng-container>
<span *ngIf="helper.hasBadge(item)" [ngClass]="helper.getBadgeClass(item)">{{ item.badge.text }}</span>
<span *ngIf="helper.hasBadge(item)" [ngClass]="item | appSidebarNavBadge">{{ item.badge.text }}</span>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ import {SidebarNavHelper} from '../app-sidebar-nav.service';
export class AppSidebarNavLabelComponent implements OnInit {
@Input() item: any;

private classes = {
'nav-label': true,
'active': true
};
private iconClasses = {};

constructor(
public helper: SidebarNavHelper
) { }

ngOnInit() {
this.iconClasses = this.helper.getIconClass(this.item);
}

getItemClass() {
const labelClass = {
'nav-label': true,
'active': true
};
const itemClass = this.item.class;
labelClass[itemClass] = !!itemClass;
return labelClass;
this.classes[itemClass] = !!itemClass;
return this.classes;
}
getLabelIconClass() {
const classes = this.helper.getIconClass(this.item);
const variant = `text-${this.item.label.variant}`;
classes[variant] = !!variant;
this.iconClasses[variant] = !!this.item.label.variant;
const labelClass = this.item.label.class;
classes[labelClass] = !!labelClass;
return classes;
this.iconClasses[labelClass] = !!labelClass;
return this.iconClasses;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[ngClass]="getLinkClass()"
href="{{item.url}}"
[appHtmlAttr]="item.attributes">
<i *ngIf="helper.hasIcon(item)" [ngClass]="helper.getIconClass(item)"></i>
<i *ngIf="helper.hasIcon(item)" [ngClass]="item | appSidebarNavIcon"></i>
<ng-container>{{item.name}}</ng-container>
<span *ngIf="helper.hasBadge(item)" [ngClass]="helper.getBadgeClass(item)">{{ item.badge.text }}</span>
<span *ngIf="helper.hasBadge(item)" [ngClass]="item | appSidebarNavBadge">{{ item.badge.text }}</span>
</a>
<a *ngSwitchDefault
[ngClass]="getLinkClass()"
Expand All @@ -14,8 +14,8 @@
routerLinkActive="active"
[routerLink]="[item.url]"
(click)="hideMobile()">
<i *ngIf="helper.hasIcon(item)" [ngClass]="helper.getIconClass(item)"></i>
<i *ngIf="helper.hasIcon(item)" [ngClass]="item | appSidebarNavIcon"></i>
<ng-container>{{item.name}}</ng-container>
<span *ngIf="helper.hasBadge(item)" [ngClass]="helper.getBadgeClass(item)">{{ item.badge.text }}</span>
<span *ngIf="helper.hasBadge(item)" [ngClass]="item | appSidebarNavBadge">{{ item.badge.text }}</span>
</a>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class AppSidebarNavLinkComponent implements OnInit {
public linkType: string;
public href: string;

private classes = { 'nav-link': true };

constructor(
@Inject(DOCUMENT) private document: any,
private renderer: Renderer2,
Expand All @@ -25,16 +27,13 @@ export class AppSidebarNavLinkComponent implements OnInit {

public getLinkClass() {
const disabled = this.isDisabled();
const classes = {
'nav-link': true,
'disabled': disabled,
'btn-link': disabled
};
this.classes['disabled'] = disabled;
this.classes['btn-link'] = disabled;
if (this.hasVariant()) {
const variant = `nav-link-${this.item.variant}`;
classes[variant] = true;
this.classes[variant] = true;
}
return classes;
return this.classes;
}

public getLinkType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { AppSidebarNavLinkComponent } from './app-sidebar-nav/app-sidebar-nav-li
import { AppSidebarNavTitleComponent } from './app-sidebar-nav/app-sidebar-nav-title.component';
import { SidebarNavHelper } from './app-sidebar-nav.service';
import { AppSidebarNavLabelComponent } from './app-sidebar-nav/app-sidebar-nav-label.component';
import { AppSidebarNavIconPipe } from './app-sidebar-nav/app-sidebar-nav-icon.pipe';
import { AppSidebarNavBadgePipe } from './app-sidebar-nav/app-sidebar-nav-badge.pipe';

@NgModule({
imports: [
Expand Down Expand Up @@ -57,7 +59,9 @@ import { AppSidebarNavLabelComponent } from './app-sidebar-nav/app-sidebar-nav-l
AppSidebarNavTitleComponent,
NavDropdownDirective,
NavDropdownToggleDirective,
AppSidebarNavLabelComponent
AppSidebarNavLabelComponent,
AppSidebarNavIconPipe,
AppSidebarNavBadgePipe
],
providers: [
SidebarNavHelper
Expand Down

0 comments on commit 53f28f8

Please sign in to comment.