Merge branch 'develop' of github.com:tainacan/tainacan into develop

This commit is contained in:
vnmedeiros 2024-07-19 15:07:31 -03:00
commit 8ca72b8bbc
9 changed files with 116 additions and 28 deletions

View File

@ -411,7 +411,7 @@
</span> </span>
</label> </label>
<help-button <help-button
v-if="metadataSection.description" v-if="metadataSection.description && metadataSection.description_bellow_name !== 'yes'"
:title="metadataSection.name" :title="metadataSection.name"
:message="metadataSection.description" /> :message="metadataSection.description" />
</span> </span>
@ -422,7 +422,7 @@
class="metadata-section-metadata-list"> class="metadata-section-metadata-list">
<p <p
v-if="metadataSection.description && metadataSection.description_bellow_name == 'yes'" v-if="metadataSection.description && metadataSection.description_bellow_name == 'yes'"
class="metadatum-description-help-info"> class="metadata-section-description-help-info metadatum-description-help-info">
{{ metadataSection.description }} {{ metadataSection.description }}
</p> </p>
@ -1326,9 +1326,16 @@ export default {
parentMetaId: 0 parentMetaId: 0
}); });
} }
/**
if ( this.collection && this.item ) * Fires action tainacan_item_edition_item_loaded
wp.hooks.doAction('tainacan_item_edition_item_loaded', JSON.parse(JSON.stringify(this.collection)), JSON.parse(JSON.stringify(this.item))); * once the existing item is loaded. We cannot reliabilily send collection here since
* it is loaded async outside of the component.
*/
wp.hooks.doAction(
'tainacan_item_edition_item_loaded',
this.collection ? JSON.parse(JSON.stringify(this.collection)) : false,
this.item ? JSON.parse(JSON.stringify(this.item)) : false
);
// Loads metadata and attachments // Loads metadata and attachments
this.loadMetadata(); this.loadMetadata();
@ -1371,8 +1378,17 @@ export default {
} }
} }
if ( this.collection && this.item && metadata) /**
wp.hooks.doAction('tainacan_item_edition_metadata_loaded', JSON.parse(JSON.stringify(this.collection)), JSON.parse(JSON.stringify(this.item)), metadata); * Fires action tainacan_item_edition_metadata_loaded
* once the metadata is loaded. We cannot reliabilily send collection here since
* it is loaded async outside of the component.
*/
wp.hooks.doAction(
'tainacan_item_edition_metadata_loaded',
this.colection ? JSON.parse(JSON.stringify(this.collection)) : false,
this.item ? JSON.parse(JSON.stringify(this.item)) : false,
metadata ? metadata : []
);
this.isLoading = false; this.isLoading = false;
}); });
@ -1770,9 +1786,17 @@ export default {
this.urlIframeWidth = this.form.document_options['forced_iframe_width']; this.urlIframeWidth = this.form.document_options['forced_iframe_width'];
if (this.form.document_options !== undefined && this.form.document_options['forced_iframe_height'] !== undefined) if (this.form.document_options !== undefined && this.form.document_options['forced_iframe_height'] !== undefined)
this.urlIframeHeight = this.form.document_options['forced_iframe_height']; this.urlIframeHeight = this.form.document_options['forced_iframe_height'];
if ( this.collection && this.item ) /**
wp.hooks.doAction('tainacan_item_edition_item_loaded', JSON.parse(JSON.stringify(this.collection)), JSON.parse(JSON.stringify(this.item))); * Fires action tainacan_item_edition_item_loaded
* once the existing item is loaded. We cannot reliabilily send collection here since
* it is loaded async outside of the component.
*/
wp.hooks.doAction(
'tainacan_item_edition_item_loaded',
this.collection ? JSON.parse(JSON.stringify(this.collection)) : false,
this.item ? JSON.parse(JSON.stringify(this.item)) : false
);
this.loadMetadata(); this.loadMetadata();
this.setLastUpdated(this.item.modification_date); this.setLastUpdated(this.item.modification_date);
@ -2041,6 +2065,9 @@ export default {
margin-left: 12px; margin-left: 12px;
} }
} }
.metadata-section-description-help-info {
margin: 0.25em 0 0 1.125rem;
}
.item-edition-tab-content .tab-item>.field:last-child { .item-edition-tab-content .tab-item>.field:last-child {
margin-bottom: 187px; margin-bottom: 187px;
} }

