Adds "item_enable_metadata_enumeration" option to collection. #827.

This commit is contained in:
mateuswetah 2023-11-16 18:20:32 -03:00
parent 3bad3bd8f9
commit eda24e73e3
7 changed files with 70 additions and 7 deletions

View File

@ -50,7 +50,8 @@ class Collection extends Entity {
$item_enable_metadata_focus_mode,
$item_enable_metadata_required_filter,
$item_enable_metadata_searchbar,
$item_enable_metadata_collapses;
$item_enable_metadata_collapses,
$item_enable_metadata_enumeration;
/**
* {@inheritDoc}
@ -707,12 +708,21 @@ class Collection extends Entity {
/**
* Check if metadata collapses are enabled for this collection.
*
* @return bool True if metadata collapses are enabled, 'no' otherwise.
* @return bool 'yes' if metadata collapses are enabled, 'no' otherwise.
*/
function get_item_enable_metadata_collapses() {
return $this->get_mapped_property('item_enable_metadata_collapses');
}
/**
* Check if metadata and metadata section should be enumerated in the edition form.
*
* @return bool 'yes' if metadata are enumerated, 'no' otherwise.
*/
function get_item_enable_metadata_enumeration() {
return $this->get_mapped_property('item_enable_metadata_enumeration');
}
// Setters
/**
* Set the collection name
@ -1088,6 +1098,16 @@ class Collection extends Entity {
$this->set_mapped_property('item_enable_metadata_collapses', $value);
}
/**
* Enable or disable metadata and metadata sections enumeration for the item edition form this collection.
*
* @param string $value 'yes' to enable metadata enumeration, 'no' to disable.
* @return void
*/
function set_item_enable_metadata_enumeration( $value ) {
$this->set_mapped_property('item_enable_metadata_enumeration', $value);
}
/**
* Validate Collection
*

View File

@ -455,6 +455,16 @@ class Collections extends Repository {
'enum' => [ 'yes', 'no' ],
'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no
],
'item_enable_metadata_enumeration' => [
'map' => 'meta',
'title' => __( 'Metadata enumeration', 'tainacan' ),
'type' => 'string',
'description' => __( 'If enabled, the metadata sections and their metadata in the item form will be enumerated automatically.', 'tainacan' ),
'default' => 'no',
'on_error' => __( 'Value should be yes or no', 'tainacan' ),
'enum' => [ 'yes', 'no' ],
'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no
]
] );
}

View File

@ -387,6 +387,12 @@
false-value="no">
{{ $i18n.getHelperTitle('collections', 'item_enable_metadata_searchbar') }}
</b-checkbox>
<b-checkbox
v-model="form.item_enable_metadata_enumeration"
true-value="yes"
false-value="no">
{{ $i18n.getHelperTitle('collections', 'item_enable_metadata_enumeration') }}
</b-checkbox>
</div>
</b-field>
@ -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

View File

@ -398,6 +398,11 @@
<span class="icon has-text-gray4">
<i class="tainacan-icon tainacan-icon-metadata"/>
</span>
<span
v-if="metadataSections.length > 1 && collection.item_enable_metadata_enumeration === 'yes'"
style="opacity: 0.65;">
{{ Number(sectionIndex) + 1 }}.
</span>
{{ metadataSection.name }}&nbsp;
<span
v-if="metadataSection.metadata_object_list && metadataSection.metadata_object_list.length"
@ -438,6 +443,7 @@
:hide-help-buttons="false"
:help-info-bellow-label="false"
:is-mobile-screen="isMobileScreen"
:enumerate-metadatum="metadataSections.length > 1 && collection.item_enable_metadata_enumeration === 'yes' ? ( (Number(sectionIndex) + 1) + '.' + (Number(index) + 1) ) : false"
:is-last-metadatum="index > 2 && (index == itemMetadata.length - 1)"
:is-focused="focusedMetadatum === index"
:is-metadata-navigation="isMetadataNavigation"

View File

@ -30,6 +30,11 @@
<i class="has-text-secondary tainacan-icon tainacan-icon-1-25em tainacan-icon-arrowdown" />
</span>
<label class="label has-tooltip">
<span
v-if="enumerateMetadatum"
style="opacity: 0.65;">
{{ enumerateMetadatum }}.
</span>
{{ childItemMetadatum.metadatum.name }}
</label>
<span
@ -69,6 +74,7 @@
}"
:is-focused="(focusedGroupMetadatum === groupIndex) && (focusedChildMetadatum === childIndex)"
:is-metadata-navigation="isMetadataNavigation"
:enumerate-metadatum="enumerateMetadatum ? ( enumerateMetadatum + ( childItemMetadataGroups.length > 1 ? ( '.' + (Number(groupIndex) + 1) ) : '' ) + '.' + (Number(childIndex) + 1) ) : false"
@touchstart.native="isMetadataNavigation ? setMetadatumChildFocus({ groupIndex: groupIndex, childIndex: childIndex, scrollIntoView: false }): ''"
@mousedown.native="isMetadataNavigation ? setMetadatumChildFocus({ groupIndex: groupIndex, childIndex: childIndex, scrollIntoView: false }) : ''"
@mobileSpecialFocus="setMetadatumChildFocus({ groupIndex: groupIndex, childIndex: childIndex, scrollIntoView: true })"
@ -129,6 +135,7 @@
metadataNameFilterString: '',
isMobileScreen: false,
isMetadataNavigation: false,
enumerateMetadatum: [Boolean|String],
isFocused: false
},
data() {

View File

@ -20,6 +20,11 @@
class="has-text-secondary tainacan-icon tainacan-icon-1-25em"/>
</span>
<label class="label">
<span
v-if="enumerateMetadatum"
style="opacity: 0.65;">
{{ enumerateMetadatum }}.
</span>
{{ itemMetadatum.metadatum.name }}
</label>
<span
@ -147,7 +152,8 @@
:metadata-name-filter-string="metadataNameFilterString"
@mobileSpecialFocus="onMobileSpecialFocus"
:is-focused="isFocused"
:is-metadata-navigation="isMetadataNavigation" />
:is-metadata-navigation="isMetadataNavigation"
:enumerate-metadatum="enumerateMetadatum" />
</div>
</transition>
</b-field>
@ -169,7 +175,8 @@
metadataNameFilterString: '',
isMobileScreen: false,
isFocused: false,
isMetadataNavigation: false
isMetadataNavigation: false,
enumerateMetadatum: [String, Boolean]
},
data(){
return {

View File

@ -239,7 +239,7 @@ export const fetchCollection = ({ commit, }, id) => {
export const fetchCollectionBasics = ({ commit }, {collectionId, isContextEdit }) => {
return new Promise((resolve, reject) => {
let endpoint = '/collections/' + collectionId + '?fetch_only=name,url,status,allow_comments,hide_items_thumbnail_on_lists,item_enabled_document_types,item_document_label,item_thumbnail_label,item_enable_thumbnail,item_attachment_label,item_enable_attachments,item_enable_metadata_focus_mode,item_enable_metadata_required_filter,item_enable_metadata_searchbar,item_enable_metadata_collapses';
let endpoint = '/collections/' + collectionId + '?fetch_only=name,url,status,allow_comments,hide_items_thumbnail_on_lists,item_enabled_document_types,item_document_label,item_thumbnail_label,item_enable_thumbnail,item_attachment_label,item_enable_attachments,item_enable_metadata_focus_mode,item_enable_metadata_required_filter,item_enable_metadata_searchbar,item_enable_metadata_collapses,item_enable_metadata_enumeration';
if (isContextEdit)
endpoint += '&context=edit';