member_webapp/@overflow/infra/component/infra-map.component.ts

115 lines
2.9 KiB
TypeScript
Raw Normal View History

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';
import { InfraService } from '../service/infra.service';
2018-06-07 07:28:27 +00:00
import { Page, PageParams } from '@overflow/commons-typescript/core/model';
2018-06-07 06:07:45 +00:00
import { Infra } from '@overflow/commons-typescript/model/infra';
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 {
infras: Infra[];
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-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,
private infraService: InfraService,
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();
this.getInfras(probeHosts[0].probe.id);
}),
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-07 06:07:45 +00:00
onProbeChange(event) {
this.getInfras(this.probeHosts[event.index].probe.id);
2018-04-26 11:23:57 +00:00
}
2018-06-07 06:07:45 +00:00
getInfras(probeID: number) {
const pageParams: PageParams = {
pageNo: 0,
countPerPage: 99999,
sortCol: 'id',
sortDirection: 'descending'
};
this.infraService.readAllByProbeID(probeID, pageParams)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((infraPage: Page<Infra>) => {
this.infras = infraPage.content;
console.log(this.infras);
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
take(1),
).subscribe();
}
2018-04-11 13:05:09 +00:00
}