1
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
2
|
import {AuthService} from '../../../auth/services/auth.service';
|
3
|
import {User} from '../../../auth/models/user';
|
4
|
import {Subscription} from 'rxjs';
|
5
|
import {Right} from '../../api/endpoints/models/right';
|
6
|
import {Phenomenon} from '../../api/endpoints/models/phenomenon';
|
7
|
import {SensorsService} from '../../api/endpoints/services/sensors.service';
|
8
|
|
9
|
@Component({
|
10
|
selector: 'app-nav-bar',
|
11
|
templateUrl: './nav-bar.component.html',
|
12
|
styleUrls: ['./nav-bar.component.scss']
|
13
|
})
|
14
|
export class NavBarComponent implements OnInit, OnDestroy {
|
15
|
|
16
|
loggedUser: User;
|
17
|
subscription: Subscription[] = [];
|
18
|
showAddUserPopup = false;
|
19
|
rights: Right[];
|
20
|
showInsertUnitPopup = false;
|
21
|
phenomenons: Phenomenon[];
|
22
|
constructor(
|
23
|
private authService: AuthService,
|
24
|
private sensorService: SensorsService
|
25
|
) {
|
26
|
}
|
27
|
|
28
|
ngOnInit(): void {
|
29
|
this.setUser();
|
30
|
}
|
31
|
|
32
|
setUser(){
|
33
|
this.authService.getUserState().subscribe(res => {
|
34
|
if(res){
|
35
|
this.loggedUser = res;
|
36
|
}
|
37
|
});
|
38
|
}
|
39
|
|
40
|
insertUnitPopup() {
|
41
|
this.sensorService.getPhenomenons().subscribe(
|
42
|
response => this.phenomenons = response
|
43
|
);
|
44
|
this.showInsertUnitPopup = true;
|
45
|
}
|
46
|
|
47
|
logOut(): void {
|
48
|
this.authService.doLogout();
|
49
|
}
|
50
|
|
51
|
ngOnDestroy(): void {
|
52
|
this.subscription.forEach(subs => subs.unsubscribe());
|
53
|
}
|
54
|
|
55
|
addUser() {
|
56
|
this.showAddUserPopup = true;
|
57
|
}
|
58
|
}
|