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

63 lines
1.5 KiB
TypeScript
Raw Normal View History

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