2018-09-18 12:25:47 +00:00
|
|
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
import { Host } from '@overflow/model/discovery';
|
|
|
|
import { ProbeService } from '../service/probe.service';
|
|
|
|
import { map, catchError, take } from 'rxjs/operators';
|
2018-09-18 13:39:46 +00:00
|
|
|
import { PingResult, PingResponse } from '@overflow/model/ping';
|
2018-09-18 12:25:47 +00:00
|
|
|
import { of } from 'rxjs';
|
2018-09-18 13:39:46 +00:00
|
|
|
import { Message } from 'primeng/primeng';
|
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-18 13:39:46 +00:00
|
|
|
pingResult: PingResult;
|
2018-09-09 10:20:21 +00:00
|
|
|
|
|
|
|
constructor(
|
2018-09-13 11:01:01 +00:00
|
|
|
private probeService: ProbeService
|
2018-09-09 10:20:21 +00:00
|
|
|
) {
|
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() {
|
|
|
|
const option = {
|
|
|
|
Retry: 3,
|
|
|
|
Interval: 1,
|
|
|
|
Deadline: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
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-18 12:25:47 +00:00
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
console.log(error);
|
|
|
|
alert('An error has occurred.');
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
take(1)
|
|
|
|
)
|
|
|
|
.subscribe();
|
2018-09-09 10:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|