app/src/commons/component/host-detail.component.ts
2018-09-21 13:42:21 +09:00

74 lines
1.6 KiB
TypeScript

import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { of } from 'rxjs';
import { map, catchError, take } from 'rxjs/operators';
import { Host } from '@overflow/model/discovery';
import { PingResult } from '@overflow/model/ping';
import { ProbeService } from '../service/probe.service';
@Component({
selector: 'app-host-detail',
templateUrl: './host-detail.component.html',
styleUrls: ['./host-detail.component.scss'],
})
export class HostDetailComponent implements OnChanges {
@Input() host: Host;
pingWaiting: boolean;
count: number;
interval: number;
deadline: number;
pingResult: PingResult;
pingResultRaw: string;
constructor(
private probeService: ProbeService,
) {
this.pingWaiting = false;
this.count = 5;
this.interval = 1;
this.deadline = 1;
}
ngOnChanges(simpleChanges: SimpleChanges): void {
this.pingResult = null;
}
doPing() {
this.pingWaiting = true;
const option = {
Count: this.count,
Interval: this.interval,
Deadline: this.deadline,
};
this.probeService
.call<PingResult>('PingService.PingHost', this.host, option)
.pipe(
map((pingResult: PingResult) => {
if (pingResult) {
this.pingResult = pingResult;
this.pingResultRaw = pingResult.raw.join('\r\n');
}
this.pingWaiting = false;
}),
catchError(error => {
console.log(error);
alert('An error has occurred.');
this.pingWaiting = false;
return of();
}),
take(1)
)
.subscribe();
}
}