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'; import { NoAuthProbe, InfraHostIP } from '@overflow/commons-typescript'; import { ConfirmationService } from 'primeng/primeng'; @Component({ selector: 'of-noauth-probe-detail', templateUrl: './noauth-probe-detail.component.html', providers: [ConfirmationService] }) export class NoAuthProbeDetailComponent implements OnInit { @Input() id: number; pending$: Observable; noAuthProbe: NoAuthProbe; error$: Observable; selectedNIC: InfraHostIP; @Output() back = new EventEmitter(); constructor( private noAuthProbeService: NoAuthProbeService, private confirmationService: ConfirmationService, ) { } ngOnInit() { 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); } 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'); } }