member_webapp/src/packages/target/component/detail/detail.component.ts

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-04-30 08:12:31 +00:00
import { Component, ViewChild, OnInit, Input, AfterContentInit, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
2018-04-16 08:28:39 +00:00
import { Sensor } from 'packages/sensor/model';
2018-04-30 08:12:31 +00:00
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';
2018-04-06 11:02:18 +00:00
2018-04-16 08:28:39 +00:00
@Component({
selector: 'of-target-detail',
templateUrl: './detail.component.html',
})
2018-04-30 08:12:31 +00:00
export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
2018-04-06 11:02:18 +00:00
2018-04-30 08:12:31 +00:00
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<InfraDetailStore.State>,
private sensorListStore: Store<SensorListStore.State>
) { }
2018-04-06 11:02:18 +00:00
2018-04-16 08:28:39 +00:00
ngOnInit() {
2018-04-30 08:12:31 +00:00
this.infraSubscription$ = this.infra$.subscribe(
(infra: Infra) => {
this.infra = infra;
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
2018-04-16 08:28:39 +00:00
}
2018-04-06 11:02:18 +00:00
2018-04-16 08:28:39 +00:00
ngAfterContentInit() {
2018-04-30 08:12:31 +00:00
const infraId = this.route.snapshot.paramMap.get('id');
this.infraDetailStore.dispatch(
new InfraDetailStore.Read(
{ id: infraId }
)
);
2018-04-16 08:28:39 +00:00
}
2018-04-06 11:02:18 +00:00
2018-04-30 08:12:31 +00:00
ngOnDestroy() {
if (this.infraSubscription$) {
this.infraSubscription$.unsubscribe();
}
2018-04-16 08:28:39 +00:00
}
2018-04-06 11:02:18 +00:00
2018-04-30 08:12:31 +00:00
onAddSensor() {
this.sensorSettingDisplay = true;
2018-04-16 08:28:39 +00:00
}
2018-04-06 11:02:18 +00:00
2018-04-30 08:12:31 +00:00
onSensorSettingClose() {
this.sensorSettingDisplay = false;
2018-04-16 08:28:39 +00:00
}
2018-04-30 08:12:31 +00:00
2018-04-16 08:28:39 +00:00
}