This commit is contained in:
crusader 2018-05-28 17:58:10 +09:00
parent 93647f176a
commit 7f10b3dd8a
10 changed files with 88 additions and 107 deletions

View File

@ -10,6 +10,9 @@ import { MessageService } from 'primeng/components/common/messageservice';
}) })
export class NoAuthProbeListComponent { export class NoAuthProbeListComponent {
@Input() noauthProbes: NoAuthProbe[]; @Input() noauthProbes: NoAuthProbe[];
@Input() pending: boolean;
@Input() error: any;
@Output() accept = new EventEmitter<NoAuthProbe>(); @Output() accept = new EventEmitter<NoAuthProbe>();
@Output() deny = new EventEmitter<NoAuthProbe>(); @Output() deny = new EventEmitter<NoAuthProbe>();
msgs: Message[]; msgs: Message[];

View File

@ -1 +1,7 @@
<of-noauth-probe-list [noauthProbes]="noauthProbes$ | async" (accept)="accept($event)" (deny)="deny($event)"></of-noauth-probe-list> <of-noauth-probe-list
[noauthProbes]="noauthProbes$ | async"
[pending]="pending$ | async"
[error]="error$ | async"
(accept)="accept($event)"
(deny)="deny($event)">
</of-noauth-probe-list>

View File

@ -3,13 +3,14 @@ import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import { AuthSelector } from '@overflow/member/store'; import { AuthContainerSelector } from '@overflow/shared/auth/store';
import { Domain } from '@overflow/commons-typescript/model/domain'; import { Domain, DomainMember } from '@overflow/commons-typescript/model/domain';
import * as ListStore from '../store/entity/noauth-probe'; import * as NoAuthProbeEntityStore from '../store/entity/noauth-probe';
import { NoAuthProbeEntitySelector } from '../store'; import { NoAuthProbeListContainerSelector } from '../store';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth'; import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { ConfirmationService } from 'primeng/primeng'; import { ConfirmationService } from 'primeng/primeng';
import { MessageService } from 'primeng/components/common/messageservice'; import { MessageService } from 'primeng/components/common/messageservice';
import { RPCClientError } from '@loafer/ng-rpc';
@Component({ @Component({
selector: 'of-noauth-probe-list-container', selector: 'of-noauth-probe-list-container',
@ -18,11 +19,18 @@ import { MessageService } from 'primeng/components/common/messageservice';
}) })
export class NoAuthProbeListContainerComponent implements OnInit { export class NoAuthProbeListContainerComponent implements OnInit {
noauthProbes$: Observable<NoAuthProbe[]>; noauthProbes$: Observable<NoAuthProbe[]>;
pending$: Observable<boolean>;
error$: Observable<RPCClientError>;
constructor( constructor(
private store: Store<ListStore.State>, private store: Store<any>,
) { ) {
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) { if (null === _noauthProbes) {
return null; return null;
} }
@ -31,21 +39,19 @@ export class NoAuthProbeListContainerComponent implements OnInit {
}); });
return _noauthProbes; return _noauthProbes;
}); });
}
ngOnInit() { this.store.select(AuthContainerSelector.selectDomainMember).subscribe(
this.store.select(AuthSelector.select('domain')).subscribe( (domainMember: DomainMember) => {
(domain: Domain) => { this.store.dispatch(new NoAuthProbeEntityStore.ReadAllByDomainID(domainMember.domain.id));
this.store.dispatch(new ListStore.ReadAllByDomainID(domain.id));
} }
); );
} }
accept(selected) { accept(selected) {
this.store.dispatch(new ListStore.Accept(selected)); this.store.dispatch(new NoAuthProbeEntityStore.Accept(selected));
} }
deny(selected) { deny(selected) {
this.store.dispatch(new ListStore.Deny(selected)); this.store.dispatch(new NoAuthProbeEntityStore.Deny(selected));
} }
} }

View File

@ -0,0 +1,2 @@
export * from './noauth-probe-list.reducer';
export * from './noauth-probe-list.state';

View File

@ -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;
}
}
}

View File

@ -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<NoAuthProbe, RPCClientError>();
export interface State extends EntityState<NoAuthProbe, RPCClientError> {
pending: boolean;
}
export const initialState: State = noAuthProbeListContainerAdapter.getInitialState({
pending: false,
});
export function getSelectors(selector: Selector<any, State>) {
return {
...noAuthProbeListContainerAdapter.getSelectors(selector),
selectPending: createSelector(selector, (state: State) => state.pending),
};
}

View File

@ -1,4 +1,2 @@
export * from './noauth-probe.action'; export * from './noauth-probe.action';
export * from './noauth-probe.effect'; export * from './noauth-probe.effect';
export * from './noauth-probe.reducer';
export * from './noauth-probe.state';

View File

@ -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;
}
}
}

View File

@ -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<NoAuthProbe, RPCClientError>();
export interface State extends EntityState<NoAuthProbe, RPCClientError> {
}
export const initialState: State = noAuthProbeAdapter.getInitialState();
export function getSelectors<S>(selector: Selector<any, State>) {
return noAuthProbeAdapter.getSelectors(selector);
}

View File

@ -7,12 +7,14 @@ import { MODULE } from '../noauth-probe.constant';
import * as NoAuthProbeEntityStore from './entity/noauth-probe'; import * as NoAuthProbeEntityStore from './entity/noauth-probe';
import * as NoAuthProbeListContainerStore from './container/noauth-probe-list';
export interface State { export interface State {
noAuthProbe: NoAuthProbeEntityStore.State; noauth_probe_list: NoAuthProbeListContainerStore.State;
} }
export const REDUCERS = { export const REDUCERS = {
noAuthProbe: NoAuthProbeEntityStore.reducer, noauth_probe_list: NoAuthProbeListContainerStore.reducer,
}; };
export const EFFECTS = [ export const EFFECTS = [
@ -21,7 +23,7 @@ export const EFFECTS = [
export const selectState = createFeatureSelector<State>(MODULE.name); export const selectState = createFeatureSelector<State>(MODULE.name);
export const NoAuthProbeEntitySelector = NoAuthProbeEntityStore.getSelectors(createSelector( export const NoAuthProbeListContainerSelector = NoAuthProbeListContainerStore.getSelectors(createSelector(
selectState, selectState,
(state: State) => state.noAuthProbe (state: State) => state.noauth_probe_list
)); ));