member_webapp/@overflow/sensor/component/sensor-detail.component.ts

85 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-06-04 05:19:55 +00:00
import { Component, OnInit, Inject, AfterContentInit, OnDestroy, Input } from '@angular/core';
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-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',
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;
sensor: Sensor;
sensorSettingDisplay: boolean;
pending$: Observable<boolean>;
error$: Observable<any>;
constructor(
private confirmationService: ConfirmationService,
private store: Store<any>,
private sensorService: SensorService,
) {
this.sensorSettingDisplay = false;
}
ngOnInit() {
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);
}),
2018-06-04 08:55:47 +00:00
take(1),
).subscribe();
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: () => {
}
});
}
onTargetClick(target) {
// this.router.navigate(['sensors'], { queryParams: { target: target.id } });
// this.router.navigate(['target', target.id, 'info']);
}
2018-04-16 06:00:05 +00:00
}
2018-04-06 11:02:18 +00:00