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>
</label>
<help-button
v-if="metadataSection.description"
v-if="metadataSection.description && metadataSection.description_bellow_name !== 'yes'"
:title="metadataSection.name"
:message="metadataSection.description" />
</span>
@ -422,7 +422,7 @@
class="metadata-section-metadata-list">
<p
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 }}
</p>
@ -1326,9 +1326,16 @@ export default {
parentMetaId: 0
});
}
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
);
// Loads metadata and attachments
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;
});
@ -1771,8 +1787,16 @@ export default {
if (this.form.document_options !== undefined && this.form.document_options['forced_iframe_height'] !== undefined)
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.setLastUpdated(this.item.modification_date);
@ -2041,6 +2065,9 @@ export default {
margin-left: 12px;
}
}
.metadata-section-description-help-info {
margin: 0.25em 0 0 1.125rem;
}
.item-edition-tab-content .tab-item>.field:last-child {
margin-bottom: 187px;
}

View File

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

View File

@ -19,7 +19,9 @@
}"
class="has-text-secondary tainacan-icon tainacan-icon-1-25em" />
</span>
<label class="label">
<label
class="label"
:class="{ 'has-text-danger': errorMessage }">
<span
v-if="enumerateMetadatum"
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.description ? ' has-description' : '') +
(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() {

View File

@ -113,6 +113,21 @@
:title="$i18n.getHelperTitle('tainacan-taxonomy', 'do_not_dispaly_term_as_link')"
:message="$i18n.getHelperMessage('tainacan-taxonomy', 'do_not_dispaly_term_as_link')" />
</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">
<label class="label">
{{ $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) )"
field="name"
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="[]"
:aria-close-label="$i18n.get('remove_value')"
:class="{'has-selected': link_filtered_by_collections != undefined && link_filtered_by_collections != []}"
@ -194,6 +209,7 @@
allow_new_terms: 'yes',
hide_hierarchy_path: 'no',
do_not_dispaly_term_as_link: 'no',
link_filtered_by_current_collection: 'no',
link_filtered_by_collections: [],
visible_options_list: false,
input_type: 'tainacan-taxonomy-radio',
@ -265,6 +281,7 @@
this.taxonomy_id = this.value.taxonomy_id;
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.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';
if (this.metadatum && this.metadatum.multiple === 'no') {
@ -331,6 +348,7 @@
input_type: this.input_type,
allow_new_terms: this.allow_new_terms,
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,
hide_hierarchy_path: this.hide_hierarchy_path,
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([
'allow_new_terms' => 'no',
'link_filtered_by_current_collection' => 'no',
'link_filtered_by_collections' => [],
'input_type' => 'tainacan-taxonomy-radio',
'hide_hierarchy_path' => 'no',
@ -100,6 +101,10 @@ class Taxonomy extends Metadata_Type {
'title' => __( 'Allow new terms', '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' => [
'title' => __( 'Link filtered by collections', '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 'do_not_dispaly_term_as_link':
case 'link_filtered_by_current_collection':
if ($option_value == 'yes')
$readable_option_value = __('Yes', 'tainacan');
else if ($option_value == 'no')
@ -374,7 +380,7 @@ class Taxonomy extends Metadata_Type {
if ( $term instanceof \Tainacan\Entities\Term ) {
$return .= $prefix;
$return .= $this->get_term_hierarchy_html($term);
$return .= $this->get_term_hierarchy_html($term, $item_metadata->get_item());
$return .= $suffix;
if ( $count <= $total ) {
@ -384,24 +390,24 @@ class Taxonomy extends Metadata_Type {
}
} else {
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;
}
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' )
return $this->term_to_html($term);
return $this->term_to_html($term, $item);
$terms = [];
$terms[] = $this->term_to_html($term);
$terms[] = $this->term_to_html($term, $item);
while ($term->get_parent() > 0) {
$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);
@ -410,8 +416,8 @@ class Taxonomy extends Metadata_Type {
return \implode($glue, $terms);
}
private function term_to_html($term) {
$collections = $this->get_option( 'link_filtered_by_collections' );
private function term_to_html($term, \Tainacan\Entities\Item $item = null) {
$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';
if ( !empty( $collections ) ) {

View File

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

View File

@ -44,11 +44,28 @@
color: var(--tainacan-danger);
}
}
.input, .textarea {
&.is-danger {
background-color: var(--tainacan-red1);
.field.is-danger {
.input,
.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"] {
opacity: 0.5;
user-select: none;

View File

@ -490,7 +490,7 @@
<p
v-if="metadataSection.description && (!hideHelpButtons && helpInfoBellowLabel)"
class="metadatum-description-help-info">
class="metadata-section-description-help-info metadatum-description-help-info">
{{ metadataSection.description }}
</p>
<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 {
font-size: 0.75em;
color: var(--tainacan-info-color);

View File

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