|
|
@@ -1,5 +1,5 @@
|
|
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
|
|
-import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
+import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
import {HttpResponse} from '@angular/common/http';
|
|
|
import {map} from 'rxjs/operators';
|
|
|
import {ObservationService} from '../../../api/endpoints/services/observation.service';
|
|
|
@@ -7,8 +7,10 @@ import { ToastService } from '../../../services/toast.service';
|
|
|
import { SensorsService } from '../../../api/endpoints/services/sensors.service';
|
|
|
import { DataService } from '../../../api/endpoints/services/data.service';
|
|
|
import { Sensor } from '../../../api/endpoints/models/sensor';
|
|
|
+import { Unit } from '../../../api/endpoints/models/unit';
|
|
|
import * as moment from 'moment-timezone';
|
|
|
import { DashboardComponent } from '../../../../dashboard/components/dashboard.component';
|
|
|
+import { formatDate } from '@angular/common';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-data-download-popup',
|
|
|
@@ -19,13 +21,15 @@ export class DataDownloadPopupComponent implements OnInit {
|
|
|
|
|
|
downloadForm: FormGroup;
|
|
|
items: FormArray;
|
|
|
- dateFrom: Date = moment().hour(0).minutes(0).subtract(7, 'days').toDate();
|
|
|
+ dateFrom: Date = moment().hour(0).minutes(0).subtract(1, 'days').toDate();
|
|
|
dateTo: Date = moment().toDate();
|
|
|
+ selectedUnits: Unit[];
|
|
|
|
|
|
inProgress: Boolean = false;
|
|
|
@Input() isVisible;
|
|
|
@Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
|
|
|
@Input() sensors: Sensor[];
|
|
|
+ @Input() units: Unit[];
|
|
|
|
|
|
constructor(
|
|
|
private formBuilder: FormBuilder,
|
|
|
@@ -48,33 +52,27 @@ export class DataDownloadPopupComponent implements OnInit {
|
|
|
this.downloadForm = this.formBuilder.group({
|
|
|
from: [this.dateFrom, Validators.required],
|
|
|
to: [this.dateTo, Validators.required],
|
|
|
- sensor_id: ['', Validators.required]
|
|
|
+ sensor_id: [null, Validators.required],
|
|
|
+ selectedUnits: new FormControl([])
|
|
|
});
|
|
|
|
|
|
this.dataService.getData().subscribe(data => {
|
|
|
if (data && data.length > 0) {
|
|
|
+ this.units = Array.from(data, d => d.unit );
|
|
|
let firstUnitId: number = data[0].unit.unitId;
|
|
|
+
|
|
|
this.sensorsService.getUnitSensors({ unit_id: firstUnitId }).subscribe(sens => {
|
|
|
if (sens) {
|
|
|
this.sensors = sens;
|
|
|
+ this.downloadForm.patchValue({
|
|
|
+ selectedUnits: Array.from(this.units, u => u.unitId)
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}, err => this.toastService.showError(err.error.message));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * Clear form
|
|
|
- */
|
|
|
- clearFormArray() {
|
|
|
- const frmArray = this.downloadForm?.get('sensors') as FormArray;
|
|
|
- if (frmArray) {
|
|
|
- frmArray.clear();
|
|
|
- }
|
|
|
- this.downloadForm.reset();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Insert unit with sensor and position if form valid
|
|
|
*/
|