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) => {
if (errors.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.prepareErrors(errors);
this.form.status = previousStatus;
this.item.status = previousStatus;
@ -1527,16 +1517,7 @@ export default {
this.isLoading = false;
})
.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.prepareErrors(errors);
this.isLoading = false;
});
},
@ -1610,16 +1591,7 @@ export default {
}
})
.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.prepareErrors(errors);
this.isLoading = false;
});
},
@ -1638,15 +1610,7 @@ export default {
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.prepareErrors(errors);
});
},
deleteThumbnail() {
@ -1698,29 +1662,24 @@ export default {
this.form.document = file.id + '';
this.updateItemDocument({ item_id: this.itemId, document: this.form.document, document_type: this.form.document_type })
.then((item) => {
this.isLoading = false;
this.item.document_as_html = item.document_as_html;
this.item.document_mimetype = item.document_mimetype;
.then((item) => {
this.isLoading = false;
this.item.document_as_html = item.document_as_html;
this.item.document_mimetype = item.document_mimetype;
let oldThumbnail = this.item.thumbnail;
if (item.document_type == 'attachment' && oldThumbnail != item.thumbnail ) {
this.item.thumbnail = item.thumbnail;
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]});
let oldThumbnail = this.item.thumbnail;
if (item.document_type == 'attachment' && oldThumbnail != item.thumbnail ) {
this.item.thumbnail = item.thumbnail;
this.item.thumbnail_id = item.thumbnail_id;
}
}
this.formErrorMessage = errors.error_message;
this.isLoading = false;
});
this.shouldLoadAttachments = !this.shouldLoadAttachments;
})
.catch((errors) => {
this.prepareErrors(errors);
this.isLoading = false;
});
}
}
);
@ -2024,6 +1983,39 @@ export default {
}
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() {
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) {
for (let error of this.errors)
if ( this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length ) {
for (let error of this.errors) {
this.$emitter.emit('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error);
}
}
},
deep: true
@ -37,7 +38,7 @@ export const itemMetadataMixin = {
]),
updateItemMetadataValue({ itemId, metadatumId, values, parentMetaId, parentId }) {
if (itemId) {
if ( itemId ) {
this.isUpdatingValues = true;
@ -54,15 +55,18 @@ export const itemMetadataMixin = {
})
.then(() => {
this.isUpdatingValues = false;
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true ));
if (index >= 0)
let index = this.errors.findIndex( errorItem => ( errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true ) ) || ( errorItem.metadatum_id == parentId ) );
if ( index >= 0 )
this.errors.splice( index, 1);
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
if ( parentId )
this.$emitter.emit('updateErrorMessageOf#' + parentId );
})
.catch(({ error_message, error, item_metadata }) => {
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 = [];
for (let index in error)
@ -71,9 +75,15 @@ export const itemMetadataMixin = {
if ( index >= 0) {
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]);
if ( parentId )
this.$emitter.emit('updateErrorMessageOf#' + parentId );
} else {
this.errors.push( { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } );
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[0]);
if ( parentId )
this.$emitter.emit('updateErrorMessageOf#' + parentId );
}
});