Project

General

Profile

1
/**
2
 * Created by stefania on 7/5/16.
3
 */
4
import { Component, DoCheck, OnInit, ViewEncapsulation } from '@angular/core';
5
import { AuthenticationService } from '../../services/authentication.service';
6
import { environment } from '../../../environments/environment';
7

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

    
15
export class TopMenuComponent implements OnInit {
16
  userLoggedIn = false;
17
  userName = '';
18
  isUserAdmin = false;
19
  adminHomePage = environment.FAQ_HOMEPAGE;
20

    
21
  inBeta: boolean;
22

    
23
  constructor(public authService: AuthenticationService) { }
24

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

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

    
34
  onClick(id: string) {
35
    const 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
    this.authService.logout();
46
  }
47

    
48

    
49
  getUserName() {
50
    this.userName = this.authService.getUserName();
51
    return this.userName;
52
  }
53

    
54
  getIsUserLoggedIn() {
55
    this.userLoggedIn = this.authService.getIsUserLoggedIn();
56
    return this.userLoggedIn;
57
  }
58

    
59
  getIsUserAdmin() {
60
    this.isUserAdmin = (this.authService.getUserRole().includes('ROLE_ADMIN') ||
61
                        this.authService.getUserRole().includes('ROLE_PORTAL_ADMIN'));
62
    return this.isUserAdmin;
63
  }
64
}
(3-3/3)