1
|
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} 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
|
import {InsertUnit} from '../../api/endpoints/models/insert-unit';
|
9
|
import {InsertSensor} from '../../api/endpoints/models/insert-sensor';
|
10
|
|
11
|
@Component({
|
12
|
selector: 'app-nav-bar',
|
13
|
templateUrl: './nav-bar.component.html',
|
14
|
styleUrls: ['./nav-bar.component.scss']
|
15
|
})
|
16
|
export class NavBarComponent implements OnInit, OnDestroy {
|
17
|
|
18
|
loggedUser: User;
|
19
|
subscription: Subscription[] = [];
|
20
|
showAddUserPopup = false;
|
21
|
rights: Right[];
|
22
|
showInsertUnitPopup = false;
|
23
|
phenomenons: Phenomenon[];
|
24
|
@Output() emitNewUnit: EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}> =
|
25
|
new EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}>();
|
26
|
@Input() sensorTypes;
|
27
|
|
28
|
constructor(
|
29
|
private authService: AuthService,
|
30
|
private sensorService: SensorsService
|
31
|
) {
|
32
|
}
|
33
|
|
34
|
ngOnInit(): void {
|
35
|
this.setUser();
|
36
|
}
|
37
|
|
38
|
setUser(){
|
39
|
this.authService.getUserState().subscribe(res => {
|
40
|
if(res){
|
41
|
this.loggedUser = res;
|
42
|
}
|
43
|
});
|
44
|
}
|
45
|
|
46
|
insertUnitPopup() {
|
47
|
this.sensorService.getPhenomenons().subscribe(
|
48
|
response => this.phenomenons = response
|
49
|
);
|
50
|
this.showInsertUnitPopup = true;
|
51
|
}
|
52
|
|
53
|
logOut(): void {
|
54
|
this.authService.doLogout();
|
55
|
}
|
56
|
|
57
|
ngOnDestroy(): void {
|
58
|
this.subscription.forEach(subs => subs.unsubscribe());
|
59
|
}
|
60
|
|
61
|
addUser() {
|
62
|
this.showAddUserPopup = true;
|
63
|
}
|
64
|
|
65
|
addUnit(inserted: any) {
|
66
|
this.emitNewUnit.emit(inserted);
|
67
|
}
|
68
|
}
|