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
import {FormGroup} from "@angular/forms";
8

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

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

    
22
  inBeta: boolean;
23

    
24
  toggle: number[] = [];
25

    
26
  constructor(public authService: AuthenticationService) { }
27

    
28
  ngOnInit() {
29
    this.getIsUserLoggedIn();
30
    this.getUserName();
31
    this.getIsUserAdmin();
32

    
33
    const baseUrl = window.location.origin;
34
    this.inBeta = ( baseUrl.includes('beta') || baseUrl.includes('athenarc') );
35
  }
36

    
37
  onClick(id: string) {
38
    const el: HTMLElement = document.getElementById(id);
39
    el.classList.remove('uk-open');
40
  }
41

    
42

    
43
  login() {
44
    this.authService.loginWithState();
45
  }
46

    
47
  logout() {
48
    this.authService.logout();
49
  }
50

    
51

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

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

    
62
  getIsUserAdmin() {
63
    this.isUserAdmin = (this.authService.getUserRole().includes('ROLE_ADMIN') ||
64
      this.authService.getUserRole().includes('ROLE_PROVIDE_ADMIN'));
65
    return this.isUserAdmin;
66
  }
67

    
68
  setToggle(position: number) {
69
    if (this.toggle[position] === position) {
70
      this.toggle[position] = 0;
71
    } else {
72
      this.toggle[position] = position;
73
    }
74
  }
75

    
76
  checkIfCollapsed(position: number) {
77
    return this.toggle[position] === position;
78
  }
79
}
(2-2/2)