From 57316126bcd5899e1d99f249bb92eb904e1e6481 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 26 Sep 2023 10:21:54 -0300 Subject: [PATCH 01/87] Sets maximum size for search bar in desktop. --- .../blocks/faceted-search/theme-search/scss/_layout.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/gutenberg-blocks/blocks/faceted-search/theme-search/scss/_layout.scss b/src/views/gutenberg-blocks/blocks/faceted-search/theme-search/scss/_layout.scss index fcff907eb..8ab017360 100644 --- a/src/views/gutenberg-blocks/blocks/faceted-search/theme-search/scss/_layout.scss +++ b/src/views/gutenberg-blocks/blocks/faceted-search/theme-search/scss/_layout.scss @@ -151,8 +151,8 @@ } } .search-control .search-control-item .search-area { - min-width: 13.75%; - min-width: 13.75vw; + min-width: calc(min(13.75%, 280px)); + min-width: calc(min(13.75vw, 280px)); } } From 47b53631f1a673a0b413af2a91eca8951ea5c2e6 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 2 Oct 2023 10:49:18 -0300 Subject: [PATCH 02/87] Add filter to set the thumbnail placeholder. #319. --- src/classes/theme-helper/template-tags.php | 10 +++++++++- src/views/admin/js/utilities.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/classes/theme-helper/template-tags.php b/src/classes/theme-helper/template-tags.php index e6c00ebeb..24bb34936 100644 --- a/src/classes/theme-helper/template-tags.php +++ b/src/classes/theme-helper/template-tags.php @@ -1019,7 +1019,15 @@ function tainacan_get_the_mime_type_icon($mime_type, $image_size = 'medium') { $icon_file = 'placeholder_square'; } - return $images_path . $icon_file . $image_size . '.png'; + /** + * Filter the image source for the empty thumbnail placeholder. + * + * @param string src The image source for the empty thumbnail placeholder. + * Default is 'placeholder_square'. + * @param string mime_type The document type of the item. + * @param string image_size The size of the image to be loaded. + */ + return apply_filters('tainacan-get-the-mime-type-icon', $images_path . $icon_file . $image_size . '.png', $mime_type, $image_size); } /** diff --git a/src/views/admin/js/utilities.js b/src/views/admin/js/utilities.js index 61c9b6345..fc7b8437d 100644 --- a/src/views/admin/js/utilities.js +++ b/src/views/admin/js/utilities.js @@ -72,7 +72,15 @@ export const ThumbnailHelperFunctions = () => { imageSrc = 'placeholder_square'; } - return this.getEmptyThumbnailPlaceholderBySize(imageSrc, tainacanSize); + /** + * Filter the image source for the empty thumbnail placeholder. + * + * @param string imageSrc The image source for the empty thumbnail placeholder. + * Default is 'placeholder_square'. + * @param string documentType The document type of the item. + * @param string size The size of the image to be loaded. + */ + return wp.hooks.applyFilters('tainacan_get_the_mime_type_icon', this.getEmptyThumbnailPlaceholderBySize(imageSrc, tainacanSize), documentType, tainacanSize); }, getEmptyThumbnailPlaceholderBySize(imageSrc, tainacanSize) { switch(tainacanSize) { From 16434d07199a4da4b1a7db9fbbe0129614860225 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 3 Oct 2023 09:07:31 -0300 Subject: [PATCH 03/87] fix: remove the sanitize text file name on 404 `template_redirect` --- src/classes/class-tainacan-private-files.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/class-tainacan-private-files.php b/src/classes/class-tainacan-private-files.php index 2402e64b6..c97ced581 100644 --- a/src/classes/class-tainacan-private-files.php +++ b/src/classes/class-tainacan-private-files.php @@ -191,7 +191,7 @@ class Private_Files { $upload_dir = wp_get_upload_dir(); $base_upload_url = preg_replace('/^https?:\/\//', '', $upload_dir['baseurl']); - $requested_uri = sanitize_text_field($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); + $requested_uri = ($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); if ( strpos($requested_uri, $base_upload_url) === false ) { // Not uploads @@ -228,7 +228,7 @@ class Private_Files { if ( !$existing_file && \file_exists( $prefixed_both ) ) { $existing_file = $prefixed_both; } - + echo "-----------> $file
$prefixed_file
$prefixed_collection $prefixed_both: $existing_file"; if ($existing_file) { $item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $item_id, (int) $collection_id ); From c33270e22e8fecd02818a20746806f1701aad570 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 3 Oct 2023 09:09:08 -0300 Subject: [PATCH 04/87] fix: add the TAINACAN_INDEX_PDF_CONTENT in public search --- src/classes/class-tainacan-media.php | 12 +++++------- src/classes/class-tainacan-search-engine.php | 8 +++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/classes/class-tainacan-media.php b/src/classes/class-tainacan-media.php index 75890920b..d0623f1f3 100644 --- a/src/classes/class-tainacan-media.php +++ b/src/classes/class-tainacan-media.php @@ -7,10 +7,11 @@ namespace Tainacan; class Media { private static $instance = null; - private static $file_handle = null; private static $file_name = null; private $attachment_html_url_base = 'tainacan_attachment_html'; + public static $content_index_meta = 'document_content_index'; + public static function get_instance() { if(!isset(self::$instance)) { self::$instance = new self(); @@ -246,10 +247,8 @@ class Media { return; } - $content_index_meta = 'document_content_index'; - if ($file == null) { - $meta_id = update_post_meta( $item_id, $content_index_meta, null ); + update_post_meta( $item_id, SELF::$content_index_meta, null ); return true; } @@ -274,9 +273,8 @@ class Media { $wp_charset = get_bloginfo('charset'); $content_charset = mb_detect_encoding($content); $content = mb_convert_encoding($content, $wp_charset, $content_charset); - - $meta_id = update_post_meta( $item_id, $content_index_meta, $content ); - } catch(Exception $e) { + update_post_meta( $item_id, SELF::$content_index_meta, $content ); + } catch(\Exception $e) { error_log('Caught exception: ' . $e->getMessage() . "\n"); return false; } diff --git a/src/classes/class-tainacan-search-engine.php b/src/classes/class-tainacan-search-engine.php index 05e8ea7e2..2fcdf86ee 100644 --- a/src/classes/class-tainacan-search-engine.php +++ b/src/classes/class-tainacan-search-engine.php @@ -176,10 +176,16 @@ class Search_Engine { $seperator = ' OR '; } if ( empty($search_meta_query) ) return ''; + + $content_index_meta = ''; + if ( defined('TAINACAN_INDEX_PDF_CONTENT') && true === TAINACAN_INDEX_PDF_CONTENT ) { + $content_index_meta_meta_key = \TAINACAN\Media::$content_index_meta; + $content_index_meta = "OR (m.meta_key='{$content_index_meta_meta_key}')"; + } $join = \is_user_logged_in() ? '' - : " INNER JOIN $wpdb->posts pmeta ON m.meta_key = pmeta.ID AND pmeta.post_status = 'publish'"; + : " INNER JOIN $wpdb->posts pmeta ON (m.meta_key = pmeta.ID AND pmeta.post_status = 'publish') $content_index_meta"; return "EXISTS ( SELECT m.post_id FROM $wpdb->postmeta m $join From cd44dc5bcae814c4f61e3e9112edeae512f8f0e6 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 3 Oct 2023 10:04:36 -0300 Subject: [PATCH 05/87] fix: get `comment_status` for item --- src/classes/entities/class-tainacan-item.php | 16 ++++++++++------ .../repositories/class-tainacan-items.php | 12 ++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index ede1a2681..0ce9e8ae5 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -307,7 +307,9 @@ class Item extends Entity { * @return string "open"|"closed" */ public function get_comment_status() { - return apply_filters('tainacan-item-comments_open', $this->get_mapped_property('comment_status'), $this->get_id()); + $comment_status = $this->get_mapped_property('comment_status'); + $comment_status_filtered = apply_filters('comments_open', $comment_status == 'open', $this->get_id()) == true ? 'open' : 'closed'; + return $comment_status_filtered; } /** @@ -1183,13 +1185,15 @@ class Item extends Entity { if ( $metadata_section->is_conditional_section() ) { $rules = $metadata_section->get_conditional_section_rules(); - $item_id = $this->get_id(); + if( !empty($rules) ) { + $item_id = $this->get_id(); - foreach ( $rules as $meta_id => $meta_values_conditional ) { + foreach ( $rules as $meta_id => $meta_values_conditional ) { - $meta_values = get_post_meta( $item_id, $meta_id ); - if (!array_intersect($meta_values, $meta_values_conditional)) - return $return; + $meta_values = get_post_meta( $item_id, $meta_id ); + if (!array_intersect($meta_values, $meta_values_conditional)) + return $return; + } } } diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 0f18e3aef..9b7d4fa5e 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -26,7 +26,7 @@ class Items extends Repository { protected function __construct() { parent::__construct(); - add_filter( 'tainacan-item-comments_open', [$this, 'hook_comments_open'], 10, 2); + add_filter( 'comments_open', [$this, 'hook_comments_open'], 10, 2); add_action( 'tainacan-api-item-updated', array( &$this, 'hook_api_updated_item' ), 10, 2 ); add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 10, 4 ); } @@ -582,19 +582,19 @@ class Items extends Repository { /** * Return if comment are open for this item (post_id) and the collection too * - * @param string $open_comment + * @param bool $comments_open * @param integer $post_id Item id - * @return string + * @return bool */ - public function hook_comments_open($open_comment, $post_id) { + public function hook_comments_open($comments_open, $post_id) { $item = self::get_entity_by_post($post_id); if($item != false && $item instanceof Entities\Item) { $collection = $item->get_collection(); - if( $collection != null && $collection->get_allow_comments() !== 'open' ) return 'closed'; + if( $collection != null && $collection->get_allow_comments() !== 'open' ) return false; } - return $open_comment; + return $comments_open; } /** From 5882c6dd752493a5ac4d18a4dfa24bfcc5991808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Nunes=20Medeiros?= Date: Thu, 5 Oct 2023 10:53:58 -0300 Subject: [PATCH 06/87] fix: remove echo re --- src/classes/class-tainacan-private-files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/class-tainacan-private-files.php b/src/classes/class-tainacan-private-files.php index c97ced581..d7aab700c 100644 --- a/src/classes/class-tainacan-private-files.php +++ b/src/classes/class-tainacan-private-files.php @@ -228,7 +228,7 @@ class Private_Files { if ( !$existing_file && \file_exists( $prefixed_both ) ) { $existing_file = $prefixed_both; } - echo "-----------> $file
$prefixed_file
$prefixed_collection $prefixed_both: $existing_file"; + if ($existing_file) { $item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $item_id, (int) $collection_id ); From 8c958127d4d75f192ad1df9d6fc13361885d7440 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 9 Oct 2023 15:13:00 -0300 Subject: [PATCH 07/87] Checks if user can edit taxonomy before displaying add new term button. --- ...-tainacan-rest-item-metadata-controller.php | 2 +- .../components/edition/item-edition-form.vue | 5 +++++ .../components/edition/term-edition-form.vue | 12 +++++++++--- .../metadata-types/taxonomy/Taxonomy.vue | 6 +++++- .../admin/js/store/modules/taxonomy/actions.js | 18 ++++++++++++++++-- .../class-tainacan-gutenberg-block.php | 2 +- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php index d50e20fe6..0329721a7 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -132,7 +132,7 @@ class REST_Item_Metadata_Controller extends REST_Controller { public function prepare_item_for_response( $item, $request ) { $item_arr = $item->_toArray(true, true); - if($request['context'] === 'edit'){ + if ($request['context'] === 'edit') { $item_arr['current_user_can_edit'] = $item->can_edit(); $item_arr['current_user_can_delete'] = $item->can_delete(); } diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 2c027cc0f..21eb9981d 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -1172,6 +1172,11 @@ export default { this.isLoading = false; + if ( wp && wp.hooks && wp.hooks.hasFilter(`tainacan_item_edition_form_submit--redirect`) ) { + window.location = wp.hooks.applyFilters(`tainacan_item_edition_form_submit--redirect`, this.item, this.form.collectionId, tainacan_plugin.admin_url); + return; + } + if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode) { if (!this.isOnSequenceEdit) { diff --git a/src/views/admin/components/edition/term-edition-form.vue b/src/views/admin/components/edition/term-edition-form.vue index 7bb11f7a4..689d5acb4 100644 --- a/src/views/admin/components/edition/term-edition-form.vue +++ b/src/views/admin/components/edition/term-edition-form.vue @@ -233,7 +233,9 @@ originalForm: Object, taxonomyId: '', isHierarchical: Boolean, - isTermInsertionFlow: false + isTermInsertionFlow: false, + metadatumId: [String, Number], + itemId: [String, Number] }, data() { return { @@ -308,7 +310,9 @@ this.isLoading = true; this.sendChildTerm({ taxonomyId: this.taxonomyId, - term: data + term: data, + metadatumId: this.metadatumId, + itemId: this.itemId }) .then((term) => { this.$emit('onEditionFinished', {term: term, hasChangedParent: this.hasChangedParent, initialParent: this.initialParentId }); @@ -342,7 +346,9 @@ this.isLoading = true; this.updateTerm({ taxonomyId: this.taxonomyId, - term: data + term: data, + metadatumId: this.metadatumId, + itemId: this.itemId }) .then((term) => { this.formErrors = {}; diff --git a/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue b/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue index 42558db5d..fa4a0b4ac 100644 --- a/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue +++ b/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue @@ -59,6 +59,8 @@ custom-class="tainacan-modal" :close-button-aria-label="$i18n.get('close')"> { +export const sendChildTerm = ({ commit }, { taxonomyId, term, itemId, metadatumId }) => { + + if ( itemId != undefined ) + term['item_id'] = itemId; + + if ( metadatumId != undefined ) + term['metadatum_id'] = metadatumId; + return new Promise(( resolve, reject ) => { axios.tainacan.post(`/taxonomy/${taxonomyId}/terms/`, term) .then( res => { @@ -172,7 +179,14 @@ export const sendChildTerm = ({ commit }, { taxonomyId, term }) => { }); }; -export const updateTerm = ({}, { taxonomyId, term }) => { +export const updateTerm = ({}, { taxonomyId, term, itemId, metadatumId }) => { + + if ( itemId != undefined ) + term['item_id'] = itemId; + + if ( metadatumId != undefined ) + term['metadatum_id'] = metadatumId; + return new Promise(( resolve, reject ) => { axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${term.id}`, term) .then( res => { diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index f84a1ee5b..4fac8f1af 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -284,7 +284,7 @@ function tainacan_blocks_get_category_icon_script() { wp_enqueue_script( 'tainacan-blocks-register-category-icon', $TAINACAN_BASE_URL . '/assets/js/tainacan_blocks_category_icon.js', - array('wp-blocks'), + array('wp-blocks', 'wp-element'), $TAINACAN_VERSION ); } From 2fb84e6d78e223a1220b86ec87bbe42779be9b3a Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 10 Oct 2023 11:20:36 -0300 Subject: [PATCH 08/87] Removes abandoned filter on item edition form to redriect after submit. --- src/views/admin/components/edition/item-edition-form.vue | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 21eb9981d..2c027cc0f 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -1172,11 +1172,6 @@ export default { this.isLoading = false; - if ( wp && wp.hooks && wp.hooks.hasFilter(`tainacan_item_edition_form_submit--redirect`) ) { - window.location = wp.hooks.applyFilters(`tainacan_item_edition_form_submit--redirect`, this.item, this.form.collectionId, tainacan_plugin.admin_url); - return; - } - if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode) { if (!this.isOnSequenceEdit) { From c08ae9a74221401c667e2e5d4a193f0837a5b89b Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 10 Oct 2023 16:52:41 -0300 Subject: [PATCH 09/87] Adds options to hide certain elements of the item edition form and change labels. #811. --- .../entities/class-tainacan-collection.php | 208 ++++++++- .../class-tainacan-collections.php | 123 +++++ .../edition/collection-edition-form.vue | 424 ++++++++++++++---- .../edition/item-attachments-edition-form.vue | 5 +- .../edition/item-document-edition-form.vue | 11 +- .../components/edition/item-edition-form.vue | 37 +- .../edition/item-thumbnail-edition-form.vue | 3 +- .../js/store/modules/collection/actions.js | 3 +- src/views/admin/pages/singles/item-page.vue | 20 +- src/views/tainacan-i18n.php | 6 +- 10 files changed, 704 insertions(+), 136 deletions(-) diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index 3ab6d06fd..b4922de52 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -40,7 +40,17 @@ class Collection extends Entity { $hide_items_thumbnail_on_lists, $submission_anonymous_user, $submission_default_status, - $submission_use_recaptcha; + $submission_use_recaptcha, + $item_enabled_document_types, + $item_document_label, + $item_thumbnail_label, + $item_attachment_label_singular, + $item_attachment_label_plural, + $item_enable_attachments, + $item_enable_metadata_focus_mode, + $item_enable_metadata_required_filter, + $item_enable_metadata_searchbar, + $item_enable_metadata_collapses; /** * {@inheritDoc} @@ -607,14 +617,103 @@ class Collection extends Entity { /** * Get the default metadata section properties. * - * @param [string] $value - * * @return void */ function get_default_metadata_section_properties( ) { return $this->get_mapped_property( 'default_metadata_section_properties' ); } + /** + * Get the enabled document types for this collection. + * + * @return array The enabled document types. + */ + function get_item_enabled_document_types() { + return $this->get_mapped_property('item_enabled_document_types'); + } + + /** + * Get the label for the section in this collection. + * + * @return string The label for the section. + */ + function get_item_document_label() { + return $this->get_mapped_property('item_document_label'); + } + + /** + * Get the label for the thumbnail section in this collection. + * + * @return string The label for the thumbnail section. + */ + function get_item_thumbnail_label() { + return $this->get_mapped_property('item_thumbnail_label'); + } + + /** + * Get the singular label for the attachment section in this collection. + * + * @return string The singular label for the attachment section. + */ + function get_item_attachment_label_singular() { + return $this->get_mapped_property('item_attachment_label_singular'); + } + + /** + * Get the plural label for the attachment section in this collection. + * + * @return string The plural label for the attachment section. + */ + function get_item_attachment_label_plural() { + return $this->get_mapped_property('item_attachment_label_plural'); + } + + /** + * Check if attachments are enabled for this collection. + * + * @return string 'yes' if attachments are enabled, 'no' otherwise. + */ + function get_item_enable_attachments() { + return $this->get_mapped_property('item_enable_attachments'); + } + + /** + * Check if metadata focus mode is enabled for this collection. + * + * @return string 'yes' if metadata focus mode is enabled, 'no' otherwise. + */ + function get_item_enable_metadata_focus_mode() { + return $this->get_mapped_property('item_enable_metadata_focus_mode'); + } + + /** + * Check if metadata required filter is enabled for this collection. + * + * @return string 'yes' if metadata required filter is enabled, 'no' otherwise. + */ + function get_item_enable_metadata_required_filter() { + return $this->get_mapped_property('item_enable_metadata_required_filter'); + } + + /** + * Check if metadata search bar is enabled for this collection. + * + * @return string 'yes' if metadata search bar is enabled, 'no' otherwise. + */ + function get_item_enable_metadata_searchbar() { + return $this->get_mapped_property('item_enable_metadata_searchbar'); + } + + /** + * Check if metadata collapses are enabled for this collection. + * + * @return bool True if metadata collapses are enabled, 'no' otherwise. + */ + function get_item_enable_metadata_collapses() { + return $this->get_mapped_property('item_enable_metadata_collapses'); + } + + // Setters /** * Set the collection name * @@ -750,7 +849,7 @@ class Collection extends Entity { * @return void */ function set_metadata_section_order( $value ) { - if( !empty($value) ) { + if( !empty( $value ) ) { $metadata_order = array( ); foreach($value as $section) { $metadata_order = array_merge($metadata_order, $section['metadata_order']); @@ -888,6 +987,107 @@ class Collection extends Entity { return $this->set_mapped_property( 'default_metadata_section_properties', $value); } + + /** + * Set the enabled document types for this collection. + * + * @param array $value The enabled document types. + * @return void + */ + function set_item_enabled_document_types( $value ) { + $this->set_mapped_property('item_enabled_document_types', $value); + } + + /** + * Set the label for the document section in this collection. + * + * @param string $value The label for the document section. + * @return void + */ + function set_item_document_label( $value ) { + $this->set_mapped_property('item_document_label', $value); + } + + /** + * Set the label for the thumbnail section in this collection. + * + * @param string $value The label for the thumbnail section. + * @return void + */ + function set_item_thumbnail_label( $value ) { + $this->set_mapped_property('item_thumbnail_label', $value); + } + + /** + * Set the singular label for the attachment section in this collection. + * + * @param string $value The singular label for the attachment section. + * @return void + */ + function set_item_attachment_label_singular( $value ) { + $this->set_mapped_property('item_attachment_label_singular', $value); + } + + /** + * Set the plural label for the attachment section in this collection. + * + * @param string $value The plural label for the attachment section. + * @return void + */ + function set_item_attachment_label_plural( $value ) { + $this->set_mapped_property('item_attachment_label_plural', $value); + } + + /** + * Enable or disable attachments for this collection. + * + * @param string $value 'yes' to enable attachments, 'no' to disable. + * @return void + */ + function set_item_enable_attachments( $value ) { + $this->set_mapped_property('item_enable_attachments', $value); + } + + /** + * Enable or disable metadata focus mode for this collection. + * + * @param string $value 'yes' to enable metadata focus mode, 'no' to disable. + * @return void + */ + function set_item_enable_metadata_focus_mode( $value ) { + $this->set_mapped_property('item_enable_metadata_focus_mode', $value); + } + + /** + * Enable or disable metadata required filter for this collection. + * + * @param string $value 'yes' to enable metadata required filter, 'no' to disable. + * @return void + */ + function set_item_enable_metadata_required_filter( $value ) { + $this->set_mapped_property('item_enable_metadata_required_filter', $value); + } + + /** + * Enable or disable metadata search bar for this collection. + * + * @param string $value 'yes' to enable metadata search bar, 'no' to disable. + * @return void + */ + function set_item_enable_metadata_searchbar( $value ) { + $this->set_mapped_property('item_enable_metadata_searchbar', $value); + } + + /** + * Enable or disable metadata collapses for this collection. + * + * @param string $value 'yes' to enable metadata collapses, 'no' to disable. + * @return void + */ + function set_item_enable_metadata_collapses( $value ) { + $this->set_mapped_property('item_enable_metadata_collapses', $value); + } + /** * Validate Collection * diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index 509e55b6f..7e454d114 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -330,6 +330,129 @@ class Collections extends Repository { ] ] ], + 'item_enabled_document_types' => [ + 'map' => 'meta', + 'title' => __( 'Enabled document types', 'tainacan' ), + 'type' => 'object', + 'description' => __( 'The document types that are available in the item edition form.', 'tainacan' ), + 'items' => [ + 'type' => 'object', + 'properties' => [ + 'enabled' => [ + 'description' => __( 'Whether the document type is enabled or not.', 'tainacan' ), + 'type' => 'string', + 'enum' => [ 'yes', 'no' ], + ], + 'label' => [ + 'description' => __( 'The label that will represent the document type.', 'tainacan' ), + 'type' => 'string', + ], + 'icon' => [ + 'description' => __( 'The slug of the icon that will represent the document type.', 'tainacan' ), + 'type' => 'string', + ], + ] + ], + 'default' => [ + 'attachment' => [ + 'enabled' => 'yes', + 'label' => __( 'File', 'tainacan' ), + 'icon' => 'attachments' + ], + 'url' => [ + 'enabled' => 'yes', + 'label' => __('URL', 'tainacan' ), + 'icon' => 'url' + ], + 'text' => [ + 'enabled' => 'yes', + 'label' => __('Text', 'tainacan' ), + 'icon' => 'text' + ] + ] + ], + 'item_document_label' => [ + 'map' => 'meta', + 'title' => __( 'Main document label', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'The label for the main document section in the item edition form', 'tainacan' ), + 'default' => __( 'Document', 'tainacan' ), + //'validation' => v::stringType(), + ], + 'item_thumbnail_label' => [ + 'map' => 'meta', + 'title' => __( 'Thumbnail label', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'The label for the thumbnail section in the item edition form', 'tainacan' ), + 'default' => __( 'Thumbnail', 'tainacan' ), + //'validation' => v::stringType(), + ], + 'item_attachment_label_singular' => [ + 'map' => 'meta', + 'title' => __( 'Attachments singular label', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'The singular label for the attachments section in the item edition form', 'tainacan' ), + 'default' => __( 'Attachment', 'tainacan' ), + //'validation' => v::stringType(), + ], + 'item_attachment_label_plural' => [ + 'map' => 'meta', + 'title' => __( 'Attachments plural label', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'The plural label for the attachments section in the item edition form', 'tainacan' ), + 'default' => __( 'Attachments', 'tainacan' ), + //'validation' => v::stringType(), + ], + 'item_enable_attachments' => [ + 'map' => 'meta', + 'title' => __( 'Item attachments', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'If enabled, each item can have a set of files attached to it, complementary to the item document.', 'tainacan' ), + 'default' => 'yes', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'enum' => [ 'yes', 'no' ], + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no + ], + 'item_enable_metadata_focus_mode' => [ + 'map' => 'meta', + 'title' => __( 'Metadata focus mode', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'If enabled, a button can start a special navigation mode, that focus one metadatum per time in the item edition form.', 'tainacan' ), + 'default' => 'yes', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'enum' => [ 'yes', 'no' ], + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no + ], + 'item_enable_metadata_required_filter' => [ + 'map' => 'meta', + 'title' => __( 'Metadata required filter', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'If enabled, a switch can be toggled to display only required metadata in the item edition form.', 'tainacan' ), + 'default' => 'yes', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'enum' => [ 'yes', 'no' ], + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no + ], + 'item_enable_metadata_searchbar' => [ + 'map' => 'meta', + 'title' => __( 'Metadata search bar', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'If enabled, a search bar can be used for filtering the list of metadata in the item edition form.', 'tainacan' ), + 'default' => 'yes', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'enum' => [ 'yes', 'no' ], + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no + ], + 'item_enable_metadata_collapses' => [ + 'map' => 'meta', + 'title' => __( 'Metadata collapses', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'If enabled, each metadata in the item form will be wrapped in a collapsable component.', 'tainacan' ), + 'default' => 'yes', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'enum' => [ 'yes', 'no' ], + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no + ], ] ); } diff --git a/src/views/admin/components/edition/collection-edition-form.vue b/src/views/admin/components/edition/collection-edition-form.vue index b9871b6e9..81a5fc818 100644 --- a/src/views/admin/components/edition/collection-edition-form.vue +++ b/src/views/admin/components/edition/collection-edition-form.vue @@ -221,116 +221,225 @@ :message="$i18n.getHelperMessage('collections', 'hide_items_thumbnail_on_lists')"/> - - -   - - - + +
+ + + + {{ $i18n.get('label_item_edition_form_options') }} +
- - -   - - - - +
+ v-show="showItemEditionFormOptions" + class="options-columns"> - + +
+ + + + + + + + + +
+ + + +   + + + + + +
+ + + + + + + + + +
+ + + :label="$i18n.getHelperTitle('collections', 'allow_comments')"> +   + + + + +
+
+ + +
+ + + + {{ $i18n.get('label_item_submission_options') }} +
+ +
+ +
+ + +   + v-model="form.allows_submission" /> - - - - - -
- - - - - {{ statusOption.name }} - -
- -

- {{ $i18n.get('info_item_submission_draft_status') }} -

-
-
- - - -   - - -

+ :title="$i18n.getHelperTitle('collections', 'allows_submission')" + :message="$i18n.getHelperMessage('collections', 'allows_submission')"/> + +

+ + + +   + + + + + + + +
+ + + + + {{ statusOption.name }} + +
+ +

+ {{ $i18n.get('info_item_submission_draft_status') }} +

+
+
+ + + +   + + +

+ + + +

+
@@ -723,7 +832,33 @@ export default { submission_default_status: 'draft', submission_anonymous_user: 'no', hide_items_thumbnail_on_lists: '', - submission_use_recaptcha: 'no' + submission_use_recaptcha: 'no', + item_enabled_document_types: { + attachment: { + enabled: 'yes', + label: this.$i18n.get( 'File', 'tainacan'), + icon: 'attachments' + }, + url: { + enabled: 'yes', + label: this.$i18n.get( 'URL', 'tainacan'), + icon: 'url' + }, + text: { + enabled: 'yes', + label: this.$i18n.get( 'Text', 'tainacan'), + icon: 'text' + } + }, + item_document_label: this.$i18n.get( 'Document', 'tainacan' ), + item_thumbnail_label: this.$i18n.get( 'Thumbnail', 'tainacan' ), + item_attachment_label_singular: this.$i18n.get( 'Attachment', 'tainacan' ), + item_attachment_label_plural: this.$i18n.get( 'Attachments', 'tainacan' ), + item_enable_attachments: 'yes', + item_enable_metadata_focus_mode: 'yes', + item_enable_metadata_required_filter: 'yes', + item_enable_metadata_searchbar: 'yes', + item_enable_metadata_collapses: 'yes' }, thumbnail: {}, cover: {}, @@ -754,7 +889,9 @@ export default { metadataSearchCancel: undefined, isLoadingMetadata: true, sortingMetadata: [], - localDefaultOrderBy: 'date' + localDefaultOrderBy: 'date', + showItemEditionFormOptions: false, + showItemSubmissionOptions: false } }, computed: { @@ -844,6 +981,16 @@ export default { this.form.submission_default_status = this.collection.submission_default_status; this.form.submission_use_recaptcha = this.collection.submission_use_recaptcha; this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists; + this.form.item_enabled_document_types = this.collection.item_enabled_document_types; + this.form.item_document_label = this.collection.item_document_label; + this.form.item_thumbnail_label = this.collection.item_thumbnail_label; + this.form.item_attachment_label_singular = this.collection.item_attachment_label_singular; + this.form.item_attachment_label_plural = this.collection.item_attachment_label_plural; + this.form.item_enable_attachments = this.collection.item_enable_attachments; + this.form.item_enable_metadata_focus_mode = this.collection.item_enable_metadata_focus_mode; + this.form.item_enable_metadata_required_filter = this.collection.item_enable_metadata_required_filter; + this.form.item_enable_metadata_searchbar = this.collection.item_enable_metadata_searchbar; + this.form.item_enable_metadata_collapses = this.collection.item_enable_metadata_collapses; // Generates CoverPage from current cover_page_id info if (this.form.cover_page_id != undefined && this.form.cover_page_id != '') { @@ -954,7 +1101,17 @@ export default { submission_default_status: this.form.submission_default_status, submission_use_recaptcha: this.form.submission_use_recaptcha, allow_comments: this.form.allow_comments, - hide_items_thumbnail_on_lists: this.form.hide_items_thumbnail_on_lists + hide_items_thumbnail_on_lists: this.form.hide_items_thumbnail_on_lists, + item_enabled_document_types: this.form.item_enabled_document_types, + item_document_label: this.form.item_document_label, + item_thumbnail_label: this.form.item_thumbnail_label, + item_attachment_label_singular: this.form.item_attachment_label_singular, + item_attachment_label_plural: this.form.item_attachment_label_plural, + item_enable_attachments: this.form.item_enable_attachments, + item_enable_metadata_focus_mode: this.form.item_enable_metadata_focus_mode, + item_enable_metadata_required_filter: this.form.item_enable_metadata_required_filter, + item_enable_metadata_searchbar: this.form.item_enable_metadata_searchbar, + item_enable_metadata_collapses: this.form.item_enable_metadata_collapses }; this.fillExtraFormData(data); @@ -983,6 +1140,16 @@ export default { this.form.submission_default_status = this.collection.submission_default_status; this.form.submission_use_recaptcha = this.collection.submission_use_recaptcha; this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists; + this.form.item_enabled_document_types = this.collection.item_enabled_document_types; + this.form.item_document_label = this.collection.item_document_label; + this.form.item_thumbnail_label = this.collection.item_thumbnail_label; + this.form.item_attachment_label_singular = this.collection.item_attachment_label_singular; + this.form.item_attachment_label_plural = this.collection.item_attachment_label_plural; + this.form.item_enable_attachments = this.collection.item_enable_attachments; + this.form.item_enable_metadata_focus_mode = this.collection.item_enable_metadata_focus_mode; + this.form.item_enable_metadata_required_filter = this.collection.item_enable_metadata_required_filter; + this.form.item_enable_metadata_searchbar = this.collection.item_enable_metadata_searchbar; + this.form.item_enable_metadata_collapses = this.collection.item_enable_metadata_collapses; this.isLoading = false; this.formErrorMessage = ''; @@ -1043,6 +1210,16 @@ export default { this.form.submission_default_status = this.collection.submission_default_status; this.form.submission_use_recaptcha = this.collection.submission_use_recaptcha; this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists; + this.form.item_enabled_document_types = this.collection.item_enabled_document_types; + this.form.item_document_label = this.collection.item_document_label; + this.form.item_thumbnail_label = this.collection.item_thumbnail_label; + this.form.item_attachment_label_singular = this.collection.item_attachment_label_singular; + this.form.item_attachment_label_plural = this.collection.item_attachment_label_plural; + this.form.item_enable_attachments = this.collection.item_enable_attachments; + this.form.item_enable_metadata_focus_mode = this.collection.item_enable_metadata_focus_mode; + this.form.item_enable_metadata_required_filter = this.collection.item_enable_metadata_required_filter; + this.form.item_enable_metadata_searchbar = this.collection.item_enable_metadata_searchbar; + this.form.item_enable_metadata_collapses = this.collection.item_enable_metadata_collapses; // Pre-fill status with publish to incentivate it this.form.status = 'publish'; @@ -1327,6 +1504,55 @@ export default { color: var(--tainacan-white) !important; } } + + .collection-form-section { + margin: 1.5em 0 0.5em -0.5em; + position: relative; + cursor: pointer; + + .icon { + background: var(--tainacan-background-color); + z-index: 1; + position: relative; + } + strong { + background: var(--tainacan-background-color); + color: var(--tainacan-gray4); + font-size: 0.875em; + z-index: 1; + position: relative; + padding-right: 12px; + } + hr { + position: absolute; + top: -0.75em; + width: calc(100% - 42px); + height: 1px; + background-color: var(--tainacan-gray2); + margin-left: 42px; + } + } + + .options-columns { + margin-left: 0.25rem; + padding-left: 1.25em; + padding-right: 0.25em; + padding-bottom: 1.25em;border-left: 1px solid var(--tainacan-gray2); + + &>div:not(.field) { + -moz-column-count: 2; + -moz-column-gap: 0; + -moz-column-rule: 1px solid var(--tainacan-gray1); + -webkit-column-count: 2; + -webkit-column-gap: 0; + -webkit-column-rule: 1px solid var(--tainacan-gray1); + column-count: 2; + column-gap: 4em; + column-rule: 1px solid var(--tainacan-gray1); + margin-bottom: 1.125rem; + } + } + .header-field { padding-top: 1px; @@ -1472,7 +1698,7 @@ export default { } .item-submission-options { padding-left: 1em; - padding-top: 1.25em; + padding-top: 1.0em; margin-top: -1.5em; border-left: 1px solid var(--tainacan-gray2); } diff --git a/src/views/admin/components/edition/item-attachments-edition-form.vue b/src/views/admin/components/edition/item-attachments-edition-form.vue index ee5773fc5..487d93aeb 100644 --- a/src/views/admin/components/edition/item-attachments-edition-form.vue +++ b/src/views/admin/components/edition/item-attachments-edition-form.vue @@ -8,7 +8,7 @@ - {{ $i18n.get('label_attachments') }}  + {{ collection && collection.item_attachment_label_plural ? collection.item_attachment_label_plural : $i18n.get('label_attachments') }}  - {{ $i18n.get('label_add_or_update_attachments') }} + {{ $i18n.getWithVariables('label_add_or_update_%s', [ collection && collection.item_attachment_label_plural ? collection.item_attachment_label_plural : $i18n.get('label_attachments') ]) }}
- {{ form.document != undefined && form.document != null && form.document != '' ? $i18n.get('label_document') : $i18n.get('label_document_empty') }} + {{ collection && collection.item_document_label ? collection.item_document_label : ( (form.document != undefined && form.document != null && form.document != '') ? $i18n.get('label_document') : $i18n.get('label_document_empty') ) }} -
  • +
  • {{ $i18n.get('label_file') }}

  • -
  • +
  • {{ $i18n.get('label_text') }}

  • -
  • +
  • @@ -944,7 +950,8 @@ export default { item_enable_metadata_focus_mode: 'yes', item_enable_metadata_required_filter: 'yes', item_enable_metadata_searchbar: 'yes', - item_enable_metadata_collapses: 'yes' + item_enable_metadata_collapses: 'yes', + item_enable_metadata_enumeration: 'yes', }, thumbnail: {}, cover: {}, @@ -1078,6 +1085,7 @@ export default { this.form.item_enable_metadata_required_filter = this.collection.item_enable_metadata_required_filter; this.form.item_enable_metadata_searchbar = this.collection.item_enable_metadata_searchbar; this.form.item_enable_metadata_collapses = this.collection.item_enable_metadata_collapses; + this.form.item_enable_metadata_enumeration = this.collection.item_enable_metadata_enumeration; // Generates CoverPage from current cover_page_id info if (this.form.cover_page_id != undefined && this.form.cover_page_id != '') { @@ -1198,7 +1206,8 @@ export default { item_enable_metadata_focus_mode: this.form.item_enable_metadata_focus_mode, item_enable_metadata_required_filter: this.form.item_enable_metadata_required_filter, item_enable_metadata_searchbar: this.form.item_enable_metadata_searchbar, - item_enable_metadata_collapses: this.form.item_enable_metadata_collapses + item_enable_metadata_collapses: this.form.item_enable_metadata_collapses, + item_enable_metadata_enumeration: this.form.item_enable_metadata_enumeration, }; this.fillExtraFormData(data); @@ -1237,6 +1246,7 @@ export default { this.form.item_enable_metadata_required_filter = this.collection.item_enable_metadata_required_filter; this.form.item_enable_metadata_searchbar = this.collection.item_enable_metadata_searchbar; this.form.item_enable_metadata_collapses = this.collection.item_enable_metadata_collapses; + this.form.item_enable_metadata_enumeration = this.collection.item_enable_metadata_enumeration; this.isLoading = false; this.formErrorMessage = ''; @@ -1307,6 +1317,7 @@ export default { this.form.item_enable_metadata_required_filter = this.collection.item_enable_metadata_required_filter; this.form.item_enable_metadata_searchbar = this.collection.item_enable_metadata_searchbar; this.form.item_enable_metadata_collapses = this.collection.item_enable_metadata_collapses; + this.form.item_enable_metadata_enumeration = this.collection.item_enable_metadata_enumeration; // Pre-fill status with publish to incentivate it this.form.status = 'publish'; @@ -1780,6 +1791,8 @@ export default { .options-checkboxes { display: flex; margin: 5px 0; + flex-wrap: wrap; + gap: 0.5rem; justify-content: space-between; /deep/ .b-checkbox.checkbox { width: auto diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 274bc3092..08705dfb1 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -398,6 +398,11 @@