app/src/commons/component/host-detail.component.ts

68 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-09-18 12:25:47 +00:00
import { Component, Input, Output, EventEmitter } from '@angular/core';
2018-09-19 12:34:44 +00:00
import { of } from 'rxjs';
2018-09-18 12:25:47 +00:00
import { map, catchError, take } from 'rxjs/operators';
2018-09-19 12:34:44 +00:00
import { Host } from '@overflow/model/discovery';
2018-09-19 04:40:32 +00:00
import { PingResult } from '@overflow/model/ping';
2018-09-19 12:34:44 +00:00
import { ProbeService } from '../service/probe.service';
2018-09-09 10:20:21 +00:00
@Component({
selector: 'app-host-detail',
templateUrl: './host-detail.component.html',
styleUrls: ['./host-detail.component.scss'],
})
export class HostDetailComponent {
@Input() host: Host;
2018-09-19 04:40:32 +00:00
pingWaiting: boolean;
2018-09-19 12:00:54 +00:00
2018-09-19 04:40:32 +00:00
retries: number;
2018-09-19 12:00:54 +00:00
interval: number;
deadline: number;
pingResult: PingResult;
2018-09-09 10:20:21 +00:00
constructor(
2018-09-19 04:40:32 +00:00
private probeService: ProbeService,
2018-09-09 10:20:21 +00:00
) {
2018-09-19 04:40:32 +00:00
this.pingWaiting = false;
this.retries = 5;
2018-09-19 12:00:54 +00:00
this.interval = 1;
this.deadline = 1;
2018-09-13 11:01:01 +00:00
}
2018-09-09 10:20:21 +00:00
2018-09-18 12:25:47 +00:00
doPing() {
2018-09-19 04:40:32 +00:00
this.pingWaiting = true;
2018-09-18 12:25:47 +00:00
const option = {
2018-09-19 04:40:32 +00:00
Retry: this.retries,
2018-09-19 12:00:54 +00:00
Interval: this.interval,
Deadline: this.deadline,
2018-09-18 12:25:47 +00:00
};
this.probeService
.call<PingResult>('PingService.PingHost', this.host, option)
.pipe(
map((pingResult: PingResult) => {
2018-09-18 13:39:46 +00:00
if (pingResult) {
this.pingResult = pingResult;
}
2018-09-19 04:40:32 +00:00
this.pingWaiting = false;
2018-09-18 12:25:47 +00:00
}),
catchError(error => {
console.log(error);
alert('An error has occurred.');
2018-09-19 04:40:32 +00:00
this.pingWaiting = false;
2018-09-18 12:25:47 +00:00
return of();
}),
take(1)
)
.subscribe();
2018-09-09 10:20:21 +00:00
}
}