mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
add ordering functionality to editionlist table
This commit is contained in:
parent
b4076aeef7
commit
ef6662e859
@ -11,13 +11,15 @@ class EditionListActions {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchEditionList(pieceId) {
|
fetchEditionList(pieceId, orderBy, orderAsc) {
|
||||||
EditionListFetcher
|
EditionListFetcher
|
||||||
.fetch(pieceId)
|
.fetch(pieceId, orderBy, orderAsc)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updateEditionList({
|
this.actions.updateEditionList({
|
||||||
'editionListOfPiece': res.editions,
|
'editionListOfPiece': res.editions,
|
||||||
pieceId
|
pieceId,
|
||||||
|
orderBy,
|
||||||
|
orderAsc
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -14,7 +14,10 @@ let AccordionListItemTable = React.createClass({
|
|||||||
itemList: React.PropTypes.array,
|
itemList: React.PropTypes.array,
|
||||||
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
||||||
numOfTableItems: React.PropTypes.number,
|
numOfTableItems: React.PropTypes.number,
|
||||||
show: React.PropTypes.bool
|
show: React.PropTypes.bool,
|
||||||
|
changeOrder: React.PropTypes.func,
|
||||||
|
orderBy: React.PropTypes.string,
|
||||||
|
orderAsc: React.PropTypes.bool
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -23,7 +26,10 @@ let AccordionListItemTable = React.createClass({
|
|||||||
<div className={this.props.className}>
|
<div className={this.props.className}>
|
||||||
<Table
|
<Table
|
||||||
columnList={this.props.columnList}
|
columnList={this.props.columnList}
|
||||||
itemList={this.props.itemList}>
|
itemList={this.props.itemList}
|
||||||
|
changeOrder={this.props.changeOrder}
|
||||||
|
orderBy={this.props.orderBy}
|
||||||
|
orderAsc={this.props.orderAsc}>
|
||||||
{this.props.itemList.map((item, i) => {
|
{this.props.itemList.map((item, i) => {
|
||||||
return (
|
return (
|
||||||
<TableItem
|
<TableItem
|
||||||
|
@ -48,7 +48,11 @@ let AccordionListItemTableEditions = React.createClass({
|
|||||||
|
|
||||||
toggleTable() {
|
toggleTable() {
|
||||||
PieceListActions.showEditionList(this.props.parentId);
|
PieceListActions.showEditionList(this.props.parentId);
|
||||||
EditionListActions.fetchEditionList(this.props.parentId);
|
EditionListActions.fetchEditionList(this.props.parentId, this.state.orderBy, this.state.orderAsc);
|
||||||
|
},
|
||||||
|
|
||||||
|
changeEditionListOrder(orderBy, orderAsc) {
|
||||||
|
EditionListActions.fetchEditionList(this.props.parentId, orderBy, orderAsc);
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -72,11 +76,11 @@ let AccordionListItemTableEditions = React.createClass({
|
|||||||
return {
|
return {
|
||||||
'content': item.edition_number
|
'content': item.edition_number
|
||||||
}},
|
}},
|
||||||
'num_editions',
|
'edition_number',
|
||||||
'#',
|
'#',
|
||||||
TableItemText,
|
TableItemText,
|
||||||
1,
|
1,
|
||||||
false
|
true
|
||||||
),
|
),
|
||||||
new TableColumnContentModel(
|
new TableColumnContentModel(
|
||||||
(item) => {
|
(item) => {
|
||||||
@ -87,7 +91,7 @@ let AccordionListItemTableEditions = React.createClass({
|
|||||||
getLangText('Bitcoin Address'),
|
getLangText('Bitcoin Address'),
|
||||||
TableItemText,
|
TableItemText,
|
||||||
5,
|
5,
|
||||||
false
|
true
|
||||||
),
|
),
|
||||||
new TableColumnContentModel(
|
new TableColumnContentModel(
|
||||||
(item) => {
|
(item) => {
|
||||||
@ -110,7 +114,10 @@ let AccordionListItemTableEditions = React.createClass({
|
|||||||
itemList={this.state.editionList[this.props.parentId]}
|
itemList={this.state.editionList[this.props.parentId]}
|
||||||
columnList={columnList}
|
columnList={columnList}
|
||||||
numOfTableItems={this.props.numOfEditions}
|
numOfTableItems={this.props.numOfEditions}
|
||||||
show={this.props.show}>
|
show={this.props.show}
|
||||||
|
orderBy={this.state.orderBy}
|
||||||
|
orderAsc={this.state.orderAsc}
|
||||||
|
changeOrder={this.changeEditionListOrder}>
|
||||||
<AccordionListItemTableToggle
|
<AccordionListItemTableToggle
|
||||||
className="ascribe-accordion-list-table-toggle"
|
className="ascribe-accordion-list-table-toggle"
|
||||||
onClick={this.toggleTable}
|
onClick={this.toggleTable}
|
||||||
|
@ -9,7 +9,9 @@ let Table = React.createClass({
|
|||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
||||||
changeOrder: React.PropTypes.func
|
changeOrder: React.PropTypes.func,
|
||||||
|
orderBy: React.PropTypes.string,
|
||||||
|
orderAsc: React.PropTypes.bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
renderChildren() {
|
renderChildren() {
|
||||||
@ -27,11 +29,10 @@ let Table = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<div className="ascribe-table">
|
<div className="ascribe-table">
|
||||||
<TableHeader
|
<TableHeader
|
||||||
columnList={this.props.columnList}
|
columnList={this.props.columnList}
|
||||||
itemList={this.props.itemList}
|
itemList={this.props.itemList}
|
||||||
fetchList={this.props.fetchList}
|
changeOrder={this.props.changeOrder}
|
||||||
changeOrder={this.props.changeOrder}
|
orderAsc={this.props.orderAsc}
|
||||||
orderAsc={this.props.orderAsc}
|
|
||||||
orderBy={this.props.orderBy} />
|
orderBy={this.props.orderBy} />
|
||||||
<div className="row">
|
<div className="row">
|
||||||
{this.renderChildren()}
|
{this.renderChildren()}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import fetch from '../utils/fetch';
|
import fetch from '../utils/fetch';
|
||||||
|
|
||||||
|
import { generateOrderingQueryParams } from '../utils/fetch_api_utils';
|
||||||
|
|
||||||
import AppConstants from '../constants/application_constants';
|
import AppConstants from '../constants/application_constants';
|
||||||
|
|
||||||
|
|
||||||
@ -7,8 +9,9 @@ let EditionListFetcher = {
|
|||||||
/**
|
/**
|
||||||
* Fetches a list of editions from the API.
|
* Fetches a list of editions from the API.
|
||||||
*/
|
*/
|
||||||
fetch(pieceId) {
|
fetch(pieceId, orderBy, orderAsc) {
|
||||||
return fetch.get('editions_list', { 'piece_id': pieceId });
|
let ordering = generateOrderingQueryParams(orderBy, orderAsc);
|
||||||
|
return fetch.get('editions_list', { 'piece_id': pieceId, ordering });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@ import EditionsListActions from '../actions/edition_list_actions';
|
|||||||
class EditionListStore {
|
class EditionListStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.editionList = {};
|
this.editionList = {};
|
||||||
|
this.orderBy = 'edition_number';
|
||||||
|
this.orderAsc = true;
|
||||||
this.bindActions(EditionsListActions);
|
this.bindActions(EditionsListActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdateEditionList({pieceId, editionListOfPiece}) {
|
onUpdateEditionList({pieceId, editionListOfPiece, orderBy, orderAsc}) {
|
||||||
if(this.editionList[pieceId]) {
|
if(this.editionList[pieceId]) {
|
||||||
this.editionList[pieceId].forEach((edition, i) => {
|
this.editionList[pieceId].forEach((edition, i) => {
|
||||||
// This uses the index of the new editionList for determining the edition.
|
// This uses the index of the new editionList for determining the edition.
|
||||||
@ -18,6 +20,8 @@ class EditionListStore {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.editionList[pieceId] = editionListOfPiece;
|
this.editionList[pieceId] = editionListOfPiece;
|
||||||
|
this.orderBy = orderBy;
|
||||||
|
this.orderAsc = orderAsc;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectEdition({pieceId, editionId}) {
|
onSelectEdition({pieceId, editionId}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user