Project

General

Profile

1
import {Component, Input, OnInit} from '@angular/core';
2
import {RootMenuItem, SideMenuItem} from '../menu';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Observable} from 'rxjs/Observable';
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

    
15
  constructor(private router: Router,
16
              private route: ActivatedRoute) {
17
  }
18

    
19
  ngOnInit(): void {
20
    this.route.queryParams.subscribe(params => {
21
      this.currentParams = params;
22
    });
23
  }
24

    
25
  private getCurrentRoute(): string {
26
    return this.router.url.split('?')[0];
27
  }
28

    
29
  isTheActiveMenu(route: string, params: any): boolean {
30
    return route === this.getCurrentRoute() &&
31
      (!params || JSON.stringify(this.currentParams) === JSON.stringify(params));
32
  }
33
}
(2-2/3)