openaire-library/sharedComponents/sidebar/sideBar.component.ts

34 lines
931 B
TypeScript

import {Component, Input, OnInit} from '@angular/core';
import {RootMenuItem, SideMenuItem} from '../menu';
import {ActivatedRoute, Router} from '@angular/router';
import {Observable} from 'rxjs/Observable';
@Component({
selector: 'sidebar',
templateUrl: 'sideBar.component.html'
})
export class SideBarComponent implements OnInit {
@Input() communityId: string = '';
@Input() menuItems: SideMenuItem[] = [];
currentParams: any = {};
constructor(private router: Router,
private route: ActivatedRoute) {
}
ngOnInit(): void {
this.route.queryParams.subscribe(params => {
this.currentParams = params;
});
}
private getCurrentRoute(): string {
return this.router.url.split('?')[0];
}
isTheActiveMenu(route: string, params: any): boolean {
return route === this.getCurrentRoute() &&
(!params || JSON.stringify(this.currentParams) === JSON.stringify(params));
}
}