member_webapp/@overflow/probe/component/probe-list.component.ts

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-05-31 09:45:40 +00:00
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
import { Store, select } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { ProbeHostService } from '../service/probe-host.service';
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';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
@Component({
selector: 'of-probe-list',
templateUrl: './probe-list.component.html',
})
export class ProbeListComponent implements OnInit {
probeHosts$: Observable<ProbeHost[]>;
pending$: Observable<boolean>;
error$: Observable<any>;
@Output() select = new EventEmitter<ProbeHost>();
constructor(
private store: Store<any>,
private probeHostService: ProbeHostService,
) {
}
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) =>
this.probeHostService.readAllByDomainID(domainMember.domain.id)
.pipe(
map((probeHosts: ProbeHost[]) => {
this.probeHosts$ = of(probeHosts);
}),
catchError(error => {
this.error$ = of(error);
return of();
})
)
),
tap(() => {
this.pending$ = of(false);
}),
).take(1).subscribe();
}
onProbeSelect(event) {
this.select.emit(event.data);
}
getUptime(probe: Probe) {
2018-06-04 06:14:00 +00:00
// if (!probe.connectDate) {
// return 'Not Connected.';
// }
// const hours = Math.abs(new Date().getTime() - probe.connectDate.getTime());
// return this.convertUptimeString(hours);
2018-05-31 09:45:40 +00:00
}
convertUptimeString(hours: number) {
if (hours === 0) {
return 'Less than an hour.';
} else {
return 'About ' + hours;
}
}
}