import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core'; import { Store, select } from '@ngrx/store'; import { Observable, of } from 'rxjs'; import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators'; import { AuthSelector } from '@overflow/shared/auth/store'; import { DomainMember } from '@overflow/commons-typescript/model/domain'; import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe'; import { ProbeHostService } from '../service/probe-host.service'; @Component({ selector: 'of-probe-list', templateUrl: './probe-list.component.html', }) export class ProbeListComponent implements OnInit { probeHosts$: Observable; pending$: Observable; error$: Observable; @Output() select = new EventEmitter(); constructor( private store: Store, private probeHostService: ProbeHostService, ) { } ngOnInit(): void { 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$ = 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) { // if (!probe.connectDate) { // return 'Not Connected.'; // } // const hours = Math.abs(new Date().getTime() - probe.connectDate.getTime()); // return this.convertUptimeString(hours); } convertUptimeString(hours: number) { if (hours === 0) { return 'Less than an hour.'; } else { return 'About ' + hours; } } }