63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
|
import { Service } from '@overflow/model/discovery';
|
|
import { PingResult } from '@overflow/model/ping';
|
|
import { ProbeService } from '../service/probe.service';
|
|
import { map, catchError, take } from 'rxjs/operators';
|
|
import { of } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'app-service-detail',
|
|
templateUrl: './service-detail.component.html',
|
|
styleUrls: ['./service-detail.component.scss'],
|
|
})
|
|
export class ServiceDetailComponent {
|
|
|
|
@Input() service: Service;
|
|
pingWaiting: boolean;
|
|
pingResult: PingResult;
|
|
|
|
retries: number;
|
|
interval: number;
|
|
deadline: number;
|
|
|
|
constructor(
|
|
private probeService: ProbeService
|
|
) {
|
|
this.pingWaiting = false;
|
|
this.retries = 5;
|
|
this.interval = 1;
|
|
this.deadline = 1;
|
|
}
|
|
|
|
doPing() {
|
|
this.pingWaiting = true;
|
|
|
|
const option = {
|
|
Retry: this.retries,
|
|
Interval: this.interval,
|
|
Deadline: this.deadline,
|
|
};
|
|
|
|
this.probeService
|
|
.call<PingResult>('PingService.PingService', this.service, option)
|
|
.pipe(
|
|
map((pingResult: PingResult) => {
|
|
console.log(pingResult);
|
|
if (pingResult) {
|
|
this.pingResult = pingResult;
|
|
}
|
|
this.pingWaiting = false;
|
|
}),
|
|
catchError(error => {
|
|
console.log(error);
|
|
alert('An error has occurred.');
|
|
this.pingWaiting = false;
|
|
return of();
|
|
}),
|
|
take(1)
|
|
)
|
|
.subscribe();
|
|
}
|
|
|
|
}
|