2018-04-11 13:05:09 +00:00
|
|
|
import {
|
2018-06-07 06:07:45 +00:00
|
|
|
Component, OnInit, EventEmitter, Output, Input, OnChanges, SimpleChanges,
|
2018-04-11 13:05:09 +00:00
|
|
|
} from '@angular/core';
|
2018-06-07 06:07:45 +00:00
|
|
|
import { ProbeHostService } from '@overflow/probe/service/probe-host.service';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
|
2018-06-01 09:45:28 +00:00
|
|
|
import { AuthSelector } from '@overflow/shared/auth/store';
|
2018-06-07 06:07:45 +00:00
|
|
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
|
|
|
import { Observable, Subscription, of } from 'rxjs';
|
|
|
|
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
|
|
|
import { MenuItem } from 'primeng/primeng';
|
2018-04-16 11:23:43 +00:00
|
|
|
|
2018-04-10 12:37:09 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-infra-map',
|
2018-06-07 06:07:45 +00:00
|
|
|
templateUrl: './infra-map.component.html',
|
|
|
|
providers: [
|
|
|
|
ProbeHostService
|
|
|
|
]
|
2018-04-10 12:37:09 +00:00
|
|
|
})
|
2018-06-07 06:07:45 +00:00
|
|
|
export class InfraMapComponent implements OnInit {
|
|
|
|
|
2018-06-01 10:27:27 +00:00
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
|
|
|
|
2018-06-07 06:07:45 +00:00
|
|
|
tabs: MenuItem[];
|
|
|
|
probeHosts: ProbeHost[];
|
|
|
|
probeTabIdx: number;
|
2018-04-26 11:23:57 +00:00
|
|
|
|
2018-06-08 11:37:13 +00:00
|
|
|
selectedProbeHost: ProbeHost;
|
|
|
|
|
2018-06-07 06:10:17 +00:00
|
|
|
@Output() discovery = new EventEmitter();
|
|
|
|
|
2018-06-01 10:27:27 +00:00
|
|
|
constructor(
|
2018-06-07 06:07:45 +00:00
|
|
|
private store: Store<any>,
|
|
|
|
private probeHostService: ProbeHostService,
|
2018-06-01 10:27:27 +00:00
|
|
|
) {
|
2018-04-11 13:05:09 +00:00
|
|
|
}
|
2018-04-11 12:26:51 +00:00
|
|
|
|
2018-06-07 06:07:45 +00:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.getProbes();
|
|
|
|
}
|
|
|
|
|
|
|
|
getProbes() {
|
|
|
|
this.store.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
select(AuthSelector.selectDomainMember),
|
|
|
|
exhaustMap((domainMember: DomainMember) =>
|
|
|
|
this.probeHostService.readAllByDomainID(domainMember.domain.id)
|
|
|
|
.pipe(
|
|
|
|
map((probeHosts: ProbeHost[]) => {
|
|
|
|
this.probeHosts = probeHosts;
|
|
|
|
this.generateTabs();
|
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.error$ = of(error);
|
|
|
|
return of();
|
|
|
|
})
|
|
|
|
)
|
|
|
|
),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
|
|
|
take(1),
|
|
|
|
).subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
generateTabs() {
|
|
|
|
this.tabs = [];
|
|
|
|
this.probeHosts.forEach((ph, i) => {
|
|
|
|
this.tabs.push({
|
|
|
|
label: ph.probe.cidr
|
2018-04-11 13:05:09 +00:00
|
|
|
});
|
2018-04-26 12:33:37 +00:00
|
|
|
});
|
2018-06-12 05:45:21 +00:00
|
|
|
this.selectedProbeHost = this.probeHosts[0];
|
2018-04-26 11:23:57 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 11:37:13 +00:00
|
|
|
onProbeChange(event) {
|
|
|
|
this.selectedProbeHost = this.probeHosts[event.index];
|
2018-06-07 06:07:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 13:05:09 +00:00
|
|
|
}
|