From b2bf464700f565631f431ad7da48d2642e062c0e Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 23 Aug 2017 19:39:03 +0900 Subject: [PATCH] history paging --- src/ts/@overflow/commons/api/model/Page.ts | 13 ++++ .../history/react/components/HistoryList.tsx | 73 +++++++++++++------ 2 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 src/ts/@overflow/commons/api/model/Page.ts diff --git a/src/ts/@overflow/commons/api/model/Page.ts b/src/ts/@overflow/commons/api/model/Page.ts new file mode 100644 index 0000000..a62b459 --- /dev/null +++ b/src/ts/@overflow/commons/api/model/Page.ts @@ -0,0 +1,13 @@ +interface Page { + content: any; + first: boolean; + last: boolean; + number: number; + numberOfElements: number; + size: number; + sort: any; + totalElements: number; + totalPages: number; +} + +export default Page; diff --git a/src/ts/@overflow/history/react/components/HistoryList.tsx b/src/ts/@overflow/history/react/components/HistoryList.tsx index dbc5df5..710b6b7 100644 --- a/src/ts/@overflow/history/react/components/HistoryList.tsx +++ b/src/ts/@overflow/history/react/components/HistoryList.tsx @@ -21,6 +21,7 @@ export interface State { export class HistoryList extends React.Component { + private countPerPage: number = 10; constructor(props: Props, context: State) { super(props, context); @@ -33,11 +34,11 @@ export class HistoryList extends React.Component { let probe: Probe = { id: Number(1), }; - this.props.onReadAllByProbe(probe, String(this.state.page), '10'); + this.props.onReadAllByProbe(probe, String(this.state.page), String(this.countPerPage)); } public handlePaging = (pageNo: number) => { - if(pageNo === this.state.page) { + if (pageNo === this.state.page) { return; } this.setState({ @@ -46,7 +47,23 @@ export class HistoryList extends React.Component { let probe: Probe = { id: Number(1), }; - this.props.onReadAllByProbe(probe, String(pageNo), '10'); + this.props.onReadAllByProbe(probe, String(pageNo), String(this.countPerPage)); + } + + public handlePrevPage = (pn: string) => { + let p = 0; + if (pn === 'P') { + p = this.state.page - 1; + } else if (pn === 'N') { + p = this.state.page + 1; + } + this.setState({ + page: p, + }); + let probe: Probe = { + id: Number(1), + }; + this.props.onReadAllByProbe(probe, String(p), String(this.countPerPage)); } public renderPagination = (pageObj: any): (JSX.Element | JSX.Element[]) => { @@ -56,13 +73,26 @@ export class HistoryList extends React.Component { let totalPage = pageObj.totalPages; let currPage = pageObj.number; let elems = new Array; + let prevIndicator = pageObj.first ? + : + + + ; + elems.push(prevIndicator); for (let i = 0; i < totalPage; i++) { if (i === currPage) { - elems.push({i + 1}); + elems.push({i + 1}); } else { elems.push({i + 1}); } } + let nextIndicator = pageObj.last ? + : + + + ; + elems.push(nextIndicator); + return {elems} ; @@ -84,23 +114,24 @@ export class HistoryList extends React.Component { - {this.props.histories && this.props.histories.content ? this.props.histories.content.map((history: History, index: number) => ( - - {index + 1} - - {history.type.name} - - - {history.message} - - - {history.createDate} - - - {history.member.name} - - - )) : ''} + {this.props.histories && this.props.histories.content ? + this.props.histories.content.map((history: History, index: number) => ( + + {history.id} + + {history.type.name} + + + {history.message} + + + {history.createDate} + + + {history.member.name} + + + )) : ''}