1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/piece_list.js

99 lines
3.5 KiB
JavaScript
Raw Normal View History

import React from 'react';
import AltContainer from 'alt/AltContainer';
import PieceListStore from '../stores/piece_list_store';
import PieceListActions from '../actions/piece_list_actions';
2015-05-20 15:22:29 +02:00
2015-05-21 15:14:05 +02:00
import Table from './ascribe_table/table';
import TableItem from './ascribe_table/table_item';
2015-05-21 15:14:05 +02:00
import TableItemImg from './ascribe_table/table_item_img';
import TableItemText from './ascribe_table/table_item_text';
import TableItemSubtable from './ascribe_table/table_item_subtable';
import TableItemSubtableButton from './ascribe_table/table_item_subtable_button';
import TableColumnContentModel from '../models/table_column_content_model';
2015-05-26 10:41:41 +02:00
import Pagination from './ascribe_pagination/pagination';
2015-05-20 16:44:45 +02:00
2015-05-19 17:16:01 +02:00
let PieceList = React.createClass({
2015-05-21 12:12:25 +02:00
getInitialState() {
return PieceListStore.getState();
},
componentDidMount() {
2015-05-26 13:14:35 +02:00
PieceListStore.listen(this.onChange);
let page = this.props.query.page || this.state.page;
PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
2015-05-26 11:47:56 +02:00
PieceListStore.listen(this.onChange);
},
2015-05-22 17:11:17 +02:00
componentWillUnmount() {
PieceListStore.unlisten(this.onChange);
},
2015-05-26 13:14:35 +02:00
onChange(state) {
this.setState(state);
2015-05-22 17:11:17 +02:00
},
2015-05-22 12:58:06 +02:00
paginationGoToPage(page) {
2015-05-22 17:11:17 +02:00
return (e) => PieceListActions.fetchPieceList(page, this.state.pageSize,
this.state.search, this.state.orderBy,
this.state.orderAsc);
},
tableChangeOrder(orderBy, orderAsc) {
2015-05-22 17:11:17 +02:00
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize,
this.state.search, orderBy, orderAsc);
2015-05-22 12:58:06 +02:00
},
render() {
let columnList = [
new TableColumnContentModel('thumbnail', '', TableItemImg, 2, false),
new TableColumnContentModel('artist_name', 'Artist', TableItemText, 4, true),
new TableColumnContentModel('title', 'Title', TableItemText, 4, true)
];
2015-05-20 19:19:57 +02:00
2015-05-22 17:11:17 +02:00
let currentPage = parseInt(this.props.query.page, 10);
let totalPages = Math.ceil(this.state.pieceListCount / this.state.pageSize)
2015-05-26 13:14:35 +02:00
if(this.state.pieceList && this.state.pieceList.length > 0) {
return (
<div>
<Table
columnList={columnList}
changeOrder={this.tableChangeOrder}
itemList={this.state.pieceList}
itemListCount={this.state.pieceListCount}
orderBy={this.state.orderBy}
orderAsc={this.state.orderAsc}
search={this.state.search}
page={this.state.page}
pageSize={this.state.pageSize}>
{this.state.pieceList.map((item, i) => {
return (
<TableItemSubtable
key={i}>
</TableItemSubtable>
);
})}
</Table>
<Pagination currentPage={currentPage}
totalPages={totalPages}
goToPage={this.paginationGoToPage}>
</Pagination>
</div>
);
} else {
return (
<p>Loading</p>
);
}
}
});
export default PieceList;