member_webapp/@overflow/discovery/component/discovery.component.ts
crusader 2707f4f869 ing
2018-06-04 12:42:30 +09:00

104 lines
3.0 KiB
TypeScript

import {
Component, Input, Output, EventEmitter, OnDestroy, ViewChild,
} from '@angular/core';
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';
import { Anim } from './animation';
import { Store, select } from '@ngrx/store';
import { Observable, of, Subscription } from 'rxjs';
import { DiscoveryService } from '../service/discovery.service';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery';
import { DiscoverySubscriber, DiscoveryNotify } from '../subscriber/discovery.subscriber';
import { SearchResultComponent } from './search-result.component';
@Component({
selector: 'of-discovery',
templateUrl: './discovery.component.html',
animations: Anim,
})
export class DiscoveryComponent implements OnDestroy {
@Input() probeHostID;
pending$: Observable<boolean>;
error$: Observable<any>;
discoverySubscription: Subscription;
selectedProbe: ProbeHost;
requested: boolean;
discoverZone: DiscoverZone;
@ViewChild('discoveryResult') discoveryResult: SearchResultComponent;
constructor(
private discoveryService: DiscoveryService,
private discoverySubscriber: DiscoverySubscriber,
private store: Store<any>
) {
this.discoverySubscription = null;
}
ngOnDestroy(): void {
if (null !== this.discoverySubscription) {
this.discoverySubscription.unsubscribe();
}
}
onRequestDiscovery(dz: DiscoverZone) {
this.requested = true;
this.discoverZone = dz;
this.discoverySubscription = this.discoverySubscriber.observable().pipe(
tap(() => {
this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz);
}),
map((discoveryNotify: DiscoveryNotify) => {
switch (discoveryNotify.method) {
case 'DiscoveryService.discoveryStart': {
const startDate = discoveryNotify.params as Date;
break;
}
case 'DiscoveryService.discoveryStop': {
const stopDate = discoveryNotify.params as Date;
this.discoverySubscription.unsubscribe();
this.discoverySubscription = null;
break;
}
case 'DiscoveryService.discoveredZone': {
const zone = discoveryNotify.params as Zone;
break;
}
case 'DiscoveryService.discoveredHost': {
const host = discoveryNotify.params as Host;
break;
}
case 'DiscoveryService.discoveredPort': {
const port = discoveryNotify.params as Port;
break;
}
case 'DiscoveryService.discoveredService': {
const service = discoveryNotify.params as Service;
break;
}
default: {
break;
}
}
}),
catchError(error => {
return of();
}),
).subscribe();
}
onRequestDiscoveryStop() {
this.discoverZone = null;
this.requested = false;
}
}