import React from 'react';
import PropTypes from 'prop-types';
import Pagination from 'react-bootstrap/lib/Pagination';
export default class RecentCreated extends React.Component {
constructor(props) {
super(props);
this.state = {
RecentCreatedData : '',
pages : [] ,
limit : 10, // TODO GC-941で対応予定
active : 1,
totalPage: 0,
};
this.getRecentCreatedList = this.getRecentCreatedList.bind(this);
}
componentWillMount() {
this.getRecentCreatedList(1);
console.log(this.state);
}
getRecentCreatedList(selectPageNumber) {
const pageId = this.props.pageId;
const userId = this.props.crowi.me;
const limit = this.state.limit;
const offset = (selectPageNumber - 1) * limit;
this.props.crowi.apiGet('/pages.recentCreated', {page_id: pageId , user: userId , limit: limit , offset: offset , })
.then(res => {
console.log("res.pages=", res.pages);
const totalCount = res.pages[0].totalCount;
const totalPage = totalCount % limit == 0 ? totalCount / limit : Math.floor(totalCount / limit) + 1;
const pages = res.pages[1];
let inUse = {};
const active = selectPageNumber;
this.setState({
pages: pages,
inUse: inUse,
active: active,
totalPage: totalPage,
});
});
}
render() {
let totalPage = this.state.totalPage;
let active = this.state.active;
let items = [];
let paginationStart = active;
console.log(this.state);
if (1 === active) {
items.push(
);
items.push(
);
}
else {
items.push(
this.getRecentCreatedList(1)} />
);
items.push(
this.getRecentCreatedList(this.state.active - 1)} />
);
}
if (0 < (active - 2) && active < (totalPage - 2 )) {
paginationStart = active - 2;
}else if( active < 3){
paginationStart = 1;
}else if( active >= (totalPage -2) ){
paginationStart = (totalPage > 5)? totalPage -4 : totalPage = 4 ? totalPage - 3 : totalPage -2 ;
}
let MaxViewNum = (paginationStart ) + 4;
if(totalPage < paginationStart + 4){
MaxViewNum = totalPage;
}
for (let number = paginationStart; number <= MaxViewNum; number++) { // TODO GC-992で対応予定
items.push(
this.getRecentCreatedList(number)}>{number}
);
}
if (totalPage === active) {
items.push(
);
items.push(
);
}
else {
items.push(
this.getRecentCreatedList(this.state.active + 1)} />
);
items.push(
this.getRecentCreatedList(totalPage)} />
);
}
// TODO same key Warning
return (
);
}
}
RecentCreated.propTypes = {
pageId: PropTypes.string.isRequired,
};
RecentCreated.defaultProps = {
};