diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index 78cc0eeb..f07d7d18 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -11,13 +11,15 @@ class EditionListActions { ); } - fetchEditionList(pieceId) { + fetchEditionList(pieceId, orderBy, orderAsc) { EditionListFetcher - .fetch(pieceId) + .fetch(pieceId, orderBy, orderAsc) .then((res) => { this.actions.updateEditionList({ 'editionListOfPiece': res.editions, - pieceId + pieceId, + orderBy, + orderAsc }); }) .catch((err) => { diff --git a/js/components/ascribe_accordion_list/accordion_list_item_table.js b/js/components/ascribe_accordion_list/accordion_list_item_table.js index 1cf410df..82b9a23a 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_table.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_table.js @@ -14,7 +14,10 @@ let AccordionListItemTable = React.createClass({ itemList: React.PropTypes.array, columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)), 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() { @@ -23,7 +26,10 @@ let AccordionListItemTable = React.createClass({
+ itemList={this.props.itemList} + changeOrder={this.props.changeOrder} + orderBy={this.props.orderBy} + orderAsc={this.props.orderAsc}> {this.props.itemList.map((item, i) => { return ( { @@ -87,7 +91,7 @@ let AccordionListItemTableEditions = React.createClass({ getLangText('Bitcoin Address'), TableItemText, 5, - false + true ), new TableColumnContentModel( (item) => { @@ -110,7 +114,10 @@ let AccordionListItemTableEditions = React.createClass({ itemList={this.state.editionList[this.props.parentId]} columnList={columnList} numOfTableItems={this.props.numOfEditions} - show={this.props.show}> + show={this.props.show} + orderBy={this.state.orderBy} + orderAsc={this.state.orderAsc} + changeOrder={this.changeEditionListOrder}>
{this.renderChildren()} diff --git a/js/fetchers/edition_list_fetcher.js b/js/fetchers/edition_list_fetcher.js index 07e52d87..2cec37a7 100644 --- a/js/fetchers/edition_list_fetcher.js +++ b/js/fetchers/edition_list_fetcher.js @@ -1,5 +1,7 @@ import fetch from '../utils/fetch'; +import { generateOrderingQueryParams } from '../utils/fetch_api_utils'; + import AppConstants from '../constants/application_constants'; @@ -7,8 +9,9 @@ let EditionListFetcher = { /** * Fetches a list of editions from the API. */ - fetch(pieceId) { - return fetch.get('editions_list', { 'piece_id': pieceId }); + fetch(pieceId, orderBy, orderAsc) { + let ordering = generateOrderingQueryParams(orderBy, orderAsc); + return fetch.get('editions_list', { 'piece_id': pieceId, ordering }); } }; diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index b8855896..4c93fd5c 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -6,10 +6,12 @@ import EditionsListActions from '../actions/edition_list_actions'; class EditionListStore { constructor() { this.editionList = {}; + this.orderBy = 'edition_number'; + this.orderAsc = true; this.bindActions(EditionsListActions); } - onUpdateEditionList({pieceId, editionListOfPiece}) { + onUpdateEditionList({pieceId, editionListOfPiece, orderBy, orderAsc}) { if(this.editionList[pieceId]) { this.editionList[pieceId].forEach((edition, i) => { // This uses the index of the new editionList for determining the edition. @@ -18,6 +20,8 @@ class EditionListStore { }) } this.editionList[pieceId] = editionListOfPiece; + this.orderBy = orderBy; + this.orderAsc = orderAsc; } onSelectEdition({pieceId, editionId}) {