Emmits errors of parent compound metadata.

This commit is contained in:
mateuswetah 2024-11-06 10:37:10 -03:00
parent 30e8335ec9
commit 07d6243aba
2 changed files with 70 additions and 68 deletions

View File

@ -1280,17 +1280,7 @@ export default {
}) })
.catch((errors) => { .catch((errors) => {
if (errors.errors) { this.prepareErrors(errors);
for (let error of errors.errors) {
for (let metadatum of Object.keys(error)){
this.errors.push({
metadatum_id: metadatum,
errors: error[metadatum]
});
}
}
this.formErrorMessage = errors.error_message;
}
this.form.status = previousStatus; this.form.status = previousStatus;
this.item.status = previousStatus; this.item.status = previousStatus;
@ -1527,16 +1517,7 @@ export default {
this.isLoading = false; this.isLoading = false;
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { this.prepareErrors(errors);
for (let metadatum of Object.keys(error)){
this.errors.push({
metadatum_id: metadatum,
errors: error[metadatum]
});
}
}
this.formErrorMessage = errors.error_message;
this.isLoading = false; this.isLoading = false;
}); });
}, },
@ -1610,16 +1591,7 @@ export default {
} }
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { this.prepareErrors(errors);
for (let metadatum of Object.keys(error)){
this.errors.push({
metadatum_id: metadatum,
errors: error[metadatum]
});
}
}
this.formErrorMessage = errors.error_message;
this.isLoading = false; this.isLoading = false;
}); });
}, },
@ -1638,15 +1610,7 @@ export default {
this.shouldLoadAttachments = !this.shouldLoadAttachments; this.shouldLoadAttachments = !this.shouldLoadAttachments;
}) })
.catch((errors) => { .catch((errors) => {
for (let error of errors.errors) { this.prepareErrors(errors);
for (let metadatum of Object.keys(error)){
this.errors.push({
metadatum_id: metadatum,
errors: error[metadatum]
});
}
}
this.formErrorMessage = errors.error_message;
}); });
}, },
deleteThumbnail() { deleteThumbnail() {
@ -1698,29 +1662,24 @@ export default {
this.form.document = file.id + ''; this.form.document = file.id + '';
this.updateItemDocument({ item_id: this.itemId, document: this.form.document, document_type: this.form.document_type }) this.updateItemDocument({ item_id: this.itemId, document: this.form.document, document_type: this.form.document_type })
.then((item) => { .then((item) => {
this.isLoading = false; this.isLoading = false;
this.item.document_as_html = item.document_as_html; this.item.document_as_html = item.document_as_html;
this.item.document_mimetype = item.document_mimetype; this.item.document_mimetype = item.document_mimetype;
let oldThumbnail = this.item.thumbnail; let oldThumbnail = this.item.thumbnail;
if (item.document_type == 'attachment' && oldThumbnail != item.thumbnail ) { if (item.document_type == 'attachment' && oldThumbnail != item.thumbnail ) {
this.item.thumbnail = item.thumbnail; this.item.thumbnail = item.thumbnail;
this.item.thumbnail_id = item.thumbnail_id; this.item.thumbnail_id = item.thumbnail_id;
}
this.shouldLoadAttachments = !this.shouldLoadAttachments;
})
.catch((errors) => {
for (let error of errors.errors) {
for (let metadatum of Object.keys(error)){
this.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
} }
}
this.formErrorMessage = errors.error_message; this.shouldLoadAttachments = !this.shouldLoadAttachments;
this.isLoading = false;
}); })
.catch((errors) => {
this.prepareErrors(errors);
this.isLoading = false;
});
} }
} }
); );
@ -2024,6 +1983,39 @@ export default {
} }
return enabledMetadata.indexOf(metadatum.id); return enabledMetadata.indexOf(metadatum.id);
},
prepareErrors(errors) {
if ( errors.errors ) {
for (let error of errors.errors) {
for (let metadatumId of Object.keys(error)) {
let parentCompoundId = false;
for (let itemMetadatum of this.itemMetadata) {
if (
itemMetadatum.metadatum.metadata_type == 'Tainacan\\Metadata_Types\\Compound' &&
itemMetadatum.metadatum.metadata_type_options &&
itemMetadatum.metadatum.metadata_type_options.children_objects
) {
for (let childMetadatum of itemMetadatum.metadatum.metadata_type_options.children_objects) {
if ( childMetadatum.id == metadatumId ) {
parentCompoundId = itemMetadatum.metadatum.id;
break;
}
}
}
}
this.errors.push({
metadatum_id: parentCompoundId ? parentCompoundId : metadatumId,
errors: error[metadatumId]
});
}
}
this.formErrorMessage = errors.error_message;
}
} }
} }
} }

View File

@ -20,9 +20,10 @@ export const itemMetadataMixin = {
handler() { handler() {
this.hasErrorsOnForm( this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length ); this.hasErrorsOnForm( this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length );
if (this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length) { if ( this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length ) {
for (let error of this.errors) for (let error of this.errors) {
this.$emitter.emit('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error); this.$emitter.emit('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error);
}
} }
}, },
deep: true deep: true
@ -36,8 +37,8 @@ export const itemMetadataMixin = {
'deleteGroupFromItemSubmissionMetadatum' 'deleteGroupFromItemSubmissionMetadatum'
]), ]),
updateItemMetadataValue({ itemId, metadatumId, values, parentMetaId, parentId }) { updateItemMetadataValue({ itemId, metadatumId, values, parentMetaId, parentId }) {
if (itemId) { if ( itemId ) {
this.isUpdatingValues = true; this.isUpdatingValues = true;
@ -54,15 +55,18 @@ export const itemMetadataMixin = {
}) })
.then(() => { .then(() => {
this.isUpdatingValues = false; this.isUpdatingValues = false;
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true )); let index = this.errors.findIndex( errorItem => ( errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true ) ) || ( errorItem.metadatum_id == parentId ) );
if (index >= 0) if ( index >= 0 )
this.errors.splice( index, 1); this.errors.splice( index, 1);
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]); this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
if ( parentId )
this.$emitter.emit('updateErrorMessageOf#' + parentId );
}) })
.catch(({ error_message, error, item_metadata }) => { .catch(({ error_message, error, item_metadata }) => {
this.isUpdatingValues = false; this.isUpdatingValues = false;
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true )); let index = this.errors.findIndex( errorItem => ( errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true ) ) || ( errorItem.metadatum_id == parentId ) );
let messages = []; let messages = [];
for (let index in error) for (let index in error)
@ -71,9 +75,15 @@ export const itemMetadataMixin = {
if ( index >= 0) { if ( index >= 0) {
Object.assign( this.errors, { [index]: { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } }); Object.assign( this.errors, { [index]: { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } });
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]); this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
if ( parentId )
this.$emitter.emit('updateErrorMessageOf#' + parentId );
} else { } else {
this.errors.push( { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } ); this.errors.push( { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } );
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[0]); this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[0]);
if ( parentId )
this.$emitter.emit('updateErrorMessageOf#' + parentId );
} }
}); });