2018-05-31 07:38:44 +00:00
|
|
|
import { Component, Input, Output, EventEmitter, AfterContentInit, OnInit, OnDestroy } from '@angular/core';
|
2018-05-31 06:48:49 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2018-05-31 07:38:44 +00:00
|
|
|
import { Observable, of, Subscription } from 'rxjs';
|
2018-05-31 06:48:49 +00:00
|
|
|
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
2018-04-11 08:41:38 +00:00
|
|
|
import { ConfirmationService, Message } from 'primeng/primeng';
|
2018-04-24 05:31:20 +00:00
|
|
|
|
2018-05-31 06:48:49 +00:00
|
|
|
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
|
|
|
|
import { AuthContainerSelector } from '@overflow/shared/auth/store';
|
|
|
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
|
|
|
|
|
|
|
import { NoAuthProbeService } from '../service/noauth-probe.service';
|
2018-05-31 07:38:44 +00:00
|
|
|
import { NoAuthProbeConnectingSelector } from '../store';
|
2018-05-31 06:48:49 +00:00
|
|
|
|
2018-04-11 06:20:23 +00:00
|
|
|
@Component({
|
2018-05-28 05:41:56 +00:00
|
|
|
selector: 'of-noauth-probe-list',
|
|
|
|
templateUrl: './noauth-probe-list.component.html',
|
2018-05-28 13:40:44 +00:00
|
|
|
providers: [ConfirmationService]
|
2018-04-11 06:20:23 +00:00
|
|
|
})
|
2018-05-31 07:38:44 +00:00
|
|
|
export class NoAuthProbeListComponent implements OnInit, OnDestroy {
|
2018-05-31 06:48:49 +00:00
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-31 07:38:44 +00:00
|
|
|
noauthProbes: NoAuthProbe[];
|
|
|
|
connectingSubscription$: Subscription;
|
|
|
|
|
2018-04-11 06:20:23 +00:00
|
|
|
constructor(
|
2018-04-11 08:41:38 +00:00
|
|
|
private confirmationService: ConfirmationService,
|
2018-05-31 06:48:49 +00:00
|
|
|
private store: Store<any>,
|
|
|
|
private noAuthProbeService: NoAuthProbeService,
|
2018-04-11 06:20:23 +00:00
|
|
|
) {
|
2018-05-31 08:27:00 +00:00
|
|
|
this.noauthProbes = [];
|
2018-04-11 06:20:23 +00:00
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-31 06:48:49 +00:00
|
|
|
ngOnInit() {
|
|
|
|
this.store.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
select(AuthContainerSelector.selectDomainMember),
|
|
|
|
exhaustMap((domainMember: DomainMember) =>
|
|
|
|
this.noAuthProbeService.readAllByDomainID(domainMember.domain.id)
|
|
|
|
.pipe(
|
|
|
|
map((noauthProbes: NoAuthProbe[]) => {
|
2018-05-31 08:37:38 +00:00
|
|
|
this.setNoauthProbes(noauthProbes);
|
2018-05-31 06:48:49 +00:00
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.setError$(error);
|
|
|
|
return of();
|
|
|
|
})
|
|
|
|
)
|
|
|
|
),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
|
|
|
).take(1).subscribe();
|
|
|
|
|
2018-05-31 07:38:44 +00:00
|
|
|
this.connectingSubscription$ = this.store.pipe(
|
|
|
|
select(NoAuthProbeConnectingSelector.selectEntities),
|
|
|
|
tap((entities: { [id: number]: NoAuthProbe }) => {
|
|
|
|
const noauthProbes = [];
|
|
|
|
this.noauthProbes.forEach(noauthProbe => {
|
|
|
|
const t = entities[noauthProbe.id];
|
|
|
|
if (undefined !== t) {
|
|
|
|
noauthProbes.push(t);
|
|
|
|
} else {
|
|
|
|
noauthProbes.push(noauthProbe);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-31 08:37:38 +00:00
|
|
|
this.setNoauthProbes(noauthProbes);
|
2018-05-31 07:38:44 +00:00
|
|
|
}
|
|
|
|
),
|
|
|
|
).subscribe();
|
|
|
|
|
2018-05-31 06:48:49 +00:00
|
|
|
// this.noauthProbes$ = this.store.pipe(
|
|
|
|
// select(AuthContainerSelector.selectDomainMember),
|
|
|
|
// exhaustMap((domainMember: DomainMember) =>
|
|
|
|
// this.noAuthProbeService.readAllByDomainID(domainMember.domain.id)
|
|
|
|
// .pipe(
|
|
|
|
// map((noauthProbes: NoAuthProbe[]) => {
|
|
|
|
// this.pending$ = of(false);
|
|
|
|
|
|
|
|
// if (null === noauthProbes) {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
// noauthProbes.forEach(noauthProbe => {
|
|
|
|
// noauthProbe.descriptions = JSON.parse(noauthProbe.description);
|
|
|
|
// });
|
|
|
|
// return noauthProbes;
|
|
|
|
// }),
|
|
|
|
// catchError(error => {
|
|
|
|
// this.pending$ = of(false);
|
|
|
|
// this.error$ = of(error);
|
|
|
|
// return of(null);
|
|
|
|
// })
|
|
|
|
// )
|
|
|
|
// )
|
|
|
|
// );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:38:44 +00:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.connectingSubscription$.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-24 05:47:03 +00:00
|
|
|
onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) {
|
2018-04-11 08:41:38 +00:00
|
|
|
const title = isAccept ?
|
|
|
|
'Are you sure to accept this Probe?' : 'Are you sure to deny this Probe';
|
|
|
|
const message = isAccept ?
|
|
|
|
'Start collecting data as a Probe.' : 'It will be permanently deleted.';
|
|
|
|
|
|
|
|
this.confirmationService.confirm({
|
|
|
|
header: title,
|
|
|
|
message: message,
|
|
|
|
icon: isAccept ? 'fa-check' : 'fa fa-trash',
|
|
|
|
accept: () => {
|
2018-05-31 06:48:49 +00:00
|
|
|
if (isAccept) {
|
|
|
|
this.noAuthProbeService.acceptNoAuthProbe(selected.id)
|
|
|
|
.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
map((noauthProbes: NoAuthProbe[]) => {
|
2018-05-31 08:37:38 +00:00
|
|
|
this.setNoauthProbes(noauthProbes);
|
2018-05-31 06:48:49 +00:00
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.setError$(error);
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
|
|
|
).take(1).subscribe();
|
|
|
|
} else {
|
|
|
|
this.noAuthProbeService.denyNoauthProbe(selected.id)
|
|
|
|
.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
map((noauthProbes: NoAuthProbe[]) => {
|
2018-05-31 08:37:38 +00:00
|
|
|
this.setNoauthProbes(noauthProbes);
|
2018-05-31 06:48:49 +00:00
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
this.setError$(error);
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
|
|
|
).take(1).subscribe();
|
|
|
|
}
|
2018-04-11 08:41:38 +00:00
|
|
|
},
|
|
|
|
reject: () => {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-05-31 06:48:49 +00:00
|
|
|
|
2018-05-31 08:37:38 +00:00
|
|
|
private setNoauthProbes(noauthProbes: NoAuthProbe[]): void {
|
2018-05-31 06:48:49 +00:00
|
|
|
if (null === noauthProbes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
noauthProbes.forEach(noauthProbe => {
|
|
|
|
noauthProbe.descriptions = JSON.parse(noauthProbe.description);
|
|
|
|
});
|
2018-05-31 07:38:44 +00:00
|
|
|
this.noauthProbes = noauthProbes;
|
2018-05-31 06:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private setError$(error: any): void {
|
|
|
|
this.error$ = of(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-11 06:20:23 +00:00
|
|
|
}
|