1
|
import {Component, Input, OnInit} from '@angular/core';
|
2
|
import {SideMenuItem} from '../menu';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
import {Subscriber} from "rxjs";
|
5
|
|
6
|
@Component({
|
7
|
selector: 'sidebar',
|
8
|
templateUrl: 'sideBar.component.html'
|
9
|
})
|
10
|
export class SideBarComponent implements OnInit {
|
11
|
@Input() communityId: string = '';
|
12
|
@Input() menuItems: SideMenuItem[] = [];
|
13
|
currentParams: any = {};
|
14
|
sub;
|
15
|
constructor(private router: Router,
|
16
|
private route: ActivatedRoute) {
|
17
|
}
|
18
|
ngOnDestroy() {
|
19
|
if (this.sub instanceof Subscriber) {
|
20
|
this.sub.unsubscribe();
|
21
|
}
|
22
|
}
|
23
|
ngOnInit(): void {
|
24
|
this.sub = this.route.queryParams.subscribe(params => {
|
25
|
this.currentParams = params;
|
26
|
});
|
27
|
}
|
28
|
|
29
|
private getCurrentRoute(): string {
|
30
|
return this.router.url.split('?')[0];
|
31
|
}
|
32
|
|
33
|
isTheActiveMenu(route: string, params: any): boolean {
|
34
|
return route === this.getCurrentRoute() &&
|
35
|
(!params || JSON.stringify(this.currentParams) === JSON.stringify(params));
|
36
|
}
|
37
|
}
|