César Calvo
2017-03-14 f3f2452adb2723f2dde0b3429c282b835b5cdfcf
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Observable } from 'rxjs/Observable';
import { BaseRequestOptions, Http } from '@angular/http';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
import { AfterViewInit, Component, ViewContainerRef, ViewChild } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { MdIconRegistry } from '@angular/material';
import { UserService } from './user.service';
import { LocalStorageService } from 'angular-2-local-storage';
import { TdMediaService } from '@covalent/core';
import { Router } from '@angular/router';
import { TdNavigationDrawerComponent } from '@covalent/core'
// https://github.com/Teradata/covalent-quickstart/tree/develop/src/app
// https://teradata.github.io/covalent-quickstart/#/
@Component({
  selector: 'app-home',
  templateUrl: 'src/app/home.component.html' 
})
export class HomeComponent implements AfterViewInit {
  @ViewChild('varName') child: TdNavigationDrawerComponent;
  securisVersion : string;
  showMenu : boolean = false;
  constructor(private userService: UserService,
              toaster: ToastsManager,
              vRef: ViewContainerRef,
              private router: Router,
              http: Http,
              private media: TdMediaService,
              private _iconRegistry: MdIconRegistry,
              private _domSanitizer: DomSanitizer,
              private store: LocalStorageService) {
      this.registerIcons();
      toaster.setRootViewContainerRef(vRef);
      http.get("version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions())
        .map((res) => <string>res.json().version)
        .subscribe(
          version => this.securisVersion = version,
          err => this.securisVersion = '0.0.0'
        );
  }
  private registerIcons() : void {
    this._iconRegistry.addSvgIconInNamespace('assets', 'logo',
      this._domSanitizer.bypassSecurityTrustResourceUrl('assets/securis_logo.svg'));
    this._iconRegistry.addSvgIconInNamespace('assets', 'logo-bw',
      this._domSanitizer.bypassSecurityTrustResourceUrl('assets/securis_logo_bw.svg'));
    this._iconRegistry.addSvgIconInNamespace('assets', 'logo-white',
      this._domSanitizer.bypassSecurityTrustResourceUrl('assets/securis_logo_white.svg'));
    this._iconRegistry.addSvgIconInNamespace('assets', 'logo-black',
      this._domSanitizer.bypassSecurityTrustResourceUrl('assets/securis_logo_black.svg'));
  }
  public clicked() {
    //this.child.open();
  }
  ngAfterViewInit(): void {
     // this.showMenu = true;    
      this.media.broadcast();
      this.userService.isLoggedIn().subscribe(authOk => {
        //this.showMenu = authOk.valueOf();
        this.router.navigateByUrl(authOk ? 'packs' : 'login');
      }, 
      err => /* Show message */ this.router.navigateByUrl('login'));
  }
}