import { Component, ViewChild, OnInit, Input, AfterContentInit, OnDestroy } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { Sensor } from 'packages/sensor/model'; import { Infra } from 'packages/infra/model'; import { Store, select } from '@ngrx/store'; import { DetailSelector as InfraDetailSelector } from 'packages/infra/store'; import * as InfraDetailStore from 'packages/infra/store/detail'; import { Subscription } from 'rxjs/Subscription'; import { RPCClientError } from '@loafer/ng-rpc/protocol'; import { sensorListSelector } from 'packages/sensor/store'; import * as SensorListStore from 'packages/sensor/store/list'; @Component({ selector: 'of-target-detail', templateUrl: './detail.component.html', }) export class DetailComponent implements OnInit, AfterContentInit, OnDestroy { infraSubscription$: Subscription; infra$ = this.infraDetailStore.pipe(select(InfraDetailSelector.select('infra'))); sensorsSubscription$: Subscription; sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page'))); infra: Infra; sensorSettingDisplay = false; constructor( private router: Router, private route: ActivatedRoute, private infraDetailStore: Store, private sensorListStore: Store ) { } ngOnInit() { this.infraSubscription$ = this.infra$.subscribe( (infra: Infra) => { this.infra = infra; }, (error: RPCClientError) => { console.log(error.response.message); } ); } ngAfterContentInit() { const infraId = this.route.snapshot.paramMap.get('id'); this.infraDetailStore.dispatch( new InfraDetailStore.Read( { id: infraId } ) ); } ngOnDestroy() { if (this.infraSubscription$) { this.infraSubscription$.unsubscribe(); } } onAddSensor() { this.sensorSettingDisplay = true; } onSensorSettingClose() { this.sensorSettingDisplay = false; } }