1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 00:28:00 +02:00

Filter the collection to only show the consignable items by default

This commit is contained in:
Brett Sun 2015-11-06 14:10:54 +01:00
parent 799ccb9b8d
commit 318a0bf4b2
4 changed files with 29 additions and 38 deletions

View File

@ -6,12 +6,6 @@ import { mergeOptions } from '../../utils/general_utils';
import EditionListActions from '../../actions/edition_list_actions';
import UserStore from '../../stores/user_store';
import UserActions from '../../actions/user_actions';
import PieceListStore from '../../stores/piece_list_store';
import PieceListActions from '../../actions/piece_list_actions';
import PieceListBulkModalSelectedEditionsWidget from './piece_list_bulk_modal_selected_editions_widget';
import { getLangText } from '../../utils/lang_utils.js';
@ -30,31 +24,6 @@ let PieceListBulkModal = React.createClass({
])
},
getInitialState() {
return mergeOptions(
UserStore.getState(),
PieceListStore.getState()
);
},
componentDidMount() {
UserStore.listen(this.onChange);
PieceListStore.listen(this.onChange);
UserActions.fetchCurrentUser();
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
},
componentWillUnmount() {
PieceListStore.unlisten(this.onChange);
UserStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
},
clearAllSelections() {
EditionListActions.clearAllEditionSelections();
EditionListActions.closeAllEditionLists();

View File

@ -28,7 +28,7 @@ let PieceListToolbarFilterWidget = React.createClass({
},
generateFilterByStatement(param) {
let filterBy = this.props.filterBy;
const { filterBy } = this.props;
if(filterBy) {
// we need hasOwnProperty since the values are all booleans
@ -56,13 +56,13 @@ let PieceListToolbarFilterWidget = React.createClass({
*/
filterBy(param) {
return () => {
let filterBy = this.generateFilterByStatement(param);
const filterBy = this.generateFilterByStatement(param);
this.props.applyFilterBy(filterBy);
};
},
isFilterActive() {
let trueValuesOnly = Object.keys(this.props.filterBy).filter((acl) => acl);
const trueValuesOnly = Object.keys(this.props.filterBy).filter((acl) => acl);
// We're hiding the star in that complicated matter so that,
// the surrounding button is not resized up on appearance
@ -74,7 +74,7 @@ let PieceListToolbarFilterWidget = React.createClass({
},
render() {
let filterIcon = (
const filterIcon = (
<span>
<span className="ascribe-icon icon-ascribe-filter" aria-hidden="true"></span>
<span style={this.isFilterActive()}>*</span>
@ -140,4 +140,4 @@ let PieceListToolbarFilterWidget = React.createClass({
}
});
export default PieceListToolbarFilterWidget;
export default PieceListToolbarFilterWidget;

View File

@ -60,11 +60,17 @@ let PieceList = React.createClass({
}]
};
},
getInitialState() {
return mergeOptions(
const stores = mergeOptions(
PieceListStore.getState(),
EditionListStore.getState()
);
// Use the default filters but use the stores' settings if they're available
stores.filterBy = Object.assign(this.getDefaultFilterBy(), stores.filterBy);
return stores;
},
componentDidMount() {
@ -96,6 +102,21 @@ let PieceList = React.createClass({
this.setState(state);
},
getDefaultFilterBy() {
const { filterParams } = this.props;
const defaultFilterBy = {};
filterParams.forEach(({ label, items }) => {
items.forEach((item) => {
if (typeof item === 'object' && item.defaultValue) {
defaultFilterBy[item.key] = true;
}
});
});
return defaultFilterBy;
},
paginationGoToPage(page) {
return () => {
// if the users clicks a pager of the pagination,

View File

@ -25,7 +25,8 @@ let LumenusPieceList = React.createClass({
label: getLangText('Show works I can'),
items: [{
key: 'acl_consign',
label: getLangText('consign to Lumenus')
label: getLangText('consign to Lumenus'),
defaultValue: true
}]
}]}
location={this.props.location}/>