member_webapp/@overflow/noauth-probe/component/noauth-probe-detail.component.ts

90 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-06-14 05:35:59 +00:00
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';
import { Store, select } from '@ngrx/store';
import { Observable, of, Subscription } from 'rxjs';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import { NoAuthProbeService } from '../service/noauth-probe.service';
2018-06-14 06:45:39 +00:00
import { NoAuthProbe, InfraHostIP } from '@overflow/commons-typescript';
import { ConfirmationService } from 'primeng/primeng';
2018-06-14 05:35:59 +00:00
@Component({
selector: 'of-noauth-probe-detail',
templateUrl: './noauth-probe-detail.component.html',
2018-06-14 06:45:39 +00:00
providers: [ConfirmationService]
2018-06-14 05:35:59 +00:00
})
export class NoAuthProbeDetailComponent implements OnInit {
2018-06-14 06:45:39 +00:00
@Input() id: number;
2018-06-14 05:35:59 +00:00
pending$: Observable<boolean>;
2018-06-14 06:45:39 +00:00
noAuthProbe: NoAuthProbe;
2018-06-14 05:35:59 +00:00
error$: Observable<any>;
2018-06-14 06:45:39 +00:00
selectedNIC: InfraHostIP;
@Output() back = new EventEmitter();
2018-06-14 05:35:59 +00:00
constructor(
private noAuthProbeService: NoAuthProbeService,
2018-06-14 06:45:39 +00:00
private confirmationService: ConfirmationService,
2018-06-14 05:35:59 +00:00
) {
}
ngOnInit() {
2018-06-14 06:45:39 +00:00
this.noAuthProbeService.read(this.id)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((noauthProbe: NoAuthProbe) => {
noauthProbe.infraHost = JSON.parse(noauthProbe.infraHostMeta);
this.noAuthProbe = noauthProbe;
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
take(1),
).subscribe();
}
onNICSelect(infraHostIP: InfraHostIP) {
this.selectedNIC = infraHostIP;
console.log(this.selectedNIC);
2018-06-14 05:35:59 +00:00
}
2018-06-14 06:45:39 +00:00
accept() {
this.confirmationService.confirm({
header: 'Are you sure to accept this Probe?',
message: 'Start collecting data as a Probe.',
icon: 'fa-check',
accept: () => {
this.noAuthProbeService.acceptNoAuthProbe(this.id, this.selectedNIC.address)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((noauthProbes: NoAuthProbe[]) => {
this.back.emit();
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
take(1),
).subscribe();
},
reject: () => {
}
});
}
deny() {
alert('609호에 있는 강아지 deny');
}
2018-06-14 05:35:59 +00:00
}