2018-06-04 12:15:15 +00:00
|
|
|
import { Component, OnInit, Inject, AfterContentInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
|
2018-06-04 05:19:55 +00:00
|
|
|
|
2018-04-18 11:28:53 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2018-06-04 05:19:55 +00:00
|
|
|
|
|
|
|
import { Observable, of, Subscription } from 'rxjs';
|
2018-06-04 08:55:47 +00:00
|
|
|
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
|
2018-06-04 05:19:55 +00:00
|
|
|
|
|
|
|
import { ConfirmationService } from 'primeng/primeng';
|
|
|
|
|
2018-05-24 06:44:13 +00:00
|
|
|
import { RPCClientError } from '@loafer/ng-rpc';
|
2018-06-04 05:19:55 +00:00
|
|
|
|
2018-05-02 08:09:39 +00:00
|
|
|
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
2018-06-04 05:19:55 +00:00
|
|
|
import { SensorService } from '../service/sensor.service';
|
2018-06-04 12:15:15 +00:00
|
|
|
import { Target } from '@overflow/commons-typescript/model/target';
|
2018-06-05 11:29:35 +00:00
|
|
|
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-04-16 06:00:05 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'of-sensor-detail',
|
2018-06-01 10:54:44 +00:00
|
|
|
templateUrl: './sensor-detail.component.html',
|
2018-04-18 11:28:53 +00:00
|
|
|
providers: [ConfirmationService]
|
2018-04-16 06:00:05 +00:00
|
|
|
})
|
2018-06-04 05:19:55 +00:00
|
|
|
export class SensorDetailComponent implements OnInit, OnDestroy {
|
|
|
|
@Input() sensorID: number;
|
2018-06-04 12:15:15 +00:00
|
|
|
@Output() selectTarget = new EventEmitter<Target>();
|
2018-06-04 05:19:55 +00:00
|
|
|
|
|
|
|
sensor: Sensor;
|
|
|
|
sensorSettingDisplay: boolean;
|
|
|
|
|
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
|
|
|
|
2018-06-05 11:29:35 +00:00
|
|
|
metaCrawler: MetaCrawler;
|
|
|
|
|
2018-06-04 05:19:55 +00:00
|
|
|
constructor(
|
|
|
|
private confirmationService: ConfirmationService,
|
|
|
|
private store: Store<any>,
|
|
|
|
private sensorService: SensorService,
|
|
|
|
) {
|
|
|
|
this.sensorSettingDisplay = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-06-05 11:29:35 +00:00
|
|
|
if (0 < this.sensorID) {
|
|
|
|
// get sensor
|
|
|
|
this.sensorService.read(this.sensorID)
|
|
|
|
.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
map((sensor: Sensor) => {
|
|
|
|
this.sensor = sensor;
|
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.error$ = of(error);
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
|
|
|
take(1),
|
|
|
|
).subscribe();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// new sensor
|
|
|
|
this.sensor = {};
|
|
|
|
}
|
2018-06-04 05:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
}
|
|
|
|
|
|
|
|
onStartOrStop() { }
|
|
|
|
|
|
|
|
onEdit() {
|
|
|
|
this.sensorSettingDisplay = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemove() {
|
|
|
|
this.confirmationService.confirm({
|
|
|
|
header: 'Are you sure to remove this Sensor?',
|
|
|
|
icon: 'fa fa-trash',
|
|
|
|
message: 'All the related data will be deleted. ',
|
|
|
|
accept: () => {
|
|
|
|
alert('으앙 안돼 지우지마ㅠㅠ');
|
|
|
|
},
|
|
|
|
reject: () => {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-06-05 11:29:35 +00:00
|
|
|
|
|
|
|
onMetaCrawlerSelected(metaCrawler: MetaCrawler) {
|
|
|
|
this.metaCrawler = metaCrawler;
|
|
|
|
}
|
2018-04-16 06:00:05 +00:00
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|