member_webapp/@overflow/noauth-probe/container/noauth-probe-list-container.component.ts

68 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-05-28 13:40:44 +00:00
import { Component, OnInit, OnDestroy } from '@angular/core';
2018-05-18 08:49:13 +00:00
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
2018-05-28 08:58:10 +00:00
import { AuthContainerSelector } from '@overflow/shared/auth/store';
import { Domain, DomainMember } from '@overflow/commons-typescript/model/domain';
import * as NoAuthProbeEntityStore from '../store/entity/noauth-probe';
import { NoAuthProbeListContainerSelector } from '../store';
2018-05-18 08:49:13 +00:00
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { ConfirmationService } from 'primeng/primeng';
import { MessageService } from 'primeng/components/common/messageservice';
2018-05-28 08:58:10 +00:00
import { RPCClientError } from '@loafer/ng-rpc';
2018-05-28 13:40:44 +00:00
import { Subscription } from 'rxjs';
2018-05-18 08:49:13 +00:00
@Component({
2018-05-28 05:41:56 +00:00
selector: 'of-noauth-probe-list-container',
templateUrl: './noauth-probe-list-container.component.html',
2018-05-18 08:49:13 +00:00
providers: [ConfirmationService, MessageService]
})
2018-05-28 13:40:44 +00:00
export class NoAuthProbeListContainerComponent implements OnInit, OnDestroy {
2018-05-18 08:49:13 +00:00
noauthProbes$: Observable<NoAuthProbe[]>;
2018-05-28 08:58:10 +00:00
pending$: Observable<boolean>;
2018-05-28 13:40:44 +00:00
errorSubscription: Subscription;
2018-05-18 08:49:13 +00:00
constructor(
2018-05-28 08:58:10 +00:00
private store: Store<any>,
2018-05-28 13:40:44 +00:00
private messageService: MessageService,
2018-05-18 08:49:13 +00:00
) {
2018-05-28 08:58:10 +00:00
}
ngOnInit() {
this.pending$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectPending));
2018-05-28 13:40:44 +00:00
this.errorSubscription = this.store.pipe(select(NoAuthProbeListContainerSelector.selectError)).subscribe(
(e: any) => {
this.messageService.add({severity: 'error', summary: 'Service Message', detail: 'Via MessageService'});
}
);
2018-05-28 08:58:10 +00:00
this.noauthProbes$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectAll)).map((_noauthProbes: NoAuthProbe[]) => {
2018-05-18 08:49:13 +00:00
if (null === _noauthProbes) {
return null;
}
_noauthProbes.forEach(_noauthProbe => {
_noauthProbe.descriptions = JSON.parse(_noauthProbe.description);
});
return _noauthProbes;
});
2018-05-28 08:58:10 +00:00
this.store.select(AuthContainerSelector.selectDomainMember).subscribe(
(domainMember: DomainMember) => {
this.store.dispatch(new NoAuthProbeEntityStore.ReadAllByDomainID(domainMember.domain.id));
2018-05-18 08:49:13 +00:00
}
);
}
2018-05-28 13:40:44 +00:00
ngOnDestroy(): void {
this.errorSubscription.unsubscribe();
}
2018-05-28 13:19:31 +00:00
accept(noAuthProbe: NoAuthProbe) {
2018-05-28 13:40:44 +00:00
this.store.dispatch(new NoAuthProbeEntityStore.Accept({aa: noAuthProbe.id} as any));
2018-05-18 08:49:13 +00:00
}
2018-05-28 13:19:31 +00:00
deny(noAuthProbe: NoAuthProbe) {
this.store.dispatch(new NoAuthProbeEntityStore.Deny(noAuthProbe.id));
2018-05-18 08:49:13 +00:00
}
}