2018-06-04 10:03:59 +00:00
|
|
|
import { Component, OnInit, Output, EventEmitter, Input, OnDestroy } from '@angular/core';
|
2018-05-31 09:45:40 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2018-06-04 08:55:47 +00:00
|
|
|
|
2018-06-04 10:03:59 +00:00
|
|
|
import { Observable, Subscription, of } from 'rxjs';
|
2018-06-04 08:55:47 +00:00
|
|
|
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-05-31 09:45:40 +00:00
|
|
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
2018-06-04 08:55:47 +00:00
|
|
|
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
|
|
|
|
|
|
|
import { ProbeHostService } from '../service/probe-host.service';
|
2018-06-04 10:03:59 +00:00
|
|
|
import { ProbeSubscriber, ProbeNotify } from '../subscriber/probe.subscriber';
|
2018-05-31 09:45:40 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-probe-list',
|
|
|
|
templateUrl: './probe-list.component.html',
|
|
|
|
})
|
2018-06-04 10:03:59 +00:00
|
|
|
export class ProbeListComponent implements OnInit, OnDestroy {
|
|
|
|
@Output() select = new EventEmitter<ProbeHost>();
|
2018-05-31 09:45:40 +00:00
|
|
|
|
2018-06-04 10:03:59 +00:00
|
|
|
probeHosts: ProbeHost[];
|
2018-05-31 09:45:40 +00:00
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
2018-06-04 10:03:59 +00:00
|
|
|
|
|
|
|
probeSubscription: Subscription;
|
2018-05-31 09:45:40 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private store: Store<any>,
|
|
|
|
private probeHostService: ProbeHostService,
|
2018-06-04 10:03:59 +00:00
|
|
|
private probeSubscriber: ProbeSubscriber,
|
2018-05-31 09:45:40 +00:00
|
|
|
) {
|
2018-06-04 10:03:59 +00:00
|
|
|
this.probeSubscription = null;
|
2018-05-31 09:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.store.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
2018-06-01 09:45:28 +00:00
|
|
|
select(AuthSelector.selectDomainMember),
|
2018-05-31 09:45:40 +00:00
|
|
|
exhaustMap((domainMember: DomainMember) =>
|
2018-06-14 11:20:17 +00:00
|
|
|
this.probeHostService.readAllByDomainID(domainMember.domain.id)
|
2018-05-31 09:45:40 +00:00
|
|
|
.pipe(
|
|
|
|
map((probeHosts: ProbeHost[]) => {
|
2018-06-04 10:03:59 +00:00
|
|
|
this.probeHosts = probeHosts;
|
2018-06-14 11:20:17 +00:00
|
|
|
console.log(this.probeHosts);
|
2018-05-31 09:45:40 +00:00
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.error$ = of(error);
|
|
|
|
return of();
|
|
|
|
})
|
|
|
|
)
|
|
|
|
),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
2018-06-04 08:55:47 +00:00
|
|
|
take(1),
|
|
|
|
).subscribe();
|
2018-06-04 10:03:59 +00:00
|
|
|
|
|
|
|
this.probeSubscription = this.probeSubscriber.observable().pipe(
|
|
|
|
tap((probeNotify: ProbeNotify) => {
|
|
|
|
const probeHosts = [];
|
|
|
|
this.probeHosts.forEach(probeHost => {
|
|
|
|
const n = probeNotify.params;
|
|
|
|
if (probeHost.probe.id === n.id) {
|
|
|
|
probeHost.probe = n;
|
|
|
|
}
|
|
|
|
probeHosts.push(probeHost);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.probeHosts = probeHosts;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
).subscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (null !== this.probeSubscription) {
|
|
|
|
this.probeSubscription.unsubscribe();
|
|
|
|
}
|
2018-05-31 09:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onProbeSelect(event) {
|
|
|
|
this.select.emit(event.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
getUptime(probe: Probe) {
|
2018-06-06 08:57:19 +00:00
|
|
|
if (!probe.connectDate) {
|
|
|
|
return 'Not Connected.';
|
|
|
|
}
|
|
|
|
return 'TODO';
|
2018-05-31 09:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
convertUptimeString(hours: number) {
|
|
|
|
if (hours === 0) {
|
|
|
|
return 'Less than an hour.';
|
|
|
|
} else {
|
|
|
|
return 'About ' + hours;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|