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