member_webapp/@overflow/noauth-probe/container/noauth-probe-list-container.component.ts
crusader e854e6751e ing
2018-05-28 22:19:31 +09:00

58 lines
2.1 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
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';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { ConfirmationService } from 'primeng/primeng';
import { MessageService } from 'primeng/components/common/messageservice';
import { RPCClientError } from '@loafer/ng-rpc';
@Component({
selector: 'of-noauth-probe-list-container',
templateUrl: './noauth-probe-list-container.component.html',
providers: [ConfirmationService, MessageService]
})
export class NoAuthProbeListContainerComponent implements OnInit {
noauthProbes$: Observable<NoAuthProbe[]>;
pending$: Observable<boolean>;
error$: Observable<any>;
constructor(
private store: Store<any>,
) {
}
ngOnInit() {
this.pending$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectPending));
this.error$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectError));
this.noauthProbes$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectAll)).map((_noauthProbes: NoAuthProbe[]) => {
if (null === _noauthProbes) {
return null;
}
_noauthProbes.forEach(_noauthProbe => {
_noauthProbe.descriptions = JSON.parse(_noauthProbe.description);
});
return _noauthProbes;
});
this.store.select(AuthContainerSelector.selectDomainMember).subscribe(
(domainMember: DomainMember) => {
this.store.dispatch(new NoAuthProbeEntityStore.ReadAllByDomainID(domainMember.domain.id));
}
);
}
accept(noAuthProbe: NoAuthProbe) {
this.store.dispatch(new NoAuthProbeEntityStore.Accept(noAuthProbe.id));
}
deny(noAuthProbe: NoAuthProbe) {
this.store.dispatch(new NoAuthProbeEntityStore.Deny(noAuthProbe.id));
}
}