View File

@ -5,6 +5,7 @@
:disabled="disabled" :disabled="disabled"
:placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''" :placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''"
:model-value="value === 0 || value ? Number(value) : null" :model-value="value === 0 || value ? Number(value) : null"
:data-is-danger="!isInputValid"
lang="en" lang="en"
:min="getMin" :min="getMin"
:max="getMax" :max="getMax"
@ -26,6 +27,11 @@
'blur', 'blur',
'mobile-special-focus' 'mobile-special-focus'
], ],
data() {
return {
isInputValid: true
}
},
computed: { computed: {
getStep() { getStep() {
if (this.itemMetadatum && this.itemMetadatum.metadatum.metadata_type_options && this.itemMetadatum.metadatum.metadata_type_options.step) if (this.itemMetadatum && this.itemMetadatum.metadatum.metadata_type_options && this.itemMetadatum.metadatum.metadata_type_options.step)
@ -49,8 +55,13 @@
methods: { methods: {
onInput(value) { onInput(value) {
const inputRef = this.$refs['tainacan-item-metadatum_id-' + this.itemMetadatum.metadatum.id + (this.itemMetadatum.parent_meta_id ? ('_parent_meta_id-' + this.itemMetadatum.parent_meta_id) : '')]; const inputRef = this.$refs['tainacan-item-metadatum_id-' + this.itemMetadatum.metadatum.id + (this.itemMetadatum.parent_meta_id ? ('_parent_meta_id-' + this.itemMetadatum.parent_meta_id) : '')];
if ( inputRef && !inputRef.checkHtml5Validity())
return; if ( inputRef ) {
this.isInputValid = inputRef.checkHtml5Validity();
if ( !this.isInputValid )
return;
}
// Allowing empty value as a state different of 0 // Allowing empty value as a state different of 0
if ( value === null || value === undefined || value === '' ) if ( value === null || value === undefined || value === '' )

View File

@ -19,7 +19,9 @@
}" }"
class="has-text-secondary tainacan-icon tainacan-icon-1-25em" /> class="has-text-secondary tainacan-icon tainacan-icon-1-25em" />
</span> </span>
<label class="label"> <label
class="label"
:class="{ 'has-text-danger': errorMessage }">
<span <span
v-if="enumerateMetadatum" v-if="enumerateMetadatum"
style="opacity: 0.65;" style="opacity: 0.65;"
@ -237,7 +239,8 @@
(this.itemMetadatum && this.itemMetadatum.metadatum && this.itemMetadatum.metadatum.placeholder ? ' has-placeholder' : '') + (this.itemMetadatum && this.itemMetadatum.metadatum && this.itemMetadatum.metadatum.placeholder ? ' has-placeholder' : '') +
(this.itemMetadatum && this.itemMetadatum.metadatum && this.itemMetadatum.metadatum.description ? ' has-description' : '') + (this.itemMetadatum && this.itemMetadatum.metadatum && this.itemMetadatum.metadatum.description ? ' has-description' : '') +
(this.itemMetadatum && this.itemMetadatum.metadatum && this.itemMetadatum.metadatum.id ? ' tainacan-metadatum-id--' + this.itemMetadatum.metadatum.id : '') + (this.itemMetadatum && this.itemMetadatum.metadatum && this.itemMetadatum.metadatum.id ? ' tainacan-metadatum-id--' + this.itemMetadatum.metadatum.id : '') +
(this.isFocused ? ' is-focused' : ''); (this.isFocused ? ' is-focused' : '') +
(this.errorMessage ? ' is-danger' : '');
} }
}, },
created() { created() {

View File

@ -113,6 +113,21 @@
:title="$i18n.getHelperTitle('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" :title="$i18n.getHelperTitle('tainacan-taxonomy', 'do_not_dispaly_term_as_link')"
:message="$i18n.getHelperMessage('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" /> :message="$i18n.getHelperMessage('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" />
</b-field> </b-field>
<b-field
:addons="false"
:label="$i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_current_collection')">
&nbsp;
<b-switch
v-model="link_filtered_by_current_collection"
size="is-small"
:disabled="do_not_dispaly_term_as_link == 'yes'"
true-value="yes"
false-value="no"
@update:model-value="emitValues()" />
<help-button
:title="$i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_current_collection')"
:message="$i18n.getHelperMessage('tainacan-taxonomy', 'link_filtered_by_current_collection')" />
</b-field>
<b-field :addons="false"> <b-field :addons="false">
<label class="label"> <label class="label">
{{ $i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_collections') }} {{ $i18n.getHelperTitle('tainacan-taxonomy', 'link_filtered_by_collections') }}
@ -127,7 +142,7 @@
:data="collections.filter((collection) => !link_filtered_by_collections.includes(collection.id) && (collectionSearchString ? (collection.name.toLowerCase().indexOf(collectionSearchString.toLowerCase()) >= 0) : true) )" :data="collections.filter((collection) => !link_filtered_by_collections.includes(collection.id) && (collectionSearchString ? (collection.name.toLowerCase().indexOf(collectionSearchString.toLowerCase()) >= 0) : true) )"
field="name" field="name"
attached attached
:disabled="do_not_dispaly_term_as_link == 'yes'" :disabled="link_filtered_by_current_collection === 'yes' || do_not_dispaly_term_as_link == 'yes'"
:remove-on-keys="[]" :remove-on-keys="[]"
:aria-close-label="$i18n.get('remove_value')" :aria-close-label="$i18n.get('remove_value')"
:class="{'has-selected': link_filtered_by_collections != undefined && link_filtered_by_collections != []}" :class="{'has-selected': link_filtered_by_collections != undefined && link_filtered_by_collections != []}"
@ -194,6 +209,7 @@
allow_new_terms: 'yes', allow_new_terms: 'yes',
hide_hierarchy_path: 'no', hide_hierarchy_path: 'no',
do_not_dispaly_term_as_link: 'no', do_not_dispaly_term_as_link: 'no',
link_filtered_by_current_collection: 'no',
link_filtered_by_collections: [], link_filtered_by_collections: [],
visible_options_list: false, visible_options_list: false,
input_type: 'tainacan-taxonomy-radio', input_type: 'tainacan-taxonomy-radio',
@ -265,6 +281,7 @@
this.taxonomy_id = this.value.taxonomy_id; this.taxonomy_id = this.value.taxonomy_id;
this.allow_new_terms = ( this.value.allow_new_terms ) ? this.value.allow_new_terms : 'no'; this.allow_new_terms = ( this.value.allow_new_terms ) ? this.value.allow_new_terms : 'no';
this.hide_hierarchy_path = ( this.value.hide_hierarchy_path ) ? this.value.hide_hierarchy_path : 'no'; this.hide_hierarchy_path = ( this.value.hide_hierarchy_path ) ? this.value.hide_hierarchy_path : 'no';
this.link_filtered_by_current_collection = ( this.value.link_filtered_by_current_collection ) ? this.value.link_filtered_by_current_collection : 'no';
this.do_not_dispaly_term_as_link = ( this.value.do_not_dispaly_term_as_link ) ? this.value.do_not_dispaly_term_as_link : 'no'; this.do_not_dispaly_term_as_link = ( this.value.do_not_dispaly_term_as_link ) ? this.value.do_not_dispaly_term_as_link : 'no';
if (this.metadatum && this.metadatum.multiple === 'no') { if (this.metadatum && this.metadatum.multiple === 'no') {
@ -331,6 +348,7 @@
input_type: this.input_type, input_type: this.input_type,
allow_new_terms: this.allow_new_terms, allow_new_terms: this.allow_new_terms,
visible_options_list: this.visible_options_list, visible_options_list: this.visible_options_list,
link_filtered_by_current_collection: this.link_filtered_by_current_collection,
link_filtered_by_collections: this.link_filtered_by_collections, link_filtered_by_collections: this.link_filtered_by_collections,
hide_hierarchy_path: this.hide_hierarchy_path, hide_hierarchy_path: this.hide_hierarchy_path,
do_not_dispaly_term_as_link: this.do_not_dispaly_term_as_link, do_not_dispaly_term_as_link: this.do_not_dispaly_term_as_link,

View File

@ -21,6 +21,7 @@ class Taxonomy extends Metadata_Type {
$this->set_default_options([ $this->set_default_options([
'allow_new_terms' => 'no', 'allow_new_terms' => 'no',
'link_filtered_by_current_collection' => 'no',
'link_filtered_by_collections' => [], 'link_filtered_by_collections' => [],
'input_type' => 'tainacan-taxonomy-radio', 'input_type' => 'tainacan-taxonomy-radio',
'hide_hierarchy_path' => 'no', 'hide_hierarchy_path' => 'no',
@ -100,6 +101,10 @@ class Taxonomy extends Metadata_Type {
'title' => __( 'Allow new terms', 'tainacan' ), 'title' => __( 'Allow new terms', 'tainacan' ),
'description' => __( 'Allows to create new terms directly on the item form.', 'tainacan' ), 'description' => __( 'Allows to create new terms directly on the item form.', 'tainacan' ),
], ],
'link_filtered_by_current_collection' => [
'title' => __( 'Link filtered by current collection', 'tainacan' ),
'description' => __( 'Links to term items list filtered by the collection of the current item instead of a repository level term items page.', 'tainacan' ),
],
'link_filtered_by_collections' => [ 'link_filtered_by_collections' => [
'title' => __( 'Link filtered by collections', 'tainacan' ), 'title' => __( 'Link filtered by collections', 'tainacan' ),
'description' => __( 'Links to term items list filtered by certain collections instead of repository level term items page.', 'tainacan' ), 'description' => __( 'Links to term items list filtered by certain collections instead of repository level term items page.', 'tainacan' ),
@ -173,6 +178,7 @@ class Taxonomy extends Metadata_Type {
case 'allow_new_terms': case 'allow_new_terms':
case 'do_not_dispaly_term_as_link': case 'do_not_dispaly_term_as_link':
case 'link_filtered_by_current_collection':
if ($option_value == 'yes') if ($option_value == 'yes')
$readable_option_value = __('Yes', 'tainacan'); $readable_option_value = __('Yes', 'tainacan');
else if ($option_value == 'no') else if ($option_value == 'no')
@ -374,7 +380,7 @@ class Taxonomy extends Metadata_Type {
if ( $term instanceof \Tainacan\Entities\Term ) { if ( $term instanceof \Tainacan\Entities\Term ) {
$return .= $prefix; $return .= $prefix;
$return .= $this->get_term_hierarchy_html($term); $return .= $this->get_term_hierarchy_html($term, $item_metadata->get_item());
$return .= $suffix; $return .= $suffix;
if ( $count <= $total ) { if ( $count <= $total ) {
@ -384,24 +390,24 @@ class Taxonomy extends Metadata_Type {
} }
} else { } else {
if ( $value instanceof \Tainacan\Entities\Term ) { if ( $value instanceof \Tainacan\Entities\Term ) {
$return .= $this->get_term_hierarchy_html($value); $return .= $this->get_term_hierarchy_html($value, $item_metadata->get_item());
} }
} }
return $return; return $return;
} }
private function get_term_hierarchy_html( \Tainacan\Entities\Term $term ) { private function get_term_hierarchy_html( \Tainacan\Entities\Term $term, \Tainacan\Entities\Item $item = null) {
if ( $this->get_option('hide_hierarchy_path') == 'yes' ) if ( $this->get_option('hide_hierarchy_path') == 'yes' )
return $this->term_to_html($term); return $this->term_to_html($term, $item);
$terms = []; $terms = [];
$terms[] = $this->term_to_html($term); $terms[] = $this->term_to_html($term, $item);
while ($term->get_parent() > 0) { while ($term->get_parent() > 0) {
$term = \Tainacan\Repositories\Terms::get_instance()->fetch( (int) $term->get_parent(), $term->get_taxonomy() ); $term = \Tainacan\Repositories\Terms::get_instance()->fetch( (int) $term->get_parent(), $term->get_taxonomy() );
$terms[] = $this->term_to_html($term); $terms[] = $this->term_to_html($term, $item);
} }
$terms = \array_reverse($terms); $terms = \array_reverse($terms);
@ -410,8 +416,8 @@ class Taxonomy extends Metadata_Type {
return \implode($glue, $terms); return \implode($glue, $terms);
} }
private function term_to_html($term) { private function term_to_html($term, \Tainacan\Entities\Item $item = null) {
$collections = $this->get_option( 'link_filtered_by_collections' ); $collections = ( isset($item) && $this->get_option( 'link_filtered_by_current_collection' ) === 'yes' ) ? [ $item->get_collection_id() ] : $this->get_option( 'link_filtered_by_collections' );
$do_not_display_term_as_link = $this->get_option('do_not_dispaly_term_as_link') == 'yes'; $do_not_display_term_as_link = $this->get_option('do_not_dispaly_term_as_link') == 'yes';
if ( !empty( $collections ) ) { if ( !empty( $collections ) ) {

View File

@ -84,7 +84,7 @@
], ],
data() { data() {
return { return {
selectedStatus: !this.$adminOptions.hideItemEditionStatusPublishOption ? 'publish' : 'private' selectedStatus: this.currentUserCanPublish ? ( !this.$adminOptions.hideItemEditionStatusPublishOption ? 'publish' : 'private' ) : 'draft'
} }
}, },
computed: { computed: {

View File

@ -44,11 +44,28 @@
color: var(--tainacan-danger); color: var(--tainacan-danger);
} }
} }
.input, .textarea { .field.is-danger {
&.is-danger { .input,
background-color: var(--tainacan-red1); .textarea,
.select,
.dropdown,
.autocomplete {
--tainacan-input-border-color: var(--tainacan-danger);
--tainacan-input-background-color: var(--tainacan-red1);
} }
} }
.input,
.textarea,
.select {
&.is-danger {
--tainacan-input-border-color: var(--tainacan-danger);
--tainacan-input-background-color: var(--tainacan-red1);
}
}
input[data-is-danger="true"] {
--tainacan-input-border-color: var(--tainacan-danger);
--tainacan-input-background-color: var(--tainacan-red1);
}
a[disabled="true"] { a[disabled="true"] {
opacity: 0.5; opacity: 0.5;
user-select: none; user-select: none;

View File

@ -490,7 +490,7 @@
<p <p
v-if="metadataSection.description && (!hideHelpButtons && helpInfoBellowLabel)" v-if="metadataSection.description && (!hideHelpButtons && helpInfoBellowLabel)"
class="metadatum-description-help-info"> class="metadata-section-description-help-info metadatum-description-help-info">
{{ metadataSection.description }} {{ metadataSection.description }}
</p> </p>
<template v-if="itemMetadata && Array.isArray(itemMetadata)"> <template v-if="itemMetadata && Array.isArray(itemMetadata)">
@ -1498,6 +1498,11 @@ export default {
} }
} }
.metadata-section-description-help-info {
margin: 0.25em 0 0 1.125rem;
}
.metadatum-description-help-info { .metadatum-description-help-info {
font-size: 0.75em; font-size: 0.75em;
color: var(--tainacan-info-color); color: var(--tainacan-info-color);

View File

@ -643,6 +643,7 @@ class Taxonomies extends TAINACAN_UnitTestCase {
'metadata_type_options' => [ 'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(), 'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => 'no', 'allow_new_terms' => 'no',
'link_filtered_by_current_collection' => 'no',
'link_filtered_by_collections' => [$collectionOnly->get_id()] 'link_filtered_by_collections' => [$collectionOnly->get_id()]
] ]
), ),