From b2090e37a5f6ba8c123c2c56c5cd64f6ea0f9bd0 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 12 Sep 2018 15:30:14 -0300 Subject: [PATCH 1/9] Adds no description informed label to taxonomy and collection lists. Disables view mode seletion on theme items list at repository level while we don't deal with this. --- src/admin/components/lists/collections-list.vue | 8 ++++---- src/admin/components/lists/taxonomies-list.vue | 8 ++++---- src/admin/pages/lists/items-page.vue | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/admin/components/lists/collections-list.vue b/src/admin/components/lists/collections-list.vue index 5a80bfc2b..a89460210 100644 --- a/src/admin/components/lists/collections-list.vue +++ b/src/admin/components/lists/collections-list.vue @@ -116,14 +116,14 @@ class="column-large-width" @click="onClickCollection($event, collection.id, index)" :label="$i18n.get('label_description')" - :aria-label="$i18n.get('label_description') + ': ' + collection.description"> + :aria-label="$i18n.get('label_description') + ': ' + (collection.description != undefined && collection.description != '') ? collection.description : `` + $i18n.get('label_description_not_informed') + ``">

- {{ collection.description }}

+ }" + v-html="(collection.description != undefined && collection.description != '') ? collection.description : `` + $i18n.get('label_description_not_informed') + ``"/> + :aria-label="$i18n.get('label_description') + ': ' + taxonomy.description != undefined && taxonomy.description != '' ? taxonomy.description : `` + $i18n.get('label_description_not_informed') + ``">

- {{ taxonomy.description }}

