1
|
import {Component, EventEmitter, 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
|
constructor(
|
27
|
private authService: AuthService,
|
28
|
private sensorService: SensorsService
|
29
|
) {
|
30
|
}
|
31
|
|
32
|
ngOnInit(): void {
|
33
|
this.setUser();
|
34
|
}
|
35
|
|
36
|
setUser(){
|
37
|
this.authService.getUserState().subscribe(res => {
|
38
|
if(res){
|
39
|
this.loggedUser = res;
|
40
|
}
|
41
|
});
|
42
|
}
|
43
|
|
44
|
insertUnitPopup() {
|
45
|
this.sensorService.getPhenomenons().subscribe(
|
46
|
response => this.phenomenons = response
|
47
|
);
|
48
|
this.showInsertUnitPopup = true;
|
49
|
}
|
50
|
|
51
|
logOut(): void {
|
52
|
this.authService.doLogout();
|
53
|
}
|
54
|
|
55
|
ngOnDestroy(): void {
|
56
|
this.subscription.forEach(subs => subs.unsubscribe());
|
57
|
}
|
58
|
|
59
|
addUser() {
|
60
|
this.showAddUserPopup = true;
|
61
|
}
|
62
|
|
63
|
addUnit(inserted: any) {
|
64
|
this.emitNewUnit.emit(inserted);
|
65
|
}
|
66
|
}
|