|
@@ -29,13 +29,13 @@ export default class RecentCreated extends React.Component {
|
|
|
const limit = this.state.limit;
|
|
const limit = this.state.limit;
|
|
|
const offset = (selectPageNumber - 1) * limit;
|
|
const offset = (selectPageNumber - 1) * limit;
|
|
|
|
|
|
|
|
- // pagiNation
|
|
|
|
|
|
|
+ // pagesList get and pagination calculate
|
|
|
this.props.crowi.apiGet('/pages.recentCreated', {page_id: pageId, user: userId, limit: limit, offset: offset, })
|
|
this.props.crowi.apiGet('/pages.recentCreated', {page_id: pageId, user: userId, limit: limit, offset: offset, })
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
const totalCount = res.pages[0].totalCount;
|
|
const totalCount = res.pages[0].totalCount;
|
|
|
const activePage = selectPageNumber;
|
|
const activePage = selectPageNumber;
|
|
|
const pages = res.pages[1];
|
|
const pages = res.pages[1];
|
|
|
- // pageNation calculate function call
|
|
|
|
|
|
|
+ // pagiNation calculate function call
|
|
|
const PaginationNumbers = this.calculatePagination(limit, totalCount, activePage);
|
|
const PaginationNumbers = this.calculatePagination(limit, totalCount, activePage);
|
|
|
this.setState({
|
|
this.setState({
|
|
|
pages,
|
|
pages,
|
|
@@ -47,27 +47,24 @@ export default class RecentCreated extends React.Component {
|
|
|
calculatePagination(limit, totalCount, activePage) {
|
|
calculatePagination(limit, totalCount, activePage) {
|
|
|
let PaginationNumbers = {};
|
|
let PaginationNumbers = {};
|
|
|
// pagiNation totalPageNumber calculate
|
|
// pagiNation totalPageNumber calculate
|
|
|
- let totalPage = totalCount % limit === 0 ? totalCount / limit : Math.floor(totalCount / limit) + 1;
|
|
|
|
|
- let paginationStart;
|
|
|
|
|
|
|
+ let totalPage = Math.floor(totalCount / limit) + (totalCount % limit === 0 ? 0 : 1);
|
|
|
|
|
+ let paginationStart = activePage - 2;
|
|
|
|
|
+ let maxViewPageNum = activePage + 2;
|
|
|
// pagiNation Number area size = 5 , pageNuber calculate in here
|
|
// pagiNation Number area size = 5 , pageNuber calculate in here
|
|
|
// activePage Position calculate ex. 4 5 [6] 7 8 (Page8 over is Max), 3 4 5 [6] 7 (Page7 is Max)
|
|
// activePage Position calculate ex. 4 5 [6] 7 8 (Page8 over is Max), 3 4 5 [6] 7 (Page7 is Max)
|
|
|
- if ( activePage < 4) {
|
|
|
|
|
- paginationStart = 1;
|
|
|
|
|
|
|
+ if ( paginationStart < 1 ) {
|
|
|
|
|
+ const diff = 1 - paginationStart;
|
|
|
|
|
+ paginationStart += diff;
|
|
|
|
|
+ maxViewPageNum = Math.min(totalPage, maxViewPageNum + diff);
|
|
|
}
|
|
}
|
|
|
- else if ( activePage <= (totalPage - 2 )) {
|
|
|
|
|
- paginationStart = activePage- 2;
|
|
|
|
|
- }
|
|
|
|
|
- else if ( activePage >= (totalPage -2) ) {
|
|
|
|
|
- paginationStart = (totalPage > 5)? totalPage -4 : 1;
|
|
|
|
|
- }
|
|
|
|
|
- // MaxViewPageNum calculate ex. 4 5 6 7 8 , 1 2 3 4
|
|
|
|
|
- let MaxViewPageNum = (paginationStart ) + 4;
|
|
|
|
|
- if (totalPage < paginationStart + 4) {
|
|
|
|
|
- MaxViewPageNum = totalPage;
|
|
|
|
|
|
|
+ if ( maxViewPageNum > totalPage ) {
|
|
|
|
|
+ const diff = maxViewPageNum - totalPage;
|
|
|
|
|
+ maxViewPageNum -= diff;
|
|
|
|
|
+ paginationStart = Math.max(1, paginationStart - diff);
|
|
|
}
|
|
}
|
|
|
PaginationNumbers.totalPage = totalPage;
|
|
PaginationNumbers.totalPage = totalPage;
|
|
|
PaginationNumbers.paginationStart = paginationStart;
|
|
PaginationNumbers.paginationStart = paginationStart;
|
|
|
- PaginationNumbers.MaxViewPageNum = MaxViewPageNum;
|
|
|
|
|
|
|
+ PaginationNumbers.maxViewPageNum = maxViewPageNum;
|
|
|
|
|
|
|
|
return PaginationNumbers;
|
|
return PaginationNumbers;
|
|
|
}
|
|
}
|
|
@@ -121,9 +118,9 @@ export default class RecentCreated extends React.Component {
|
|
|
* ex. << < 4 5 6 7 8 > >>, << < 1 2 3 4 > >>
|
|
* ex. << < 4 5 6 7 8 > >>, << < 1 2 3 4 > >>
|
|
|
* this function set numbers
|
|
* this function set numbers
|
|
|
*/
|
|
*/
|
|
|
- generatePaginations(activePage, paginationStart, MaxViewPageNum) {
|
|
|
|
|
|
|
+ generatePaginations(activePage, paginationStart, maxViewPageNum) {
|
|
|
let paginationItems = [];
|
|
let paginationItems = [];
|
|
|
- for (let number = paginationStart; number <= MaxViewPageNum; number++) {
|
|
|
|
|
|
|
+ for (let number = paginationStart; number <= maxViewPageNum; number++) {
|
|
|
paginationItems.push(
|
|
paginationItems.push(
|
|
|
<Pagination.Item key={number} active={number === activePage} onClick={ () => this.getRecentCreatedList(number)}>{number}</Pagination.Item>
|
|
<Pagination.Item key={number} active={number === activePage} onClick={ () => this.getRecentCreatedList(number)}>{number}</Pagination.Item>
|
|
|
);
|
|
);
|
|
@@ -168,10 +165,10 @@ export default class RecentCreated extends React.Component {
|
|
|
let activePage = this.state.activePage;
|
|
let activePage = this.state.activePage;
|
|
|
let totalPage = this.state.PaginationNumbers.totalPage;
|
|
let totalPage = this.state.PaginationNumbers.totalPage;
|
|
|
let paginationStart = this.state.PaginationNumbers.paginationStart;
|
|
let paginationStart = this.state.PaginationNumbers.paginationStart;
|
|
|
- let MaxViewPageNum = this.state.PaginationNumbers.MaxViewPageNum;
|
|
|
|
|
|
|
+ let maxViewPageNum = this.state.PaginationNumbers.maxViewPageNum;
|
|
|
let firstPrevItems = this.generateFirstPrev(activePage);
|
|
let firstPrevItems = this.generateFirstPrev(activePage);
|
|
|
paginationItems.push(firstPrevItems);
|
|
paginationItems.push(firstPrevItems);
|
|
|
- let paginations = this.generatePaginations(activePage, paginationStart, MaxViewPageNum);
|
|
|
|
|
|
|
+ let paginations = this.generatePaginations(activePage, paginationStart, maxViewPageNum);
|
|
|
paginationItems.push(paginations);
|
|
paginationItems.push(paginations);
|
|
|
let nextLastItems = this.generateNextLast(activePage, totalPage);
|
|
let nextLastItems = this.generateNextLast(activePage, totalPage);
|
|
|
paginationItems.push(nextLastItems);
|
|
paginationItems.push(nextLastItems);
|