mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Implement more pagination functionality
This commit is contained in:
parent
d77cc20da6
commit
654d9b93c3
@ -20,7 +20,8 @@ class PieceListActions {
|
|||||||
search,
|
search,
|
||||||
orderBy,
|
orderBy,
|
||||||
orderAsc,
|
orderAsc,
|
||||||
'pieceList': res.pieces
|
'pieceList': res.pieces,
|
||||||
|
'pieceListCount': res.count
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -4,23 +4,29 @@ import PaginationButton from './pagination_button';
|
|||||||
|
|
||||||
let Pagination = React.createClass({
|
let Pagination = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
goToPage: React.PropTypes.func.isRequired
|
goToPage: React.PropTypes.func.isRequired,
|
||||||
|
currentPage: React.PropTypes.oneOfType([
|
||||||
|
React.PropTypes.string,
|
||||||
|
React.PropTypes.number
|
||||||
|
]).isRequired
|
||||||
|
//itemListCount: React.PropTypes.number.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let prev = parseInt(this.props.page, 10) - 1;
|
let currentPage = parseInt(this.props.currentPage, 10);
|
||||||
let next = parseInt(this.props.page, 10) + 1;
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<nav>
|
<nav>
|
||||||
<ul className="pager">
|
<ul className="pager">
|
||||||
<PaginationButton
|
<PaginationButton
|
||||||
direction='previous'
|
direction='previous'
|
||||||
goToPage={this.props.goToPage}>
|
goToPage={this.props.goToPage}
|
||||||
|
currentPage={currentPage}>
|
||||||
</PaginationButton>
|
</PaginationButton>
|
||||||
<PaginationButton
|
<PaginationButton
|
||||||
direction='next'
|
direction='next'
|
||||||
goToPage={this.props.goToPage}>
|
goToPage={this.props.goToPage}
|
||||||
|
currentPage={currentPage}>
|
||||||
</PaginationButton>
|
</PaginationButton>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -6,13 +6,16 @@ let Link = Router.Link;
|
|||||||
let PaginationButton = React.createClass({
|
let PaginationButton = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
direction: React.PropTypes.oneOf(['previous', 'next']),
|
direction: React.PropTypes.oneOf(['previous', 'next']),
|
||||||
goToPage: React.PropTypes.func.isRequired
|
goToPage: React.PropTypes.func.isRequired,
|
||||||
|
currentPage: React.PropTypes.number.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let page = parseInt(this.props.page, 10);
|
let page = parseInt(this.props.currentPage, 10);
|
||||||
let directionDisplay;
|
let directionDisplay;
|
||||||
|
|
||||||
|
let isDisabled = '';
|
||||||
|
|
||||||
if(this.props.direction === 'previous') {
|
if(this.props.direction === 'previous') {
|
||||||
page -= 1;
|
page -= 1;
|
||||||
directionDisplay = (
|
directionDisplay = (
|
||||||
@ -29,8 +32,12 @@ let PaginationButton = React.createClass({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(page === 0) {
|
||||||
|
isDisabled += ' disabled';
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className={this.props.direction}>
|
<li className={this.props.direction + isDisabled }>
|
||||||
<Link to="pieces"
|
<Link to="pieces"
|
||||||
query={{page}}
|
query={{page}}
|
||||||
onClick={this.props.goToPage(page)}>
|
onClick={this.props.goToPage(page)}>
|
||||||
|
@ -15,7 +15,6 @@ import Pagination from './pagination'
|
|||||||
|
|
||||||
let PieceList = React.createClass({
|
let PieceList = React.createClass({
|
||||||
|
|
||||||
// FIXME: this might be useless
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return PieceListStore.getState();
|
return PieceListStore.getState();
|
||||||
},
|
},
|
||||||
@ -38,13 +37,15 @@ let PieceList = React.createClass({
|
|||||||
new TableColumnModel('title', 'Title', TableItemText, 4, true)
|
new TableColumnModel('title', 'Title', TableItemText, 4, true)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Could wrap this altContainer potentially once again.
|
||||||
return (
|
return (
|
||||||
<AltContainer
|
<AltContainer
|
||||||
store={PieceListStore}
|
store={PieceListStore}
|
||||||
actions={PieceListActions}
|
actions={PieceListActions}
|
||||||
transform={(props) => {
|
transform={(props) => {
|
||||||
return {
|
return {
|
||||||
'itemList': props.pieceList,
|
'itemList': props.pieceList,
|
||||||
|
'itemListCount': props.pieceListCount,
|
||||||
'fetchList': props.fetchPieceList,
|
'fetchList': props.fetchPieceList,
|
||||||
'orderBy': props.orderBy,
|
'orderBy': props.orderBy,
|
||||||
'orderAsc': props.orderAsc,
|
'orderAsc': props.orderAsc,
|
||||||
|
@ -4,7 +4,18 @@ import PieceListActions from '../actions/piece_list_actions';
|
|||||||
|
|
||||||
class PieceListStore {
|
class PieceListStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pieceList = []; // rename this to pieceList after figuring out AltContainer transform
|
/**
|
||||||
|
* The store manages the state that is introduced by fetching
|
||||||
|
* the resource with certain parameters.
|
||||||
|
*
|
||||||
|
* This means that pieceList for example only contains pageSize-many items.
|
||||||
|
* Of course this can be altered by page as well.
|
||||||
|
*
|
||||||
|
* This is also the reason why we store a pieceListCount, which is essentially
|
||||||
|
* the number of items the resource actually - without pagination - provides.
|
||||||
|
*/
|
||||||
|
this.pieceList = [];
|
||||||
|
this.pieceListCount = 0;
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.pageSize = 10;
|
this.pageSize = 10;
|
||||||
this.search = "";
|
this.search = "";
|
||||||
@ -13,13 +24,14 @@ class PieceListStore {
|
|||||||
this.bindActions(PieceListActions);
|
this.bindActions(PieceListActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc }) {
|
onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc, pieceListCount }) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
this.search = search;
|
this.search = search;
|
||||||
this.orderAsc = orderAsc;
|
this.orderAsc = orderAsc;
|
||||||
this.orderBy = orderBy;
|
this.orderBy = orderBy;
|
||||||
this.pieceList = pieceList;
|
this.pieceList = pieceList;
|
||||||
|
this.pieceListCount = pieceListCount;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user