This commit is contained in:
insanity 2018-03-13 19:41:08 +09:00
parent 311dfee153
commit 61feaf3d6a
12 changed files with 115 additions and 37 deletions

View File

@ -35,8 +35,8 @@ export class RPCClientJSONCodec extends RPCClientCodec {
const _res: ClientResponse = {
id: res.id,
jsonrpc: res.jsonrpc,
result: undefined !== res.result ? JSON.parse(res.result) : undefined,
error: undefined !== res.error ? JSON.parse(res.error) : undefined,
result: res.result,
error: res.error,
};
return new RPCClientJSONResponseCodec(_res);
}

View File

@ -1 +1,29 @@
<div>list</div>
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="id">
<mat-header-cell *matHeaderCellDef mat-sort-header> Name </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.id}} </mat-cell>
</ng-container>
<ng-container matColumnDef="title">
<mat-header-cell *matHeaderCellDef mat-sort-header> Title </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.title}} </mat-cell>
</ng-container>
<ng-container matColumnDef="message">
<mat-header-cell *matHeaderCellDef mat-sort-header> Message </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.message}} </mat-cell>
</ng-container>
<ng-container matColumnDef="member">
<mat-header-cell *matHeaderCellDef mat-sort-header> Member </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.member.name}} </mat-cell>
</ng-container>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="handleRowClick(row)"></mat-row>
</mat-table>
<mat-paginator [length]="length" [pageIndex]="0" [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 25, 100]">
</mat-paginator>
</div>

View File

