2019-10-16 12:45:01 +02:00
|
|
|
import {Component, Input, OnInit} from '@angular/core';
|
2020-11-11 15:43:13 +01:00
|
|
|
import {SideMenuItem} from '../menu';
|
2019-10-16 12:45:01 +02:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2019-04-22 12:32:25 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'sidebar',
|
|
|
|
templateUrl: 'sideBar.component.html'
|
|
|
|
})
|
2019-10-16 12:45:01 +02:00
|
|
|
export class SideBarComponent implements OnInit {
|
2019-04-22 12:32:25 +02:00
|
|
|
@Input() communityId: string = '';
|
|
|
|
@Input() menuItems: SideMenuItem[] = [];
|
2019-10-16 12:45:01 +02:00
|
|
|
currentParams: any = {};
|
2020-11-11 15:43:13 +01:00
|
|
|
sub;
|
2019-10-16 12:45:01 +02:00
|
|
|
constructor(private router: Router,
|
|
|
|
private route: ActivatedRoute) {
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.sub instanceof Subscriber) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2019-10-16 12:45:01 +02:00
|
|
|
ngOnInit(): void {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
2019-10-16 12:45:01 +02:00
|
|
|
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));
|
|
|
|
}
|
2019-04-22 12:32:25 +02:00
|
|
|
}
|