v-hammer:swipe="onSwipeFiltersMenu"
+ :class="{
+ 'repository-level-page': isRepositoryLevel,
+ 'is-fullscreen': registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].full_screen
+ }"> -->
+
-->
+
diff --git a/src/admin/scss/_tables.scss b/src/admin/scss/_tables.scss
index 48d3e3600..ca0251cc0 100644
--- a/src/admin/scss/_tables.scss
+++ b/src/admin/scss/_tables.scss
@@ -155,8 +155,9 @@
font-size: 0.875rem;
margin: 0px;
text-overflow: ellipsis;
- overflow-x: hidden;
+ overflow: hidden;
white-space: nowrap;
+ // max-height: 1rem;
}
}
img.table-thumb {
diff --git a/src/admin/scss/_variables.scss b/src/admin/scss/_variables.scss
index d32313a5b..063d40e46 100644
--- a/src/admin/scss/_variables.scss
+++ b/src/admin/scss/_variables.scss
@@ -400,7 +400,7 @@ $modal-z: 9999999;
animation-duration: 0.2s;
animation-timing-function: ease;
}
-.filtes-menu-leave-active {
+.filters-menu-leave-active {
animation-name: filters-menu-out;
animation-duration: 0.2s;
animation-timing-function: ease;
@@ -487,4 +487,89 @@ $modal-z: 9999999;
animation-name: slide-right-out;
animation-duration: 0.3s;
animation-timing-function: ease;
+}
+
+// Sequence page
+
+// Slide
+@keyframes page-left-in {
+ from {
+ opacity: 0;
+ -ms-transform: translate(-5%, 0%); /* IE 9 */
+ -webkit-transform: translate(-5%, 0%); /* Safari */
+ transform: translate(-5%, 0%);
+ }
+ to {
+ opacity: 1;
+ -ms-transform: translate(0, 0); /* IE 9 */
+ -webkit-transform: translate(0, 0); /* Safari */
+ transform: translate(0, 0);
+ }
+}
+
+@keyframes page-left-out {
+ from {
+ opacity: 1;
+ -ms-transform: translate(0, 0); /* IE 9 */
+ -webkit-transform: translate(0, 0); /* Safari */
+ transform: translate(0, 0);
+ }
+ to {
+ opacity: 0;
+ -ms-transform: translate(10%, 0%); /* IE 9 */
+ -webkit-transform: translate(10%, 0%); /* Safari */
+ transform: translate(10%, 0%);
+ }
+}
+
+.page-left-enter-active {
+ animation-name: page-left-in;
+ animation-duration: 0.4s;
+ animation-timing-function: ease;
+}
+.page-left-leave-active {
+ animation-name: page-left-out;
+ animation-duration: 0.4s;
+ animation-timing-function: ease;
+}
+
+@keyframes page-right-in {
+ from {
+ opacity: 0;
+ -ms-transform: translate(10%, 0%); /* IE 9 */
+ -webkit-transform: translate(10%, 0%); /* Safari */
+ transform: translate(10%, 0%);
+ }
+ to {
+ opacity: 1;
+ -ms-transform: translate(0, 0); /* IE 9 */
+ -webkit-transform: translate(0, 0); /* Safari */
+ transform: translate(0, 0);
+ }
+}
+
+@keyframes page-right-out {
+ from {
+ opacity: 1;
+ -ms-transform: translate(0, 0); /* IE 9 */
+ -webkit-transform: translate(0, 0); /* Safari */
+ transform: translate(0, 0);
+ }
+ to {
+ opacity: 0;
+ -ms-transform: translate(-5%, 0%); /* IE 9 */
+ -webkit-transform: translate(-5%, 0%); /* Safari */
+ transform: translate(-5%, 0%);
+ }
+}
+
+.page-right-enter-active {
+ animation-name: page-right-in;
+ animation-duration: 0.3s;
+ animation-timing-function: ease;
+}
+.page-right-leave-active {
+ animation-name: page-right-out;
+ animation-duration: 0.3s;
+ animation-timing-function: ease;
}
\ No newline at end of file
diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php
index 519800137..381678d56 100644
--- a/src/admin/tainacan-admin-i18n.php
+++ b/src/admin/tainacan-admin-i18n.php
@@ -31,6 +31,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'mapping' => __( 'Mapping', 'tainacan' ),
'importers' => __( 'Importers', 'tainacan' ),
'processes' => __( 'Processes', 'tainacan' ),
+ 'sequence' => __( 'Sequence', 'tainacan' ),
// Actions
'close' => __( 'Close', 'tainacan' ),
@@ -44,6 +45,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'remove_value' => __( 'Remove value', 'tainacan' ),
'save' => __( 'Save', 'tainacan' ),
'next' => __( 'Next', 'tainacan' ),
+ 'previous' => __( 'Previous', 'tainacan' ),
'back' => __( 'Back', 'tainacan' ),
'exit' => __( 'Exit', 'tainacan' ),
'see' => __( 'View', 'tainacan' ),
@@ -232,7 +234,8 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_delete_permanently' => __( 'Delete permanently', 'tainacan' ),
'label_send_to_trash' => __( 'Send to trash', 'tainacan' ),
'label_delete_selected_taxonomies' => __( 'Delete selected taxonomies', 'tainacan' ),
- 'label_edit_selected_items' => __( 'Edit selected items', 'tainacan' ),
+ 'label_bulk_edit_selected_items' => __( 'Bulk edit selected items', 'tainacan' ),
+ 'label_sequence_edit_selected_items' => __( 'Edit selected items in sequence', 'tainacan' ),
'label_edit_selected_taxonomies' => __( 'Edit selected taxonomies', 'tainacan' ),
'label_select_all_collections_page' => __( 'Select all collections on page', 'tainacan' ),
'label_select_all_items_page' => __( 'Select all items on page', 'tainacan' ),
@@ -310,6 +313,8 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_show_metadata' => __( 'Show metadata', 'tainacan' ),
'label_all_terms' => __( 'All terms', 'tainacan' ),
'label_selected_terms' => __( 'Selected terms', 'tainacan'),
+ 'label_editing_item_number' => __( 'Editing item n.', 'tainacan'),
+ 'label_sequence_editing_item' => __( 'Sequence editing: Item', 'tainacan'),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),
diff --git a/src/api/endpoints/class-tainacan-rest-exporters-controller.php b/src/api/endpoints/class-tainacan-rest-exporters-controller.php
index 3e93d9f2f..51c4a4c57 100644
--- a/src/api/endpoints/class-tainacan-rest-exporters-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-exporters-controller.php
@@ -5,6 +5,7 @@ namespace Tainacan\API\EndPoints;
use \Tainacan\API\REST_Controller;
use Tainacan\Repositories;
use Tainacan\Entities;
+use \Tainacan\Exposers\Mappers\Value;
/**
* Represents the Exporters REST Controller
@@ -213,7 +214,49 @@ class REST_Exporters_Controller extends REST_Controller {
];
return new \WP_REST_Response( $response, 200 );
}
+
+ protected function map($item_arr, $mapper) {
+ $ret = $item_arr;
+ if(array_key_exists('metadatum', $item_arr)) { // getting a unique metadatum
+ $ret = $this->map_metadatum($item_arr, $mapper);
+ } else { // array of elements
+ $ret = [];
+ foreach ($item_arr as $item) {
+ if(array_key_exists('metadatum', $item)) {
+ $ret = array_merge($ret, $this->map($item, $mapper) );
+ } else {
+ $ret[] = $this->map($item, $mapper);
+ }
+ }
+ }
+ return $ret;
+ }
+ protected function map_metadatum($item_arr, $mapper) {
+ $ret = $item_arr;
+ $metadatum_mapping = $item_arr['metadatum']['exposer_mapping'];
+ if(array_key_exists($mapper->slug, $metadatum_mapping)) {
+ if(
+ is_string($metadatum_mapping[$mapper->slug]) && is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ||
+ is_array($metadatum_mapping[$mapper->slug]) && $mapper->allow_extra_metadata != true
+ ) {
+ throw new \Exception('Invalid Mapper Option');
+ }
+ $slug = '';
+ if(is_string($metadatum_mapping[$mapper->slug])) {
+ $slug = $metadatum_mapping[$mapper->slug];
+ } else {
+ $slug = $metadatum_mapping[$mapper->slug]['slug'];
+ }
+ $ret = [$mapper->prefix.$slug.$mapper->sufix => $item_arr['value']]; //TODO Validate option
+ } elseif($mapper->slug == 'value') {
+ $ret = [$item_arr['metadatum']['name'] => $item_arr['value']];
+ } else {
+ $ret = [];
+ }
+ return $ret;
+ }
+
}
?>
diff --git a/src/api/endpoints/class-tainacan-rest-facets-controller.php b/src/api/endpoints/class-tainacan-rest-facets-controller.php
index 946bebaff..8ad06ad10 100644
--- a/src/api/endpoints/class-tainacan-rest-facets-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-facets-controller.php
@@ -8,6 +8,18 @@ use \Tainacan\API\REST_Controller;
class REST_Facets_Controller extends REST_Controller {
+ private $total_pages;
+ private $total_items;
+
+ private $collection;
+ private $collection_repository;
+ private $metadatum_repository;
+ private $filter_repository;
+ private $terms_repository;
+ private $taxonomy_repository;
+ private $items_repository;
+ private $taxonomy;
+
/**
* REST_Facets_Controller constructor.
*/
@@ -38,7 +50,7 @@ class REST_Facets_Controller extends REST_Controller {
register_rest_route($this->namespace, '/collection/(?P
[\d]+)/' . $this->rest_base . '/(?P[\d]+)', array(
array(
'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_item'),
+ 'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check')
)
));
@@ -46,7 +58,7 @@ class REST_Facets_Controller extends REST_Controller {
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array(
array(
'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_item'),
+ 'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check')
)
));
@@ -57,7 +69,7 @@ class REST_Facets_Controller extends REST_Controller {
*
* @return \WP_Error|\WP_REST_Response
*/
- public function get_item( $request ) {
+ public function get_items( $request ) {
$metadatum_id = $request['metadatum_id'];
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
@@ -83,6 +95,7 @@ class REST_Facets_Controller extends REST_Controller {
*/
public function prepare_item_for_response($metadatum, $request){
$response = [];
+ $metadatum_type = null;
if( !empty($metadatum) ){
@@ -202,8 +215,8 @@ class REST_Facets_Controller extends REST_Controller {
else {
$metadatum_id = $metadatum->get_id();
- $offset = '';
- $number = '';
+ $offset = null;
+ $number = null;
$collection_id = ( isset($request['collection_id']) ) ? $request['collection_id'] : false;
$selected = $this->getTextSelectedValues($request, $metadatum_id);
@@ -221,42 +234,40 @@ class REST_Facets_Controller extends REST_Controller {
} else {
if($collection_id) {
- $response = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, '', $offset, $number);
+ $response = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, null, $offset, $number);
} else {
- $response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id, '', $offset, $number);
+ $response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id, null, $offset, $number);
}
}
+ $rawResponse = $response;
+
// retrieve selected items
- if( $selected && $request['getSelected'] && $request['getSelected'] === '1'){
+ if( count($selected) && $request['getSelected'] && $request['getSelected'] === '1'){
$rawValues = $this->get_values( $response );
$realResponse = [];
foreach( $selected as $index => $value ){
-
- $row = ['mvalue' => $value, 'metadatum_id' => $metadatum_id ];
+ $row = (object) ['mvalue' => $value, 'metadatum_id' => $metadatum_id ];
$realResponse[] = $row;
-
}
foreach( $rawValues as $index => $row0 ){
- if( in_array($row0, $selected) ){
- continue;
- }
+ if( !in_array($row0, $selected) ){
+ $realResponse[] = (object) ['mvalue' => $row0, 'metadatum_id' => $metadatum_id];
- $realResponse[] = ['mvalue' => $row0, 'metadatum_id' => $metadatum_id];
-
- if( isset($request['number']) && count($realResponse) >= $request['number']){
- break;
+ if( isset($request['number']) && count($realResponse) >= $request['number']){
+ break;
+ }
}
}
$response = $realResponse;
}
- $this->set_pagination_properties_text_type( $collection_id, $metadatum_id, ($request['search']) ? $request['search'] : '' , $offset, $number );
+ $this->set_pagination_properties_text_type( $offset, $number, $rawResponse );
}
}
@@ -285,8 +296,7 @@ class REST_Facets_Controller extends REST_Controller {
foreach ( $response as $key => $item ) {
if( $type === 'Tainacan\Metadata_Types\Taxonomy' ){
-
- $row = [
+ $result[] = [
'label' => $item['name'],
'value' => $item['id'],
'img' => ( isset($item['header_image']) ) ? $item['header_image'] : false ,
@@ -296,10 +306,8 @@ class REST_Facets_Controller extends REST_Controller {
'taxonomy_id' => $this->taxonomy->WP_Post->ID,
'taxonomy' => ( isset($item['taxonomy']) ) ? $item['taxonomy'] : false,
];
-
} else if( $type === 'Tainacan\Metadata_Types\Relationship' ){
-
- $row = [
+ $result[] = [
'label' => $item['title'],
'value' => $item['id'],
'img' => ( isset($item['thumbnail']['thumb']) ) ? $item['thumbnail']['thumb'] : false,
@@ -307,21 +315,16 @@ class REST_Facets_Controller extends REST_Controller {
'total_children' => 0,
'type' => 'Relationship'
];
-
} else {
-
- $row = [
- 'label' => $item['mvalue'],
- 'value' => $item['mvalue'],
+ $result[] = [
+ 'label' => $item->mvalue,
+ 'value' => $item->mvalue,
'img' => false,
'parent' => false,
'total_children' => 0,
'type' => 'Text'
];
-
}
-
- $result[] = $row;
}
}
@@ -330,15 +333,17 @@ class REST_Facets_Controller extends REST_Controller {
/**
* set attributes for text metadata
+ *
+ * @param $offset
+ * @param $number
+ * @param $response
*/
- private function set_pagination_properties_text_type( $collection_id, $metadatum_id, $search , $offset, $number ){
- $response = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, $search);
-
+ private function set_pagination_properties_text_type( $offset, $number, $response ){
if( $response && is_array( $response ) ){
if ( $offset !== '' && $number) {
$per_page = (int) $number;
- $page = ceil( ( ( (int) $offset ) / $per_page ) + 1 );
+ //$page = ceil( ( ( (int) $offset ) / $per_page ) + 1 );
$this->total_items = count( $response );
@@ -357,12 +362,15 @@ class REST_Facets_Controller extends REST_Controller {
/**
* set attributes for term metadata
+ *
+ * @param $args
+ * @param $response
*/
private function set_pagination_properties_term_type( $args, $response ){
if(isset($args['number'], $args['offset'])){
$number = $args['number'];
- $offset = $args['offset'];
+ //$offset = $args['offset'];
unset( $args['number'], $args['offset'] );
$total_terms = wp_count_terms( $this->taxonomy->get_db_identifier(), $args );
@@ -372,7 +380,7 @@ class REST_Facets_Controller extends REST_Controller {
}
$per_page = (int) $number;
- $page = ceil( ( ( (int) $offset ) / $per_page ) + 1 );
+ //$page = ceil( ( ( (int) $offset ) / $per_page ) + 1 );
$this->total_items = (int) $total_terms ;
@@ -386,10 +394,12 @@ class REST_Facets_Controller extends REST_Controller {
}
/**
- * get text metadata selected facets
- *
+ * get text metadata selected facets
+ *
* @param $request
- * @param $taxonomy_id
+ * @param $taxonomy_id
+ *
+ * @return array
*/
private function getTaxonomySelectedValues($request, $taxonomy_id){
$selected = [];
@@ -411,9 +421,11 @@ class REST_Facets_Controller extends REST_Controller {
/**
* get text metadata selected facets
- *
+ *
* @param $request
* @param $metadatum_id
+ *
+ * @return array
*/
private function getTextSelectedValues($request, $metadatum_id){
if( isset($request['current_query']['metaquery']) ){
@@ -432,9 +444,11 @@ class REST_Facets_Controller extends REST_Controller {
/**
* get only selected relationship values
- *
+ *
* @param $request
* @param $metadatum_id
+ *
+ * @return array
*/
private function getRelationshipSelectedValues($request, $metadatum_id){
$selected = [];
@@ -468,26 +482,29 @@ class REST_Facets_Controller extends REST_Controller {
}
/**
- *
+ * @param $rows
+ *
+ * @return array
*/
private function get_values( $rows ){
$values = [];
foreach( $rows as $row ){
- $values[] = $row['mvalue'];
+ $values[] = $row->mvalue;
}
return $values;
}
-
+
/**
- * method responsible to return the total of items for the facet value
- *
- * @param value string/int the facet value
- * @param reference_id int the taxonomy or the metadataid
- * @param is_taxonomy (default) false if the value param is a term
- * @param query the actual request query to filter the items
- *
+ * method responsible to return the total of items for the facet value
+ *
+ * @param $value
+ * @param $reference_id
+ * @param bool $is_taxonomy
+ * @param $query
+ * @param $collection_id
+ *
* @return int total of items found
*/
private function add_items_count( $value, $reference_id, $is_taxonomy = false, $query, $collection_id){
diff --git a/src/classes/filter-types/autocomplete/Autocomplete.vue b/src/classes/filter-types/autocomplete/Autocomplete.vue
index 0a07ef6d7..3ebb7c13f 100644
--- a/src/classes/filter-types/autocomplete/Autocomplete.vue
+++ b/src/classes/filter-types/autocomplete/Autocomplete.vue
@@ -59,11 +59,7 @@
this.$console.log(error);
});
-
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
- if (filterTag.filterId == this.filter.id)
- this.cleanSearch();
- })
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
data(){
return {
@@ -98,10 +94,16 @@
});
this.selectedValues();
},
- search( query ){
+ search: _.debounce( function(query) {
if (query != '') {
let promise = null;
this.options = [];
+
+ // Cancels previous Request
+ if (this.getOptionsValuesCancel != undefined)
+ this.getOptionsValuesCancel.cancel('Facet search Canceled.');
+
+
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
this.metadatum_object.metadata_type_options.collection_id : this.collection_id;
@@ -111,13 +113,17 @@
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
}
- promise.catch( error => {
+ promise.request.catch( error => {
this.$console.log('error select', error );
});
+
+ // Search Request Token for cancelling
+ this.getOptionsValuesCancel = promise.source;
+
} else {
this.cleanSearch();
}
- },
+ }, 500),
selectedValues(){
const instance = this;
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
@@ -162,6 +168,10 @@
return false;
}
},
+ cleanSearchFromTags(filterTag) {
+ if (filterTag.filterId == this.filter.id)
+ this.cleanSearch();
+ },
cleanSearch(){
this.results = '';
this.label = '';
@@ -173,6 +183,9 @@
value: ''
});
},
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue
index f8020f0b5..1ad0b6f0b 100644
--- a/src/classes/filter-types/checkbox/Checkbox.vue
+++ b/src/classes/filter-types/checkbox/Checkbox.vue
@@ -32,6 +32,7 @@
export default {
created(){
+
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
const vm = this;
@@ -55,38 +56,7 @@
this.$console.log(error);
});
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
- if (filterTag.filterId == this.filter.id) {
-
- let selectedIndex = this.selected.findIndex(option => option == filterTag.singleValue);
- let optionIndex = this.options.findIndex(option => option.label == filterTag.singleValue);
- let alternativeIndex;
-
- if (optionIndex >= 0) {
- alternativeIndex = this.selected.findIndex(option => this.options[optionIndex].value == option);
- }
-
- if (selectedIndex >= 0 || alternativeIndex >= 0) {
-
- selectedIndex >= 0 ? this.selected.splice(selectedIndex, 1) : this.selected.splice(alternativeIndex, 1);
-
- this.$emit('input', {
- filter: 'checkbox',
- compare: 'IN',
- metadatum_id: this.metadatum,
- collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
- value: this.selected
- });
-
- this.$eventBusSearch.$emit( 'sendValuesToTags', {
- filterId: this.filter.id,
- value: this.selected
- });
-
- this.selectedValues();
- }
- }
- });
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
props: {
isRepositoryLevel: Boolean,
@@ -112,46 +82,56 @@
methods: {
loadOptions(){
let promise = null;
- this.isLoading = true;
+
+ // Cancels previous Request
+ if (this.getOptionsValuesCancel != undefined)
+ this.getOptionsValuesCancel.cancel('Facet search Canceled.');
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
+ this.isLoading = true;
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, false, '1');
- promise
+ promise.request
.then(() => {
-
- this.isLoading = false;
+ this.isLoading = false;
if(this.options.length > this.filter.max_options){
this.options.splice(this.filter.max_options);
}
+ this.selectedValues();
}).catch((error) => {
this.$console.error(error);
- })
+ })
} else {
+ this.isLoading = true;
promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' );
- promise
+ promise.request
.then(() => {
- this.isLoading = false;
+ this.isLoading = false;
if(this.options.length > this.filter.max_options){
this.options.splice(this.filter.max_options);
}
+ this.selectedValues();
}).catch((error) => {
this.$console.error(error);
- })
+ });
}
- promise
- .then(() => {
- this.isLoading = false;
- this.selectedValues()
- })
- .catch( error => {
- this.$console.log('error select', error );
- this.isLoading = false;
- });
+ // promise.request
+ // .then(() => {
+ // this.isLoading = false;
+
+ // })
+ // .catch( error => {
+ // this.$console.log('error select', error );
+ // this.isLoading = false;
+ // });
+
+ // Search Request Token for cancelling
+ this.getOptionsValuesCancel = promise.source;
+
},
onSelect(){
this.$emit('input', {
@@ -213,7 +193,42 @@
appliedCheckBoxModal: () => this.loadOptions()
}
});
+ },
+ cleanSearchFromTags(filterTag) {
+ if (filterTag.filterId == this.filter.id) {
+
+ let selectedIndex = this.selected.findIndex(option => option == filterTag.singleValue);
+ let optionIndex = this.options.findIndex(option => option.label == filterTag.singleValue);
+ let alternativeIndex;
+
+ if (optionIndex >= 0) {
+ alternativeIndex = this.selected.findIndex(option => this.options[optionIndex].value == option);
+ }
+
+ if (selectedIndex >= 0 || alternativeIndex >= 0) {
+
+ selectedIndex >= 0 ? this.selected.splice(selectedIndex, 1) : this.selected.splice(alternativeIndex, 1);
+
+ this.$emit('input', {
+ filter: 'checkbox',
+ compare: 'IN',
+ metadatum_id: this.metadatum,
+ collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
+ value: this.selected
+ });
+
+ this.$eventBusSearch.$emit( 'sendValuesToTags', {
+ filterId: this.filter.id,
+ value: this.selected
+ });
+
+ this.selectedValues();
+ }
+ }
}
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
diff --git a/src/classes/filter-types/custom-interval/CustomInterval.vue b/src/classes/filter-types/custom-interval/CustomInterval.vue
index b82769a67..fb007a6a8 100644
--- a/src/classes/filter-types/custom-interval/CustomInterval.vue
+++ b/src/classes/filter-types/custom-interval/CustomInterval.vue
@@ -69,10 +69,7 @@
this.$console.log(error);
});
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
- if (filterTag.filterId == this.filter.id)
- this.clearSearch();
- });
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
data(){
return {
@@ -193,6 +190,10 @@
// return this.value_init + ' - ' +this.value_end;
// }
},
+ cleanSearchFromTags(filterTag) {
+ if (filterTag.filterId == this.filter.id)
+ this.cleanSearch();
+ },
clearSearch(){
this.clear = true;
@@ -281,6 +282,9 @@
});
}
}
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
diff --git a/src/classes/filter-types/filter-types-mixin.js b/src/classes/filter-types/filter-types-mixin.js
index e15c97b8b..8bf142104 100644
--- a/src/classes/filter-types/filter-types-mixin.js
+++ b/src/classes/filter-types/filter-types-mixin.js
@@ -1,10 +1,11 @@
import qs from 'qs';
-import { tainacan as axios } from '../../js/axios/axios';
+import axios from '../../js/axios/axios';
export const filter_type_mixin = {
data () {
return {
- thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png'
+ thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
+ getOptionsValuesCancel: undefined
}
},
props: {
@@ -19,7 +20,17 @@ export const filter_type_mixin = {
},
methods: {
getValuesPlainText(metadatumId, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') {
- let query_items = { 'current_query': this.query };
+
+ const source = axios.CancelToken.source();
+
+ let currentQuery = JSON.parse(JSON.stringify(this.query));
+ if (currentQuery.fetch_only != undefined) {
+ for (let key of Object.keys(currentQuery.fetch_only)) {
+ if (currentQuery.fetch_only[key] == null)
+ delete currentQuery.fetch_only[key];
+ }
+ }
+ let query_items = { 'current_query': currentQuery };
let url = `/collection/${this.collection}/facets/${metadatumId}?getSelected=${getSelected}&`;
@@ -36,74 +47,92 @@ export const filter_type_mixin = {
} else if(search){
url += `search=${search}&` + qs.stringify(query_items);
} else {
- url += qs.stringify(query_items, { addQueryPrefix: true });
+ url += qs.stringify(query_items);
}
- return axios.get(url)
- .then(res => {
- let sResults = [];
- let opts = [];
+ return new Object ({
+ request:
+ axios.tainacan.get(url, { cancelToken: source.token })
+ .then(res => {
+ let sResults = [];
+ let opts = [];
- for (let metadata of res.data) {
- if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
- let indexToIgnore = valuesToIgnore.findIndex(value => value == metadata.value);
+ for (let metadata of res.data) {
+ if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
+ let indexToIgnore = valuesToIgnore.findIndex(value => value == metadata.value);
- if (search && isInCheckboxModal) {
- sResults.push({
- label: metadata.label,
- value: metadata.value
- });
- } else if (indexToIgnore < 0) {
- opts.push({
- label: metadata.label,
- value: metadata.value
- });
+ if (search && isInCheckboxModal) {
+ sResults.push({
+ label: metadata.label,
+ value: metadata.value
+ });
+ } else if (indexToIgnore < 0) {
+ opts.push({
+ label: metadata.label,
+ value: metadata.value
+ });
+ }
+ } else {
+ if (search && isInCheckboxModal) {
+ sResults.push({
+ label: metadata.label,
+ value: metadata.value
+ });
+ } else {
+ opts.push({
+ label: metadata.label,
+ value: metadata.value
+ });
+ }
+ }
}
- } else {
- if (search && isInCheckboxModal) {
- sResults.push({
- label: metadata.label,
- value: metadata.value
- });
+
+
+ this.searchResults = sResults;
+
+ if (opts.length) {
+ this.options = opts;
+ } else if(!search) {
+ this.noMorePage = 1;
+ }
+
+ if(this.options.length < this.maxNumOptionsCheckboxList && !search){
+ this.noMorePage = 1;
+ }
+
+ if (this.filter.max_options && this.options.length >= this.filter.max_options) {
+ let seeMoreLink = ` ${ this.$i18n.get('label_view_all') } `;
+
+ if(this.options.length === this.filter.max_options){
+ this.options[this.filter.max_options-1].seeMoreLink = seeMoreLink;
+ } else {
+ this.options[this.options.length-1].seeMoreLink = seeMoreLink;
+ }
+ }
+
+ })
+ .catch((thrown) => {
+ if (axios.isCancel(thrown)) {
+ console.log('Request canceled: ', thrown.message);
} else {
- opts.push({
- label: metadata.label,
- value: metadata.value
- });
+ reject(thrown);
}
- }
- }
-
-
- this.searchResults = sResults;
-
- if (opts.length) {
- this.options = opts;
- } else if(!search) {
- this.noMorePage = 1;
- }
-
- if(this.options.length < this.maxNumOptionsCheckboxList && !search){
- this.noMorePage = 1;
- }
-
- if (this.filter.max_options && this.options.length >= this.filter.max_options) {
- let seeMoreLink = ` ${ this.$i18n.get('label_view_all') } `;
-
- if(this.options.length === this.filter.max_options){
- this.options[this.filter.max_options-1].seeMoreLink = seeMoreLink;
- } else {
- this.options[this.options.length-1].seeMoreLink = seeMoreLink;
- }
- }
-
- })
- .catch(error => {
- this.$console.error(error);
- });
+ }),
+ source: source
+ });
},
getValuesRelationship(collectionTarget, search, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') {
- let query_items = { 'current_query': this.query };
+
+ const source = axios.CancelToken.source();
+
+ let currentQuery = JSON.parse(JSON.stringify(this.query));
+ if (currentQuery.fetch_only != undefined) {
+ for (let key of Object.keys(currentQuery.fetch_only)) {
+ if (currentQuery.fetch_only[key] == null)
+ delete currentQuery.fetch_only[key];
+ }
+ }
+ let query_items = { 'current_query': currentQuery };
let url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`;
if(offset != undefined && number != undefined){
@@ -116,72 +145,76 @@ export const filter_type_mixin = {
url += `&search=${search}`;
}
- return axios.get(url + '&fetch_only[0]=thumbnail&fetch_only[1]=title&fetch_only[2]=id&' + qs.stringify(query_items))
- .then(res => {
- let sResults = [];
- let opts = [];
+ return new Object ({
+ request:
+ axios.tainacan.get(url + '&fetch_only[0]=thumbnail&fetch_only[1]=title&fetch_only[2]=id&' + qs.stringify(query_items))
+ .then(res => {
+ let sResults = [];
+ let opts = [];
- if (res.data.length > 0) {
- for (let item of res.data) {
- if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
- let indexToIgnore = valuesToIgnore.findIndex(value => value == item.value);
+ if (res.data.length > 0) {
+ for (let item of res.data) {
+ if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
+ let indexToIgnore = valuesToIgnore.findIndex(value => value == item.value);
- if (search && isInCheckboxModal) {
- sResults.push({
- label: item.label,
- value: item.value
- });
- } else if (indexToIgnore < 0) {
- opts.push({
- label: item.label,
- value: item.value,
- img: (item.img ? item.img : this.thumbPlaceholderPath)
- });
- }
- } else {
- if (search && isInCheckboxModal) {
- sResults.push({
- label: item.label,
- value: item.value,
- img: (item.img ? item.img : this.thumbPlaceholderPath)
- });
- } else {
- opts.push({
- label: item.label,
- value: item.value,
- img: (item.img ? item.img : this.thumbPlaceholderPath)
- });
+ if (search && isInCheckboxModal) {
+ sResults.push({
+ label: item.label,
+ value: item.value
+ });
+ } else if (indexToIgnore < 0) {
+ opts.push({
+ label: item.label,
+ value: item.value,
+ img: (item.img ? item.img : this.thumbPlaceholderPath)
+ });
+ }
+ } else {
+ if (search && isInCheckboxModal) {
+ sResults.push({
+ label: item.label,
+ value: item.value,
+ img: (item.img ? item.img : this.thumbPlaceholderPath)
+ });
+ } else {
+ opts.push({
+ label: item.label,
+ value: item.value,
+ img: (item.img ? item.img : this.thumbPlaceholderPath)
+ });
+ }
+ }
}
}
- }
- }
- this.searchResults = sResults;
+ this.searchResults = sResults;
- if (opts.length) {
- this.options = opts;
- } else {
- this.noMorePage = 1;
- }
+ if (opts.length) {
+ this.options = opts;
+ } else {
+ this.noMorePage = 1;
+ }
- if(this.options.length < this.maxNumOptionsCheckboxList){
- this.noMorePage = 1;
- }
+ if(this.options.length < this.maxNumOptionsCheckboxList){
+ this.noMorePage = 1;
+ }
- if (this.filter.max_options && this.options.length >= this.filter.max_options) {
- let seeMoreLink = ` ${ this.$i18n.get('label_view_all') } `;
+ if (this.filter.max_options && this.options.length >= this.filter.max_options) {
+ let seeMoreLink = ` ${ this.$i18n.get('label_view_all') } `;
- if(this.options.length === this.filter.max_options){
- this.options[this.filter.max_options-1].seeMoreLink = seeMoreLink;
- } else {
- this.options[this.options.length-1].seeMoreLink = seeMoreLink;
- }
- }
+ if(this.options.length === this.filter.max_options){
+ this.options[this.filter.max_options-1].seeMoreLink = seeMoreLink;
+ } else {
+ this.options[this.options.length-1].seeMoreLink = seeMoreLink;
+ }
+ }
- })
- .catch(error => {
- this.$console.error(error);
- });
+ })
+ .catch(error => {
+ this.$console.error(error);
+ }),
+ source: source
+ });
}
}
};
\ No newline at end of file
diff --git a/src/classes/filter-types/selectbox/Selectbox.vue b/src/classes/filter-types/selectbox/Selectbox.vue
index 0fa750749..7ac0e8e5b 100644
--- a/src/classes/filter-types/selectbox/Selectbox.vue
+++ b/src/classes/filter-types/selectbox/Selectbox.vue
@@ -46,10 +46,7 @@
this.$console.error(error);
});
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
- if (filterTag.filterId == this.filter.id)
- this.onSelect();
- });
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
props: {
isRepositoryLevel: Boolean,
@@ -76,21 +73,29 @@
}
return undefined;
}
- },
+ },
methods: {
loadOptions(){
this.isLoading = true;
+ // Cancels previous Request
+ if (this.getOptionsValuesCancel != undefined)
+ this.getOptionsValuesCancel.cancel('Facet search Canceled.');
+
let promise = null;
promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel );
- promise.then(() => {
- this.isLoading = false;
- })
- .catch( error => {
- this.$console.error('error select', error );
- this.isLoading = false;
- });
+ promise.request
+ .then(() => {
+ this.isLoading = false;
+ })
+ .catch( error => {
+ this.$console.error('error select', error );
+ this.isLoading = false;
+ });
+
+ // Search Request Token for cancelling
+ this.getOptionsValuesCancel = promise.source;
},
onSelect(value){
this.selected = value;
@@ -120,7 +125,14 @@
} else {
return false;
}
+ },
+ cleanSearchFromTags(filterTag) {
+ if (filterTag.filterId == this.filter.id)
+ this.onSelect();
}
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
diff --git a/src/classes/filter-types/taginput/Taginput.vue b/src/classes/filter-types/taginput/Taginput.vue
index da4e2ba87..231c12020 100644
--- a/src/classes/filter-types/taginput/Taginput.vue
+++ b/src/classes/filter-types/taginput/Taginput.vue
@@ -60,37 +60,7 @@
this.$console.log(error);
});
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
-
- if (filterTag.filterId == this.filter.id) {
-
- let selectedIndex = this.selected.findIndex(option => option.label == filterTag.singleValue);
- if (selectedIndex >= 0) {
-
- this.selected.splice(selectedIndex, 1);
-
- let values = [];
- let labels = [];
- for(let val of this.selected){
- values.push( val.value );
- labels.push( val.label );
- }
-
- this.$emit('input', {
- filter: 'taginput',
- compare: 'IN',
- metadatum_id: this.metadatum,
- collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
- value: values
- });
-
- this.$eventBusSearch.$emit( 'sendValuesToTags', {
- filterId: this.filter.id,
- value: labels
- });
- }
- }
- });
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
data(){
return {
@@ -134,7 +104,7 @@
}
},
methods: {
- search( query ){
+ search: _.debounce( function(query) {
let promise = null;
this.options = [];
let valuesToIgnore = [];
@@ -142,20 +112,28 @@
for(let val of this.selected)
valuesToIgnore.push( val.value );
+ // Cancels previous Request
+ if (this.getOptionsValuesCancel != undefined)
+ this.getOptionsValuesCancel.cancel('Facet search Canceled.');
+
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
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, query, valuesToIgnore );
-
+
} else {
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel, valuesToIgnore );
}
- promise
- .catch( error => {
- this.$console.log('error select', error );
- });
- },
+ promise.request
+ .catch( error => {
+ this.$console.log('error select', error );
+ });
+
+ // Search Request Token for cancelling
+ this.getOptionsValuesCancel = promise.source;
+
+ }, 500),
selectedValues(){
const instance = this;
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
@@ -188,7 +166,41 @@
} else {
return false;
}
+ },
+ cleanSearchFromTags(filterTag) {
+
+ if (filterTag.filterId == this.filter.id) {
+
+ let selectedIndex = this.selected.findIndex(option => option.label == filterTag.singleValue);
+ if (selectedIndex >= 0) {
+
+ this.selected.splice(selectedIndex, 1);
+
+ let values = [];
+ let labels = [];
+ for(let val of this.selected){
+ values.push( val.value );
+ labels.push( val.label );
+ }
+
+ this.$emit('input', {
+ filter: 'taginput',
+ compare: 'IN',
+ metadatum_id: this.metadatum,
+ collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
+ value: values
+ });
+
+ this.$eventBusSearch.$emit( 'sendValuesToTags', {
+ filterId: this.filter.id,
+ value: labels
+ });
+ }
+ }
}
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
\ No newline at end of file
diff --git a/src/classes/filter-types/taxonomy/Checkbox.vue b/src/classes/filter-types/taxonomy/Checkbox.vue
index 76437c2ff..1bcd02d8e 100644
--- a/src/classes/filter-types/taxonomy/Checkbox.vue
+++ b/src/classes/filter-types/taxonomy/Checkbox.vue
@@ -37,37 +37,7 @@
this.type = ( this.filter_type ) ? this.filter_type : this.filter.metadatum.metadata_type;
this.loadOptions();
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
- if (filterTag.filterId == this.filter.id) {
-
- let selectedOption = this.options.find(option => option.label == filterTag.singleValue);
-
- if(selectedOption) {
-
- let selectedIndex = this.selected.findIndex(option => option == selectedOption.value);
- if (selectedIndex >= 0) {
-
- this.selected.splice(selectedIndex, 1);
-
- this.$emit('input', {
- filter: 'checkbox',
- compare: 'IN',
- taxonomy: this.taxonomy,
- metadatum_id: this.metadatum,
- collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
- terms: this.selected
- });
-
- this.$eventBusSearch.$emit( 'sendValuesToTags', {
- filterId: this.filter.id,
- value: this.selected
- });
-
- this.selectedValues();
- }
- }
- }
- });
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTag);
},
data(){
return {
@@ -237,7 +207,41 @@
},
width: 'calc(100% - 8.333333333%)',
});
+ },
+ cleanSearchFromTag(filterTag) {
+ if (filterTag.filterId == this.filter.id) {
+
+ let selectedOption = this.options.find(option => option.label == filterTag.singleValue);
+
+ if(selectedOption) {
+
+ let selectedIndex = this.selected.findIndex(option => option == selectedOption.value);
+ if (selectedIndex >= 0) {
+
+ this.selected.splice(selectedIndex, 1);
+
+ this.$emit('input', {
+ filter: 'checkbox',
+ compare: 'IN',
+ taxonomy: this.taxonomy,
+ metadatum_id: this.metadatum,
+ collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
+ terms: this.selected
+ });
+
+ this.$eventBusSearch.$emit( 'sendValuesToTags', {
+ filterId: this.filter.id,
+ value: this.selected
+ });
+
+ this.selectedValues();
+ }
+ }
+ }
}
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
diff --git a/src/classes/filter-types/taxonomy/Taginput.vue b/src/classes/filter-types/taxonomy/Taginput.vue
index 9f51c961c..9da74cecc 100644
--- a/src/classes/filter-types/taxonomy/Taginput.vue
+++ b/src/classes/filter-types/taxonomy/Taginput.vue
@@ -38,38 +38,7 @@
this.selectedValues( metadatum.metadata_type_options.taxonomy_id );
});
- this.$eventBusSearch.$on('removeFromFilterTag', (filterTag) => {
-
- if (filterTag.filterId == this.filter.id) {
-
- let selectedIndex = this.selected.findIndex(option => option.label == filterTag.singleValue);
- if (selectedIndex >= 0) {
-
- this.selected.splice(selectedIndex, 1);
-
- let values = [];
- let labels = [];
- for(let val of this.selected){
- values.push( val.value );
- labels.push( val.label );
- }
-
- this.$emit('input', {
- filter: 'taginput',
- compare: 'IN',
- taxonomy: this.taxonomy,
- metadatum_id: ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum,
- collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
- terms: values
- });
- this.$eventBusSearch.$emit( 'sendValuesToTags', {
- filterId: this.filter.id,
- value: labels
- });
-
- }
- }
- });
+ this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTag);
},
data(){
return {
@@ -124,7 +93,7 @@
}
},
methods: {
- search( query ){
+ search: _.debounce( function(query) {
this.isLoading = true;
this.options = [];
@@ -161,7 +130,7 @@
this.isLoading = false;
this.$console.log(error);
});
- },
+ }, 500),
selectedValues( taxonomy ){
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false;
@@ -185,7 +154,42 @@
.catch(error => {
this.$console.log(error);
});
+ },
+ cleanSearchFromTag(filterTag) {
+
+ if (filterTag.filterId == this.filter.id) {
+
+ let selectedIndex = this.selected.findIndex(option => option.label == filterTag.singleValue);
+ if (selectedIndex >= 0) {
+
+ this.selected.splice(selectedIndex, 1);
+
+ let values = [];
+ let labels = [];
+ for(let val of this.selected){
+ values.push( val.value );
+ labels.push( val.label );
+ }
+
+ this.$emit('input', {
+ filter: 'taginput',
+ compare: 'IN',
+ taxonomy: this.taxonomy,
+ metadatum_id: ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum,
+ collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
+ terms: values
+ });
+ this.$eventBusSearch.$emit( 'sendValuesToTags', {
+ filterId: this.filter.id,
+ value: labels
+ });
+
+ }
+ }
}
+ },
+ beforeDestroy() {
+ this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
diff --git a/src/classes/repositories/class-tainacan-metadata.php b/src/classes/repositories/class-tainacan-metadata.php
index 7c06919c3..542e47115 100644
--- a/src/classes/repositories/class-tainacan-metadata.php
+++ b/src/classes/repositories/class-tainacan-metadata.php
@@ -996,7 +996,7 @@ class Metadata extends Repository {
);
}
- $pre_result = $wpdb->get_results( $sql_string, ARRAY_A );
+ $pre_result = $wpdb->get_results( $sql_string, OBJECT );
if ( ! empty( $pre_result ) ) {
foreach ( $pre_result as $pre ) {
@@ -1045,7 +1045,7 @@ class Metadata extends Repository {
);
}
- $pre_result = $wpdb->get_results( $sql_string, ARRAY_A );
+ $pre_result = $wpdb->get_results( $sql_string, OBJECT );
if ( ! empty( $pre_result ) ) {
foreach ( $pre_result as $pre ) {
diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php
index 4a01d1f8b..c72601f4b 100644
--- a/src/classes/repositories/class-tainacan-repository.php
+++ b/src/classes/repositories/class-tainacan-repository.php
@@ -753,10 +753,11 @@ abstract class Repository {
$key_array = array();
foreach ( $array as $val ) {
- if ( ! in_array( $val[ $key ], $key_array ) ) {
- $key_array[ $i ] = $val[ $key ];
+ if ( ! in_array( $val->$key, $key_array ) ) {
+ $key_array[ $i ] = $val->$key;
$temp_array[ $i ] = $val;
}
+
$i ++;
}
diff --git a/src/exporter/class-tainacan-csv.php b/src/exporter/class-tainacan-csv.php
index 3c2955c03..e3f267736 100644
--- a/src/exporter/class-tainacan-csv.php
+++ b/src/exporter/class-tainacan-csv.php
@@ -8,7 +8,8 @@ class CSV extends Exporter {
public function __construct($attributes = array()) {
parent::__construct($attributes);
- $this->set_mapping_method('any');
+ $this->set_mapping_method('any'); // set all method to mapping
+ //$this->set_mapping_method('list', [ "dublin-core" => "Tainacan\\Exposers\\Mappers\\Dublin_Core" ]); // set specific list of methods to mapping
}
public function process_item( $index, $collection_definition ) {
@@ -16,23 +17,98 @@ class CSV extends Exporter {
$tainacan_items = \Tainacan\Repositories\Items::get_instance();
$filters = [
- 'posts_per_page' => 12,
+ 'posts_per_page' => 1,
'paged' => $index+1,
'order' => 'DESC'
];
-
+
$this->add_log('Proccessing item index ' . $index . ' in collection ' . $collection_definition['id'] );
$items = $tainacan_items->fetch($filters, $collection_id, 'WP_Query');
$export_items = "";
while ($items->have_posts()) {
$items->the_post();
$item = new Entities\Item($items->post);
- $export_items .= json_encode($item);
+ $printCol = $index == 0;
+ $export_items .= $this->get_item_csv($item, $printCol);
+ $this->add_log('export_items ' . $export_items );
}
wp_reset_postdata();
return $export_items;
}
+ private function get_item_csv($item, $printCol) {
+ $items_metadata = $item->get_metadata();
+ $prepared_item = [];
+ foreach ($items_metadata as $item_metadata) {
+ array_push($prepared_item, $item_metadata->_toArray());
+ }
+ $mapper = $this->mapping_list[$this->mapping_selected];
+ $instance_mapper = new $mapper();
+ $data = $this->map($prepared_item, $instance_mapper);
+ return $this->str_putcsv($data, ',', '"', $printCol);
+ }
+
+ protected function map($item_arr, $mapper) {
+ $ret = $item_arr;
+ if(array_key_exists('metadatum', $item_arr)) { // getting a unique metadatum
+ $ret = $this->map_metadatum($item_arr, $mapper);
+ } else { // array of elements
+ $ret = [];
+ foreach ($item_arr as $item) {
+ if(array_key_exists('metadatum', $item)) {
+ $ret = array_merge($ret, $this->map($item, $mapper) );
+ } else {
+ $ret[] = $this->map($item, $mapper);
+ }
+ }
+ }
+ return $ret;
+ }
+
+ protected function map_metadatum($item_arr, $mapper) {
+ $ret = $item_arr;
+ $metadatum_mapping = $item_arr['metadatum']['exposer_mapping'];
+ if(array_key_exists($mapper->slug, $metadatum_mapping)) {
+ if(
+ is_string($metadatum_mapping[$mapper->slug]) && is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ||
+ is_array($metadatum_mapping[$mapper->slug]) && $mapper->allow_extra_metadata != true
+ ) {
+ throw new \Exception('Invalid Mapper Option');
+ }
+ $slug = '';
+ if(is_string($metadatum_mapping[$mapper->slug])) {
+ $slug = $metadatum_mapping[$mapper->slug];
+ } else {
+ $slug = $metadatum_mapping[$mapper->slug]['slug'];
+ }
+ $ret = [$mapper->prefix.$slug.$mapper->sufix => $item_arr['value']];
+ } elseif($mapper->slug == 'value') {
+ $ret = [$item_arr['metadatum']['name'] => $item_arr['value']];
+ } else {
+ $ret = [];
+ }
+ return $ret;
+ }
+
+ function str_putcsv($item, $delimiter = ',', $enclosure = '"', $printCol = false) {
+ // Open a memory "file" for read/write...
+ $fp = fopen('php://temp', 'r+');
+ $out=[];
+ $col=[];
+ foreach ($item as $key => $value) {
+ $col[] = $key;
+ $out[] = $value;
+ }
+ if ($printCol) {
+ fputcsv($fp, $col, $delimiter, $enclosure);
+ }
+ fputcsv($fp, $out, $delimiter, $enclosure);
+ rewind($fp);
+ $data = fread($fp, 1048576);
+ fclose($fp);
+ return rtrim($data, "\n");
+ }
+
public function options_form() {
ob_start();
?>
diff --git a/src/exporter/class-tainacan-exporter.php b/src/exporter/class-tainacan-exporter.php
index dddb2b5b3..46cbd9a63 100644
--- a/src/exporter/class-tainacan-exporter.php
+++ b/src/exporter/class-tainacan-exporter.php
@@ -469,10 +469,10 @@ class Exporter extends CommunImportExport {
private $output_files = [];
private $mapping_accept = [
'any' => true,
- 'list' => false,
- 'none' => false,
+ 'list' => false
];
- private $mapping_list = [];
+ protected $mapping_list = [];
+ public $mapping_selected = "";
public function __construct($attributess = array()) {
$this->array_attributes = array_merge($this->array_attributes, ['current_collection_item', 'current_collection']);
@@ -488,6 +488,7 @@ class Exporter extends CommunImportExport {
}
}
+ //"Tainacan\\Exposers\\Mappers\\Value"
public function _to_Array($short = false) {
$return = ['id' => $this->get_id()];
foreach ($this->array_attributes as $attr) {
@@ -500,12 +501,12 @@ class Exporter extends CommunImportExport {
$exporter_definition = $Tainacan_Exporter_Handler->get_exporter_by_object($this);
if ($short === false) {
- $return['manual_collection'] = $exporter_definition['manual_collection'];
- $return['manual_mapping'] = $exporter_definition['manual_mapping'];
- $return['mapping_accept'] = $this->mapping_accept;
- $return['mapping_list'] = $this->mapping_list;
- $return['output_files'] = $this->output_files;
- $return['options_form'] = $this->options_form();
+ $return['manual_collection'] = $exporter_definition['manual_collection'];
+ $return['mapping_selected'] = $this->mapping_selected;
+ $return['mapping_accept'] = $this->mapping_accept;
+ $return['mapping_list'] = $this->mapping_list;
+ $return['output_files'] = $this->output_files;
+ $return['options_form'] = $this->options_form();
}
return $return;
@@ -594,26 +595,40 @@ class Exporter extends CommunImportExport {
$this->append_to_file($key, $data);
}
}
-
- public function set_mapping_method($method, $list = []) {
+
+ public function set_mapping_method($method, $default_mapping = 'value', $list = []) {
if ( array_key_exists($method, $this->mapping_accept) ) {
foreach ($this->mapping_accept as &$value) {
$value = false;
}
$this->mapping_accept[$method] = true;
- if(!empty($list)) {
+ if($method == 'any') {
+ $Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
+ $metadatum_mappers = $Tainacan_Exposers->get_mappers();
+ $this->mapping_list = $metadatum_mappers;
+ } else if(!empty($list)) {
$this->mapping_list = $list;
}
+ $this->mapping_selected = $default_mapping;
return true;
}
return false;
}
+
+ public function set_mapping_selected($mapping_selected) {
+ $this->mapping_selected = $mapping_selected;
+ }
+ public function finished() {
+
+ }
+
/**
* runs one iteration
*/
public function run() {
if ($this->is_finished()) {
+ $this->finished();
return false;
}
$steps = $this->get_steps();
diff --git a/src/gutenberg-blocks/tainacan-collections/collections-carousel/index.js b/src/gutenberg-blocks/tainacan-collections/collections-carousel/index.js
index e2941725f..3e6bb2546 100644
--- a/src/gutenberg-blocks/tainacan-collections/collections-carousel/index.js
+++ b/src/gutenberg-blocks/tainacan-collections/collections-carousel/index.js
@@ -25,14 +25,28 @@ registerBlockType('tainacan/collections-carousel', {
},
selectedCollections: {
type: 'array',
- source: 'html',
+ source: 'query',
selector: 'div',
- default: [],
+ query: {
+ dataValue: { source: 'attribute', attribute: 'data-value'},
+ },
+ default: []
},
- featuredItems: {
+ items: {
type: 'array',
- source: 'html',
- selector: 'div',
+ source: 'query',
+ selector: 'picture',
+ query: {
+ style: { source: 'attribute', attribute: 'style'},
+ img: {
+ source: 'query',
+ selector: 'img',
+ query: {
+ src: { source: 'attribute', attribute: 'src'},
+ alt: { source: 'attribute', attribute: 'alt' },
+ }
+ }
+ },
default: [],
},
content1: {
@@ -42,7 +56,7 @@ registerBlockType('tainacan/collections-carousel', {
default: [],
},
content: {
- type: 'array',
+ type: 'string',
source: 'html',
selector: 'div',
default: []
@@ -52,9 +66,21 @@ registerBlockType('tainacan/collections-carousel', {
align: ['full']
},
edit({ attributes, setAttributes, className }) {
+ console.log('edit', attributes);
+
function prepareCollection(collection) {
return ({ collection.name }
);
}
+
+ function prepareItem(item, style) {
+ return (
+
+ );
+ }
function getTop3ItemsOf(collection) {
let collectionID = collection.id;
@@ -70,7 +96,7 @@ registerBlockType('tainacan/collections-carousel', {
});
}
- function prepareContent(content, featuredItems, setAttributes, collection){
+ function prepareContent(content, items, setAttributes, collection){
content.push(
- {featuredItems[0] ?
-
: null
- }
+ {items[0] ? prepareItem(items[0]) : null}
- {featuredItems[1] ?
-
: null
- }
- {featuredItems[2] ?
-
: null
- }
+ {items[1] ? prepareItem(items[1], {width: '42px', height: '42px', marginBottom: '3px'}) : null}
+ {items[2] ? prepareItem(items[2], {width: '42px', height: '42px'}) : null}
-
{collection.name}
+
+ {collection.name}
+
);
@@ -137,11 +153,13 @@ registerBlockType('tainacan/collections-carousel', {
attributes.selectedCollections.push(prepareCollection(option));
getTop3ItemsOf(option).then((res) => {
- attributes.featuredItems.push(res);
+ res.map((item) => {
+ attributes.items.push(prepareItem(item))
+ });
prepareContent(attributes.content1, res, setAttributes, option);
- setAttributes({ featuredItems: attributes.featuredItems });
+ setAttributes({ items: attributes.items });
});
setAttributes({ selectedCollections: attributes.selectedCollections });
@@ -160,7 +178,20 @@ registerBlockType('tainacan/collections-carousel', {
setAttributes( { isOpen: false } ) }>
+ onRequestClose={ () => {
+ setAttributes( { isOpen: false } );
+ setAttributes({
+ content: (
+
+ {attributes.content1.length ?
+ = 3 ? 3 : attributes.content1.length}
+ arrows
+ slides={attributes.content1}/> : null
+ }
+ )});
+ }}>
@@ -179,7 +210,20 @@ registerBlockType('tainacan/collections-carousel', {
{ __('Type '+ autoCompleters[0].triggerPrefix +' for triggering the autocomplete.', 'tainacan') }
-
@@ -187,24 +231,28 @@ registerBlockType('tainacan/collections-carousel', {
}
- = 3 ? 3 : attributes.content1.length}
- arrows
- slides={attributes.content1}/>
+ {attributes.content1.length ?
+ = 3 ? 3 : attributes.content1.length}
+ arrows
+ slides={attributes.content1}/> : null
+ }
);
},
save({ attributes }) {
- return (
-
- = 3 ? 3 : attributes.content1.length}
- arrows
- slides={attributes.content1}/>
-
- );
+ // return (
+ //
+ // = 3 ? 3 : attributes.content1.length}
+ // arrows
+ // slides={attributes.content1}/>
+ //
+ // );
+
+ return attributes.content;
},
});
\ No newline at end of file
diff --git a/src/importer/class-tainacan-csv.php b/src/importer/class-tainacan-csv.php
index 7a050c22d..88ee4268f 100644
--- a/src/importer/class-tainacan-csv.php
+++ b/src/importer/class-tainacan-csv.php
@@ -2,6 +2,7 @@
namespace Tainacan\Importer;
use Tainacan;
+use Tainacan\Entities;
class CSV extends Importer {
@@ -140,6 +141,10 @@ class CSV extends Importer {
return false;
}
+ if( $this->get_option('item_id_index') ){
+ $this->handle_item_id( $values );
+ }
+
foreach ( $collection_definition['mapping'] as $metadatum_id => $header) {
$metadatum = new \Tainacan\Entities\Metadatum($metadatum_id);
@@ -562,6 +567,9 @@ class CSV extends Importer {
}
+ /**
+ * @param $status string the item ID
+ */
private function handle_item_id( $values ){
$item_id_index = $this->set_option('item_id_index');
@@ -570,4 +578,151 @@ class CSV extends Importer {
$this->add_transient( 'item_action',$this->get_option('repeated_item') );
}
}
+
+ /**
+ * insert processed item from source to Tainacan
+ *
+ * @param array $processed_item Associative array with metadatum source's as index with
+ * its value or values
+ * @param integet $collection_index The index in the $this->collections array of the collection the item is beeing inserted into
+ *
+ * @return Tainacan\Entities\Item Item inserted
+ */
+ public function insert( $processed_item, $collection_index ) {
+
+ remove_action( 'post_updated', 'wp_save_post_revision' );
+ $collections = $this->get_collections();
+ $collection_definition = isset($collections[$collection_index]) ? $collections[$collection_index] : false;
+ if ( !$collection_definition || !is_array($collection_definition) || !isset($collection_definition['id']) || !isset($collection_definition['mapping']) ) {
+ $this->add_error_log('Collection misconfigured');
+ return false;
+ }
+
+ $collection = \Tainacan\Repositories\Collections::get_instance()->fetch($collection_definition['id']);
+
+ $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
+ $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
+ $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
+
+ $Tainacan_Items->disable_logs();
+ $Tainacan_Metadata->disable_logs();
+ $Tainacan_Item_Metadata->disable_logs();
+
+ $item = new Entities\Item( ( $this->get_transient('item_id') ) ? $this->get_transient('item_id') : 0 );
+ $itemMetadataArray = [];
+
+ if( is_array( $processed_item ) ){
+ foreach ( $processed_item as $metadatum_source => $values ){
+ $tainacan_metadatum_id = array_search( $metadatum_source, $collection_definition['mapping'] );
+ $metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id );
+
+ if( $metadatum instanceof Entities\Metadatum ){
+ $singleItemMetadata = new Entities\Item_Metadata_Entity( $item, $metadatum); // *empty item will be replaced by inserted in the next foreach
+
+ if( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Taxonomy' ){
+
+ $ids = $this->insert_hierarchy( $metadatum, $values );
+ $singleItemMetadata->set_value( $ids );
+ } else {
+ $singleItemMetadata->set_value( $values );
+ }
+
+ $itemMetadataArray[] = $singleItemMetadata;
+ } else {
+ $this->add_error_log('Metadata ' . $metadatum_source . ' not found');
+ }
+
+ }
+ }
+
+ if( !empty( $itemMetadataArray ) && $collection instanceof Entities\Collection ){
+ $item->set_collection( $collection );
+
+ if( $item->validate() ){
+ $insertedItem = $Tainacan_Items->insert( $item );
+ } else {
+ $this->add_error_log( 'Error inserting item' );
+ $this->add_error_log( $item->get_errors() );
+ return false;
+ }
+
+ foreach ( $itemMetadataArray as $itemMetadata ) {
+ $itemMetadata->set_item( $insertedItem ); // *I told you
+
+ if( $itemMetadata->validate() ){
+ $result = $Tainacan_Item_Metadata->insert( $itemMetadata );
+ } else {
+ $this->add_error_log('Error saving value for ' . $itemMetadata->get_metadatum()->get_name());
+ $this->add_error_log($itemMetadata->get_errors());
+ continue;
+ }
+
+ //if( $result ){
+ // $values = ( is_array( $itemMetadata->get_value() ) ) ? implode( PHP_EOL, $itemMetadata->get_value() ) : $itemMetadata->get_value();
+ // $this->add_log( 'Item ' . $insertedItem->get_id() .
+ // ' has inserted the values: ' . $values . ' on metadata: ' . $itemMetadata->get_metadatum()->get_name() );
+ //} else {
+ // $this->add_error_log( 'Item ' . $insertedItem->get_id() . ' has an error' );
+ //}
+ }
+
+ $insertedItem->set_status('publish' );
+
+ if($insertedItem->validate()) {
+ $insertedItem = $Tainacan_Items->update( $insertedItem );
+
+ $this->after_inserted_item( $insertedItem, $collection_index );
+ } else {
+ $this->add_error_log( 'Error publishing Item' );
+ $this->add_error_log( $insertedItem->get_errors() );
+ return false;
+ }
+
+ return $insertedItem;
+
+ } else {
+ $this->add_error_log( 'Collection not set');
+ return false;
+ }
+
+ }
+
+ /**
+ * @param $metadatum the metadata
+ * @param $values the categories names
+ *
+ * @return array empty with no category or array with IDs
+ */
+ private function insert_hierarchy( $metadatum, $values ){
+
+ $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
+ $taxonomy = new Entities\Taxonomy( $metadatum->get_metadata_type_options()['taxonomy_id']);
+ $exploded_values = explode(">>",$values);
+
+ if( is_array($exploded_values) ){
+ $parent = 0;
+
+ foreach ( $exploded_values as $key => $value) {
+ $value = trim($value);
+
+ $exists = term_exists( $value ,$taxonomy->get_db_identifier(), $parent );
+ if( 0 !== $exists && null !== $exists && isset($exists['term_id']) ){
+ $exists = new Entities\Term($exists['term_id']);
+ $parent = $term->get_id();
+ } else {
+ $term = new Entities\Term();
+ $term->set_name( $value );
+ $term->set_parent( $parent );
+ $term->set_taxonomy( $taxonomy->get_db_identifier() );
+ $term = $Tainacan_Terms->insert( $term );
+
+ $parent = $term->get_id();
+ }
+ }
+
+ return $parent !== 0 ? $parent : false;
+ } else {
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php
index db7b25e68..bd39a9e07 100644
--- a/src/importer/class-tainacan-importer.php
+++ b/src/importer/class-tainacan-importer.php
@@ -786,7 +786,7 @@ abstract class Importer {
$Tainacan_Metadata->disable_logs();
$Tainacan_Item_Metadata->disable_logs();
- $item = new Entities\Item();
+ $item = new Entities\Item( ( $this->get_transient('item_id') ) ? $this->get_transient('item_id') : 0 );
$itemMetadataArray = [];
if( is_array( $processed_item ) ){
diff --git a/src/importer/class-tainacan-old-tainacan.php b/src/importer/class-tainacan-old-tainacan.php
index 2e4305e7c..032b9dcfa 100644
--- a/src/importer/class-tainacan-old-tainacan.php
+++ b/src/importer/class-tainacan-old-tainacan.php
@@ -117,7 +117,9 @@ class Old_Tainacan extends Importer{
foreach ($this->get_repo_metadata() as $metadata) {
if (isset($metadata->slug) && strpos($metadata->slug, 'socialdb_property_fixed') === false) {
- $metadatum_id = $this->create_metadata( $metadata );
+ $metadatum_id = $this->create_metadata( $metadata );
+ } elseif ( strpos($metadata->slug, 'socialdb_property_fixed_tags') !== false ){
+ $metadatum_id = $this->create_metadata( $metadata );
}
}
@@ -150,6 +152,14 @@ class Old_Tainacan extends Importer{
$map[$metadatum_id] = $metadatum_old->id;
}
+ } else if( isset($metadatum_old->slug) && strpos($metadatum_old->slug, 'socialdb_property_fixed_tags') !== false
+ && isset($metadatum_old->type) && strpos($metadatum_old->type, 'checkbox') !== false
+ ){
+ $metadatum_id = $this->create_metadata( $metadatum_old, $collection_id );
+ $this->add_log('Creating tag');
+ if( $metadatum_id ){
+ $map[$metadatum_id] = $metadatum_old->id;
+ }
}
}
@@ -383,10 +393,6 @@ class Old_Tainacan extends Importer{
$value = $values;
}
- if( is_array($value) ){
- $value = array_filter($value);
- }
-
$item_metadata->set_value($value);
} else if( $metadatum->type === 'item' ){ // RELATIONSHIPS
@@ -711,6 +717,8 @@ class Old_Tainacan extends Importer{
* @return int $metadatum_id
*/
protected function create_metadata( $node_metadata_old, $collection_id = null){
+ $this->add_log('Creating metadata' . $meta->name);
+
$newMetadatum = new Entities\Metadatum();
$meta = $node_metadata_old;
@@ -841,7 +849,7 @@ class Old_Tainacan extends Importer{
$type = "Numeric";
} else if(strcmp($type, 'item') === 0) {
$type = "Relationship";
- } else if(strcmp($type, 'tree') === 0 || strcmp($type, 'selectbox')) {
+ } else if(strcmp($type, 'tree') === 0 || strcmp($type, 'selectbox') || strcmp($type, 'checkbox')) {
$type = "Taxonomy";
} else if(strcmp($type, 'compound') === 0) {
$type = "Compound";
diff --git a/src/js/axios/axios.js b/src/js/axios/axios.js
index 7568594c1..c0a0f0127 100644
--- a/src/js/axios/axios.js
+++ b/src/js/axios/axios.js
@@ -12,4 +12,7 @@ export const wp = axios.create({
wp.defaults.headers.common['X-WP-Nonce'] = tainacan_plugin.nonce;
-export default { tainacan, wp };
\ No newline at end of file
+export const CancelToken = axios.CancelToken;
+export const isCancel = axios.isCancel;
+
+export default { tainacan, wp, CancelToken, isCancel };
\ No newline at end of file
diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js
index 08aadbcc0..d15823f8b 100644
--- a/src/js/event-bus-search.js
+++ b/src/js/event-bus-search.js
@@ -11,10 +11,10 @@ export default {
query: {},
collectionId: undefined,
taxonomy: undefined,
- termId: undefined
+ termId: undefined,
+ searchCancel: undefined
},
- created(){
-
+ created() {
this.$on('input', data => {
this.$store.dispatch('search/setPage', 1);
@@ -212,16 +212,16 @@ export default {
let error = this.errors.find( errorItem => errorItem.metadatum_id === filter_id );
return ( error ) ? error.errors : false;
},
- listener(){
- const components = this.getAllComponents();
- for (let eventElement of components){
- eventElement.addEventListener('input', (event) => {
- if( event.detail ) {
- this.add_metaquery( event.detail[0] );
- }
- });
- }
- },
+ // listener(){
+ // const components = this.getAllComponents();
+ // for (let eventElement of components){
+ // eventElement.addEventListener('input', (event) => {
+ // if( event.detail ) {
+ // this.add_metaquery( event.detail[0] );
+ // }
+ // });
+ // }
+ // },
setPage(page) {
this.$store.dispatch('search/setPage', page);
this.updateURLQueries();
@@ -304,24 +304,36 @@ export default {
// Forces fetch_only to be filled before any search happens
if (this.$store.getters['search/getPostQuery']['fetch_only'] == undefined) {
this.$emit( 'hasToPrepareMetadataAndFilters', to);
- } else {
+ } else {
+
+ // Cancels previous Request
+ if (this.searchCancel != undefined)
+ this.searchCancel.cancel('Item search Canceled.');
+
this.$store.dispatch('collection/fetchItems', {
'collectionId': this.collectionId,
'isOnTheme': (this.$route.name == null),
'termId': this.termId,
'taxonomy': this.taxonomy
- })
- .then((res) => {
- this.$emit( 'isLoadingItems', false);
- this.$emit( 'hasFiltered', res.hasFiltered);
+ }).then((resp) => {
+ // The actual fetch item request
+ resp.request.then((res) => {
+ this.$emit( 'isLoadingItems', false);
+ this.$emit( 'hasFiltered', res.hasFiltered);
- if(res.advancedSearchResults){
- this.$emit('advancedSearchResults', res.advancedSearchResults);
- }
- })
- .catch(() => {
- this.$emit( 'isLoadingItems', false);
+ if(res.advancedSearchResults){
+ this.$emit('advancedSearchResults', res.advancedSearchResults);
+ }
+ })
+ .catch(() => {
+ this.$emit( 'isLoadingItems', false);
+ });
+
+ // Search Request Token for cancelling
+ this.searchCancel = resp.source;
});
+
+
}
},
diff --git a/src/js/event-bus-web-components.js b/src/js/event-bus-web-components.js
index f7562685c..11207947a 100644
--- a/src/js/event-bus-web-components.js
+++ b/src/js/event-bus-web-components.js
@@ -11,7 +11,7 @@ export const eventBus = new Vue({
if( tainacan_plugin.components ){
this.componentsTag = tainacan_plugin.components;
}
- this.$on('input', data => this.updateValue(data) );
+ this.$on('input', this.updateValue );
},
watch: {
errors() {
@@ -24,21 +24,21 @@ export const eventBus = new Vue({
this.componentsTag.push( name );
}
},
- listener(){
- const components = this.getAllComponents();
- for (let eventElement of components){
- eventElement.addEventListener('input', (event) => {
+ // listener(){
+ // const components = this.getAllComponents();
+ // for (let eventElement of components){
+ // eventElement.addEventListener('input', (event) => {
- if (event.detail && event.detail[0] ){
- this.updateValue({
- item_id: $(eventElement).attr("item_id"),
- metadatum_id: $(eventElement).attr("metadatum_id"),
- values: event.detail
- })
- }
- });
- }
- },
+ // if (event.detail && event.detail[0] ){
+ // this.updateValue({
+ // item_id: $(eventElement).attr("item_id"),
+ // metadatum_id: $(eventElement).attr("metadatum_id"),
+ // values: event.detail
+ // })
+ // }
+ // });
+ // }
+ // },
updateValue(data){
this.$emit('isUpdatingValue', true);
@@ -128,6 +128,9 @@ export const eventBus = new Vue({
}
}
}
+ },
+ beforeUpdate() {
+ this.$off('input', this.updateValue );
}
});
diff --git a/src/js/store/modules/bulk-edition/actions.js b/src/js/store/modules/bulk-edition/actions.js
index 0bd4929e9..f210be364 100644
--- a/src/js/store/modules/bulk-edition/actions.js
+++ b/src/js/store/modules/bulk-edition/actions.js
@@ -10,6 +10,12 @@ export const createEditGroup = ({commit}, parameters) => {
bulkEditParams = {
items_ids: object,
};
+ if (parameters.order != undefined && parameters.order != undefined)
+ bulkEditParams['options'] = {
+ order: parameters.order,
+ orderby: parameters.orderBy
+ };
+
} else if(object.constructor.name === 'Object'){
bulkEditParams = {
use_query: object,
@@ -25,6 +31,21 @@ export const createEditGroup = ({commit}, parameters) => {
});
};
+export const fetchGroup = ({commit}, { collectionId, groupId }) => {
+
+ return new Promise ((resolve, reject) => {
+ axios.tainacan.get(`/collection/${collectionId}/bulk-edit/${groupId}`)
+ .then(response => {
+ commit('setGroup', response.data);
+ resolve(response.data);
+ })
+ .catch(error => {
+ console.log(error);
+ reject(error);
+ });
+ });
+};
+
export const setValueInBulk = ({commit}, parameters) => {
let groupID = parameters.groupID;
let collectionID = parameters.collectionID;
@@ -168,4 +189,20 @@ export const deleteItemsInBulk = ({commit}, parameters) => {
console.log(error);
commit('setActionResult', error.response.data);
});
+};
+
+// SEQUENCE EDIT SPECIFIC
+export const fetchItemIdInSequence = ({commit}, { collectionId, sequenceId, itemPosition }) => {
+
+ return new Promise ((resolve, reject) => {
+ axios.tainacan.get(`/collection/${collectionId}/bulk-edit/${sequenceId}/sequence/${itemPosition}`)
+ .then(response => {
+ commit('setItemIdInSequence', response.data);
+ resolve(response.data);
+ })
+ .catch(error => {
+ console.log(error);
+ reject(error);
+ });
+ });
};
\ No newline at end of file
diff --git a/src/js/store/modules/bulk-edition/getters.js b/src/js/store/modules/bulk-edition/getters.js
index ca3bb84bc..d7b245096 100644
--- a/src/js/store/modules/bulk-edition/getters.js
+++ b/src/js/store/modules/bulk-edition/getters.js
@@ -2,6 +2,14 @@ export const getGroupID = state => {
return state.group.id;
};
+export const getGroup = state => {
+ return state.group;
+};
+
export const getActionResult = state => {
return state.actionResult;
+};
+
+export const getItemIdInSequence = state => {
+ return state.itemIdInSequence;
};
\ No newline at end of file
diff --git a/src/js/store/modules/bulk-edition/index.js b/src/js/store/modules/bulk-edition/index.js
index 41339308c..1f5baddb7 100644
--- a/src/js/store/modules/bulk-edition/index.js
+++ b/src/js/store/modules/bulk-edition/index.js
@@ -5,6 +5,7 @@ import * as getters from './getters.js'
const state = {
group: null,
actionResult: null,
+ itemIdInSequence: null
};
export default {
diff --git a/src/js/store/modules/bulk-edition/mutations.js b/src/js/store/modules/bulk-edition/mutations.js
index 6e8060eae..dc1b7f51d 100644
--- a/src/js/store/modules/bulk-edition/mutations.js
+++ b/src/js/store/modules/bulk-edition/mutations.js
@@ -4,4 +4,8 @@ export const setGroup = (state, group) => {
export const setActionResult = (state, actionResult) => {
state.actionResult = actionResult;
+};
+
+export const setItemIdInSequence = (state, itemIdInSequence) => {
+ state.itemIdInSequence = itemIdInSequence;
};
\ No newline at end of file
diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js
index f0535047d..d9de66164 100644
--- a/src/js/store/modules/collection/actions.js
+++ b/src/js/store/modules/collection/actions.js
@@ -1,97 +1,109 @@
import axios from '../../../axios/axios';
import qs from 'qs';
+// THE ITEMS SEARCH
export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, isOnTheme, termId, taxonomy }) => {
commit('cleanItems');
- return new Promise ((resolve, reject) => {
-
- // Adds queries for filtering
- let postQueries = JSON.parse(JSON.stringify(rootGetters['search/getPostQuery']));
+ const source = axios.CancelToken.source();
- // Sets a flag to inform components that an empty sate is or not due to filtering
- let hasFiltered = false;
- let advancedSearchResults = false;
+ return new Object({
+ request: new Promise ((resolve, reject) => {
+
+ // Adds queries for filtering
+ let postQueries = JSON.parse(JSON.stringify(rootGetters['search/getPostQuery']));
- if ( (postQueries.metaquery != undefined &&
- (Object.keys(postQueries.metaquery).length > 0 ||
- postQueries.metaquery.length > 0)) || (postQueries.taxquery != undefined &&
- (Object.keys(postQueries.taxquery).length > 0 ||
- postQueries.taxquery.length > 0)) ) {
-
- hasFiltered = true;
+ // Sets a flag to inform components that an empty sate is or not due to filtering
+ let hasFiltered = false;
+ let advancedSearchResults = false;
- if(postQueries.advancedSearch){
- advancedSearchResults = postQueries.advancedSearch;
+ if ( (postQueries.metaquery != undefined &&
+ (Object.keys(postQueries.metaquery).length > 0 ||
+ postQueries.metaquery.length > 0)) || (postQueries.taxquery != undefined &&
+ (Object.keys(postQueries.taxquery).length > 0 ||
+ postQueries.taxquery.length > 0)) ) {
+
+ hasFiltered = true;
+
+ if(postQueries.advancedSearch){
+ advancedSearchResults = postQueries.advancedSearch;
+ }
}
- }
-
- // Sets term query in case it's on a term items page
- if (termId != undefined && taxonomy != undefined) {
-
- if (postQueries.taxquery == undefined)
- postQueries.taxquery = [];
-
- postQueries.taxquery.push({
- taxonomy: taxonomy,
- terms:[ termId ],
- compare: 'IN'
- });
- }
-
- let query = qs.stringify(postQueries);
-
- // Guarantees at least empty fetch_only are passed in case none is found
- if (qs.stringify(postQueries.fetch_only) == ''){
- dispatch('search/add_fetchonly', {}, { root: true });
- }
-
- if (qs.stringify(postQueries.fetch_only['meta']) == ''){
- dispatch('search/add_fetchonly_meta', 0, { root: true });
- }
-
- // Differentiates between repository level and collection level queries
- let endpoint = '/collection/'+ collectionId +'/items?';
-
- if (collectionId == undefined){
- endpoint = '/items?';
- }
-
- if (!isOnTheme){
- if (postQueries.view_mode != undefined)
- postQueries.view_mode = null;
-
- endpoint = endpoint + 'context=edit&'
- } else {
- if (postQueries.admin_view_mode != undefined)
- postQueries.admin_view_mode = null;
- }
-
- axios.tainacan.get(endpoint+query)
- .then(res => {
- let items = res.data;
- let viewModeObject = tainacan_plugin.registered_view_modes[postQueries.view_mode];
+ // Sets term query in case it's on a term items page
+ if (termId != undefined && taxonomy != undefined) {
- if (isOnTheme && viewModeObject != undefined && viewModeObject.type == 'template') {
- commit('setItemsListTemplate', items);
- resolve({'itemsListTemplate': items, 'total': res.headers['x-wp-total'], hasFiltered: hasFiltered, advancedSearchResults: advancedSearchResults});
+ if (postQueries.taxquery == undefined)
+ postQueries.taxquery = [];
+
+ postQueries.taxquery.push({
+ taxonomy: taxonomy,
+ terms:[ termId ],
+ compare: 'IN'
+ });
+ }
+
+ let query = qs.stringify(postQueries);
+
+ // Guarantees at least empty fetch_only are passed in case none is found
+ if (qs.stringify(postQueries.fetch_only) == ''){
+ dispatch('search/add_fetchonly', {}, { root: true });
+ }
+
+ if (qs.stringify(postQueries.fetch_only['meta']) == ''){
+ dispatch('search/add_fetchonly_meta', 0, { root: true });
+ }
+
+ // Differentiates between repository level and collection level queries
+ let endpoint = '/collection/'+ collectionId +'/items?';
+
+ if (collectionId == undefined){
+ endpoint = '/items?';
+ }
+
+ if (!isOnTheme){
+ if (postQueries.view_mode != undefined)
+ postQueries.view_mode = null;
+
+ endpoint = endpoint + 'context=edit&'
} else {
- commit('setItems', items);
- resolve({
- 'items': items,
- 'total': res.headers['x-wp-total'],
- totalPages: res.headers['x-wp-totalpages'],
- hasFiltered: hasFiltered,
- advancedSearchResults: advancedSearchResults });
- }
- dispatch('search/setTotalItems', res.headers['x-wp-total'], { root: true } );
- dispatch('search/setTotalPages', res.headers['x-wp-totalpages'], { root: true } );
- })
- .catch(error => reject(error));
-
- });
-
+ if (postQueries.admin_view_mode != undefined)
+ postQueries.admin_view_mode = null;
+ }
+
+ axios.tainacan.get(endpoint+query, {
+ cancelToken: source.token
+ })
+ .then(res => {
+
+ let items = res.data;
+ let viewModeObject = tainacan_plugin.registered_view_modes[postQueries.view_mode];
+
+ if (isOnTheme && viewModeObject != undefined && viewModeObject.type == 'template') {
+ commit('setItemsListTemplate', items);
+ resolve({'itemsListTemplate': items, 'total': res.headers['x-wp-total'], hasFiltered: hasFiltered, advancedSearchResults: advancedSearchResults});
+ } else {
+ commit('setItems', items);
+ resolve({
+ 'items': items,
+ 'total': res.headers['x-wp-total'],
+ totalPages: res.headers['x-wp-totalpages'],
+ hasFiltered: hasFiltered,
+ advancedSearchResults: advancedSearchResults });
+ }
+ dispatch('search/setTotalItems', res.headers['x-wp-total'], { root: true } );
+ dispatch('search/setTotalPages', res.headers['x-wp-totalpages'], { root: true } );
+ })
+ .catch((thrown) => {
+ if (axios.isCancel(thrown)) {
+ console.log('Request canceled: ', thrown.message);
+ } else {
+ reject(thrown);
+ }
+ });
+ }),
+ source: source
+ })
};
export const deleteItem = ({ commit }, { itemId, isPermanently }) => {
@@ -115,9 +127,13 @@ export const deleteItem = ({ commit }, { itemId, isPermanently }) => {
});
};
-export const fetchCollections = ({commit} , { page, collectionsPerPage, status }) => {
+export const fetchCollections = ({commit} , { page, collectionsPerPage, status, contextEdit }) => {
+
return new Promise((resolve, reject) => {
- let endpoint = '/collections?paged='+page+'&perpage='+collectionsPerPage+'&context=edit';
+ let endpoint = '/collections?paged='+page+'&perpage='+collectionsPerPage;
+
+ if (contextEdit)
+ endpoint = endpoint + '&context=edit';
if (status != '' && status != undefined)
endpoint = endpoint + '&status=' + status;
diff --git a/src/js/store/modules/search/actions.js b/src/js/store/modules/search/actions.js
index 656bfe86b..6ff8b0423 100644
--- a/src/js/store/modules/search/actions.js
+++ b/src/js/store/modules/search/actions.js
@@ -8,6 +8,7 @@ export const set_postquery = ({ commit }, postquery ) => {
};
export const set_advanced_query = ({commit}, advancedSearchQuery) => {
+ commit('removePostQueryAttribute', 'search');
commit('setAdvancedSearchQuery', advancedSearchQuery);
};
@@ -74,7 +75,7 @@ export const setStatus= ({ commit }, status ) => {
// Sorting queries
export const setOrderBy = ({ state, commit }, orderBy ) => {
- commit('cleanPostQueryAttribute', { attr: 'orderby' } );
+ commit('removePostQueryAttribute', 'orderby');
// Primitive Types: string, date, item, term, compound, float
if (orderBy.slug == 'creation_date') {
diff --git a/src/js/store/modules/search/mutations.js b/src/js/store/modules/search/mutations.js
index bf9208fc5..ed3de27da 100644
--- a/src/js/store/modules/search/mutations.js
+++ b/src/js/store/modules/search/mutations.js
@@ -4,8 +4,8 @@ export const setPostQueryAttribute = ( state, { attr, value }) => {
Vue.set( state.postquery, attr , value );
};
-export const cleanPostQueryAttribute = ( state, { attr }) => {
- Vue.set( state.postquery, attr , null );
+export const removePostQueryAttribute = ( state, attr) => {
+ delete state.postquery[`${attr}`];
};
export const setPostQuery = ( state, postquery ) => {
@@ -30,7 +30,7 @@ export const addMetaQuery = ( state, filter ) => {
compare: filter.compare,
type: filter.type
} );
- } else{
+ } else {
state.postquery.metaquery.push({
key: filter.metadatum_id,
value: filter.value,
@@ -42,14 +42,16 @@ export const addMetaQuery = ( state, filter ) => {
export const addTaxQuery = ( state, filter ) => {
state.postquery.taxquery = ( ! state.postquery.taxquery || state.postquery.taxquery.length == undefined ) ? [] : state.postquery.taxquery;
+
let index = state.postquery.taxquery.findIndex( item => item.taxonomy === filter.taxonomy);
+
if ( index >= 0 ){
Vue.set( state.postquery.taxquery, index, {
taxonomy: filter.taxonomy,
terms: filter.terms,
compare: filter.compare
} );
- }else{
+ } else {
state.postquery.taxquery.push({
taxonomy: filter.taxonomy,
terms: filter.terms,
@@ -68,11 +70,13 @@ export const addFetchOnly = ( state, metadatum ) => {
};
export const addFetchOnlyMeta = ( state, metadatum ) => {
state.postquery.fetch_only = ( ! state.postquery.fetch_only ) ? { '0': 'thumbnail', 'meta': [], '1': 'creation_date', '2': 'author_name' } : state.postquery.fetch_only;
- // console.log(state.postquery.fetch_only);
+ // console.log(state.postquery.fetch_only);
//console.log(state.postquery.fetch_only['meta']);
state.postquery.fetch_only['meta'] = ( ! state.postquery.fetch_only['meta'] ) ? [] : state.postquery.fetch_only['meta'];
+
let index = state.postquery.fetch_only['meta'].findIndex( item => item == metadatum);
- if ( index >= 0 ){
+
+ if ( index >= 0 ){
state.postquery.fetch_only['meta'][index] = metadatum;
} else {
state.postquery.fetch_only['meta'].push(metadatum);
@@ -90,6 +94,7 @@ export const removeFetchOnly = ( state, metadatum ) => {
export const removeFetchOnlyMeta = ( state, metadatum ) => {
if(state.postquery.fetch_only['meta'] != undefined) {
let index = state.postquery.fetch_only['meta'].findIndex( item => item == metadatum);
+
if (index >= 0) {
state.postquery.fetch_only['meta'].splice(index, 1);
}
@@ -98,7 +103,9 @@ export const removeFetchOnlyMeta = ( state, metadatum ) => {
export const removeMetaQuery = ( state, filter ) => {
state.postquery.metaquery = ( ! state.postquery.metaquery ) ? [] : state.postquery.metaquery;
+
let index = state.postquery.metaquery.findIndex( item => item.key == filter.metadatum_id);
+
if (index >= 0) {
state.postquery.metaquery.splice(index, 1);
}
@@ -106,15 +113,12 @@ export const removeMetaQuery = ( state, filter ) => {
export const removeTaxQuery = ( state, filter ) => {
let index = state.postquery.taxquery.findIndex( item => item.taxonomy == filter.taxonomy);
+
if (index >= 0) {
state.postquery.taxquery.splice(index, 1);
}
};
-export const removePostQueryAttribute = ( state, attribute) => {
- Vue.set( state.postquery, attribute , '');
-};
-
export const setTotalItems = ( state, total ) => {
state.totalItems = total;
};
@@ -125,10 +129,11 @@ export const setTotalPages = ( state, totalPages ) => {
export const setSearchQuery = ( state, searchQuery ) => {
- if (searchQuery != '')
+ if (searchQuery != '') {
state.postquery.search = searchQuery;
- else
- state.postquery.search = undefined;
+ } else {
+ delete state.postquery.search;
+ }
};
export const setStatus = ( state, status ) => {
@@ -145,16 +150,21 @@ export const setAdminViewMode = ( state, adminViewMode ) => {
export const addFilterTag = ( state, filterTag ) => {
state.filter_tags = ( ! state.filter_tags) ? [] : state.filter_tags;
+
let index = state.filter_tags.findIndex( tag => tag.filterId == filterTag.filterId);
- if ( index >= 0 )
- Vue.set( state.filter_tags, index, filterTag );
- else
+
+ if ( index >= 0 ) {
+ Vue.set(state.filter_tags, index, filterTag);
+ } else {
state.filter_tags.push(filterTag);
+ }
};
export const removeFilterTag = ( state, filterTag ) => {
state.filter_tags = ( ! state.filter_tags ) ? [] : state.filter_tags;
+
let index = state.filter_tags.findIndex( tag => tag.filterId == filterTag.filterId);
+
if (index >= 0) {
state.filter_tags.splice(index, 1);
}
@@ -173,5 +183,5 @@ export const cleanTaxQueries = (state) => {
};
export const cleanFetchOnly = (state) => {
- state.postquery.fetch_only = undefined;
+ delete state.postquery.fetch_only;
};
\ No newline at end of file
diff --git a/src/theme-helper/view-mode-masonry.vue b/src/theme-helper/view-mode-masonry.vue
index b3beabfd8..cd85be182 100644
--- a/src/theme-helper/view-mode-masonry.vue
+++ b/src/theme-helper/view-mode-masonry.vue
@@ -14,7 +14,7 @@
{{ $i18n.get('info_no_item_found') }}
-
+