Improvements to upload error messages #388.

This commit is contained in:
mateuswetah 2020-10-29 10:05:05 -03:00
parent f96203f2d1
commit 42e70f8226
2 changed files with 33 additions and 6 deletions

View File

@ -1011,7 +1011,7 @@ class REST_Items_Controller extends REST_Controller {
move_uploaded_file($files['document']['tmp_name'], $tmp_file_name);
$document_id = $TainacanMedia->insert_attachment_from_file($tmp_file_name, $item_id);
if($document_id === false) {
$entities_erros[] = ["document" => __('error on create document', 'tainacan')];
$entities_erros[] = ["document" => __('Error while creating document', 'tainacan')];
wp_delete_attachment($document_id, true);
} else {
$item->set_document_type('attachment');
@ -1026,7 +1026,7 @@ class REST_Items_Controller extends REST_Controller {
move_uploaded_file($files['thumbnail']['tmp_name'], $tmp_file_name);
$thumbnail_id = $TainacanMedia->insert_attachment_from_file($tmp_file_name);
if($thumbnail_id === false) {
$entities_erros[] = ["thumbnail" => __('error on create thumbnail', 'tainacan')];
$entities_erros[] = ["thumbnail" => __('Error while creating thumbnail', 'tainacan')];
wp_delete_attachment($thumbnail_id, true);
} else {
$item->set__thumbnail_id($thumbnail_id);
@ -1050,7 +1050,7 @@ class REST_Items_Controller extends REST_Controller {
$attachment_id = $TainacanMedia->insert_attachment_from_file($tmp_file_name, $item_id);
unlink($tmp_file_name);
if($attachment_id === false) {
$entities_erros[] = ['attachments' => __('error on create attachment ', 'tainacan') . "($attachments_name[$i])" ];
$entities_erros[] = ['attachments' => __('Error while creating attachment ', 'tainacan') . "($attachments_name[$i])" ];
break;
}
$insert_attachments[] = $attachment_id;

View File

@ -63,10 +63,15 @@
attached
:aria-close-label="$i18n.get('delete')"
@close="form.document = ''"
:type="formErrors.find(error => error.metadatum_id== 'document') ? 'is-danger' : ''">
:type="documentErrorMessage ? 'is-danger' : ''">
{{ form.document.name }}
</b-tag>
</div>
<p
v-if="documentErrorMessage"
class="help is-danger">
{{ documentErrorMessage }}
</p>
</div>
<div v-if="form.document_type == 'text'">
<b-input
@ -177,10 +182,15 @@
attached
:aria-close-label="$i18n.get('delete')"
@close="form.thumbnail = null"
:type="formErrors.find(error => error.metadatum_id == 'thumbnail') ? 'is-danger' : ''">
:type="thumbnailErrorMessage ? 'is-danger' : ''">
{{ form.thumbnail.name }}
</b-tag>
</div>
<p
v-if="thumbnailErrorMessage"
class="help is-danger">
{{ thumbnailErrorMessage }}
</p>
</div>
</template>
@ -238,10 +248,15 @@
attached
:aria-close-label="$i18n.get('delete')"
@close="form.attachments.splice(index, 1)"
:type="formErrors.find(error => error.metadatum_id == 'attachments') ? 'is-danger' : ''">
:type="attachmentsErrorMessage.includes(attachment.name) ? 'is-danger' : ''">
{{ attachment.name }}
</b-tag>
</div>
<p
v-if="attachmentsErrorMessage"
class="help is-danger">
{{ attachmentsErrorMessage }}
</p>
</div>
</template>
@ -477,6 +492,18 @@ export default {
},
hasMoreThanOneDocumentTypeOption() {
return [ this.hideFileModalButton, this.hideTextModalButton, this.hideLinkModalButton ].filter((option) => { return option == false }).length > 1;
},
documentErrorMessage() {
const existingError = this.formErrors.find(error => error.metadatum_id == 'document');
return existingError ? existingError.errors : '';
},
attachmentsErrorMessage() {
const existingError = this.formErrors.find(error => error['attachments'] || error.metadatum_id == 'attachments');
return existingError ? existingError.errors : '';
},
thumbnailErrorMessage() {
const existingError = this.formErrors.find(error => error.metadatum_id == 'thumbnail');
return existingError ? existingError.errors : '';
}
},
created() {