From b53cc0d0e5701220eb49576b84feb2b118c36770 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Sun, 15 Jan 2023 22:12:53 -0300 Subject: [PATCH 01/57] Adds query loop block variations. #764. --- .../class-tainacan-gutenberg-block.php | 29 ++++++++++- .../js/tainacan-blocks-query-variations.js | 48 +++++++++++++++++++ webpack.common.js | 1 + 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index f9fc0ee31..1c6a84d2f 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -82,6 +82,7 @@ function tainacan_blocks_register_and_enqueue_all_blocks() { if ( is_admin() ) { tainacan_blocks_get_category_icon_script(); tainacan_blocks_get_common_editor_styles(); + tainacan_blocks_get_variations_script(); } // May be needed outside the editor, if server side render is used foreach(TAINACAN_BLOCKS as $block_slug => $block_options) { @@ -199,6 +200,12 @@ function tainacan_blocks_get_plugin_js_settings(){ global $TAINACAN_BASE_URL; global $wp_version; + $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); + $collections = $Tainacan_Collections->fetch( [], 'OBJECT' ); + foreach ( $collections as $col ) { + $cpts[$col->get_db_identifier()] = $col->get_name(); + } + $settings = [ 'wp_version' => $wp_version, 'root' => esc_url_raw( rest_url() ) . 'tainacan/v2', @@ -206,7 +213,8 @@ function tainacan_blocks_get_plugin_js_settings(){ 'base_url' => $TAINACAN_BASE_URL, 'admin_url' => admin_url(), 'site_url' => site_url(), - 'theme_items_list_url' => esc_url_raw( get_site_url() ) . '/' . \Tainacan\Theme_Helper::get_instance()->get_items_list_slug() + 'theme_items_list_url' => esc_url_raw( get_site_url() ) . '/' . \Tainacan\Theme_Helper::get_instance()->get_items_list_slug(), + 'collections_post_types' => $cpts ]; return $settings; @@ -271,3 +279,22 @@ function tainacan_blocks_get_category_icon_script() { $TAINACAN_VERSION ); } + +/** + * Registers the script that inserts the Query Loop Block variations + */ +function tainacan_blocks_get_variations_script() { + global $TAINACAN_BASE_URL; + global $TAINACAN_VERSION; + + wp_enqueue_script( + 'tainacan-blocks-query-variations', + $TAINACAN_BASE_URL . '/assets/js/tainacan_blocks_query_variations.js', + array('wp-blocks', 'wp-components'), + $TAINACAN_VERSION + ); + + $block_settings = tainacan_blocks_get_plugin_js_settings(); + wp_localize_script( 'tainacan-blocks-query-variations', 'tainacan_blocks', $block_settings ); +} + diff --git a/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js b/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js new file mode 100644 index 000000000..306231fb7 --- /dev/null +++ b/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js @@ -0,0 +1,48 @@ +const { registerBlockVariation } = wp.blocks; +const { __ } = wp.i18n; +import icon from '../blocks/items-list/icon'; + +const POST_TYPES = tainacan_blocks.collections_post_types; + +Object.keys(POST_TYPES).forEach((postType) => { + const postName = POST_TYPES[postType]; + const VARIATION_NAME = 'tainacan-items-' + postType; + + registerBlockVariation( 'core/query', { + name: VARIATION_NAME, + title: postName, + icon: icon, + description: __('Displays a list of Tainacan itens', 'tainacan'), + isActive: ( { namespace, query } ) => { + return ( + namespace === VARIATION_NAME + && query.postType === postType + ); + }, + attributes: { + category: 'tainacan-blocks', + namespace: VARIATION_NAME, + query: { + postType: postType, + perPage: 12, + offset: 0 + }, + align: 'wide', + displayLayout: { + type: 'flex', + columns: 4 + } + }, + allowedControls: [ 'inherit', 'order', 'taxQuery', 'search' ], + innerBlocks: [ + [ + 'core/post-template', + {}, + [ + [ 'core/post-featured-image' ], + [ 'core/post-title' ] + ], + ] + ] + } ); +}); diff --git a/webpack.common.js b/webpack.common.js index f8b008f6b..0a93f73eb 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -9,6 +9,7 @@ module.exports = { tainacan_pages_common_scripts: './src/views/tainacan-pages-common-scripts.js', tainacan_blocks_common_scripts: './src/views/gutenberg-blocks/tainacan-blocks-common-scripts.js', tainacan_blocks_category_icon: './src/views/gutenberg-blocks/js/tainacan-blocks-category-icon.js', + tainacan_blocks_query_variations: './src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js', block_terms_list: './src/views/gutenberg-blocks/blocks/terms-list/index.js', block_items_list: './src/views/gutenberg-blocks/blocks/items-list/index.js', From e623900c2a41e56f9388a463a8066287ed457bb1 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 16 Jan 2023 10:41:26 -0300 Subject: [PATCH 02/57] Registers a separate category for query loop variations. #764. --- .../gutenberg-blocks/class-tainacan-gutenberg-block.php | 8 +++++++- .../js/tainacan-blocks-query-variations.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index 1c6a84d2f..2caab30f5 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -67,7 +67,13 @@ function tainacan_blocks_register_categories($categories, $editor_context) { array( array( 'slug' => 'tainacan-blocks', - 'title' => __( 'Tainacan', 'tainacan' ), + 'title' => __( 'Tainacan Blocks', 'tainacan' ), + ), + ), + array( + array( + 'slug' => 'tainacan-blocks-variations', + 'title' => __( 'Tainacan Query Loop Variations', 'tainacan' ), ), ) ); diff --git a/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js b/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js index 306231fb7..2a1cca89f 100644 --- a/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js +++ b/src/views/gutenberg-blocks/js/tainacan-blocks-query-variations.js @@ -20,7 +20,7 @@ Object.keys(POST_TYPES).forEach((postType) => { ); }, attributes: { - category: 'tainacan-blocks', + category: 'tainacan-blocks-variations', namespace: VARIATION_NAME, query: { postType: postType, From cb029bf5c5936dcb243cd18cbbe0dedb97ea3070 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Thu, 26 Jan 2023 10:34:07 -0300 Subject: [PATCH 03/57] release: update version --- src/tainacan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tainacan.php b/src/tainacan.php index 60bfccf48..32f01f0ca 100644 --- a/src/tainacan.php +++ b/src/tainacan.php @@ -4,7 +4,7 @@ Plugin Name: Tainacan Plugin URI: https://tainacan.org/ Description: Open source, powerful and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional repository platform. Author: Tainacan.org -Version: 0.19.3 +Version: 0.20.0-beta Requires at least: 5.0 Tested up to: 6.1 Requires PHP: 5.6 @@ -14,7 +14,7 @@ License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html */ -const TAINACAN_VERSION = '0.19.3'; +const TAINACAN_VERSION = '0.20.0-beta'; defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); $TAINACAN_BASE_URL = plugins_url('', __FILE__); From 73f036ff8f7b5b00d88b8439499c319d82f0d332 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 26 Jan 2023 11:40:00 -0300 Subject: [PATCH 04/57] Adds proper color variable to map selection coordinate. --- src/views/admin/scss/_view-mode-map.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/admin/scss/_view-mode-map.scss b/src/views/admin/scss/_view-mode-map.scss index ff15eec7f..b857aa6a5 100644 --- a/src/views/admin/scss/_view-mode-map.scss +++ b/src/views/admin/scss/_view-mode-map.scss @@ -54,6 +54,7 @@ } .geocoordinate-panel--input { + color: var(--tainacan-label-color); display: flex; align-items: center; flex-wrap: wrap; From 4815060d21e103566e06ab1a4034b18425e728b6 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sat, 28 Jan 2023 13:41:01 -0300 Subject: [PATCH 05/57] add const `TAINACAN_DISABLE_ITEM_THE_CONTENT_FILTER` to disable the_content filter. --- src/classes/theme-helper/class-tainacan-theme-helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/classes/theme-helper/class-tainacan-theme-helper.php b/src/classes/theme-helper/class-tainacan-theme-helper.php index d15b8a044..a205bb949 100644 --- a/src/classes/theme-helper/class-tainacan-theme-helper.php +++ b/src/classes/theme-helper/class-tainacan-theme-helper.php @@ -25,7 +25,9 @@ class Theme_Helper { private function __construct() { - add_filter( 'the_content', [$this, 'the_content_filter'] ); + if ( !defined('TAINACAN_DISABLE_ITEM_THE_CONTENT_FILTER') || true !== TAINACAN_DISABLE_ITEM_THE_CONTENT_FILTER ) { + add_filter( 'the_content', [$this, 'the_content_filter'] ); + } // Replace collections permalink to post type archive if cover not enabled add_filter('post_type_link', array($this, 'permalink_filter'), 10, 3); From 5e2315bc0f5184eb8cd4a219c825bd6ebc7b3772 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sat, 28 Jan 2023 14:35:58 -0300 Subject: [PATCH 06/57] refactor: improvements function `get_default_section_metadata_object_list` --- .../class-tainacan-metadata-sections.php | 65 ++++--------------- 1 file changed, 11 insertions(+), 54 deletions(-) diff --git a/src/classes/repositories/class-tainacan-metadata-sections.php b/src/classes/repositories/class-tainacan-metadata-sections.php index 44e002c7d..9b270cfbd 100644 --- a/src/classes/repositories/class-tainacan-metadata-sections.php +++ b/src/classes/repositories/class-tainacan-metadata-sections.php @@ -378,62 +378,19 @@ class Metadata_Sections extends Repository { return false; } - public function get_default_section_metadata_object_list (Entities\Collection $collection, $args = []) { + public function get_default_section_metadata_object_list(Entities\Collection $collection, $args = []) { $metadata_repository = \Tainacan\Repositories\Metadata::get_instance(); - $metadata_sections_ids = $this->fetch_ids(); - $collection_metadata_sections_id = array_diff(array_map(function($el) {return $el->get_id();} , $this->fetch_by_collection($collection)), [\Tainacan\Entities\Metadata_Section::$default_section_slug]); + $list_all_metadatas = $metadata_repository->fetch_by_collection($collection, $args); + $metadata_sections_ids = array_map(function($el) {return $el->get_id();} , $this->fetch_by_collection($collection, ['posts_per_page' => - 1])); - if ( empty($collection_metadata_sections_id) ) { - $not_post_ids = []; - } else { - $args_exclude = array( - 'meta_query' => array( - 'relation' => 'AND', - array( - array( - 'key' => 'collection_id', - 'value' => 'default', - 'compare' => '=' - ), - array( - 'key' => 'metadata_section_id', - 'value' => $collection_metadata_sections_id, - 'compare' => 'IN' - ) - ) - ) - ); - - $list_exclude = $metadata_repository->fetch_by_collection($collection, $args_exclude); - $not_post_ids = array_map(function($el) { return $el->get_id(); }, $list_exclude); - } - - $args = array_merge( - $args, - array( - 'post__not_in' => $not_post_ids, - 'meta_query' => array( - array( - 'relation' => 'OR', - array( - 'key' => 'metadata_section_id', - 'value' => \Tainacan\Entities\Metadata_Section::$default_section_slug, - 'compare' => '=' - ), - array( - 'key' => 'metadata_section_id', - 'compare' => 'NOT EXISTS' - ), - array( - 'key' => 'metadata_section_id', - 'value' => $metadata_sections_ids, - 'compare' => 'NOT IN' - ) - ) - ) - ) - ); - $metadata_list = $metadata_repository->fetch_by_collection($collection, $args); + $metadata_list = array_filter($list_all_metadatas, function($meta) use ($metadata_sections_ids) { + $metadata_section_id = $meta->get_metadata_section_id(); + if( !isset($metadata_section_id) ) return true; + if( !is_array($metadata_section_id) ) { + return $metadata_section_id == \Tainacan\Entities\Metadata_Section::$default_section_slug; + } + return count( array_intersect($metadata_sections_ids, $metadata_section_id) ) > 0; + }); return $metadata_list; } From 864f1d3819d5aa5dd75fdd23c034675106eeae41 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sat, 28 Jan 2023 15:15:52 -0300 Subject: [PATCH 07/57] fix: metadata repository id default section --- .../repositories/class-tainacan-metadata-sections.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/classes/repositories/class-tainacan-metadata-sections.php b/src/classes/repositories/class-tainacan-metadata-sections.php index 9b270cfbd..37236957f 100644 --- a/src/classes/repositories/class-tainacan-metadata-sections.php +++ b/src/classes/repositories/class-tainacan-metadata-sections.php @@ -381,15 +381,17 @@ class Metadata_Sections extends Repository { public function get_default_section_metadata_object_list(Entities\Collection $collection, $args = []) { $metadata_repository = \Tainacan\Repositories\Metadata::get_instance(); $list_all_metadatas = $metadata_repository->fetch_by_collection($collection, $args); - $metadata_sections_ids = array_map(function($el) {return $el->get_id();} , $this->fetch_by_collection($collection, ['posts_per_page' => - 1])); - - $metadata_list = array_filter($list_all_metadatas, function($meta) use ($metadata_sections_ids) { + $sections_ids = array_map(function($el) {return $el->get_id();} , $this->fetch_by_collection($collection, ['posts_per_page' => - 1])); + $metadata_list = array_filter($list_all_metadatas, function($meta) use ($sections_ids) { $metadata_section_id = $meta->get_metadata_section_id(); if( !isset($metadata_section_id) ) return true; if( !is_array($metadata_section_id) ) { return $metadata_section_id == \Tainacan\Entities\Metadata_Section::$default_section_slug; } - return count( array_intersect($metadata_sections_ids, $metadata_section_id) ) > 0; + $diff = array_filter(array_intersect($sections_ids, $metadata_section_id), function($el) { + return $el != \Tainacan\Entities\Metadata_Section::$default_section_slug; + }); + return count( $diff ) == 0; }); return $metadata_list; } From b48f85832760394eaeee32ba319ef529809aaa57 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 31 Jan 2023 11:22:00 -0300 Subject: [PATCH 08/57] Adds better error display for item submission form. #767. --- src/views/admin/js/axios.js | 1 - .../item-submission/item-submission-form.vue | 114 +++++++++++++++--- .../blocks/item-submission-form/theme.js | 4 + 3 files changed, 98 insertions(+), 21 deletions(-) diff --git a/src/views/admin/js/axios.js b/src/views/admin/js/axios.js index 2a97f91af..85f922dc4 100644 --- a/src/views/admin/js/axios.js +++ b/src/views/admin/js/axios.js @@ -10,7 +10,6 @@ const i18nGet = function (key) { }; export const tainacanErrorHandler = function(error) { - console.error(error) if (error.response && error.response.status) { // The request was made and the server responded with a status code // that falls out of the range of 2xx diff --git a/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue b/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue index 7809c2b05..57488df74 100644 --- a/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue +++ b/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue @@ -514,6 +514,47 @@ v-html="getEndRightForm"/> + + +
+ +
+ {{ formErrorMessage }} + +
+
+ @@ -55,6 +56,7 @@ export default { @import "../../../../../node_modules/buefy/src/scss/components/_dialog.scss"; @import "../../../../../node_modules/buefy/src/scss/components/_notices.scss"; @import "../../../../../node_modules/buefy/src/scss/components/_numberinput.scss"; + @import "../../../../../node_modules/buefy/src/scss/components/_steps.scss"; // Block level custom variables @import "../../../admin/scss/_custom_variables.scss"; From f6645d2f1057fba39fbd1953a7787898390b768e Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 7 Feb 2023 10:39:03 -0300 Subject: [PATCH 23/57] Moves form to step where an error is present if exists. #736. --- .../item-submission/item-submission-form.vue | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue b/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue index 6cad9554f..6af279a20 100644 --- a/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue +++ b/src/views/gutenberg-blocks/blocks/item-submission-form/item-submission/item-submission-form.vue @@ -4,6 +4,7 @@ :is-full-page="false" :active.sync="isLoading" :can-cancel="false"/> +