Also adds option to hide thumbnail section. #811.

This commit is contained in:
mateuswetah 2023-10-16 11:21:19 -03:00
parent 5e4c159935
commit 51f39da3b7
7 changed files with 126 additions and 47 deletions

View File

@ -44,6 +44,7 @@ class Collection extends Entity {
$item_enabled_document_types,
$item_document_label,
$item_thumbnail_label,
$item_enable_thubmnail,
$item_attachment_label,
$item_enable_attachments,
$item_enable_metadata_focus_mode,
@ -649,6 +650,15 @@ class Collection extends Entity {
return $this->get_mapped_property('item_thumbnail_label');
}
/**
* Check if thumbnail are enabled for this collection.
*
* @return string 'yes' if thumbnail are enabled, 'no' otherwise.
*/
function get_item_enable_thumbnail() {
return $this->get_mapped_property('item_enable_thumbnail');
}
/**
* Get the plural label for the attachment section in this collection.
*
@ -1008,6 +1018,16 @@ class Collection extends Entity {
$this->set_mapped_property('item_thumbnail_label', $value);
}
/**
* Enable or disable thumbnail for this collection.
*
* @param string $value 'yes' to enable thumbnail, 'no' to disable.
* @return void
*/
function set_item_enable_thumbnail( $value ) {
$this->set_mapped_property('item_enable_thumbnail', $value);
}
/**
* Set the plural label for the attachment section in this collection.
*

View File

@ -387,6 +387,16 @@ class Collections extends Repository {
'default' => __( 'Thumbnail', 'tainacan' ),
//'validation' => v::stringType(),
],
'item_enable_thumbnail' => [
'map' => 'meta',
'title' => __( 'Item thumbnail', 'tainacan' ),
'type' => 'string',
'description' => __( 'If enabled, each item can have a thumbnail customized instead of the one automatically generated based on 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_attachment_label' => [
'map' => 'meta',
'title' => __( 'Attachments plural label', 'tainacan' ),

View File

@ -261,30 +261,29 @@
class="options-columns">
<!-- Allowed types of main document -------------------------------- -->
<b-field
:addons="false"
:label="$i18n.getHelperTitle('collections', 'item_enabled_document_types')">
<help-button
:title="$i18n.getHelperTitle('collections', 'item_enabled_document_types')"
:message="$i18n.getHelperMessage('collections', 'item_enabled_document_types')"/>
<div class="status-radios">
<b-checkbox
v-for="(documentType, slug) in form.item_enabled_document_types"
:key="slug"
v-model="documentType.enabled"
true-value="yes"
false-value="no">
<span class="icon">
<i :class="'tainacan-icon tainacan-icon-' + documentType.icon" />
</span>
{{ documentType.label }}
</b-checkbox>
</div>
</b-field>
<!-- Document and Thumbnail Label -------------------------------- -->
<div>
<b-field
:addons="false"
:label="$i18n.getHelperTitle('collections', 'item_enabled_document_types')">
<help-button
:title="$i18n.getHelperTitle('collections', 'item_enabled_document_types')"
:message="$i18n.getHelperMessage('collections', 'item_enabled_document_types')"/>
<div class="status-radios">
<b-checkbox
v-for="(documentType, slug) in form.item_enabled_document_types"
:key="slug"
v-model="documentType.enabled"
true-value="yes"
false-value="no">
<span class="icon">
<i :class="'tainacan-icon tainacan-icon-' + documentType.icon" />
</span>
{{ documentType.label }}
</b-checkbox>
</div>
</b-field>
<b-field
v-if="Object.values(form.item_enabled_document_types).some((aDocumentType) => aDocumentType.enabled === 'yes')"
:addons="false"
:label="$i18n.getHelperTitle('collections', 'item_document_label')">
<help-button
@ -294,8 +293,28 @@
id="tainacan-text-item-document-label"
v-model="form.item_document_label" />
</b-field>
</div>
<!-- Thumbnail Label -------------------------------- -->
<div>
<b-field
style="margin-top: 1.5rem; margin-bottom: 0rem;"
:addons="false"
:label="$i18n.getHelperTitle('collections', 'item_enable_thumbnail')">
&nbsp;
<b-switch
id="tainacan-checkbox-item-enable-thumbnail"
size="is-small"
true-value="yes"
false-value="no"
v-model="form.item_enable_thumbnail" />
<help-button
:title="$i18n.getHelperTitle('collections', 'item_enable_thumbnail')"
:message="$i18n.getHelperMessage('collections', 'item_enable_thumbnail')"/>
</b-field>
<b-field
v-if="form.item_enable_thumbnail === 'yes'"
:addons="false"
:label="$i18n.getHelperTitle('collections', 'item_thumbnail_label')">
<help-button
@ -918,6 +937,7 @@ export default {
},
item_document_label: this.$i18n.get( 'Document', 'tainacan' ),
item_thumbnail_label: this.$i18n.get( 'Thumbnail', 'tainacan' ),
item_enable_thumbnail: 'yes',
item_attachment_label: this.$i18n.get( 'Attachments', 'tainacan' ),
item_enable_attachments: 'yes',
item_enable_metadata_focus_mode: 'yes',
@ -1050,6 +1070,7 @@ export default {
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_enable_thumbnail = this.collection.item_enable_thumbnail;
this.form.item_attachment_label = this.collection.item_attachment_label;
this.form.item_enable_attachments = this.collection.item_enable_attachments;
this.form.item_enable_metadata_focus_mode = this.collection.item_enable_metadata_focus_mode;
@ -1170,6 +1191,7 @@ export default {
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_enable_thumbnail: this.form.item_enable_thumbnail,
item_attachment_label: this.form.item_attachment_label,
item_enable_attachments: this.form.item_enable_attachments,
item_enable_metadata_focus_mode: this.form.item_enable_metadata_focus_mode,
@ -1207,6 +1229,7 @@ export default {
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_enable_thumbnail = this.collection.item_enable_thumbnail;
this.form.item_attachment_label = this.collection.item_attachment_label;
this.form.item_enable_attachments = this.collection.item_enable_attachments;
this.form.item_enable_metadata_focus_mode = this.collection.item_enable_metadata_focus_mode;
@ -1276,6 +1299,7 @@ export default {
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_enable_thumbnail = this.collection.item_enable_thumbnail;
this.form.item_attachment_label = this.collection.item_attachment_label;
this.form.item_enable_attachments = this.collection.item_enable_attachments;
this.form.item_enable_metadata_focus_mode = this.collection.item_enable_metadata_focus_mode;
@ -1613,6 +1637,11 @@ export default {
padding-right: 0.25em;
padding-bottom: 1.25em;border-left: 1px solid var(--tainacan-gray2);
& .field,
&>div {
break-inside: avoid;
}
&>div:not(.field) {
-moz-column-count: 2;
-moz-column-gap: 0;
@ -1740,7 +1769,7 @@ export default {
}
.status-radios {
display: flex;
margin: 5px 0;
.control-lable {
display: flex;
align-items: center;

View File

@ -1,8 +1,6 @@
<template>
<div>
<div
v-if="!$adminOptions.hideItemEditionDocument"
class="section-label">
<div v-if="!$adminOptions.hideItemEditionDocument && ( !$adminOptions.hideItemEditionDocumentFileInput && !$adminOptions.hideItemEditionDocumentTextInput && !$adminOptions.hideItemEditionDocumentUrlInput )">
<div class="section-label">
<label>
<span class="icon has-text-gray4">
<i :class="'tainacan-icon tainacan-icon-' + ( (!form.document_type || form.document_type == 'empty' ) ? 'item' : (form.document_type == 'attachment' ? 'attachments' : form.document_type))"/>
@ -13,9 +11,7 @@
:title="collection && collection.item_document_label ? collection.item_document_label : $i18n.getHelperTitle('items', 'document')"
:message="$i18n.getHelperMessage('items', 'document')"/>
</div>
<div
v-if="!$adminOptions.hideItemEditionDocument"
class="section-box document-field">
<div class="section-box document-field">
<div
v-if="form.document != undefined && form.document != null &&
form.document_type != undefined && form.document_type != null &&

View File

@ -142,7 +142,7 @@
<span>{{ $i18n.get('label_all_metadata') }}</span>
</button>
<button
v-if="!$adminOptions.hideItemEditionDocument"
v-if="shouldDisplayItemEditionDocument || shouldDisplayItemEditionThumbnail"
@click="activeTab = 'document'; isMobileSubheaderOpen = false;">
<span><i class="tainacan-icon tainacan-icon-1-25em tainacan-icon-item" /></span>
<span>{{ $i18n.get('label_document_and_thumbnail') }}</span>
@ -177,7 +177,7 @@
<div
class="column main-column"
:class="
(( (!$adminOptions.hideItemEditionDocument || !$adminOptions.hideItemEditionThumbnail) && !$adminOptions.itemEditionDocumentInsideTabs) ||
(( (shouldDisplayItemEditionDocument || shouldDisplayItemEditionThumbnail) && !$adminOptions.itemEditionDocumentInsideTabs) ||
(shouldDisplayItemEditionAttachments && !$adminOptions.itemEditionAttachmentsInsideTabs)) ? 'is-7' : 'is-12'">
<!-- Hook for extra Form options -->
@ -535,7 +535,7 @@
</div>
<div
v-if="( (!$adminOptions.hideItemEditionDocument || !$adminOptions.hideItemEditionThumbnail) && !$adminOptions.itemEditionDocumentInsideTabs) ||
v-if="( (shouldDisplayItemEditionDocument || shouldDisplayItemEditionThumbnail) && !$adminOptions.itemEditionDocumentInsideTabs) ||
(shouldDisplayItemEditionAttachments && !$adminOptions.itemEditionAttachmentsInsideTabs)"
class="column is-5">
@ -553,7 +553,7 @@
<!-- Document -------------------------------- -->
<item-document-edition-form
v-if="!$adminOptions.itemEditionDocumentInsideTabs"
v-if="shouldDisplayItemEditionDocument && !$adminOptions.itemEditionDocumentInsideTabs"
:item="item"
:form="form"
:collection="collection"
@ -562,11 +562,12 @@
@onSetFileDocument="setFileDocument"
@onSetTextDocument="setTextDocument"
@onSetURLDocument="setURLDocument" />
<hr>
<hr v-if="shouldDisplayItemEditionDocument && shouldDisplayItemEditionThumbnail">
<!-- Thumbnail -------------------------------- -->
<item-thumbnail-edition-form
v-if="!$adminOptions.itemEditionDocumentInsideTabs"
v-if="shouldDisplayItemEditionThumbnail && !$adminOptions.itemEditionDocumentInsideTabs"
:item="item"
:form="form"
:collection="collection"
@ -880,7 +881,7 @@ export default {
name: this.$i18n.get('metadata'),
total: this.itemMetadata.length
}];
if ( this.$adminOptions.itemEditionDocumentInsideTabs && (!this.$adminOptions.hideItemEditionDocument || !this.$adminOptions.hideItemEditionThumbnail) ) {
if ( this.$adminOptions.itemEditionDocumentInsideTabs && (this.shouldDisplayItemEditionDocument || this.shouldDisplayItemEditionThumbnail) ) {
pageTabs.push({
slug: 'document',
icon: 'item',
@ -910,6 +911,18 @@ export default {
return false;
return this.itemMetadata[this.focusedMetadatum].metadatum && this.itemMetadata[this.focusedMetadatum].metadatum.metadata_type === 'Tainacan\\Metadata_Types\\Compound';
},
shouldDisplayItemEditionDocument() {
return !this.$adminOptions.hideItemEditionDocument &&
( this.collection && this.collection.item_enabled_document_types && (
( this.collection.item_enabled_document_types['attachment'] && this.collection.item_enabled_document_types['attachment']['enabled'] === 'yes' ) ||
( this.collection.item_enabled_document_types['text'] && this.collection.item_enabled_document_types['text']['enabled'] === 'yes' ) ||
( this.collection.item_enabled_document_types['url'] && this.collection.item_enabled_document_types['url']['enabled'] === 'yes' )
)
);
},
shouldDisplayItemEditionThumbnail() {
return !this.$adminOptions.hideItemEditionThumbnail && (this.collection && this.collection.item_enable_thumbnail === 'yes');
},
shouldDisplayItemEditionAttachments() {
return !this.$adminOptions.hideItemEditionAttachments && (this.collection && this.collection.item_enable_attachments === 'yes');
}

View File

@ -236,7 +236,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_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';
if (isContextEdit)
endpoint += '&context=edit';

View File

@ -36,7 +36,7 @@
<div
class="column"
:class="!$adminOptions.hideItemSingleDocument || !$adminOptions.hideItemSingleThumbnail ? 'is-7' : 'is-12'">
:class="shouldDisplayItemSingleDocument || shouldDisplayItemSingleThumbnail ? 'is-7' : 'is-12'">
<!-- Hook for extra Form options -->
<template v-if="hasBeginRightForm">
@ -179,7 +179,7 @@
</div>
<div
v-if="!$adminOptions.hideItemSingleDocument || !$adminOptions.hideItemSingleThumbnail"
v-if="shouldDisplayItemSingleDocument || shouldDisplayItemSingleThumbnail"
class="column is-5">
<div class="sticky-container">
@ -193,7 +193,7 @@
<!-- Document -------------------------------- -->
<div
v-if="!$adminOptions.hideItemSingleDocument"
v-if="shouldDisplayItemSingleDocument"
class="section-label">
<label>
<span class="icon has-text-gray4 tainacan-icon-1-125em">
@ -203,7 +203,7 @@
</label>
</div>
<div
v-if="!$adminOptions.hideItemSingleDocument"
v-if="shouldDisplayItemSingleDocument"
class="section-box document-field">
<div
v-if="item.document !== undefined && item.document !== null &&
@ -216,10 +216,9 @@
<p>{{ $i18n.get('info_no_document_to_item') }}</p>
</div>
</div>
<!-- Thumbnail -------------------------------- -->
<div
v-if="!$adminOptions.hideItemSingleThumbnail"
v-if="shouldDisplayItemSingleThumbnail"
class="section-label">
<label>
<span class="icon has-text-gray4">
@ -229,7 +228,7 @@
</label>
</div>
<div
v-if="!$adminOptions.hideItemSingleThumbnail"
v-if="shouldDisplayItemSingleThumbnail"
class="section-box section-thumbnail">
<div class="thumbnail-field">
<file-item
@ -537,6 +536,18 @@
}
return pageTabs;
},
shouldDisplayItemSingleDocument() {
return !this.$adminOptions.hideItemSingleDocument &&
( this.collection && this.collection.item_enabled_document_types && (
( this.collection.item_enabled_document_types['attachment'] && this.collection.item_enabled_document_types['attachment']['enabled'] === 'yes' ) ||
( this.collection.item_enabled_document_types['text'] && this.collection.item_enabled_document_types['text']['enabled'] === 'yes' ) ||
( this.collection.item_enabled_document_types['url'] && this.collection.item_enabled_document_types['url']['enabled'] === 'yes' )
)
);
},
shouldDisplayItemSingleThumbnail() {
return !this.$adminOptions.hideItemSingleThumbnail && (this.collection && this.collection.item_enable_thumbnail === 'yes');
},
shouldDisplayItemSingleAttachments() {
return !this.$adminOptions.hideItemSingleAttachments && (this.collection && this.collection.item_enable_attachments === 'yes');
}