From af8943fe60d1ef8f34a1d7824fa9fc07251df627 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 20 Jan 2021 16:19:31 +0700 Subject: [PATCH 1/5] fix old video preview thumbnail in add video modal --- .../adminhtml/web/js/get-video-information.js | 20 +++++++++++++++++++ .../view/adminhtml/web/js/new-video-dialog.js | 2 ++ 2 files changed, 22 insertions(+) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js index cb56a085304a7..ff446bbcae758 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js @@ -350,10 +350,14 @@ define([ _VIDEO_URL_VALIDATE_TRIGGER: 'validate_video_url', + _CANCEL_VIDEO_INFORMATION_TRIGGER: 'cancelled_video_information', + _videoInformation: null, _currentVideoUrl: null, + _shouldCancelVideoRequest: false, + /** * @private */ @@ -366,6 +370,11 @@ define([ }, this )); this.element.on(this._VIDEO_URL_VALIDATE_TRIGGER, $.proxy(this._onUrlValidateHandler, this)); + this.element.on(this._CANCEL_VIDEO_INFORMATION_TRIGGER, $.proxy( + function () { + this._shouldCancelVideoRequest = true; + }, this + )); }, /** @@ -395,6 +404,8 @@ define([ id, googleapisUrl; + this._shouldCancelVideoRequest = false; + if (this._currentVideoUrl === url) { return; } @@ -471,6 +482,10 @@ define([ return; } + if(this._shouldCancelVideoRequest){ + return; + } + tmp = data.items[0]; uploadedFormatted = tmp.snippet.publishedAt.replace('T', ' ').replace(/\..+/g, ''); respData = { @@ -502,6 +517,11 @@ define([ return null; } + + if(this._shouldCancelVideoRequest){ + return; + } + tmp = data[0]; respData = { duration: this._formatVimeoDuration(tmp.duration), diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js index 562bff2e1d472..844e0b1644848 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js @@ -722,6 +722,7 @@ define([ modalTitleElement = modal.find('.modal-title'); if (!file) { + this._videoUrlWidget.trigger('cancelled_video_information'); widget._blockActionButtons(true); modal.find('.video-delete-button').hide(); @@ -1103,6 +1104,7 @@ define([ this._previewImage = null; } this._tempPreviewImageData = null; + this._videoUrlWidget.trigger('cancelled_video_information'); this.element.trigger('reset'); newVideoForm = this.element.find(this._videoFormSelector); From 8f2a91607320ad330e2f80414a519d635badb296 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 22 Jan 2021 09:49:56 +0700 Subject: [PATCH 2/5] format code --- .../view/adminhtml/web/js/get-video-information.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js index 425cb0ac48d28..45c7b45dabaa9 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js @@ -482,7 +482,7 @@ define([ return; } - if(this._shouldCancelVideoRequest){ + if (this._shouldCancelVideoRequest) { return; } @@ -517,7 +517,7 @@ define([ return null; } - if(this._shouldCancelVideoRequest){ + if (this._shouldCancelVideoRequest) { return; } tmp = data; From 99eae8d9c7106fb82d9baebf0fbd57b58b49ac78 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 22 Jan 2021 16:47:25 +0700 Subject: [PATCH 3/5] fix jscs rules --- .../ProductVideo/view/adminhtml/web/js/get-video-information.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js index 45c7b45dabaa9..738d83a789a2b 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js @@ -517,6 +517,7 @@ define([ return null; } + if (this._shouldCancelVideoRequest) { return; } From 7e2ea6139aa4866e7598508ac8bc5a9b16efd4b2 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 22 Jan 2021 17:28:26 +0700 Subject: [PATCH 4/5] update this --- .../ProductVideo/view/adminhtml/web/js/new-video-dialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js index 844e0b1644848..c12300e43d243 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js @@ -722,7 +722,7 @@ define([ modalTitleElement = modal.find('.modal-title'); if (!file) { - this._videoUrlWidget.trigger('cancelled_video_information'); + widget._videoUrlWidget.trigger('cancelled_video_information'); widget._blockActionButtons(true); modal.find('.video-delete-button').hide(); From a0e2926941d7ec5fdb5b174cb0f09bd600c3baf1 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 18 Feb 2021 10:47:43 +0700 Subject: [PATCH 5/5] fix race condition saving video thumbnail --- .../ProductVideo/view/adminhtml/web/js/new-video-dialog.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js index c12300e43d243..460406c77a78c 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js @@ -246,6 +246,8 @@ define([ _gallery: null, + _isUpdatingVideo: false, + /** * Bind events * @private @@ -335,6 +337,7 @@ define([ _onGetVideoInformationSuccess: function (e, data) { var self = this; + this._isUpdatingVideo = true; self.element.on('finish_update_video finish_create_video', $.proxy(function (element, playerData) { if (!self._onlyVideoPlayer || !self._isEditPage && playerData.oldVideoId !== playerData.newVideoId || @@ -395,6 +398,9 @@ define([ data: 'remote_image=' + sourceUrl, type: 'post', success: $.proxy(function (result) { + if (!self._isUpdatingVideo) { + return; + } this._tempPreviewImageData = result; this._getPreviewImage().attr('src', sourceUrl).show(); this._blockActionButtons(false, true); @@ -1098,6 +1104,7 @@ define([ this._isEditPage = true; this.imageData = null; + this._isUpdatingVideo = false; if (this._previewImage) { this._previewImage.remove();