Project

General

Profile

1
import { Component, DoCheck, OnInit, ViewEncapsulation } from '@angular/core';
2
import { AuthenticationService } from '../../services/authentication.service';
3
import { environment } from '../../../environments/environment';
4

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

    
12
export class TopmenuDashboardComponent implements OnInit {
13
  userLoggedIn = false;
14
  userName = '';
15
  isUserAdmin = false;
16
  adminHomePage = environment.FAQ_HOMEPAGE;
17

    
18
  inBeta: boolean;
19

    
20
  showSideBar = true;
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
  toggleSideMenu() {
34
    const body = document.getElementsByTagName('body')[0];
35
    if (this.showSideBar === true) {
36
      body.classList.remove('sidebar_main_open');
37
    } else {
38
      body.classList.add('sidebar_main_open');
39
    }
40
    this.showSideBar = !this.showSideBar;
41
  }
42

    
43
  onClick(id: string) {
44
    const el: HTMLElement = document.getElementById(id);
45
    el.classList.remove('uk-open');
46
  }
47

    
48

    
49
  login() {
50
    this.authService.loginWithState();
51
  }
52

    
53
  logout() {
54
    this.authService.logout();
55
  }
56

    
57

    
58
  getUserName() {
59
    this.userName = this.authService.getUserName();
60
    return this.userName;
61
  }
62

    
63
  getIsUserLoggedIn() {
64
    this.userLoggedIn = this.authService.getIsUserLoggedIn();
65
    return this.userLoggedIn;
66
  }
67

    
68
  parseUsername() {
69
    let firstLetters = "";
70
    let matches = this.getUserName().match(/\b(\w)/g);
71
    if(matches)
72
      firstLetters += matches.join('');
73
    return firstLetters;
74
  }
75

    
76
  getIsUserAdmin() {
77
    this.isUserAdmin = (this.authService.getUserRole().includes('SUPER_ADMINISTRATOR') ||
78
      this.authService.getUserRole().includes('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR'));
79
    return this.isUserAdmin;
80
  }
81
}
(2-2/2)