/*
* Routes Lookup Pagination
* ------------------------
*
* This code contains a lot of overlap with the pagination
* code in components/routeservers/routes/pagination.jsx
*
* Because time right now is at the essence, we will use
* this as a base and generalize the pagionation code later.
* (I'm so sorry :/)
*
* TODO: Refactor an generalize pagination links
*/
import React from 'react'
import {connect} from 'react-redux'
import {Link} from 'react-router'
import {push} from 'react-router-redux'
import {makeLinkProps} from './state'
const PageLink = function(props) {
const linkPage = parseInt(props.page, 10);
const label = props.label || (linkPage + 1);
if (props.disabled) {
return {label};
}
const linkTo = makeLinkProps(props);
return (
{label}
);
}
const PageSelect = (props) => {
const {pages, options} = props;
if (pages.length == 0) {
return null; // nothing to do here.
}
const items = pages.map((p) => (
));
const active = props.page >= pages[0];
let itemClassName = "";
if (active) {
itemClassName = "active";
}
return (
);
}
class RoutesPaginatorView extends React.Component {
/*
* Create an array of page "ids" we can use to map our
* pagination items.
* Split result into items for direct link access and
* select for a dropdown like access.
*/
makePaginationPages(numPages) {
const MAX_ITEMS = 12;
const pages = Array.from(Array(numPages), (_, i) => i);
return {
items: pages.slice(0, MAX_ITEMS),
select: pages.slice(MAX_ITEMS)
}
}
/*
* Dispatch navigation event and go to page
*/
navigateToPage(page) {
const linkProps = makeLinkProps(Object.assign({}, this.props, {
page: page
}));
this.props.dispatch(push(linkProps));
}
render() {
if (this.props.totalPages <= 1) {
return null; // Nothing to paginate
}
const pages = this.makePaginationPages(this.props.totalPages);
const pageLinks = pages.items.map((p) => {
let className = "";
if (p == this.props.page) {
className = "active";
}
return (