diff --git a/@overflow/noauth-probe/component/noauth-probe-list.component.ts b/@overflow/noauth-probe/component/noauth-probe-list.component.ts index f562b69..934ef4b 100644 --- a/@overflow/noauth-probe/component/noauth-probe-list.component.ts +++ b/@overflow/noauth-probe/component/noauth-probe-list.component.ts @@ -10,6 +10,9 @@ import { MessageService } from 'primeng/components/common/messageservice'; }) export class NoAuthProbeListComponent { @Input() noauthProbes: NoAuthProbe[]; + @Input() pending: boolean; + @Input() error: any; + @Output() accept = new EventEmitter(); @Output() deny = new EventEmitter(); msgs: Message[]; diff --git a/@overflow/noauth-probe/container/noauth-probe-list-container.component.html b/@overflow/noauth-probe/container/noauth-probe-list-container.component.html index e75d655..2cfccb0 100644 --- a/@overflow/noauth-probe/container/noauth-probe-list-container.component.html +++ b/@overflow/noauth-probe/container/noauth-probe-list-container.component.html @@ -1 +1,7 @@ - + + diff --git a/@overflow/noauth-probe/container/noauth-probe-list-container.component.ts b/@overflow/noauth-probe/container/noauth-probe-list-container.component.ts index caf163a..f0f8b10 100644 --- a/@overflow/noauth-probe/container/noauth-probe-list-container.component.ts +++ b/@overflow/noauth-probe/container/noauth-probe-list-container.component.ts @@ -3,13 +3,14 @@ import { Store, select } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; -import { AuthSelector } from '@overflow/member/store'; -import { Domain } from '@overflow/commons-typescript/model/domain'; -import * as ListStore from '../store/entity/noauth-probe'; -import { NoAuthProbeEntitySelector } from '../store'; +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', @@ -18,11 +19,18 @@ import { MessageService } from 'primeng/components/common/messageservice'; }) export class NoAuthProbeListContainerComponent implements OnInit { noauthProbes$: Observable; + pending$: Observable; + error$: Observable; constructor( - private store: Store, + private store: Store, ) { - this.noauthProbes$ = this.store.pipe(select(NoAuthProbeEntitySelector.selectAll)).map((_noauthProbes: NoAuthProbe[]) => { + } + + 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; } @@ -31,21 +39,19 @@ export class NoAuthProbeListContainerComponent implements OnInit { }); return _noauthProbes; }); - } - ngOnInit() { - this.store.select(AuthSelector.select('domain')).subscribe( - (domain: Domain) => { - this.store.dispatch(new ListStore.ReadAllByDomainID(domain.id)); + this.store.select(AuthContainerSelector.selectDomainMember).subscribe( + (domainMember: DomainMember) => { + this.store.dispatch(new NoAuthProbeEntityStore.ReadAllByDomainID(domainMember.domain.id)); } ); } accept(selected) { - this.store.dispatch(new ListStore.Accept(selected)); + this.store.dispatch(new NoAuthProbeEntityStore.Accept(selected)); } deny(selected) { - this.store.dispatch(new ListStore.Deny(selected)); + this.store.dispatch(new NoAuthProbeEntityStore.Deny(selected)); } } diff --git a/@overflow/noauth-probe/store/container/noauth-probe-list/index.ts b/@overflow/noauth-probe/store/container/noauth-probe-list/index.ts new file mode 100644 index 0000000..b185175 --- /dev/null +++ b/@overflow/noauth-probe/store/container/noauth-probe-list/index.ts @@ -0,0 +1,2 @@ +export * from './noauth-probe-list.reducer'; +export * from './noauth-probe-list.state'; diff --git a/@overflow/noauth-probe/store/container/noauth-probe-list/noauth-probe-list.reducer.ts b/@overflow/noauth-probe/store/container/noauth-probe-list/noauth-probe-list.reducer.ts new file mode 100644 index 0000000..bedd119 --- /dev/null +++ b/@overflow/noauth-probe/store/container/noauth-probe-list/noauth-probe-list.reducer.ts @@ -0,0 +1,31 @@ +import { ActionType, Actions } from '../../entity/noauth-probe'; +import { + State, + initialState, + noAuthProbeListContainerAdapter, +} from './noauth-probe-list.state'; + +import { Probe } from '@overflow/commons-typescript/model/probe'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.ReadAllByDomainID: { + return { + ...state, + pending: true, + }; + } + + case ActionType.ReadAllByDomainIDSuccess: { + return noAuthProbeListContainerAdapter.setAll(action.payload, {...state, pending: false}); + } + + case ActionType.ReadAllByDomainIDFailure: { + return noAuthProbeListContainerAdapter.setError(action.payload, {...state, pending: false}); + } + + default: { + return state; + } + } +} diff --git a/@overflow/noauth-probe/store/container/noauth-probe-list/noauth-probe-list.state.ts b/@overflow/noauth-probe/store/container/noauth-probe-list/noauth-probe-list.state.ts new file mode 100644 index 0000000..4f06304 --- /dev/null +++ b/@overflow/noauth-probe/store/container/noauth-probe-list/noauth-probe-list.state.ts @@ -0,0 +1,20 @@ +import { RPCClientError } from '@loafer/ng-rpc'; + +import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth'; +import { Selector, createSelector } from '@ngrx/store'; +import { createEntityAdapter, EntityState } from '@loafer/ng-entity'; + +export const noAuthProbeListContainerAdapter = createEntityAdapter(); +export interface State extends EntityState { + pending: boolean; +} +export const initialState: State = noAuthProbeListContainerAdapter.getInitialState({ + pending: false, +}); + +export function getSelectors(selector: Selector) { + return { + ...noAuthProbeListContainerAdapter.getSelectors(selector), + selectPending: createSelector(selector, (state: State) => state.pending), + }; +} diff --git a/@overflow/noauth-probe/store/entity/noauth-probe/index.ts b/@overflow/noauth-probe/store/entity/noauth-probe/index.ts index b2730b4..284851e 100644 --- a/@overflow/noauth-probe/store/entity/noauth-probe/index.ts +++ b/@overflow/noauth-probe/store/entity/noauth-probe/index.ts @@ -1,4 +1,2 @@ export * from './noauth-probe.action'; export * from './noauth-probe.effect'; -export * from './noauth-probe.reducer'; -export * from './noauth-probe.state'; diff --git a/@overflow/noauth-probe/store/entity/noauth-probe/noauth-probe.reducer.ts b/@overflow/noauth-probe/store/entity/noauth-probe/noauth-probe.reducer.ts deleted file mode 100644 index e79e74f..0000000 --- a/@overflow/noauth-probe/store/entity/noauth-probe/noauth-probe.reducer.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { - ActionType, - Actions, -} from './noauth-probe.action'; - -import { - State, - initialState, - noAuthProbeAdapter, -} from './noauth-probe.state'; - -export function reducer(state = initialState, action: Actions): State { - switch (action.type) { - case ActionType.ReadAllByDomainID: { - return { - ...state, - error: null, - }; - } - - case ActionType.ReadAllByDomainIDSuccess: { - return noAuthProbeAdapter.setAll(action.payload, state); - } - - case ActionType.ReadAllByDomainIDFailure: { - return noAuthProbeAdapter.setError(action.payload, state); - } - - case ActionType.Accept: { - return { - ...state, - error: null, - }; - } - - case ActionType.AcceptSuccess: { - return noAuthProbeAdapter.setAll(action.payload, state); - } - - case ActionType.AcceptFailure: { - return noAuthProbeAdapter.setError(action.payload, state); - } - - case ActionType.Deny: { - return { - ...state, - error: null, - }; - } - - case ActionType.DenySuccess: { - return noAuthProbeAdapter.setAll(action.payload, state); - } - - case ActionType.DenyFailure: { - return noAuthProbeAdapter.setError(action.payload, state); - } - case ActionType.OnConnect: { - - return { - ...state, - }; - } - case ActionType.OnDisconnect: { - return { - ...state, - }; - } - default: { - return state; - } - } -} diff --git a/@overflow/noauth-probe/store/entity/noauth-probe/noauth-probe.state.ts b/@overflow/noauth-probe/store/entity/noauth-probe/noauth-probe.state.ts deleted file mode 100644 index bae6a7b..0000000 --- a/@overflow/noauth-probe/store/entity/noauth-probe/noauth-probe.state.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { RPCClientError } from '@loafer/ng-rpc'; - -import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth'; -import { Selector } from '@ngrx/store'; -import { createEntityAdapter, EntityState } from '@loafer/ng-entity'; - -export const noAuthProbeAdapter = createEntityAdapter(); -export interface State extends EntityState { -} -export const initialState: State = noAuthProbeAdapter.getInitialState(); - -export function getSelectors(selector: Selector) { - return noAuthProbeAdapter.getSelectors(selector); -} diff --git a/@overflow/noauth-probe/store/index.ts b/@overflow/noauth-probe/store/index.ts index bb30bcd..4d59cef 100644 --- a/@overflow/noauth-probe/store/index.ts +++ b/@overflow/noauth-probe/store/index.ts @@ -7,12 +7,14 @@ import { MODULE } from '../noauth-probe.constant'; import * as NoAuthProbeEntityStore from './entity/noauth-probe'; +import * as NoAuthProbeListContainerStore from './container/noauth-probe-list'; + export interface State { - noAuthProbe: NoAuthProbeEntityStore.State; + noauth_probe_list: NoAuthProbeListContainerStore.State; } export const REDUCERS = { - noAuthProbe: NoAuthProbeEntityStore.reducer, + noauth_probe_list: NoAuthProbeListContainerStore.reducer, }; export const EFFECTS = [ @@ -21,7 +23,7 @@ export const EFFECTS = [ export const selectState = createFeatureSelector(MODULE.name); -export const NoAuthProbeEntitySelector = NoAuthProbeEntityStore.getSelectors(createSelector( +export const NoAuthProbeListContainerSelector = NoAuthProbeListContainerStore.getSelectors(createSelector( selectState, - (state: State) => state.noAuthProbe + (state: State) => state.noauth_probe_list ));