@ -1,18 +1,62 @@
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input, ViewChild, AfterContentInit } from '@angular/core';
import { MatTableDataSource, MatSort } from '@angular/material';
import { Router } from '@angular/router';
import { Store, select } from '@ngrx/store';
import { RPCError } from 'packages/core/rpc/error';
import { Notification } from '../../model';
import * as NotificationStore from '../../store/notification';
import { ReadAllByMemberSelector } from '../../store';
import { AuthSelector } from 'packages/member/store';
import { Member } from '../../../member/model';
@Component({
selector: 'of-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.scss']
})
export class NotificationComponent implements OnInit {
export class NotificationComponent implements OnInit, AfterContentInit {
notification$ = this.store.pipe(select(ReadAllByMemberSelector.select('notifications')));
displayedColumns = ['id', 'title', 'message', 'member' ];
dataSource: MatTableDataSource<Notification>;
@ViewChild(MatSort) sort: MatSort;
constructor(
private router: Router
private router: Router,
private store: Store<NotificationStore.State>
) { }
ngOnInit() {
this.notification$.subscribe(
(notifications: Notification[]) => {
console.log('#########');
console.log(notifications);
console.log('#########');
this.dataSource = new MatTableDataSource(notifications);
this.dataSource.sort = this.sort;
},
(error: RPCError) => {
console.log(error.message);
}
);
}
ngAfterContentInit() {
this.store.select(AuthSelector.select('member')).subscribe(
(member: Member) => {
console.log(member);
this.store.dispatch(new NotificationStore.ReadAllByMember(member));
},
(error) => {
console.log(error);
}
);
}
handleRowClick(n: Notification) {
this.router.navigate([n.url]);
}
}

View File

@ -18,9 +18,6 @@ export class NotificationService {
}
public readAllByMember(member: Member): Observable<Notification[]> {
const body = {
member: member,
};
return this.rpcClient.call('NotificationService.readAllByMember', member);
}

View File

@ -8,23 +8,23 @@ import {
import { MODULE } from '../notification.constant';
import * as ReadAllByMemberStore from './readallbymember';
import * as NotificationStore from './notification';
export interface State {
readallbymember: ReadAllByMemberStore.State;
notifications: NotificationStore.State;
}
export const REDUCERS = {
readallbymember: ReadAllByMemberStore.reducer,
notifications: NotificationStore.reducer,
};
export const EFFECTS = [
ReadAllByMemberStore.Effects,
NotificationStore.Effects,
];
export const selectNotificationState = createFeatureSelector<State>(MODULE.name);
export const ReadAllByMemberSelector = new StateSelector<ReadAllByMemberStore.State>(createSelector(
export const ReadAllByMemberSelector = new StateSelector<NotificationStore.State>(createSelector(
selectNotificationState,
(state: State) => state.readallbymember
(state: State) => state.notifications
));

View File

@ -0,0 +1,4 @@
export * from './notification.action';
export * from './notification.effect';
export * from './notification.reducer';
export * from './notification.state';

View File

@ -6,9 +6,9 @@ import { Notification } from '../../model';
import { Member } from '../../../member/model';
export enum ActionType {
ReadAllByMember = '[Notification.ReadAllByMember] ReadAllByMember',
ReadAllByMemberSuccess = '[Notification.ReadAllByMemberSuccess] ReadAllByMemberSuccess',
ReadAllByMemberFailure = '[Notification.ReadAllByMemberFailure] ReadAllByMemberFailure',
ReadAllByMember = '[Notification.notification] ReadAllByMember',
ReadAllByMemberSuccess = '[Notification.notification] ReadAllByMemberSuccess',
ReadAllByMemberFailure = '[Notification.notification] ReadAllByMemberFailure',
}
export class ReadAllByMember implements Action {

View File

@ -1,8 +1,8 @@
import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './readallbymember.effect';
import { Effects } from './notification.effect';
describe('ReadAllByMember.Effects', () => {
describe('Notification.Effects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [Effects]

View File

@ -23,7 +23,7 @@ import {
ReadAllByMemberSuccess,
ReadAllByMemberFailure,
ActionType,
} from './readallbymember.action';
} from './notification.action';
@Injectable()
export class Effects {
@ -36,13 +36,22 @@ export class Effects {
@Effect()
readAllByMember$: Observable<Action> = this.actions$
// .ofType(ActionType.ReadAllByMember)
// .map((action: ReadAllByMember) => action.payload)
// .exhaustMap(member =>
// this.notificationService
// .readAllByMember(member)
// .map(notificationList => new ReadAllByMemberSuccess(notificationList))
// .catch(error => of(new ReadAllByMemberFailure(error)))
// );
.ofType(ActionType.ReadAllByMember)
.map((action: ReadAllByMember) => action.payload)
.exhaustMap(member =>
this.notificationService
.readAllByMember(member)
.map(notificationList => new ReadAllByMemberSuccess(notificationList))
.catch(error => of(new ReadAllByMemberFailure(error)))
);
.switchMap(payload => this.notificationService.readAllByMember(payload))
.map(notifications => {
return new ReadAllByMemberSuccess(notifications);
})
.catch((error: RPCError) => {
return of(new ReadAllByMemberFailure(error));
});
}

View File

@ -1,12 +1,12 @@
import {
Actions,
ActionType,
} from './readallbymember.action';
} from './notification.action';
import {
State,
initialState,
} from './readallbymember.state';
} from './notification.state';
import { Notification } from '../../model';
@ -25,7 +25,7 @@ import {
...state,
error: null,
pending: false,
notificationList: action.payload,
notifications: action.payload,
};
}
@ -34,7 +34,7 @@ import {
...state,
error: action.payload,
pending: false,
notificationList: null,
notifications: null,
};
}

View File

@ -5,11 +5,11 @@ import { Notification } from '../../model';
export interface State {
error: RPCError | null;
pending: boolean;
notificationList: Notification[] | null;
notifications: Notification[] | null;
}
export const initialState: State = {
error: null,
pending: false,
notificationList: null,
notifications: null,
};

View File

@ -1,4 +0,0 @@
export * from './readallbymember.action';
export * from './readallbymember.effect';
export * from './readallbymember.reducer';
export * from './readallbymember.state';