2018-05-27 14:17:07 +00:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
|
2018-05-25 09:18:06 +00:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import * as ProbeStore from '../store/entity/probe';
|
2018-05-27 09:12:20 +00:00
|
|
|
import { ProbeEntitySelector, ProbeDetailContainerSelector } from '../store';
|
2018-05-25 09:18:06 +00:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2018-05-18 08:30:20 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-probe-detail-container',
|
2018-05-27 14:17:07 +00:00
|
|
|
templateUrl: './probe-detail-container.component.html',
|
2018-05-18 08:30:20 +00:00
|
|
|
})
|
2018-05-27 06:52:27 +00:00
|
|
|
export class ProbeDetailContainerComponent implements OnInit, OnChanges {
|
2018-05-18 08:30:20 +00:00
|
|
|
|
2018-05-25 12:41:29 +00:00
|
|
|
@Input() probeHostID: number;
|
2018-05-25 09:18:06 +00:00
|
|
|
@Output() discovery = new EventEmitter<number>();
|
2018-05-25 11:59:18 +00:00
|
|
|
probeHost$: Observable<ProbeHost>;
|
2018-05-26 09:08:40 +00:00
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
2018-05-25 09:18:06 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private store: Store<ProbeStore.State>,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
) {
|
2018-05-26 09:08:40 +00:00
|
|
|
this.pending$ = this.store.pipe(select(ProbeDetailContainerSelector.selectPending));
|
2018-05-27 09:12:20 +00:00
|
|
|
this.error$ = this.store.pipe(select(ProbeEntitySelector.selectError));
|
2018-05-25 09:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-05-27 09:12:20 +00:00
|
|
|
this.probeHost$ = this.store.pipe(select(ProbeEntitySelector.selectOne(this.probeHostID)));
|
2018-05-27 06:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
2018-05-25 09:18:06 +00:00
|
|
|
this.store.dispatch(new ProbeStore.Read(this.probeHostID));
|
|
|
|
}
|
|
|
|
|
|
|
|
onModify(probeHost: ProbeHost) {
|
|
|
|
this.store.dispatch(new ProbeStore.Modify(probeHost.probe));
|
|
|
|
}
|
|
|
|
|
|
|
|
onDiscovery(probeHostID: number) {
|
|
|
|
this.discovery.emit(probeHostID);
|
|
|
|
}
|
2018-05-18 08:30:20 +00:00
|
|
|
}
|