+ }" + v-html="(taxonomy.description != undefined && taxonomy.description != '') ? taxonomy.description : `` + $i18n.get('label_description_not_informed') + ``" />
Date: Wed, 12 Sep 2018 18:21:21 -0300 Subject: [PATCH 2/9] avoid errors in get_item method --- src/theme-helper/template-tags.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/theme-helper/template-tags.php b/src/theme-helper/template-tags.php index 2822cc310..987955aef 100644 --- a/src/theme-helper/template-tags.php +++ b/src/theme-helper/template-tags.php @@ -278,7 +278,11 @@ function tainacan_register_view_mode($slug, $args = []) { */ function tainacan_get_item($post_id = 0) { $post = get_post( $post_id ); - + + if (!$post) { + return null; + } + $theme_helper = \Tainacan\Theme_Helper::get_instance(); if (!$theme_helper->is_post_an_item($post)) From 8e16284851f699e9dbfff9a22e5bc13d15e630c4 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Wed, 12 Sep 2018 18:21:53 -0300 Subject: [PATCH 3/9] define default and enabled view modes for repository and term items list --- src/theme-helper/template-tags.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/theme-helper/template-tags.php b/src/theme-helper/template-tags.php index 987955aef..9dc6e963d 100644 --- a/src/theme-helper/template-tags.php +++ b/src/theme-helper/template-tags.php @@ -182,13 +182,17 @@ function tainacan_the_faceted_search() { $props = ' '; + $default_view_mode = apply_filters( 'tainacan-default-view-mode-for-themes', 'masonry' ); + $enabled_view_modes = apply_filters( 'tainacan-enabled-view-modes-for-themes', ['table', 'cards', 'masonry'] ); + // if in a collection page $collection_id = tainacan_get_collection_id(); if ($collection_id) { + $props .= 'collection-id="' . $collection_id . '" '; $collection = new \Tainacan\Entities\Collection($collection_id); - $props .= 'default-view-mode="' . $collection->get_default_view_mode() . '" '; - $props .= 'enabled-view-modes="' . implode(',', $collection->get_enabled_view_modes()) . '" '; + $default_view_mode = $collection->get_default_view_mode(); + $enabled_view_modes = $collection->get_enabled_view_modes(); } // if in a tainacan taxonomy @@ -197,6 +201,9 @@ function tainacan_the_faceted_search() { $props .= 'term-id="' . $term->term_id . '" '; $props .= 'taxonomy="' . $term->taxonomy . '" '; } + + $props .= 'default-view-mode="' . $default_view_mode . '" '; + $props .= 'enabled-view-modes="' . implode(',', $enabled_view_modes) . '" '; echo "
"; From efbd349f1767e326c178b2e79bfc28756751942a Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Wed, 12 Sep 2018 18:38:54 -0300 Subject: [PATCH 4/9] fix textual search in terms names --- src/classes/class-tainacan-search-engine.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/classes/class-tainacan-search-engine.php b/src/classes/class-tainacan-search-engine.php index 438ebcfb0..2dd943691 100644 --- a/src/classes/class-tainacan-search-engine.php +++ b/src/classes/class-tainacan-search-engine.php @@ -329,14 +329,14 @@ class Search_Engine { $searchand = ''; $searchSlug = ''; foreach ( $search_terms as $term ) { - $term = $wpdb->prepare("%s", $exact ? $term : "%". sanitize_title_with_dashes($term) . "%"); - $searchSlug .= "{$searchand}(tter.slug LIKE $term)"; + $term = $wpdb->prepare("%s", $exact ? $term : "%". $term . "%"); + $searchSlug .= "{$searchand}(tter.name LIKE $term)"; $searchand = ' AND '; } - $term = $wpdb->prepare("%s", $exact ? $term : "%". sanitize_title_with_dashes($s) . "%"); + $term = $wpdb->prepare("%s", $exact ? $term : "%". $s . "%"); if ( count( $search_terms ) > 1 && $search_terms[0] != $s ) { - $searchSlug = "($searchSlug) OR (tter.slug LIKE $term)"; + $searchSlug = "($searchSlug) OR (tter.name LIKE $term)"; } if ( !empty( $searchSlug ) ) $search = " OR ({$searchSlug}) "; From 20df63a71db232d68199d16e2c8d2c3439e7b5e3 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 12 Sep 2018 22:00:55 -0300 Subject: [PATCH 5/9] Fixes error where new term option wasn't appearing on item edition form. --- src/classes/metadata-types/taxonomy/AddNewTerm.vue | 4 ++-- src/classes/metadata-types/taxonomy/Taxonomy.vue | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/classes/metadata-types/taxonomy/AddNewTerm.vue b/src/classes/metadata-types/taxonomy/AddNewTerm.vue index 5f861fd90..74a84fba5 100644 --- a/src/classes/metadata-types/taxonomy/AddNewTerm.vue +++ b/src/classes/metadata-types/taxonomy/AddNewTerm.vue @@ -12,7 +12,7 @@
- +
{{ $i18n.get('save') }}
-
+
diff --git a/src/classes/metadata-types/taxonomy/Taxonomy.vue b/src/classes/metadata-types/taxonomy/Taxonomy.vue index 823e1e1b9..adb39a391 100644 --- a/src/classes/metadata-types/taxonomy/Taxonomy.vue +++ b/src/classes/metadata-types/taxonomy/Taxonomy.vue @@ -45,7 +45,7 @@ this.taxonomy = metadata_type_options.taxonomy_id; if( metadata_type_options && metadata_type_options.allow_new_terms && this.metadatum.item ){ - this.allowNew = metadata_type_options.allow_new_terms === 'yes' + this.allowNew = metadata_type_options.allow_new_terms == 'yes'; } // This condition is temporary @@ -70,6 +70,7 @@ taxonomy: '', terms:[], // object with names totalTerms: 0, + allowNew: false, offset: 0, termsNumber: 40 } @@ -92,7 +93,6 @@ id: '', disabled: false, forcedComponentType: '', - allowNew: false, maxtags: '', allowSelectToCreate: false, }, @@ -103,6 +103,7 @@ } else if( this.metadatum.metadatum && this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.input_type ){ return this.metadatum.metadatum.metadata_type_options.input_type; + } } }, From bdcf3704e66aa991faf36f253faa1446125310df Mon Sep 17 00:00:00 2001 From: eduardohumberto Date: Wed, 12 Sep 2018 22:51:19 -0300 Subject: [PATCH 6/9] endpoint facets - priority for selected values --- .../class-tainacan-rest-facets-controller.php | 118 +++++++++++++++--- .../filter-types/checkbox/Checkbox.vue | 4 +- .../filter-types/filter-types-mixin.js | 8 +- .../filter-types/taxonomy/Checkbox.vue | 2 +- 4 files changed, 109 insertions(+), 23 deletions(-) diff --git a/src/api/endpoints/class-tainacan-rest-facets-controller.php b/src/api/endpoints/class-tainacan-rest-facets-controller.php index 2a9a01fbc..8f6d6e182 100644 --- a/src/api/endpoints/class-tainacan-rest-facets-controller.php +++ b/src/api/endpoints/class-tainacan-rest-facets-controller.php @@ -90,6 +90,8 @@ class REST_Facets_Controller extends REST_Controller { $options = $metadatum->get_metadata_type_options(); $args = $this->prepare_filters($request); + // handle filter with relationship metadata + if( $metadatum_type === 'Tainacan\Metadata_Types\Relationship' ){ $selected = $this->getRelationshipSelectedValues($request, $metadatum->get_id()); @@ -99,14 +101,13 @@ class REST_Facets_Controller extends REST_Controller { $args['posts_per_page'] = $request['number']; } - if( $selected ){ - //$args['postin'] = $selected; - } - $items = $this->items_repository->fetch($args, $options['collection_id'], 'WP_Query'); + $ids = []; + if ($items->have_posts()) { while ( $items->have_posts() ) { $items->the_post(); + $ids[] = (string) $items->post->ID; $item = new Entities\Item($items->post); $prepared_item = $restItemsClass->prepare_item_for_response($item, $request); @@ -117,10 +118,34 @@ class REST_Facets_Controller extends REST_Controller { wp_reset_postdata(); } + // retrieve selected items + + if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){ + foreach( $selected as $index => $item_id ){ + + if( in_array($item_id,$ids) ){ + continue; + } + + $item = new Entities\Item($item_id); + $prepared_item = $restItemsClass->prepare_item_for_response($item, $request); + $response[$index] = $prepared_item; + + if( isset($request['number']) && ($index+1) >= $request['number']){ + break; + } + } + } + $this->total_items = $items->found_posts; $this->total_pages = ceil($this->total_items / (int) $items->query_vars['posts_per_page']); - } else if ( $metadatum_type === 'Tainacan\Metadata_Types\Taxonomy' ){ + } + + // handle filter with Taxonomy metadata + + else if ( $metadatum_type === 'Tainacan\Metadata_Types\Taxonomy' ){ + $this->taxonomy = $this->taxonomy_repository->fetch($options['taxonomy_id']); $selected = $this->getTaxonomySelectedValues($request, $options['taxonomy_id']); @@ -131,22 +156,42 @@ class REST_Facets_Controller extends REST_Controller { } else { - if( $selected ){ - //$args['include'] = $selected; + $terms = $this->terms_repository->fetch($args, $this->taxonomy); + + // retrieve selected items + + if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){ + $ids = $this->get_terms_ids( $terms ); + + foreach( $selected as $index => $term_id ){ + + if( in_array($term_id,$ids) ){ + continue; + } + + $term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy); + array_unshift($terms, $term_selected); + + if( isset($request['number']) && ($index+1) >= $request['number']){ + break; + } + } } - $terms = $this->terms_repository->fetch($args, $this->taxonomy); $restTermClass = new REST_Terms_Controller(); } - foreach ($terms as $term) { array_push($response, $restTermClass->prepare_item_for_response( $term, $request )); } $this->set_pagination_properties_term_type( $args, $response ); - } else { + } + + // handle filter with Text metadata + + else { $metadatum_id = $metadatum->get_id(); $offset = ''; @@ -174,10 +219,25 @@ class REST_Facets_Controller extends REST_Controller { } } - if($selected){ - //foreach( $selected as $value ){ - //$response[] = ['mvalue' => $value]; - //} + // retrieve selected items + + if( $selected && $request['getSelected'] && $request['getSelected'] === '1'){ + $rawValues = $this->get_values( $response ); + + foreach( $selected as $index => $value ){ + + if( in_array($value,$rawValues) ){ + continue; + } + + $row = ['mvalue' => $value, 'metadatum_id' => $metadatum_id ]; + $response[$index] = $row; + + if( isset($request['number']) && ($index+1) >= $request['number']){ + break; + } + } + } $this->set_pagination_properties_text_type( $collection_id, $metadatum_id, ($request['search']) ? $request['search'] : '' , $offset, $number ); @@ -343,7 +403,7 @@ class REST_Facets_Controller extends REST_Controller { if( isset($request['current_query']['metaquery']) ){ foreach( $request['current_query']['metaquery'] as $metaquery ){ - if( $metaquery['key'] === $metadatum_id ){ + if( $metaquery['key'] == $metadatum_id ){ return $metaquery['value']; @@ -368,7 +428,7 @@ class REST_Facets_Controller extends REST_Controller { if( isset($request['current_query']['metaquery']) ){ foreach( $request['current_query']['metaquery'] as $metaquery ){ - if( $metaquery['key'] === $metadatum_id ){ + if( $metaquery['key'] == $metadatum_id ){ return $metaquery['value']; @@ -379,6 +439,32 @@ class REST_Facets_Controller extends REST_Controller { return []; } + + /** + * + */ + private function get_terms_ids( $terms ){ + $ids = []; + + foreach( $terms as $term ){ + $ids[] = (string) $term->WP_Term->term_id; + } + + return $ids; + } + + /** + * + */ + private function get_values( $rows ){ + $values = []; + + foreach( $rows as $row ){ + $values[] = $row['mvalue']; + } + + return $values; + } } ?> \ No newline at end of file diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue index 01c2f2936..79b93549f 100644 --- a/src/classes/filter-types/checkbox/Checkbox.vue +++ b/src/classes/filter-types/checkbox/Checkbox.vue @@ -112,7 +112,7 @@ let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ? this.metadatum_object.metadata_type_options.collection_id : this.collection_id; - promise = this.getValuesRelationship( collectionTarget, null, [], 0, this.filter.max_options); + promise = this.getValuesRelationship( collectionTarget, null, [], 0, this.filter.max_options, false, '1'); promise .then(() => { if(this.options.length > this.filter.max_options){ @@ -122,7 +122,7 @@ this.$console.error(error); }) } else { - promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, [], 0, this.filter.max_options ); + promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' ); promise .then(() => { if(this.options.length > this.filter.max_options){ diff --git a/src/classes/filter-types/filter-types-mixin.js b/src/classes/filter-types/filter-types-mixin.js index 828bd1181..b815fba35 100644 --- a/src/classes/filter-types/filter-types-mixin.js +++ b/src/classes/filter-types/filter-types-mixin.js @@ -18,10 +18,10 @@ export const filter_type_mixin = { query: {} }, methods: { - getValuesPlainText(metadatumId, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal) { + getValuesPlainText(metadatumId, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') { let query_items = { 'current_query': this.query }; - let url = `/collection/${this.collection}/facets/${metadatumId}?`; + let url = `/collection/${this.collection}/facets/${metadatumId}?getSelected=${getSelected}&`; if(offset != undefined && number != undefined){ url += `offset=${offset}&number=${number}&`; @@ -102,9 +102,9 @@ export const filter_type_mixin = { this.$console.error(error); }); }, - getValuesRelationship(collectionTarget, search, valuesToIgnore, offset, number, isInCheckboxModal) { + getValuesRelationship(collectionTarget, search, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') { let query_items = { 'current_query': this.query }; - let url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + '?'; + let url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`; if(offset != undefined && number != undefined){ url += `offset=${offset}&number=${number}`; diff --git a/src/classes/filter-types/taxonomy/Checkbox.vue b/src/classes/filter-types/taxonomy/Checkbox.vue index f3b736746..468aa0b76 100644 --- a/src/classes/filter-types/taxonomy/Checkbox.vue +++ b/src/classes/filter-types/taxonomy/Checkbox.vue @@ -99,7 +99,7 @@ let query_items = { 'current_query': this.query }; axios.get('/collection/'+ this.collection +'/facets/' + this.metadatum - + `?hideempty=0&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items)) + + `?getSelected=1&hideempty=0&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items)) .then( res => { for (let item of res.data) { From 22c5737ccd478a0a9b9abe8f09b0439e88940200 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 13 Sep 2018 09:48:08 -0300 Subject: [PATCH 7/9] Uses facets endpoint only to retrieve options on checkboxes list. --- .../other/checkbox-filter-modal.vue | 50 +------------------ .../filter-types/checkbox/Checkbox.vue | 19 ++----- .../filter-types/taxonomy/Checkbox.vue | 15 +----- 3 files changed, 6 insertions(+), 78 deletions(-) diff --git a/src/admin/components/other/checkbox-filter-modal.vue b/src/admin/components/other/checkbox-filter-modal.vue index b91d1de24..342a87d2e 100644 --- a/src/admin/components/other/checkbox-filter-modal.vue +++ b/src/admin/components/other/checkbox-filter-modal.vue @@ -438,8 +438,6 @@ applyFilter() { this.$parent.close(); - let selectedOptions = []; - if(this.isTaxonomy){ this.$eventBusSearch.$emit('input', { filter: 'checkbox', @@ -448,24 +446,7 @@ metadatum_id: this.metadatum_id, collection_id: this.collection_id, terms: this.selected - }); - - for (let selected of this.selected) { - for(let i in this.finderColumns){ - let valueIndex = this.finderColumns[i].findIndex(option => option.value == selected); - - if (valueIndex >= 0) { - selectedOptions.push(this.finderColumns[i][valueIndex]); - } - } - } - - this.$eventBusSearch.$emit('sendValuesToTags', { - filterId: this.filter.id, - value: selectedOptions, - }); - - this.$emit('appliedCheckBoxModal', selectedOptions); + }); } else { this.$eventBusSearch.$emit('input', { filter: 'checkbox', @@ -474,36 +455,9 @@ collection_id: this.collection_id ? this.collection_id : this.filter.collection_id, value: this.selected, }); - - // if(!isNaN(this.selected[0])){ - // for (let option of this.options) { - // let valueIndex = this.selected.findIndex(item => item == option.value); - - // if (valueIndex >= 0) { - // selectedOptions.push(this.options[valueIndex].label); - // } - // } - // } - if(Array.isArray(this.selected)){ - for (let aSelected of this.selected) { - let valueIndex = this.options.findIndex(option => option.value == aSelected); - - if (valueIndex >= 0) { - selectedOptions.push(this.options[valueIndex]); - } - } - } else { - let valueIndex = this.options.findIndex(option => option.value == this.selected); - - if (valueIndex >= 0) { - selectedOptions.push(this.options[valueIndex]); - } - } - - this.$emit('appliedCheckBoxModal', selectedOptions); } - + this.$emit('appliedCheckBoxModal'); } } } diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue index 79b93549f..735ff1b01 100644 --- a/src/classes/filter-types/checkbox/Checkbox.vue +++ b/src/classes/filter-types/checkbox/Checkbox.vue @@ -1,7 +1,7 @@