From 192f776bd82705119d6db06012c76298dac81368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 7 Aug 2015 13:05:50 +0200 Subject: [PATCH 1/6] Filter open edition tables correctly --- js/actions/edition_list_actions.js | 3 +- js/components/acl_proxy.js | 4 +- js/components/ascribe_detail/edition.js | 2 +- .../piece_list_bulk_modal.js | 2 +- js/components/piece_list.js | 45 +++++++++++++++---- js/stores/edition_list_store.js | 20 ++++++--- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index d13882cd..8a0bb5cd 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -13,7 +13,8 @@ class EditionListActions { 'selectEdition', 'clearAllEditionSelections', 'closeAllEditionLists', - 'toggleEditionList' + 'toggleEditionList', + 'applyFilterBy' ); } diff --git a/js/components/acl_proxy.js b/js/components/acl_proxy.js index a04e499d..be0d8466 100644 --- a/js/components/acl_proxy.js +++ b/js/components/acl_proxy.js @@ -36,9 +36,9 @@ let AclProxy = React.createClass({ ); } else { - if(typeof this.props.aclObject[this.props.aclName] === 'undefined') { + /* if(typeof this.props.aclObject[this.props.aclName] === 'undefined') { console.warn('The aclName you\'re filtering for was not present (or undefined) in the aclObject.'); - } + } */ return null; } } diff --git a/js/components/ascribe_detail/edition.js b/js/components/ascribe_detail/edition.js index 25e8a97c..3aabc9e2 100644 --- a/js/components/ascribe_detail/edition.js +++ b/js/components/ascribe_detail/edition.js @@ -89,7 +89,7 @@ let Edition = React.createClass({ PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc, this.state.filterBy); - EditionListActions.refreshEditionList(this.props.edition.parent); + EditionListActions.refreshEditionList({pieceId: this.props.edition.parent}); EditionListActions.closeAllEditionLists(); EditionListActions.clearAllEditionSelections(); diff --git a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js index 3642a667..452a9bd8 100644 --- a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js +++ b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js @@ -81,7 +81,7 @@ let PieceListBulkModal = React.createClass({ this.fetchSelectedPieceEditionList() .forEach((pieceId) => { - EditionListActions.refreshEditionList(pieceId); + EditionListActions.refreshEditionList({pieceId, filterBy: {}}); }); EditionListActions.clearAllEditionSelections(); }, diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 1792b17a..9321c693 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -6,6 +6,9 @@ import Router from 'react-router'; import PieceListStore from '../stores/piece_list_store'; import PieceListActions from '../actions/piece_list_actions'; +import EditionListStore from '../stores/edition_list_store'; +import EditionListActions from '../actions/edition_list_actions'; + import AccordionList from './ascribe_accordion_list/accordion_list'; import AccordionListItem from './ascribe_accordion_list/accordion_list_item'; import AccordionListItemTableEditions from './ascribe_accordion_list/accordion_list_item_table_editions'; @@ -17,6 +20,7 @@ import PieceListToolbar from './ascribe_piece_list_toolbar/piece_list_toolbar'; import AppConstants from '../constants/application_constants'; +import { mergeOptions } from '../utils/general_utils'; let PieceList = React.createClass({ propTypes: { @@ -27,16 +31,22 @@ let PieceList = React.createClass({ mixins: [Router.Navigation, Router.State], getInitialState() { - return PieceListStore.getState(); + return mergeOptions( + PieceListStore.getState(), + EditionListStore.getState() + ); }, componentDidMount() { let page = this.getQuery().page || 1; + PieceListStore.listen(this.onChange); + EditionListStore.listen(this.onChange); + if (this.state.pieceList.length === 0){ PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc, this.state.filterBy) - .then(PieceListActions.fetchPieceRequestActions()); + .then(PieceListActions.fetchPieceRequestActions()); } }, @@ -49,6 +59,7 @@ let PieceList = React.createClass({ componentWillUnmount() { PieceListStore.unlisten(this.onChange); + EditionListStore.unlisten(this.onChange); }, onChange(state) { @@ -56,13 +67,14 @@ let PieceList = React.createClass({ }, paginationGoToPage(page) { - // if the users clicks a pager of the pagination, - // the site should go to the top - document.body.scrollTop = document.documentElement.scrollTop = 0; - - return () => PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, + return () => { + // if the users clicks a pager of the pagination, + // the site should go to the top + document.body.scrollTop = document.documentElement.scrollTop = 0; + PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc, this.state.filterBy); + }; }, getPagination() { @@ -86,8 +98,24 @@ let PieceList = React.createClass({ }, applyFilterBy(filterBy) { + // first we need to apply the filter on the piece list PieceListActions.fetchPieceList(1, this.state.pageSize, this.state.search, - this.state.orderBy, this.state.orderAsc, filterBy); + this.state.orderBy, this.state.orderAsc, filterBy) + .then(() => { + // but also, we need to filter all the open edition lists + this.state.pieceList + .forEach((piece) => { + // but only if they're actually open + if(this.state.isEditionListOpenForPieceId[piece.id].show) { + EditionListActions.refreshEditionList({ + pieceId: piece.id, + filterBy + }); + } + + }); + }); + // we have to redirect the user always to page one as it could be that there is no page two // for filtered pieces this.transitionTo(this.getPathname(), {page: 1}); @@ -100,7 +128,6 @@ let PieceList = React.createClass({ render() { let loadingElement = (); - return (
{ // reset back to the normal pageSize and page this.editionList[pieceId].page = prevEditionListPage; From b5448b0acb11c4ab93f6abb846f9400254f87102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 7 Aug 2015 13:09:57 +0200 Subject: [PATCH 2/6] wording --- .../piece_list_toolbar_filter_widget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js b/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js index 13bfd9a0..2520c499 100644 --- a/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js +++ b/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js @@ -80,7 +80,7 @@ let PieceListToolbarFilterWidgetFilter = React.createClass({ title={filterIcon} className="ascribe-piece-list-toolbar-filter-widget">
  • - {getLangText('Show works that')}: + {getLangText('Show works I can')}:
  • {this.props.filterParams.map((param, i) => { let label; @@ -100,7 +100,7 @@ let PieceListToolbarFilterWidgetFilter = React.createClass({ className="filter-widget-item">
    - {getLangText('I can') + ' ' + getLangText(label)} + {getLangText(label)} Date: Fri, 7 Aug 2015 13:18:33 +0200 Subject: [PATCH 3/6] fix minor consistence bug --- js/stores/edition_list_store.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index f5430d6c..90f48e8f 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -133,9 +133,17 @@ class EditionListStore { } onToggleEditionList(pieceId) { + this.isEditionListOpenForPieceId[pieceId] = { show: this.isEditionListOpenForPieceId[pieceId] ? !this.isEditionListOpenForPieceId[pieceId].show : true }; + + if(!this.isEditionListOpenForPieceId[pieceId].show) { + // to clear an array, david walsh recommends to just set it's length to zero + // http://davidwalsh.name/empty-array + + this.editionList[pieceId].length = 0; + } } onCloseAllEditionLists() { From bbb0bb15b6e1902f98c8bc8f1d98fa5b96ac84f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 7 Aug 2015 13:20:31 +0200 Subject: [PATCH 4/6] add documentation --- js/stores/edition_list_store.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 90f48e8f..87b4df76 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -138,6 +138,10 @@ class EditionListStore { show: this.isEditionListOpenForPieceId[pieceId] ? !this.isEditionListOpenForPieceId[pieceId].show : true }; + // When loading all editions of a piece, closing the table and then applying the filter + // the merge fails, as the edition list is not refreshed when closed. + // Therefore in the case of a filter application when closed, we need to reload the + // edition list if(!this.isEditionListOpenForPieceId[pieceId].show) { // to clear an array, david walsh recommends to just set it's length to zero // http://davidwalsh.name/empty-array From 6fc7ac8b63b2a78a8a4b639e400a515a87e58255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 7 Aug 2015 13:21:54 +0200 Subject: [PATCH 5/6] remove unneccesary action for edition list actions --- js/actions/edition_list_actions.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index 8a0bb5cd..d13882cd 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -13,8 +13,7 @@ class EditionListActions { 'selectEdition', 'clearAllEditionSelections', 'closeAllEditionLists', - 'toggleEditionList', - 'applyFilterBy' + 'toggleEditionList' ); } From b56ae0e145fb3c807cc35dc76e3d4d74f4fbf71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 7 Aug 2015 14:50:34 +0200 Subject: [PATCH 6/6] fix requestActions requests --- js/components/piece_list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 9321c693..78917f61 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -46,7 +46,7 @@ let PieceList = React.createClass({ if (this.state.pieceList.length === 0){ PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc, this.state.filterBy) - .then(PieceListActions.fetchPieceRequestActions()); + .then(() => PieceListActions.fetchPieceRequestActions()); } },