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

122 lines
3.2 KiB
TypeScript
Raw Normal View History

2018-06-14 05:35:59 +00:00
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
2018-06-14 07:42:04 +00:00
import { Observable, of } from 'rxjs';
import { catchError, map, tap, take } from 'rxjs/operators';
2018-06-14 05:35:59 +00:00
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;
2018-06-14 05:35:59 +00:00
}
2018-06-14 06:45:39 +00:00
accept() {
2018-06-14 11:20:17 +00:00
console.log(this.selectedNIC);
this.selectedNIC.address = '192.168.1.0/24';
2018-06-14 07:42:04 +00:00
let message = 'Start collecting data as a Probe.\n';
2018-06-14 11:20:17 +00:00
message += this.selectedNIC.iface + '\n';
2018-06-14 07:42:04 +00:00
message += this.selectedNIC.address;
2018-06-14 06:45:39 +00:00
this.confirmationService.confirm({
header: 'Are you sure to accept this Probe?',
2018-06-14 07:42:04 +00:00
message: message,
2018-06-14 06:45:39 +00:00
icon: 'fa-check',
accept: () => {
this.noAuthProbeService.acceptNoAuthProbe(this.id, this.selectedNIC.address)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
2018-06-14 11:20:17 +00:00
map((noauthProbes: NoAuthProbe) => {
console.log(noauthProbes);
2018-06-14 06:45:39 +00:00
this.back.emit();
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
take(1),
).subscribe();
},
reject: () => {
}
});
}
deny() {
2018-06-14 07:42:04 +00:00
this.confirmationService.confirm({
header: 'Are you sure to deny this Probe',
message: 'It will be permanently deleted.',
icon: 'fa fa-trash',
accept: () => {
this.noAuthProbeService.denyNoauthProbe(this.id)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
2018-06-14 11:20:17 +00:00
map((noauthProbes: NoAuthProbe) => {
2018-06-14 07:42:04 +00:00
this.back.emit();
}),
catchError(error => {
this.error$ = of(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
take(1),
).subscribe();
},
reject: () => {
}
});
2018-06-14 06:45:39 +00:00
}
2018-06-14 05:35:59 +00:00
}