2018-06-14 05:35:59 +00:00
|
|
|
import { Component, OnInit, OnDestroy, Output, EventEmitter } 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-06-04 08:55:47 +00:00
|
|
|
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
|
2018-04-24 05:31:20 +00:00
|
|
|
|
2018-05-31 06:48:49 +00:00
|
|
|
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
|
2018-06-01 09:45:28 +00:00
|
|
|
import { AuthSelector } from '@overflow/shared/auth/store';
|
2018-05-31 06:48:49 +00:00
|
|
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
|
|
|
|
|
|
|
import { NoAuthProbeService } from '../service/noauth-probe.service';
|
2018-05-31 13:11:23 +00:00
|
|
|
import { NoAuthProbeSubscriber, NoAuthProbeNotify } from '../subscriber/noauth-probe.subscriber';
|
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-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[];
|
2018-06-01 09:56:00 +00:00
|
|
|
noauthProbeSubscription: Subscription;
|
2018-05-31 07:38:44 +00:00
|
|
|
|
2018-06-14 05:35:59 +00:00
|
|
|
@Output() select = new EventEmitter<NoAuthProbe>();
|
2018-06-14 04:12:20 +00:00
|
|
|
|
2018-04-11 06:20:23 +00:00
|
|
|
constructor(
|
2018-05-31 06:48:49 +00:00
|
|
|
private store: Store<any>,
|
|
|
|
private noAuthProbeService: NoAuthProbeService,
|
2018-05-31 13:11:23 +00:00
|
|
|
private noAuthProbeSubscriber: NoAuthProbeSubscriber,
|
2018-04-11 06:20:23 +00:00
|
|
|
) {
|
2018-05-31 08:27:00 +00:00
|
|
|
this.noauthProbes = [];
|
2018-06-04 10:03:59 +00:00
|
|
|
this.noauthProbeSubscription = null;
|
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);
|
|
|
|
}),
|
2018-06-01 09:45:28 +00:00
|
|
|
select(AuthSelector.selectDomainMember),
|
2018-05-31 06:48:49 +00:00
|
|
|
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);
|
|
|
|
}),
|
2018-06-04 08:55:47 +00:00
|
|
|
take(1),
|
|
|
|
).subscribe();
|
2018-05-31 06:48:49 +00:00
|
|
|
|
2018-06-01 09:56:00 +00:00
|
|
|
this.noauthProbeSubscription = this.noAuthProbeSubscriber.observable().pipe(
|
2018-05-31 13:11:23 +00:00
|
|
|
tap((noAuthProbeNotify: NoAuthProbeNotify) => {
|
2018-05-31 07:38:44 +00:00
|
|
|
const noauthProbes = [];
|
|
|
|
this.noauthProbes.forEach(noauthProbe => {
|
2018-05-31 13:11:23 +00:00
|
|
|
const n = noAuthProbeNotify.params;
|
|
|
|
if (noauthProbe.id === n.id) {
|
|
|
|
noauthProbes.push(n);
|
2018-05-31 07:38:44 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2018-05-31 07:38:44 +00:00
|
|
|
ngOnDestroy(): void {
|
2018-06-04 10:03:59 +00:00
|
|
|
if (null !== this.noauthProbeSubscription) {
|
|
|
|
this.noauthProbeSubscription.unsubscribe();
|
|
|
|
}
|
2018-05-31 07:38:44 +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;
|
|
|
|
}
|
2018-06-14 03:28:29 +00:00
|
|
|
noauthProbes.forEach(noauthProbe => {
|
|
|
|
noauthProbe.infraHost = JSON.parse(noauthProbe.infraHostMeta);
|
|
|
|
});
|
2018-05-31 07:38:44 +00:00
|
|
|
this.noauthProbes = noauthProbes;
|
2018-06-14 07:42:04 +00:00
|
|
|
console.log(this.noauthProbes);
|
2018-05-31 06:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private setError$(error: any): void {
|
|
|
|
this.error$ = of(error);
|
|
|
|
}
|
|
|
|
|
2018-06-14 07:42:04 +00:00
|
|
|
getOS(noauthProbe: NoAuthProbe): string {
|
|
|
|
if (null == noauthProbe.infraHost.infraHostOS) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let os = noauthProbe.infraHost.infraHostOS.os;
|
2018-06-14 11:20:17 +00:00
|
|
|
|
2018-06-14 07:42:04 +00:00
|
|
|
os += noauthProbe.infraHost.infraHostOS.platform ?
|
2018-06-14 11:20:17 +00:00
|
|
|
' (' + noauthProbe.infraHost.infraHostOS.platform + ') ' : '';
|
2018-06-14 07:42:04 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-04-11 06:20:23 +00:00
|
|
|
}
|