From 0286a46c9660a09437f206812e838ab9fa16f504 Mon Sep 17 00:00:00 2001 From: Julien Giannone Date: Fri, 27 Nov 2020 11:41:04 +0000 Subject: [PATCH] [IMP] mail: Rename temporary to uploading in attachments related content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit renames "temporary" into "uploading" in attachments content task-2337268 closes odoo/odoo#62526 Signed-off-by: Alexandre Kühn (aku) --- .../src/components/attachment/attachment.js | 5 ++- .../src/components/attachment/attachment.xml | 10 +++--- .../src/components/composer/composer_tests.js | 10 +++--- .../components/file_uploader/file_uploader.js | 14 ++++---- .../src/models/attachment/attachment.js | 34 +++++++++---------- .../src/models/attachment/attachment_tests.js | 2 +- .../static/src/models/composer/composer.js | 11 +++--- .../src/models/message/message_tests.js | 2 +- .../mail/static/src/models/thread/thread.js | 4 +-- .../tours/mail_full_composer_test_tour.js | 2 +- 10 files changed, 46 insertions(+), 48 deletions(-) diff --git a/addons/mail/static/src/components/attachment/attachment.js b/addons/mail/static/src/components/attachment/attachment.js index 0b8fd623f7c..6dc894027d9 100644 --- a/addons/mail/static/src/components/attachment/attachment.js +++ b/addons/mail/static/src/components/attachment/attachment.js @@ -39,13 +39,12 @@ class Attachment extends Component { } /** - * Return the url of the attachment. Temporary attachments, a.k.a. uploading - * attachments, do not have an url. + * Return the url of the attachment. Uploading attachments do not have an url. * * @returns {string} */ get attachmentUrl() { - if (this.attachment.isTemporary) { + if (this.attachment.isUploading) { return ''; } return this.env.session.url('/web/content', { diff --git a/addons/mail/static/src/components/attachment/attachment.xml b/addons/mail/static/src/components/attachment/attachment.xml index 96e96b407ee..27930259bdf 100644 --- a/addons/mail/static/src/components/attachment/attachment.xml +++ b/addons/mail/static/src/components/attachment/attachment.xml @@ -7,7 +7,7 @@ 'o-downloadable': props.isDownloadable, 'o-editable': props.isEditable, 'o-has-card-details': detailsMode === 'card', - 'o-temporary': attachment and attachment.isTemporary, + 'o-isUploading': attachment and attachment.isUploading, 'o-viewable': attachment and attachment.isViewable, }" t-att-title="attachment ? attachment.displayName : undefined" t-att-data-attachment-local-id="attachment ? attachment.localId : undefined" > @@ -49,7 +49,7 @@ - +
@@ -77,13 +77,13 @@
- +
- +
@@ -95,7 +95,7 @@
- +
diff --git a/addons/mail/static/src/components/composer/composer_tests.js b/addons/mail/static/src/components/composer/composer_tests.js index c4fec2f8169..1b88d261c1d 100644 --- a/addons/mail/static/src/components/composer/composer_tests.js +++ b/addons/mail/static/src/components/composer/composer_tests.js @@ -1749,7 +1749,7 @@ QUnit.test('composer: send button is disabled if attachment upload is not finish ); assert.containsOnce( document.body, - '.o_Attachment.o-temporary', + '.o_Attachment.o-isUploading', "attachment displayed is being uploaded" ); assert.containsOnce( @@ -1771,7 +1771,7 @@ QUnit.test('composer: send button is disabled if attachment upload is not finish ); assert.containsNone( document.body, - '.o_Attachment.o-temporary', + '.o_Attachment.o-isUploading', "attachment displayed should be uploaded" ); assert.containsOnce( @@ -1841,7 +1841,7 @@ QUnit.test('warning on send with shortcut when attempting to post message with s ); assert.containsOnce( document.body, - '.o_Attachment.o-temporary', + '.o_Attachment.o-isUploading', "attachment displayed is being uploaded" ); assert.containsOnce( @@ -1936,7 +1936,7 @@ QUnit.test('remove an uploading attachment', async function (assert) { ); assert.containsOnce( document.body, - '.o_Composer .o_Attachment.o-temporary', + '.o_Attachment.o-isUploading', "should have an uploading attachment" ); @@ -1945,7 +1945,7 @@ QUnit.test('remove an uploading attachment', async function (assert) { assert.containsNone( document.body, '.o_Composer .o_Attachment', - "should not have any attachment left after unlinking temporary one" + "should not have any attachment left after unlinking uploading one" ); }); diff --git a/addons/mail/static/src/components/file_uploader/file_uploader.js b/addons/mail/static/src/components/file_uploader/file_uploader.js index 8718f819e11..bb8c6c5b460 100644 --- a/addons/mail/static/src/components/file_uploader/file_uploader.js +++ b/addons/mail/static/src/components/file_uploader/file_uploader.js @@ -36,7 +36,7 @@ class FileUploader extends Component { */ async uploadFiles(files) { await this._unlinkExistingAttachments(files); - this._createTemporaryAttachments(files); + this._createUploadingAttachments(files); await this._performUpload(files); this._fileInputRef.el.value = ''; } @@ -81,11 +81,11 @@ class FileUploader extends Component { * @private * @param {FileList|Array} files */ - _createTemporaryAttachments(files) { + _createUploadingAttachments(files) { for (const file of files) { this._createAttachment({ filename: file.name, - isTemporary: true, + isUploading: true, name: file.name }); } @@ -98,7 +98,7 @@ class FileUploader extends Component { async _performUpload(files) { for (const file of files) { const uploadingAttachment = this.env.models['mail.attachment'].find(attachment => - attachment.isTemporary && + attachment.isUploading && attachment.filename === file.name ); if (!uploadingAttachment) { @@ -158,12 +158,12 @@ class FileUploader extends Component { type: 'danger', message: owl.utils.escape(error), }); - const relatedTemporaryAttachments = this.env.models['mail.attachment'] + const relatedUploadingAttachments = this.env.models['mail.attachment'] .find(attachment => attachment.filename === filename && - attachment.isTemporary + attachment.isUploading ); - for (const attachment of relatedTemporaryAttachments) { + for (const attachment of relatedUploadingAttachments) { attachment.delete(); } return; diff --git a/addons/mail/static/src/models/attachment/attachment.js b/addons/mail/static/src/models/attachment/attachment.js index dc4d59d52de..56dfc9cc67c 100644 --- a/addons/mail/static/src/models/attachment/attachment.js +++ b/addons/mail/static/src/models/attachment/attachment.js @@ -7,10 +7,10 @@ const { clear } = require('mail/static/src/model/model_field_command.js'); function factory(dependencies) { - let nextTemporaryId = -1; - function getAttachmentNextTemporaryId() { - const id = nextTemporaryId; - nextTemporaryId -= 1; + let nextUploadingId = -1; + function getAttachmentNextUploadingId() { + const id = nextUploadingId; + nextUploadingId -= 1; return id; } class Attachment extends dependencies['mail.model'] { @@ -58,7 +58,7 @@ function factory(dependencies) { const dataList = isMulti ? data : [data]; for (const data of dataList) { if (!data.id) { - data.id = getAttachmentNextTemporaryId(); + data.id = getAttachmentNextUploadingId(); } } return super.create(...arguments); @@ -100,7 +100,7 @@ function factory(dependencies) { if (this.isUnlinkPending) { return; } - if (!this.isTemporary) { + if (!this.isUploading) { this.update({ isUnlinkPending: true }); try { await this.async(() => this.env.services.rpc({ @@ -133,17 +133,17 @@ function factory(dependencies) { * @returns {mail.composer[]} */ _computeComposers() { - if (this.isTemporary) { + if (this.isUploading) { return []; } - const relatedTemporaryAttachment = this.env.models['mail.attachment'] + const relatedUploadingAttachment = this.env.models['mail.attachment'] .find(attachment => attachment.filename === this.filename && - attachment.isTemporary + attachment.isUploading ); - if (relatedTemporaryAttachment) { - const composers = relatedTemporaryAttachment.composers; - relatedTemporaryAttachment.delete(); + if (relatedUploadingAttachment) { + const composers = relatedUploadingAttachment.composers; + relatedUploadingAttachment.delete(); return [['replace', composers]]; } return []; @@ -272,7 +272,7 @@ function factory(dependencies) { * @returns {AbortController|undefined} */ _computeUploadingAbortController() { - if (this.isTemporary) { + if (this.isUploading) { if (!this.uploadingAbortController) { const abortController = new AbortController(); abortController.signal.onabort = () => { @@ -336,9 +336,6 @@ function factory(dependencies) { compute: '_computeIsLinkedToComposer', dependencies: ['composers'], }), - isTemporary: attr({ - default: false, - }), isTextFile: attr({ compute: '_computeIsTextFile', dependencies: ['fileType'], @@ -349,6 +346,9 @@ function factory(dependencies) { isUnlinkPending: attr({ default: false, }), + isUploading: attr({ + default: false, + }), isViewable: attr({ compute: '_computeIsViewable', dependencies: [ @@ -383,7 +383,7 @@ function factory(dependencies) { uploadingAbortController: attr({ compute: '_computeUploadingAbortController', dependencies: [ - 'isTemporary', + 'isUploading', 'uploadingAbortController', ], }), diff --git a/addons/mail/static/src/models/attachment/attachment_tests.js b/addons/mail/static/src/models/attachment/attachment_tests.js index 527bc7ec3e7..bdb0115de09 100644 --- a/addons/mail/static/src/models/attachment/attachment_tests.js +++ b/addons/mail/static/src/models/attachment/attachment_tests.js @@ -40,7 +40,7 @@ QUnit.test('create (txt)', async function (assert) { assert.strictEqual(this.env.models['mail.attachment'].find(attachment => attachment.id === 750), attachment); assert.strictEqual(attachment.filename, "test.txt"); assert.strictEqual(attachment.id, 750); - assert.notOk(attachment.isTemporary); + assert.notOk(attachment.isUploading); assert.strictEqual(attachment.mimetype, 'text/plain'); assert.strictEqual(attachment.name, "test.txt"); }); diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js index 13c4dac04a0..7505a57ce30 100644 --- a/addons/mail/static/src/models/composer/composer.js +++ b/addons/mail/static/src/models/composer/composer.js @@ -532,7 +532,7 @@ function factory(dependencies) { * @returns {boolean} */ _computeHasUploadingAttachment() { - return this.attachments.some(attachment => attachment.isTemporary); + return this.attachments.some(attachment => attachment.isUploading); } /** @@ -930,14 +930,13 @@ function factory(dependencies) { inverse: 'composers', }), /** - * This field watches the uploading (= temporary) status of attachments - * linked to this composer. + * This field watches the uploading status of attachments linked to this composer. * * Useful to determine whether there are some attachments that are being * uploaded. */ - attachmentsAreTemporary: attr({ - related: 'attachments.isTemporary', + attachmentsAreUploading: attr({ + related: 'attachments.isUploading', }), canPostMessage: attr({ compute: '_computeCanPostMessage', @@ -986,7 +985,7 @@ function factory(dependencies) { compute: '_computeHasUploadingAttachment', dependencies: [ 'attachments', - 'attachmentsAreTemporary', + 'attachmentsAreUploading', ], }), hasFocus: attr({ diff --git a/addons/mail/static/src/models/message/message_tests.js b/addons/mail/static/src/models/message/message_tests.js index 82ab11b2a41..92ac23d08a6 100644 --- a/addons/mail/static/src/models/message/message_tests.js +++ b/addons/mail/static/src/models/message/message_tests.js @@ -93,7 +93,7 @@ QUnit.test('create', async function (assert) { assert.ok(attachment); assert.strictEqual(attachment.filename, "test.txt"); assert.strictEqual(attachment.id, 750); - assert.notOk(attachment.isTemporary); + assert.notOk(attachment.isUploading); assert.strictEqual(attachment.mimetype, 'text/plain'); assert.strictEqual(attachment.name, "test.txt"); const channel = this.env.models['mail.thread'].find(thread => diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index bd37b09ffd1..5159f315118 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -1012,10 +1012,10 @@ function factory(dependencies) { const allAttachments = [...new Set(this.originThreadAttachments.concat(this.attachments))] .sort((a1, a2) => { // "uploading" before "uploaded" attachments. - if (!a1.isTemporary && a2.isTemporary) { + if (!a1.isUploading && a2.isUploading) { return 1; } - if (a1.isTemporary && !a2.isTemporary) { + if (a1.isUploading && !a2.isUploading) { return -1; } // "most-recent" before "oldest" attachments. diff --git a/addons/mail/static/tests/tours/mail_full_composer_test_tour.js b/addons/mail/static/tests/tours/mail_full_composer_test_tour.js index be61c08bb86..0f9b4a51957 100644 --- a/addons/mail/static/tests/tours/mail_full_composer_test_tour.js +++ b/addons/mail/static/tests/tours/mail_full_composer_test_tour.js @@ -40,7 +40,7 @@ tour.register('mail/static/tests/tours/mail_full_composer_test_tour.js', { }, { content: "Open full composer", trigger: '.o_Composer_buttonFullComposer', - extra_trigger: '.o_Attachment:not(.o-temporary)' // waiting the attachment to be uploaded + extra_trigger: '.o_Attachment:not(.o-isUploading)' // waiting the attachment to be uploaded }, { content: "Check the earlier provided attachment is listed", trigger: '.o_attachment[title="text.txt"]',