mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
implement ordering
This commit is contained in:
parent
284f729dca
commit
9506cf3b1b
@ -29,7 +29,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ascribe-table-header-column > span > .glyphicon {
|
.ascribe-table-header-column > span > .glyphicon {
|
||||||
font-size: .6em;
|
font-size: .5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ascribe-table-item:nth-child(even) {
|
.ascribe-table-item:nth-child(even) {
|
||||||
|
@ -9,10 +9,14 @@ class PieceListActions {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchList(page, pageSize, search, ordering) {
|
fetchList(page, pageSize, search, orderBy, orderAsc) {
|
||||||
PieceListFetcher.fetch(page, pageSize, search, ordering)
|
PieceListFetcher.fetch(page, pageSize, search, orderBy, orderAsc)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.actions.updatePieceList(res.pieces);
|
this.actions.updatePieceList({
|
||||||
|
'itemList': res.pieces,
|
||||||
|
'orderBy': orderBy,
|
||||||
|
'orderAsc': orderAsc
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -14,8 +14,12 @@ let Link = Router.Link;
|
|||||||
|
|
||||||
let PieceList = React.createClass({
|
let PieceList = React.createClass({
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
return PieceListStore.getState();
|
||||||
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
PieceListActions.fetchList(1, 10);
|
PieceListActions.fetchList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -9,12 +9,11 @@ let Table = React.createClass({
|
|||||||
columnMap: React.PropTypes.object.isRequired
|
columnMap: React.PropTypes.object.isRequired
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
if(this.props.itemList && this.props.itemList.length > 0) {
|
if(this.props.itemList && this.props.itemList.length > 0) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ascribe-table">
|
<div className="ascribe-table">
|
||||||
<TableHeader columnMap={this.props.columnMap} itemList={this.props.itemList} fetchList={this.props.fetchList} />
|
<TableHeader columnMap={this.props.columnMap} itemList={this.props.itemList} fetchList={this.props.fetchList} orderAsc={this.props.orderAsc} />
|
||||||
{this.props.itemList.map((item, i) => {
|
{this.props.itemList.map((item, i) => {
|
||||||
return (
|
return (
|
||||||
<TableItem columnMap={this.props.columnMap} columnContent={item} key={i} />
|
<TableItem columnMap={this.props.columnMap} columnContent={item} key={i} />
|
||||||
|
@ -9,11 +9,21 @@ let TableHeader = React.createClass({
|
|||||||
propTypes: {
|
propTypes: {
|
||||||
columnMap: React.PropTypes.object.isRequired,
|
columnMap: React.PropTypes.object.isRequired,
|
||||||
itemList: React.PropTypes.array.isRequired,
|
itemList: React.PropTypes.array.isRequired,
|
||||||
fetchList: React.PropTypes.func.isRequired
|
fetchList: React.PropTypes.func.isRequired,
|
||||||
|
orderAsc: React.PropTypes.bool.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
sortIndex(i) {
|
sortIndex(i) {
|
||||||
this.props.fetchList(1, 10, null, '-' + Object.keys(this.props.columnMap)[i]);
|
|
||||||
|
let orderAsc;
|
||||||
|
|
||||||
|
if(this.props.orderAsc) {
|
||||||
|
orderAsc = false;
|
||||||
|
} else {
|
||||||
|
orderAsc = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.fetchList(1, 10, null, Object.keys(this.props.columnMap)[i], orderAsc);
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -25,12 +35,20 @@ let TableHeader = React.createClass({
|
|||||||
|
|
||||||
if(columnMapValuesList[i].canBeOrdered) {
|
if(columnMapValuesList[i].canBeOrdered) {
|
||||||
|
|
||||||
let boundClick = this.sortIndex.bind(this, i)
|
let boundClick = this.sortIndex.bind(this, i);
|
||||||
|
let carretDirection = 'glyphicon-triangle-';
|
||||||
|
|
||||||
|
if(this.props.orderAsc) {
|
||||||
|
carretDirection += 'top';
|
||||||
|
} else {
|
||||||
|
carretDirection += 'bottom';
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={columnClass + ' ascribe-table-header-column'} key={i} onClick={boundClick}>
|
<div className={columnClass + ' ascribe-table-header-column'} key={i} onClick={boundClick}>
|
||||||
<span>
|
<span>
|
||||||
<span className="glyphicon glyphicon-chevron-down"></span>
|
|
||||||
{val.displayName}
|
{val.displayName}
|
||||||
|
<span className={'glyphicon ' + carretDirection}></span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -8,10 +8,10 @@ let PieceListFetcher = {
|
|||||||
/**
|
/**
|
||||||
* Fetches a list of pieces from the API.
|
* Fetches a list of pieces from the API.
|
||||||
* Can be called with all supplied queryparams the API.
|
* Can be called with all supplied queryparams the API.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
fetch(page, pageSize, search, ordering) {
|
fetch(page, pageSize, search, orderBy, orderAsc) {
|
||||||
|
|
||||||
|
let ordering = FetchApiUtils.generateOrderingQueryParams(orderBy, orderAsc);
|
||||||
|
|
||||||
let params = FetchApiUtils.argsToQueryParams({
|
let params = FetchApiUtils.argsToQueryParams({
|
||||||
page,
|
page,
|
||||||
|
@ -5,10 +5,17 @@ import PieceListActions from '../actions/piece_list_actions';
|
|||||||
class PieceListStore {
|
class PieceListStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.itemList = []; // rename this to pieceList after figuring out AltContainer transform
|
this.itemList = []; // rename this to pieceList after figuring out AltContainer transform
|
||||||
|
this.page = 1;
|
||||||
|
this.pageSize = 10;
|
||||||
|
this.search = "";
|
||||||
|
this.orderBy = "artist_name";
|
||||||
|
this.orderAsc = true;
|
||||||
this.bindActions(PieceListActions);
|
this.bindActions(PieceListActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdatePieceList(itemList) {
|
onUpdatePieceList({ itemList, orderBy, orderAsc }) {
|
||||||
|
this.orderAsc = orderAsc;
|
||||||
|
this.orderBy = orderBy;
|
||||||
this.itemList = itemList;
|
this.itemList = itemList;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -40,6 +40,20 @@ let FetchApiUtils = {
|
|||||||
return s + snakeCaseKey + '=' + encodeURIComponent(obj[key]);
|
return s + snakeCaseKey + '=' + encodeURIComponent(obj[key]);
|
||||||
})
|
})
|
||||||
.join('');
|
.join('');
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a string and a boolean and generates a string query parameter for
|
||||||
|
* an API call.
|
||||||
|
*/
|
||||||
|
generateOrderingQueryParams(orderBy, orderAsc) {
|
||||||
|
let interpolation = '';
|
||||||
|
|
||||||
|
if(!orderAsc) {
|
||||||
|
interpolation += '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
return interpolation + orderBy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user