Project

General

Profile

1
/**
2
 * Created by stefania on 7/5/16.
3
 */
4

    
5
import {Component, OnInit, ViewEncapsulation} from "@angular/core";
6
import {AuthenticationService} from '../../services/authentication.service';
7

    
8
@Component({
9
  selector: 'top-menu',
10
  templateUrl: './topmenu.component.html',
11
  encapsulation: ViewEncapsulation.None
12
})
13

    
14
export class TopMenuComponent implements OnInit {
15
  userLoggedIn: boolean = false;
16
  userName: string = '';
17
  isUserAdmin: boolean = false;
18
  adminHomePage = process.env.FAQ_HOMEPAGE;
19

    
20
  inBeta: boolean;
21

    
22
  constructor(public authService: AuthenticationService) { }
23

    
24
  ngOnInit() {
25
    this.getIsUserLoggedIn();
26
    this.getUserName();
27
    this.getIsUserAdmin();
28

    
29
    const baseUrl = window.location.origin;
30
    this.inBeta = ( baseUrl.includes('beta') || baseUrl.includes('athenarc') );
31
  }
32

    
33

    
34
  onClick(id: string) {
35
    var el: HTMLElement = document.getElementById(id);
36
    el.classList.remove('uk-open');
37
  }
38

    
39

    
40
  login(){
41
    this.authService.loginWithState();
42
  }
43

    
44
  logout(){
45
    if( this.userLoggedIn ){
46
      this.authService.logout();
47
    }
48
  }
49

    
50

    
51
  getUserName() {
52
    this.userName = this.authService.getUserName();
53
    return this.userName;
54
  }
55

    
56
  getIsUserLoggedIn() {
57
    this.userLoggedIn = this.authService.getIsUserLoggedIn();
58
    return this.userLoggedIn;
59
  }
60

    
61
  getIsUserAdmin() {
62
    this.isUserAdmin = (this.authService.getUserRole().includes('ROLE_ADMIN'));
63
    return this.isUserAdmin;
64
  }
65
}
(2-2/2)