From 747e2d11dc5e22643ebbfa10503ab64e7e5e714e Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 21 Sep 2018 09:27:14 -0300 Subject: [PATCH 01/22] create import terms --- docs/importer-flow.md | 4 +- .../class-tainacan-importer-handler.php | 9 ++ src/importer/class-tainacan-term-importer.php | 90 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/importer/class-tainacan-term-importer.php diff --git a/docs/importer-flow.md b/docs/importer-flow.md index 8fab378b1..1212f09d7 100644 --- a/docs/importer-flow.md +++ b/docs/importer-flow.md @@ -14,8 +14,8 @@ This method takes an array as argument, with the defintion of your importer. The ``` @type string $name The name of the importer. e.g. 'Example Importer' - @type string $slug A unique slug for the importer. e.g. 'This is an example importer description' - @type string $description The importer description. e.g. 'example-importer' + @type string $slug A unique slug for the importer. e.g. 'example-importer' + @type string $description The importer description. e.g. 'This is an example importer description' @type string $class_name The Importer Class. e.g. '\Tainacan\Importer\Test_Importer' @type bool $manual_mapping Wether Tainacan must present the user with an interface to manually map the metadata from the source to the target collection. diff --git a/src/importer/class-tainacan-importer-handler.php b/src/importer/class-tainacan-importer-handler.php index 920664c69..52886bbba 100644 --- a/src/importer/class-tainacan-importer-handler.php +++ b/src/importer/class-tainacan-importer-handler.php @@ -43,6 +43,15 @@ class Importer_Handler { 'manual_mapping' => false, ]); + $this->register_importer([ + 'name' => 'Vocabularies', + 'description' => __('Importa a terms - vocabularies', 'tainacan'), + 'slug' => 'term_vocabularies', + 'class_name' => '\Tainacan\Importer\Term_Importer', + 'manual_collection' => false, + 'manual_mapping' => false, + ]); + do_action('tainacan_register_importers'); } diff --git a/src/importer/class-tainacan-term-importer.php b/src/importer/class-tainacan-term-importer.php new file mode 100644 index 000000000..d72457269 --- /dev/null +++ b/src/importer/class-tainacan-term-importer.php @@ -0,0 +1,90 @@ +add_import_method('file'); + $this->remove_import_method('both'); + $this->remove_import_method('url'); + + $this->set_default_options([ + 'delimiter' => ',' + ]); + } + + public function options_form() { + ob_start(); + ?> +
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+ +
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ + namespace . '/taxonomies' + ); + $response = $this->server->dispatch($request); + echo $response; + + ?> +
+
+ + add_log('Proccessing item index ' . $index . ' in collection ' . $collection_definition['id'] ); + } +} \ No newline at end of file From d306783e1908cc173505ed1cf3c8e06c59979bd6 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sun, 23 Sep 2018 21:17:43 -0300 Subject: [PATCH 02/22] import csv with terms --- .../class-tainacan-importer-handler.php | 6 +- src/importer/class-tainacan-term-importer.php | 79 +++++++++++++++---- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/src/importer/class-tainacan-importer-handler.php b/src/importer/class-tainacan-importer-handler.php index 52886bbba..ec6588ca2 100644 --- a/src/importer/class-tainacan-importer-handler.php +++ b/src/importer/class-tainacan-importer-handler.php @@ -44,9 +44,9 @@ class Importer_Handler { ]); $this->register_importer([ - 'name' => 'Vocabularies', - 'description' => __('Importa a terms - vocabularies', 'tainacan'), - 'slug' => 'term_vocabularies', + 'name' => 'Terms', + 'description' => __('Import a terms', 'tainacan'), + 'slug' => 'terms', 'class_name' => '\Tainacan\Importer\Term_Importer', 'manual_collection' => false, 'manual_mapping' => false, diff --git a/src/importer/class-tainacan-term-importer.php b/src/importer/class-tainacan-term-importer.php index d72457269..781148a14 100644 --- a/src/importer/class-tainacan-term-importer.php +++ b/src/importer/class-tainacan-term-importer.php @@ -55,7 +55,7 @@ class Term_Importer extends Importer {
-
+

@@ -64,27 +64,78 @@ class Term_Importer extends Importer {
- namespace . '/taxonomies' - ); - $response = $this->server->dispatch($request); - echo $response; + fetch( [ + 'status' => [ + 'auto-draft', + 'draft', + 'publish', + 'private' + ] + ], 'OBJECT' ); + foreach( $taxonomies as $taxonomie) { + ?> + + +
add_log('Proccessing item index ' . $index . ' in collection ' . $collection_definition['id'] ); + + if (($handle = fopen($this->tmp_file, "r")) !== false) { + $file = $handle; + } else { + $this->add_error_log(' Error reading the file '); + return false; + } + + $term_repo = \Tainacan\Repositories\Terms::get_instance(); + $parent = array(); + $position = 0; + $last_term = 0; + $auxId = 1; + $taxonomy_id = $this->get_option('taxonomies'); + while (($values = fgetcsv($file, 0, $this->get_option('delimiter'), '"')) !== FALSE) { + if ($values[$position] == '') { // next degree + $position++; + array_push($parent, $last_term); + } + if ($position > 0 && $values[$position-1] != '') { // back degree + $position--; + array_pop($parent); + } + + $term = new \Tainacan\Entities\Term(); + $term->set_name($values[$position]); + $term->set_description($values[$position+1]); + $term->set_taxonomy($taxonomy_id); + + if(end($parent)) + $term->set_parent(end($parent)); + + if ($term->validate()) { + $term_insert = $term_repo->insert($term); + $last_term = $term_insert->get_id(); + $this->add_log('Added term: id=' . $last_term . ' name=' . $term->get_name() . ' id parent=' . $term->get_parent()); + } else { + $validationErrors = $term->get_errors(); + $err_msg = ""; + foreach($validationErrors as $err) { + $err_msg .= $err; + } + $this->add_error_log("err! = ". $err_msg); + return false; + } + } + return true; } } \ No newline at end of file From 812cbeaa2c7b3b2808e17677c9c9f56094ee6cdf Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 24 Sep 2018 10:06:10 -0300 Subject: [PATCH 03/22] update coments in class Term_Importer --- src/importer/class-tainacan-term-importer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/importer/class-tainacan-term-importer.php b/src/importer/class-tainacan-term-importer.php index 781148a14..a4e6ee137 100644 --- a/src/importer/class-tainacan-term-importer.php +++ b/src/importer/class-tainacan-term-importer.php @@ -1,6 +1,10 @@ remove_import_method('url'); $this->set_default_options([ - 'delimiter' => ',' + 'delimiter' => ',' ]); } @@ -93,7 +97,7 @@ class Term_Importer extends Importer { if (($handle = fopen($this->tmp_file, "r")) !== false) { $file = $handle; - } else { + } else { $this->add_error_log(' Error reading the file '); return false; } From 55122447156ced4d3ec9d4f94b332bf88318d3a9 Mon Sep 17 00:00:00 2001 From: weryques Date: Mon, 24 Sep 2018 17:10:52 -0300 Subject: [PATCH 04/22] Modal checkbox hierarchical: new features (#127) New tab to show selected terms as a tag list Breadcrumb at the bottom of finder view --- ...ter-modal.vue => checkbox-radio-modal.vue} | 164 ++++++++++++------ src/admin/tainacan-admin-i18n.php | 2 + .../filter-types/checkbox/Checkbox.vue | 4 +- .../filter-types/taxonomy/Checkbox.vue | 4 +- .../metadata-types/taxonomy/Taxonomy.vue | 4 +- 5 files changed, 121 insertions(+), 57 deletions(-) rename src/admin/components/other/{checkbox-filter-modal.vue => checkbox-radio-modal.vue} (80%) diff --git a/src/admin/components/other/checkbox-filter-modal.vue b/src/admin/components/other/checkbox-radio-modal.vue similarity index 80% rename from src/admin/components/other/checkbox-filter-modal.vue rename to src/admin/components/other/checkbox-radio-modal.vue index d37d88d0c..c024c3759 100644 --- a/src/admin/components/other/checkbox-filter-modal.vue +++ b/src/admin/components/other/checkbox-radio-modal.vue @@ -60,63 +60,104 @@
- + + + +
{ + this.saveSelectedTagName(res.data.id, res.data.name); + }) + .catch((error) => { + this.$console.log(error); + }); + } + }, + saveSelectedTagName(value, label){ + if(!this.selectedTagsName[value]) { + this.$set(this.selectedTagsName, `${value}`, label); + } + }, limitChars(label){ if(label.length > this.maxTextToShow){ return label.slice(0, this.maxTextToShow)+'...'; @@ -342,12 +403,13 @@ } } }, - addToHierarchicalPath(column, element){ + addToHierarchicalPath(column, element, option){ let found = undefined; let toBeAdded = { column: column, - element: element + element: element, + option: option, }; for (let f in this.hierarchicalPath) { @@ -418,7 +480,7 @@ let query_items = { 'current_query': this.query }; if(key != undefined) { - this.addToHierarchicalPath(key, index); + this.addToHierarchicalPath(key, index, option); } let parent = 0; diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index a60e3dd7f..5d765dd54 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -306,6 +306,8 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_untrash_selected_items' => __( 'Recover from trash', 'tainacan' ), 'label_value_not_informed' => __( 'Value not informed.', 'tainacan' ), 'label_description_not_informed' => __( 'Description not informed.', 'tainacan' ), + 'label_all_terms' => __( 'All terms', 'tainacan' ), + 'label_selected_terms' => __( 'Selected terms', 'tainacan'), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue index 378ebf4da..f8020f0b5 100644 --- a/src/classes/filter-types/checkbox/Checkbox.vue +++ b/src/classes/filter-types/checkbox/Checkbox.vue @@ -28,7 +28,7 @@ + + + + + diff --git a/src/admin/pages/lists/items-page.vue b/src/admin/pages/lists/items-page.vue index 597d5b90f..7672ccd45 100644 --- a/src/admin/pages/lists/items-page.vue +++ b/src/admin/pages/lists/items-page.vue @@ -141,7 +141,7 @@ - + + +
+ {{ $i18n.get('add_one_item') }} +
+
{{ $i18n.get('add_items_bulk') + ' (Not ready)' }} @@ -661,6 +669,7 @@ import Pagination from '../../components/search/pagination.vue' import AdvancedSearch from '../../components/advanced-search/advanced-search.vue'; import AvailableImportersModal from '../../components/other/available-importers-modal.vue'; + import CollectionsModal from '../../components/other/collections-modal.vue'; import { mapActions, mapGetters } from 'vuex'; export default { @@ -795,6 +804,13 @@ } }); }, + onOpenCollectionsModal() { + this.$modal.open({ + parent: this, + component: CollectionsModal, + hasModalCard: true + }); + }, updateSearch() { this.$eventBusSearch.setSearchQuery(this.futureSearchQuery); }, From 540c64306acf0d6db3df25dbab168f29211e3d54 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 27 Sep 2018 14:38:22 -0300 Subject: [PATCH 19/22] Replaces Flex by Grid on Card and Thumbnail view modes, due to lack of alignment on last items. --- src/admin/components/other/collections-modal.vue | 2 +- src/admin/scss/_view-mode-cards.scss | 13 +++++++++---- src/admin/scss/_view-mode-grid.scss | 9 ++++----- src/js/store/modules/collection/actions.js | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/admin/components/other/collections-modal.vue b/src/admin/components/other/collections-modal.vue index 88b5c59a2..4612068cc 100644 --- a/src/admin/components/other/collections-modal.vue +++ b/src/admin/components/other/collections-modal.vue @@ -10,7 +10,7 @@

{{ $i18n.get('instruction_select_a_target_collection') }}

{ }); }; - + export const fetchCollections = ({commit} , { page, collectionsPerPage, status }) => { return new Promise((resolve, reject) => { let endpoint = '/collections?paged='+page+'&perpage='+collectionsPerPage+'&context=edit'; From ec76154377f8d4a10d034afed32d0b572d138cc9 Mon Sep 17 00:00:00 2001 From: eduardohumberto Date: Thu, 27 Sep 2018 19:45:03 -0300 Subject: [PATCH 20/22] Endpoints to load facets - start method to return the total of items count to the facet list (ref. #94) --- .../class-tainacan-rest-facets-controller.php | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/src/api/endpoints/class-tainacan-rest-facets-controller.php b/src/api/endpoints/class-tainacan-rest-facets-controller.php index 006654e82..946bebaff 100644 --- a/src/api/endpoints/class-tainacan-rest-facets-controller.php +++ b/src/api/endpoints/class-tainacan-rest-facets-controller.php @@ -137,7 +137,7 @@ class REST_Facets_Controller extends REST_Controller { wp_reset_postdata(); } - $this->total_items = $items->found_posts; + $this->total_items = $items->found_posts; $this->total_pages = ceil($this->total_items / (int) $items->query_vars['posts_per_page']); } @@ -168,7 +168,6 @@ class REST_Facets_Controller extends REST_Controller { $term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy); $realResponse[] = $term_selected; - } foreach( $terms as $index => $term ){ @@ -423,7 +422,6 @@ class REST_Facets_Controller extends REST_Controller { if( $metaquery['key'] == $metadatum_id ){ return $metaquery['value']; - } } @@ -447,8 +445,7 @@ class REST_Facets_Controller extends REST_Controller { foreach( $request['current_query']['metaquery'] as $metaquery ){ if( $metaquery['key'] == $metadatum_id ){ - return $metaquery['value']; - + return $metaquery['value']; } } @@ -482,6 +479,70 @@ class REST_Facets_Controller extends REST_Controller { 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 + * + * @return int total of items found + */ + private function add_items_count( $value, $reference_id, $is_taxonomy = false, $query, $collection_id){ + $new_args = $query; + $has_value = false; + + if( !$is_taxonomy ){ + + if( isset( $query['metaquery'] ) ){ + foreach( $query['metaquery'] as $index => $metaquery ){ + if( $metaquery['key'] == $metadatum_id ){ + + $has_value = true; + + if( is_array($metaquery['value']) ) + $new_args['metaquery'][$index]['value'][] = $value; + else + $new_args['metaquery'][$index]['value'] = $value; + + } + } + } + + if( !$has_value ){ + + $new_args['metaquery'][] = [ + 'key' => $reference_id, + 'value' => $value + ]; + } + + } else { + + if( isset( $query['taxquery'] ) ){ + foreach( $query['taxquery'] as $taxquery ){ + if( $taxquery['taxonomy'] === 'tnc_tax_' . $reference_id ){ + + $has_value = true; + $new_args['taxquery'][$index]['terms'][] = $value; + } + } + } + + if( !$has_value ){ + + $new_args['taxquery'][] = [ + 'taxonomy' => 'tnc_tax_' . $reference_id, + 'value' => [$value] + ]; + } + } + + $items = $this->items_repository->fetch($new_args, $collection_id, 'WP_Query'); + return $items->found_posts; + } } ?> \ No newline at end of file From 6e83e34982931d8ce6f1cac9c66a293094a1bc18 Mon Sep 17 00:00:00 2001 From: leogermani Date: Fri, 28 Sep 2018 12:21:04 -0300 Subject: [PATCH 21/22] Change default value for metadata visibility in lists to No --- src/classes/repositories/class-tainacan-metadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/repositories/class-tainacan-metadata.php b/src/classes/repositories/class-tainacan-metadata.php index 901c302a5..7c06919c3 100644 --- a/src/classes/repositories/class-tainacan-metadata.php +++ b/src/classes/repositories/class-tainacan-metadata.php @@ -187,7 +187,7 @@ class Metadata extends Repository { 'type' => __( 'string' ), 'validation' => v::stringType()->in( [ 'yes', 'no', 'never' ] ), 'description' => __( 'Display by default on listing or do not display or never display.', 'tainacan' ), - 'default' => 'yes' + 'default' => 'no' ], 'semantic_uri' => [ 'map' => 'meta', From 6f0a4a1021b9cf687b27bdf5704b22c88edef50a Mon Sep 17 00:00:00 2001 From: leogermani Date: Fri, 28 Sep 2018 12:21:24 -0300 Subject: [PATCH 22/22] enable progress value for Terms importer --- src/importer/term-importer/class-tainacan-term-importer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/importer/term-importer/class-tainacan-term-importer.php b/src/importer/term-importer/class-tainacan-term-importer.php index df2380508..5b683b8fa 100644 --- a/src/importer/term-importer/class-tainacan-term-importer.php +++ b/src/importer/term-importer/class-tainacan-term-importer.php @@ -115,6 +115,7 @@ class Term_Importer extends Importer { if (($handle = fopen($this->tmp_file, "r")) !== false) { $file = $handle; + $this->set_current_step_total( filesize($this->tmp_file) ); } else { $this->add_error_log(' Error reading the file '); return false;