1 |
b5525aef
|
hlavja
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
2 |
|
|
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
|
3 |
|
|
import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
|
4 |
|
|
import * as moment from 'moment-timezone';
|
5 |
|
|
import {map} from 'rxjs/operators';
|
6 |
|
|
import {HttpResponse} from '@angular/common/http';
|
7 |
|
|
import {ToastService} from '../../../shared/services/toast.service';
|
8 |
|
|
import {SensorsService} from '../../../shared/api/endpoints/services/sensors.service';
|
9 |
|
|
|
10 |
|
|
@Component({
|
11 |
|
|
selector: 'app-position-insert-popup',
|
12 |
|
|
templateUrl: './position-insert-popup.component.html',
|
13 |
|
|
styleUrls: ['./position-insert-popup.component.scss']
|
14 |
|
|
})
|
15 |
|
|
export class PositionInsertPopupComponent implements OnInit {
|
16 |
|
|
|
17 |
|
|
insertForm: FormGroup;
|
18 |
|
|
|
19 |
|
|
@Input() isVisible;
|
20 |
|
|
@Input() unitId;
|
21 |
|
|
@Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
|
22 |
|
|
|
23 |
|
|
constructor(
|
24 |
|
|
private formBuilder: FormBuilder,
|
25 |
|
|
private sensorService: SensorsService,
|
26 |
|
|
private toastService: ToastService,
|
27 |
|
|
) {
|
28 |
|
|
this.initForm();
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
ngOnInit(): void {
|
32 |
|
|
}
|
33 |
|
|
initForm() {
|
34 |
|
|
this.insertForm = this.formBuilder.group({
|
35 |
|
|
lat: ['', [Validators.required, Validators.min(-90), Validators.max(90)]],
|
36 |
|
|
lon: ['', [Validators.required, Validators.min(-180), Validators.max(180)]],
|
37 |
|
|
alt: '',
|
38 |
|
|
speed: '',
|
39 |
|
|
dop: ''
|
40 |
|
|
});
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
clearFormArray() {
|
44 |
|
|
this.insertForm.reset();
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
processInsertion() {
|
48 |
|
|
if (this.insertForm.valid) {
|
49 |
|
|
const lat = this.insertForm.controls.lat.value;
|
50 |
|
|
const lon = this.insertForm.controls.lon.value;
|
51 |
|
|
const alt = this.insertForm.controls.alt.value;
|
52 |
|
|
const speed = this.insertForm.controls.speed.value;
|
53 |
|
|
const dop = this.insertForm.controls.dop.value;
|
54 |
|
|
|
55 |
|
|
this.sensorService.insertPosition$Response( {
|
56 |
|
|
lat, lon, alt, speed, dop, unit_id: this.unitId, date: moment().format('yyyy-MM-DD HH:mm:ssZZ')
|
57 |
|
|
}).pipe(
|
58 |
|
|
map((response: HttpResponse<any>) => {
|
59 |
|
|
if (response.status === 200) {
|
60 |
|
|
this.toastService.showSuccessMessage('Position to unit ' + this.unitId + ' inserted!');
|
61 |
|
|
this.close();
|
62 |
|
|
} else {
|
63 |
|
|
this.toastService.showError('Position insertion caused error!');
|
64 |
|
|
}
|
65 |
|
|
})
|
66 |
|
|
).toPromise().then().catch(err => this.toastService.showError(err.error.message));
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
close() {
|
71 |
|
|
this.isVisibleChange.emit(false);
|
72 |
|
|
}
|
73 |
|
|
}
|