paging
This commit is contained in:
parent
4ca008ec39
commit
2024d2a7dd
|
@ -24,6 +24,6 @@
|
||||||
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="handleRowClick(row)"></mat-row>
|
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="handleRowClick(row)"></mat-row>
|
||||||
</mat-table>
|
</mat-table>
|
||||||
|
|
||||||
<mat-paginator [length]="length" [pageIndex]="0" [pageSize]="pageSize" [pageSizeOptions]="[5, 10, 25, 100]">
|
<mat-paginator #paginator [length]="totalLength" [pageIndex]="0" [pageSize]="PAGE_SIZE" (page)="handlePaging($event)">
|
||||||
</mat-paginator>
|
</mat-paginator>
|
||||||
</div>
|
</div>
|
|
@ -1,5 +1,5 @@
|
||||||
import { Component, OnInit, Input, ViewChild, AfterContentInit } from '@angular/core';
|
import { Component, OnInit, Input, ViewChild, AfterContentInit } from '@angular/core';
|
||||||
import { MatTableDataSource, MatSort } from '@angular/material';
|
import { MatTableDataSource, MatSort, PageEvent } from '@angular/material';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { Store, select } from '@ngrx/store';
|
import { Store, select } from '@ngrx/store';
|
||||||
import { RPCError } from 'packages/core/rpc/error';
|
import { RPCError } from 'packages/core/rpc/error';
|
||||||
|
@ -8,7 +8,7 @@ import * as NotificationStore from '../../store/notification';
|
||||||
import { ReadAllByMemberSelector } from '../../store';
|
import { ReadAllByMemberSelector } from '../../store';
|
||||||
import { AuthSelector } from 'packages/member/store';
|
import { AuthSelector } from 'packages/member/store';
|
||||||
import { Member } from '../../../member/model';
|
import { Member } from '../../../member/model';
|
||||||
import { PageParams } from 'app/commons/model';
|
import { PageParams, Page } from 'app/commons/model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'of-notification',
|
selector: 'of-notification',
|
||||||
|
@ -17,11 +17,12 @@ import { PageParams } from 'app/commons/model';
|
||||||
})
|
})
|
||||||
export class NotificationComponent implements OnInit, AfterContentInit {
|
export class NotificationComponent implements OnInit, AfterContentInit {
|
||||||
|
|
||||||
notification$ = this.store.pipe(select(ReadAllByMemberSelector.select('notifications')));
|
notification$ = this.store.pipe(select(ReadAllByMemberSelector.select('page')));
|
||||||
|
|
||||||
displayedColumns = ['id', 'title', 'message', 'member'];
|
displayedColumns = ['id', 'title', 'message', 'member'];
|
||||||
dataSource: MatTableDataSource<Notification>;
|
dataSource: MatTableDataSource<Notification>;
|
||||||
@ViewChild(MatSort) sort: MatSort;
|
PAGE_SIZE = '10';
|
||||||
|
totalLength = 0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
@ -30,9 +31,11 @@ export class NotificationComponent implements OnInit, AfterContentInit {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.notification$.subscribe(
|
this.notification$.subscribe(
|
||||||
(notifications: Notification[]) => {
|
(page: Page) => {
|
||||||
this.dataSource = new MatTableDataSource(notifications);
|
if (page !== null) {
|
||||||
this.dataSource.sort = this.sort;
|
this.totalLength = page.totalElements;
|
||||||
|
this.dataSource = new MatTableDataSource(page.content);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
(error: RPCError) => {
|
(error: RPCError) => {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
|
@ -41,23 +44,31 @@ export class NotificationComponent implements OnInit, AfterContentInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterContentInit() {
|
ngAfterContentInit() {
|
||||||
// this.store.select(AuthSelector.select('member')).subscribe(
|
this.getNotifications(0);
|
||||||
// (member: Member) => {
|
}
|
||||||
// const pageParams: PageParams = {
|
|
||||||
// pageNo: '1',
|
|
||||||
// countPerPage: '10',
|
|
||||||
// };
|
|
||||||
// this.store.dispatch(new NotificationStore.ReadAllByMember({member, pageParams}));
|
|
||||||
// },
|
|
||||||
// (error) => {
|
|
||||||
// console.log(error);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
getNotifications(pageIndex: number) {
|
||||||
|
this.store.select(AuthSelector.select('member')).subscribe(
|
||||||
|
(member: Member) => {
|
||||||
|
const pageParams: PageParams = {
|
||||||
|
pageNo: pageIndex + '',
|
||||||
|
countPerPage: this.PAGE_SIZE,
|
||||||
|
sortCol: 'id',
|
||||||
|
sortDirection: 'descending'
|
||||||
|
};
|
||||||
|
this.store.dispatch(new NotificationStore.ReadAllByMember({ member, pageParams }));
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRowClick(n: Notification) {
|
handleRowClick(n: Notification) {
|
||||||
this.router.navigate([n.url]);
|
this.router.navigate([n.url]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePaging(e: PageEvent) {
|
||||||
|
this.getNotifications(e.pageIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,8 @@ import { Action } from '@ngrx/store';
|
||||||
|
|
||||||
import { RPCError } from 'packages/core/rpc/error';
|
import { RPCError } from 'packages/core/rpc/error';
|
||||||
|
|
||||||
import { Notification } from '../../model';
|
|
||||||
import { Member } from '../../../member/model';
|
import { Member } from '../../../member/model';
|
||||||
import { PageParams } from 'app/commons/model';
|
import { PageParams, Page } from 'app/commons/model';
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
ReadAllByMember = '[Notification.notification] ReadAllByMember',
|
ReadAllByMember = '[Notification.notification] ReadAllByMember',
|
||||||
|
@ -21,7 +20,7 @@ export class ReadAllByMember implements Action {
|
||||||
export class ReadAllByMemberSuccess implements Action {
|
export class ReadAllByMemberSuccess implements Action {
|
||||||
readonly type = ActionType.ReadAllByMemberSuccess;
|
readonly type = ActionType.ReadAllByMemberSuccess;
|
||||||
|
|
||||||
constructor(public payload: Notification[]) {}
|
constructor(public payload: any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReadAllByMemberFailure implements Action {
|
export class ReadAllByMemberFailure implements Action {
|
||||||
|
|
|
@ -47,8 +47,8 @@ export class Effects {
|
||||||
.ofType(ActionType.ReadAllByMember)
|
.ofType(ActionType.ReadAllByMember)
|
||||||
.map((action: ReadAllByMember) => action.payload)
|
.map((action: ReadAllByMember) => action.payload)
|
||||||
.switchMap(payload => this.notificationService.readAllByMember(payload.member, payload.pageParams))
|
.switchMap(payload => this.notificationService.readAllByMember(payload.member, payload.pageParams))
|
||||||
.map(notifications => {
|
.map(page => {
|
||||||
return new ReadAllByMemberSuccess(notifications);
|
return new ReadAllByMemberSuccess(page);
|
||||||
})
|
})
|
||||||
.catch((error: RPCError) => {
|
.catch((error: RPCError) => {
|
||||||
return of(new ReadAllByMemberFailure(error));
|
return of(new ReadAllByMemberFailure(error));
|
||||||
|
|
|
@ -8,8 +8,6 @@ import {
|
||||||
initialState,
|
initialState,
|
||||||
} from './notification.state';
|
} from './notification.state';
|
||||||
|
|
||||||
import { Notification } from '../../model';
|
|
||||||
|
|
||||||
export function reducer(state = initialState, action: Actions): State {
|
export function reducer(state = initialState, action: Actions): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionType.ReadAllByMember: {
|
case ActionType.ReadAllByMember: {
|
||||||
|
@ -25,7 +23,7 @@ import {
|
||||||
...state,
|
...state,
|
||||||
error: null,
|
error: null,
|
||||||
pending: false,
|
pending: false,
|
||||||
notifications: action.payload,
|
page: action.payload,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +32,7 @@ import {
|
||||||
...state,
|
...state,
|
||||||
error: action.payload,
|
error: action.payload,
|
||||||
pending: false,
|
pending: false,
|
||||||
notifications: null,
|
page: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
import { RPCError } from 'packages/core/rpc/error';
|
import { RPCError } from 'packages/core/rpc/error';
|
||||||
|
|
||||||
import { Notification } from '../../model';
|
import { Notification } from '../../model';
|
||||||
|
import { Page } from 'app/commons/model';
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
error: RPCError | null;
|
error: RPCError | null;
|
||||||
pending: boolean;
|
pending: boolean;
|
||||||
notifications: Notification[] | null;
|
page: Page;
|
||||||
|
// notifications: Notification[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: State = {
|
export const initialState: State = {
|
||||||
error: null,
|
error: null,
|
||||||
pending: false,
|
pending: false,
|
||||||
notifications: null,
|
page: null,
|
||||||
|
// notifications: null,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user