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

74 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-09-20 10:46:10 +00:00
import { Component, Input, OnChanges, SimpleChanges } 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'],
})
2018-09-20 10:46:10 +00:00
export class HostDetailComponent implements OnChanges {
2018-09-09 10:20:21 +00:00
@Input() host: Host;
2018-09-19 04:40:32 +00:00
pingWaiting: boolean;
2018-09-19 12:00:54 +00:00
2018-09-20 05:57:10 +00:00
count: number;
2018-09-19 12:00:54 +00:00
interval: number;
deadline: number;
pingResult: PingResult;
2018-09-20 10:46:10 +00:00
pingResultRaw: string;
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;
2018-09-20 05:57:10 +00:00
this.count = 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-20 10:46:10 +00:00
ngOnChanges(simpleChanges: SimpleChanges): void {
this.pingResult = null;
}
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-20 05:57:10 +00:00
Count: this.count,
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-21 04:42:21 +00:00
this.pingResultRaw = pingResult.raw.join('\r\n');
2018-09-18 13:39:46 +00:00
}
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
}
}