Project

General

Profile

1 57387 k.triantaf
import {Component, Input, OnInit} from '@angular/core';
2 59816 argiro.kok
import {SideMenuItem} from '../menu';
3 57387 k.triantaf
import {ActivatedRoute, Router} from '@angular/router';
4 59816 argiro.kok
import {Subscriber} from "rxjs";
5 50169 argiro.kok
6
@Component({
7 55405 k.triantaf
  selector: 'sidebar',
8
  templateUrl: 'sideBar.component.html'
9 50169 argiro.kok
})
10 57387 k.triantaf
export class SideBarComponent implements OnInit {
11 55405 k.triantaf
  @Input() communityId: string = '';
12
  @Input() menuItems: SideMenuItem[] = [];
13 57387 k.triantaf
  currentParams: any = {};
14 59816 argiro.kok
  sub;
15 57387 k.triantaf
  constructor(private router: Router,
16
              private route: ActivatedRoute) {
17
  }
18 59816 argiro.kok
  ngOnDestroy() {
19
    if (this.sub instanceof Subscriber) {
20
      this.sub.unsubscribe();
21
    }
22
  }
23 57387 k.triantaf
  ngOnInit(): void {
24 59816 argiro.kok
    this.sub = this.route.queryParams.subscribe(params => {
25 57387 k.triantaf
      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 50169 argiro.kok
}