rsanchez
2017-04-13 849f8f0acbe896cac7e531fee6895442382318cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { LocaleService } from './common/i18n';
import { Locker } from 'angular-safeguard';
import { Observable } from 'rxjs/Observable';
import { BaseRequestOptions, Http } from '@angular/http';
import { Component, ViewChild } from '@angular/core';
import { UserService } from './user.service';
import { ActivatedRoute, Router } from '@angular/router';
import { TdNavigationDrawerComponent } from '@covalent/core'
@Component({
  templateUrl: 'src/app/menu.component.html' 
})
export class MenuComponent {
  @ViewChild('mainMenu') mainMenu: TdNavigationDrawerComponent;
  userFullName: string;
  constructor(private userService: UserService,
              private store: Locker,
              private $L: LocaleService,
              private route: ActivatedRoute,
              private router: Router) {
  }
  ngOnInit(): void {
      this.userService.isLoggedIn().subscribe(authOk => {
        let isLoggedIn = authOk.valueOf();
        if (!isLoggedIn) {
          this.router.navigateByUrl('public/login');
          this.userFullName = null;
        } else {
          if (this.route.firstChild == null) {
            this.router.navigate(['packs']);
          }
          this.userFullName = this.store.get("user_full_name");
        }
      }  , 
      err => /* Show message */ this.router.navigateByUrl('public/login'));  
  }
  public logout() {
    this.userService.logout();
  }
  public closeMenu() {
    this.mainMenu.close();
  }
}