Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { VerticalMenu } from './../../shared/models/vertical-menu.interface';
3
import { AuthService } from './../../shared/services/auth.service';
4

    
5
@Component({
6
  selector: 'app-vertical-menu',
7
  templateUrl: './vertical-menu.component.html',
8
  styleUrls: ['./vertical-menu.component.scss']
9
})
10
export class VerticalMenuComponent implements OnInit {
11

    
12
  loggedIn = false;
13
  leftMenu: VerticalMenu;
14

    
15
  constructor(public auth: AuthService) { }
16

    
17
  ngOnInit(): void {
18
    this.loggedIn = this.auth.isLoggedIn();
19
    this.auth.authStatusChanged.subscribe(loggedIn => {
20
      this.loggedIn = loggedIn;
21
      this.initializeMenuItems();
22
    });
23
    this.initializeMenuItems();
24
  }
25

    
26
  initializeMenuItems() {
27
    this.leftMenu = {
28
      'title': 'My Menu',
29
      'items': [
30
        {
31
          label: 'Home',
32
          icon: 'pi pi-home',
33
          routerLink: '/pages/dashboard'
34
        },
35
        {
36
          label: 'Inbox',
37
          icon: 'pi pi-inbox',
38
          routerLink: '/pages/inbox'
39
        },
40
        {
41
          label: 'Processes',
42
          icon: 'pi pi-th-large',
43
          routerLink: '/pages/processes'
44
        },
45
        {
46
          label: 'Administration',
47
          icon: 'pi pi-cog',
48
          routerLink: '/pages/administration'
49
        },
50
        {
51
          label: 'Reports - Statistics',
52
          icon: 'pi pi-chart-line',
53
          disabled: true,
54
        },
55
        {
56
          label: 'My Profile',
57
          icon: 'pi pi-user',
58
          disabled: true
59
        },
60
        {
61
          label: 'Logout',
62
          icon: 'pi pi-sign-out',
63
          visible: this.loggedIn,
64
          command: () => this.logout()
65
        }
66
      ]
67
    };
68
  }
69

    
70
  logout(): void {
71
    this.auth.logout();
72
  }
73

    
74
}
(4-4/4)