From db36f193b739fe4735c98e1386fd2ea87b90b104 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich Date: Mon, 9 Nov 2020 17:25:05 -0500 Subject: [PATCH 1/5] Fix success response code on jpeg images --- app/controller/NavigationController.js | 34 +++++++++--------- app/controller/sdl/Abstract/Controller.js | 4 +-- app/model/sdl/Abstract/AppModel.js | 19 ++++------ app/model/sdl/Abstract/Model.js | 42 ++++++++++++++++++----- app/view/sdl/AlertManeuverPopUp.js | 18 ++++++---- app/view/sdl/AlertPopUp.js | 25 +++++++++++--- app/view/sdl/shared/scrollableMessage.js | 9 +++-- ffw/UIRPC.js | 18 +++++----- 8 files changed, 107 insertions(+), 62 deletions(-) diff --git a/app/controller/NavigationController.js b/app/controller/NavigationController.js index 76eb8ab57..1d0f22932 100644 --- a/app/controller/NavigationController.js +++ b/app/controller/NavigationController.js @@ -66,10 +66,10 @@ SDL.NavigationController = Em.Object.create( imageList = []; if(request.params.locationImage) { - imageList.push(request.params.locationImage.value); + imageList.push(request.params.locationImage); } - var callback = function(failed) { + var callback = function(failed, info) { var WARNINGS = SDL.SDLModel.data.resultCode.WARNINGS; var SUCCESS = SDL.SDLModel.data.resultCode.SUCCESS; @@ -77,7 +77,7 @@ SDL.NavigationController = Em.Object.create( failed ? WARNINGS : SUCCESS, request.id, request.method, - failed ? "Requested image(s) not found" : null + info ); } SDL.SDLModel.validateImages(request.id, callback, imageList); @@ -447,7 +447,7 @@ SDL.NavigationController = Em.Object.create( isPng: function(imagePath) { const img_extension = '.png'; var search_offset = imagePath.lastIndexOf('.'); - return imagePath.includes(img_extension, search_offset); + return imagePath.toLowerCase().includes(img_extension, search_offset); }, /** @@ -464,13 +464,13 @@ SDL.NavigationController = Em.Object.create( var countList=params.turnList.length; for(var i = 0; i < countList; i++) { if(params.turnList[i].turnIcon) { - var iconPath = params.turnList[i].turnIcon.value; - if(!this.isPng(iconPath)) { + var icon = params.turnList[i].turnIcon; + if(!this.isPng(icon.value)) { delete params.turnList[i].turnIcon; nonPngCounter++; continue; } - imageList.push(iconPath); + imageList.push(icon); } } } @@ -478,13 +478,13 @@ SDL.NavigationController = Em.Object.create( var countButtons=params.softButtons.length; for(var i=0;i { this.imageCheckList[requestID].push({ - 'path': image, + 'path': image.value, + 'isTemplate': image.isTemplate, 'checkResult': null }); }); + let is_valid_template_extension = function(image) { + if (image.isTemplate !== true) { + return true; + } + + return SDL.NavigationController.isPng(image.path); + }; + for(var i = 0; i < this.imageCheckList[requestID].length; i++) { + if (!is_valid_template_extension(this.imageCheckList[requestID][i])) { + SDL.SDLModel.imageCheckList[requestID][i].checkResult = { + code: false, + info : "Template image extension is not valid" + }; + SDL.SDLModel.finalizeImageValidation(requestID, callback); + continue; + } + var image = new Image(); image.onload = function() { for(var i = 0; i < SDL.SDLModel.imageCheckList[requestID].length; i++) { var formattedImgPath = this.src.substring(this.src.indexOf('://') + '://'.length); var path = SDL.SDLModel.imageCheckList[requestID][i].path; if(path === formattedImgPath) { - SDL.SDLModel.imageCheckList[requestID][i].checkResult = true; + SDL.SDLModel.imageCheckList[requestID][i].checkResult = { + code: true, + info : null + }; break; } } @@ -1025,7 +1046,10 @@ SDL.SDLModel = Em.Object.extend({ var formattedImgPath = this.src.substring(this.src.indexOf('://') + '://'.length); var path = SDL.SDLModel.imageCheckList[requestID][i].path; if(path === formattedImgPath) { - SDL.SDLModel.imageCheckList[requestID][i].checkResult = false; + SDL.SDLModel.imageCheckList[requestID][i].checkResult = { + code: false, + info : "Requested image(s) not found" + }; break; } } @@ -1043,14 +1067,16 @@ SDL.SDLModel = Em.Object.extend({ */ finalizeImageValidation: function(requestID, callback) { var failed = false; + var info = null; var BreakException = {}; try { SDL.SDLModel.imageCheckList[requestID].forEach(image => { if (image.checkResult === null) { throw BreakException; } - if (!image.checkResult) { + if (!image.checkResult.code) { failed = true; + info = image.checkResult.info; } }); } catch (exception) { @@ -1060,7 +1086,7 @@ SDL.SDLModel = Em.Object.extend({ } delete SDL.SDLModel.imageCheckList.requestID; - callback(failed); + callback(failed, info); }, /** diff --git a/app/view/sdl/AlertManeuverPopUp.js b/app/view/sdl/AlertManeuverPopUp.js index a6ea13838..cc1c29651 100644 --- a/app/view/sdl/AlertManeuverPopUp.js +++ b/app/view/sdl/AlertManeuverPopUp.js @@ -60,6 +60,10 @@ SDL.AlertManeuverPopUp = Em.ContainerView.create( * @desc Defines whether icons paths verified successfully. */ iconsAreValid: false, + /** + * @desc Defines info message if validation is failed + */ + infoMessage: null, /** * Wagning image on Alert Maneuver PopUp */ @@ -187,7 +191,7 @@ SDL.AlertManeuverPopUp = Em.ContainerView.create( var imageList = []; for (var i = 0; i < softButtons.length; i++) { if (softButtons[i].image) { - imageList.push(softButtons[i].image.value); + imageList.push(softButtons[i].image); } this.get('softbuttons.buttons.childViews').pushObject( @@ -215,11 +219,12 @@ SDL.AlertManeuverPopUp = Em.ContainerView.create( ); } - var callback = function(failed) { + var callback = function(failed, info) { SDL.AlertManeuverPopUp.iconsAreValid = !failed; + SDL.AlertManeuverPopUp.infoMessage = info; } - SDL.SDLModel.validateImages(params.appID, callback, imageList); + SDL.SDLModel.validateImages(this.alertManeuerRequestId, callback, imageList); if (softButtons.length > 0) { this.set('isCloseButtonVisible', false); @@ -237,14 +242,12 @@ SDL.AlertManeuverPopUp = Em.ContainerView.create( const resultCode = this.iconsAreValid ? SDL.SDLModel.data.resultCode.SUCCESS : SDL.SDLModel.data.resultCode.WARNINGS; - const info = this.iconsAreValid ? - null : "Requested image(s) not found"; FFW.Navigation.sendNavigationResult( resultCode, this.alertManeuerRequestId, 'Navigation.AlertManeuver', - info + this.infoMessage ); this.set('activate', false ); this.set('alertManeuerRequestId', 0); @@ -255,11 +258,12 @@ SDL.AlertManeuverPopUp = Em.ContainerView.create( this.softbuttons.buttons.rerender(); this.set('iconsAreValid', true); + this.set('infoMessage', null); this.set('isCloseButtonVisible', true); + this.set('alertManeuerRequestId', message.id); this.addSoftButtons(message.params); this.set('activate', true ); - this.set('alertManeuerRequestId', message.id); clearTimeout( this.timer ); this.timer = setTimeout( () => { diff --git a/app/view/sdl/AlertPopUp.js b/app/view/sdl/AlertPopUp.js index 9d346ced4..a725ef521 100644 --- a/app/view/sdl/AlertPopUp.js +++ b/app/view/sdl/AlertPopUp.js @@ -74,7 +74,7 @@ SDL.AlertPopUp = Em.ContainerView.create( '' + {{bindAttr src="SDL.AlertPopUp.icon.value"}}>' ) } ), @@ -86,8 +86,6 @@ SDL.AlertPopUp = Em.ContainerView.create( */ imageUndefined: function(event) { event.target.style.display='none'; - this.message = "Requested image(s) not found"; - this.reason = "WARNINGS" }, /** @@ -193,6 +191,8 @@ SDL.AlertPopUp = Em.ContainerView.create( addSoftButtons: function(params, appID) { this.softbuttons.buttons.removeAllChildren(); this.softbuttons.buttons.rerender(); + + var imageList = []; if (params) { var softButtonsClass; switch (params.length) { @@ -209,7 +209,12 @@ SDL.AlertPopUp = Em.ContainerView.create( softButtonsClass = 'four'; break; } + for (var i = 0; i < params.length; i++) { + if (params[i].image) { + imageList.push(params[i].image); + } + this.get('softbuttons.buttons.childViews') .pushObject( SDL.Button.create( @@ -235,19 +240,31 @@ SDL.AlertPopUp = Em.ContainerView.create( ); } } + + imageList.push(this.image); + + var callback = function(failed, info) { + if (failed) { + SDL.AlertPopUp.reason = 'WARNINGS'; + SDL.AlertPopUp.message = info; + } + } + + SDL.SDLModel.validateImages(this.alertRequestId, callback, imageList); }, + AlertActive: function(message, alertRequestId, priority) { var self = this; this.set('alertRequestId', alertRequestId); this.set('cancelID', message.cancelID); this.set('reason', 'timeout'); this.set('message', undefined); + this.set('icon', message.alertIcon ? message.alertIcon : { value: "images/sdl/Warning.png" }); this.addSoftButtons(message.softButtons, message.appID); this.set('progressIndicator', message.progressIndicator); this.set( 'appName', SDL.SDLController.getApplicationModel(message.appID).appName ); - this.set('icon', message.alertIcon ? message.alertIcon.value : "images/sdl/Warning.png"); for (var i = 0; i < message.alertStrings.length; i++) { switch (message.alertStrings[i].fieldName) { case 'alertText1': diff --git a/app/view/sdl/shared/scrollableMessage.js b/app/view/sdl/shared/scrollableMessage.js index 557e4587c..2b938697c 100644 --- a/app/view/sdl/shared/scrollableMessage.js +++ b/app/view/sdl/shared/scrollableMessage.js @@ -51,6 +51,7 @@ SDL.ScrollableMessage = SDL.SDLAbstractView.create( timeout: null, endTime: null, areAllImagesValid: true, + validationMessage: null, childViews: [ 'backButton', 'captionText', 'softButtons', 'listOfCommands' ], @@ -80,7 +81,7 @@ SDL.ScrollableMessage = SDL.SDLAbstractView.create( }; SDL.SDLController.scrollableMessageResponse( - calculate_result_code(this.areAllImagesValid), this.messageRequestId + calculate_result_code(this.areAllImagesValid), this.validationMessage, this.messageRequestId ); SDL.SDLController.onSystemContextChange(); SDL.SDLModel.data.registeredApps.forEach(app => { @@ -99,6 +100,7 @@ SDL.ScrollableMessage = SDL.SDLAbstractView.create( this.set('messageRequestId', messageRequestId); this.set('areAllImagesValid', true); + this.set('validationMessage', null); this.set('captionText.content', appName); this.softButtons.addItems(params.softButtons, params.appID); this.set('active', true); @@ -116,12 +118,13 @@ SDL.ScrollableMessage = SDL.SDLAbstractView.create( var imageList = []; for(var i = 0; i < params.softButtons.length; i++) { if(params.softButtons[i].image) { - imageList.push(params.softButtons[i].image.value); + imageList.push(params.softButtons[i].image); } } var that = this; - var callback = function(failed) { + var callback = function(failed, info) { that.set('areAllImagesValid', !failed); + that.set('validationMessage', info); }; SDL.SDLModel.validateImages(messageRequestId, callback, imageList); diff --git a/ffw/UIRPC.js b/ffw/UIRPC.js index 09a279a1a..6f6d3f3f1 100755 --- a/ffw/UIRPC.js +++ b/ffw/UIRPC.js @@ -267,21 +267,21 @@ FFW.UI = FFW.RPCObserver.create( imageList = []; if(request.params.graphic) { - imageList.push(request.params.graphic.value); + imageList.push(request.params.graphic); } if(request.params.secondaryGraphic) { - imageList.push(request.params.secondaryGraphic.value); + imageList.push(request.params.secondaryGraphic); } if(request.params.softButtons) { for(var i = 0; i < request.params.softButtons.length; i++) { var image = request.params.softButtons[i].image; if(image) { - imageList.push(image.value); + imageList.push(image); } } } - var callback = function(failed) { + var callback = function(failed, info) { var WARNINGS = SDL.SDLModel.data.resultCode.WARNINGS; var SUCCESS = SDL.SDLModel.data.resultCode.SUCCESS; @@ -289,7 +289,7 @@ FFW.UI = FFW.RPCObserver.create( failed ? WARNINGS : SUCCESS, request.id, request.method, - failed ? "Requested image(s) not found" : null); + info); } SDL.SDLModel.validateImages(request.id, callback, imageList); @@ -332,19 +332,19 @@ FFW.UI = FFW.RPCObserver.create( var imageList = []; if(request.params.menuIcon) { - imageList.push(request.params.menuIcon.value); + imageList.push(request.params.menuIcon); } if(request.params.vrHelp) { for(var i = 0; i < request.params.vrHelp.length; i++) { if(request.params.vrHelp[i].image) { - imageList.push(request.params.vrHelp[i].image.value); + imageList.push(request.params.vrHelp[i].image); } } } var that = this; - var callback = function(failed) { + var callback = function(failed, info) { var WARNINGS = SDL.SDLModel.data.resultCode.WARNINGS; var SUCCESS = resultCode; @@ -352,7 +352,7 @@ FFW.UI = FFW.RPCObserver.create( failed ? WARNINGS : SUCCESS, request.id, request.method, - failed ? "Requested image(s) not found" : null); + info); } SDL.SDLModel.validateImages(request.id, callback, imageList); break; From 5966cec44adf2fddb9e9f1739f73c2016490e7d3 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich Date: Tue, 10 Nov 2020 13:31:56 -0500 Subject: [PATCH 2/5] Fix checking of relative paths Also make a proper deletion of key from imageCheckList --- app/model/sdl/Abstract/Model.js | 6 +++--- app/view/sdl/AlertPopUp.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/model/sdl/Abstract/Model.js b/app/model/sdl/Abstract/Model.js index 99070df1b..b455cc0e9 100644 --- a/app/model/sdl/Abstract/Model.js +++ b/app/model/sdl/Abstract/Model.js @@ -1031,7 +1031,7 @@ SDL.SDLModel = Em.Object.extend({ for(var i = 0; i < SDL.SDLModel.imageCheckList[requestID].length; i++) { var formattedImgPath = this.src.substring(this.src.indexOf('://') + '://'.length); var path = SDL.SDLModel.imageCheckList[requestID][i].path; - if(path === formattedImgPath) { + if (formattedImgPath.endsWith(path)) { SDL.SDLModel.imageCheckList[requestID][i].checkResult = { code: true, info : null @@ -1045,7 +1045,7 @@ SDL.SDLModel = Em.Object.extend({ for(var i = 0; i < SDL.SDLModel.imageCheckList[requestID].length; i++) { var formattedImgPath = this.src.substring(this.src.indexOf('://') + '://'.length); var path = SDL.SDLModel.imageCheckList[requestID][i].path; - if(path === formattedImgPath) { + if (formattedImgPath.endsWith(path)) { SDL.SDLModel.imageCheckList[requestID][i].checkResult = { code: false, info : "Requested image(s) not found" @@ -1085,7 +1085,7 @@ SDL.SDLModel = Em.Object.extend({ } } - delete SDL.SDLModel.imageCheckList.requestID; + delete SDL.SDLModel.imageCheckList[requestID]; callback(failed, info); }, diff --git a/app/view/sdl/AlertPopUp.js b/app/view/sdl/AlertPopUp.js index a725ef521..ea7114308 100644 --- a/app/view/sdl/AlertPopUp.js +++ b/app/view/sdl/AlertPopUp.js @@ -241,7 +241,7 @@ SDL.AlertPopUp = Em.ContainerView.create( } } - imageList.push(this.image); + imageList.push(this.icon); var callback = function(failed, info) { if (failed) { From 344f8bbb7f132fde1e7c5759a2ad902fbd46fd25 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich Date: Tue, 10 Nov 2020 14:16:09 -0500 Subject: [PATCH 3/5] Add PerformInteraction choices image validation --- app/controller/sdl/Abstract/Controller.js | 8 ++- app/view/sdl/shared/interactionChoicesView.js | 52 +++++++++++++- ffw/UIRPC.js | 72 ++++++------------- 3 files changed, 75 insertions(+), 57 deletions(-) diff --git a/app/controller/sdl/Abstract/Controller.js b/app/controller/sdl/Abstract/Controller.js index 70d4f2c74..e6da38221 100644 --- a/app/controller/sdl/Abstract/Controller.js +++ b/app/controller/sdl/Abstract/Controller.js @@ -802,11 +802,15 @@ SDL.SDLController = Em.Object.extend( * Method to sent notification ABORTED for PerformInteractionChoise */ interactionChoiseCloseResponse: function(appID, result, choiceID, - manualTextEntry) { + manualTextEntry, info) { FFW.UI.interactionResponse( SDL.SDLController.getApplicationModel( appID - ).activeRequests.uiPerformInteraction, result, choiceID, manualTextEntry + ).activeRequests.uiPerformInteraction, + result, + choiceID, + manualTextEntry, + info ); SDL.SDLModel.data.set('interactionData.vrHelpTitle', null); SDL.SDLModel.data.set('interactionData.vrHelp', null); diff --git a/app/view/sdl/shared/interactionChoicesView.js b/app/view/sdl/shared/interactionChoicesView.js index d54f6bc2b..50033fc1f 100644 --- a/app/view/sdl/shared/interactionChoicesView.js +++ b/app/view/sdl/shared/interactionChoicesView.js @@ -143,6 +143,9 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( search: false, list: false, icon: false, + areAllImagesValid: true, + imagesValidationInfo: null, + /** /** * Id of app initiated performInteraction request */ @@ -172,6 +175,8 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( this.set('caption', message.params.initialText.fieldText); } this.appID = message.params.appID; + this.set('areAllImagesValid', true); + this.set('imagesValidationInfo', null); if (message.params.interactionLayout) { switch (message.params.interactionLayout) { case 'ICON_ONLY' : @@ -266,18 +271,25 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( this.set('active', false); SDL.SDLController.VRMove(); SDL.Keyboard.deactivate(); + + if (!this.areAllImagesValid && result == 'SUCCESS') { + result = 'WARNINGS'; + } + switch (result) { case 'ABORTED': { SDL.SDLController.interactionChoiseCloseResponse( - this.appID, SDL.SDLModel.data.resultCode['ABORTED'] + this.appID, SDL.SDLModel.data.resultCode['ABORTED'], + null, null, "UI.PerformInteraction has been aborted" ); break; } case 'TIMED_OUT': { SDL.SDLController.interactionChoiseCloseResponse( - this.appID, SDL.SDLModel.data.resultCode['TIMED_OUT'] + this.appID, SDL.SDLModel.data.resultCode['TIMED_OUT'], + null, null, "UI.PerformInteraction has been timed out" ); break; } @@ -293,7 +305,7 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( { SDL.SDLController.interactionChoiseCloseResponse( this.appID, SDL.SDLModel.data.resultCode.WARNINGS, choiceID, - this.input.value + this.input.value, this.imagesValidationInfo ); break; } @@ -335,6 +347,7 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( preformChoices: function(data, timeout) { this.set('timeout', timeout); if (data) { + var imageList = []; // temp for testing for (var i = 0; i < data.length; i++) { @@ -353,9 +366,25 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( } } ); + + if (data[i].image) { + imageList.push(data[i].image); + } + } + + var model = SDL.SDLController.getApplicationModel(this.appID); + if (model){ + var that = this; + var callback = function(failed, info) { + that.set('areAllImagesValid', !failed); + that.set('imagesValidationInfo', info); + }; } + + SDL.SDLModel.validateImages(model.activeRequests.uiPerformInteraction, callback, imageList); this.listOfChoices.list.refresh(); } + var self = this; this.set('endTime', Date.now() + timeout); clearTimeout(this.timer); @@ -379,6 +408,7 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( preformChoicesNavigation: function(data, timeout) { this.set('timeout', timeout); if (data) { + var imageList = []; // temp for testing for (var i = 0; i < data.length; i++) { @@ -401,8 +431,24 @@ SDL.InteractionChoicesView = SDL.SDLAbstractView.create( } ) ); + + if (data[i].image) { + imageList.push(data[i].image); + } } + + var model = SDL.SDLController.getApplicationModel(this.appID); + if (model){ + var that = this; + var callback = function(failed, info) { + that.set('areAllImagesValid', !failed); + that.set('imagesValidationInfo', info); + }; + } + + SDL.SDLModel.validateImages(model.activeRequests.uiPerformInteraction, callback, imageList); } + var self = this; setTimeout( function() { diff --git a/ffw/UIRPC.js b/ffw/UIRPC.js index 6f6d3f3f1..2b586b0af 100755 --- a/ffw/UIRPC.js +++ b/ffw/UIRPC.js @@ -2024,67 +2024,35 @@ FFW.UI = FFW.RPCObserver.create( * @param {Number} resultCode * @param {Number} commandID * @param {String} manualTextEntry + * @param {String} info */ interactionResponse: function(requestID, resultCode, commandID, - manualTextEntry) { + manualTextEntry, info) { Em.Logger.log('FFW.UI.PerformInteractionResponse'); - if (this.errorResponsePull[requestID] && - resultCode === SDL.SDLModel.data.resultCode.SUCCESS) { - - var json = { - 'jsonrpc': '2.0', - 'id': requestID, - 'result': { - 'code': SDL.SDLModel.data.resultCode.WARNINGS, - 'method': 'UI.PerformInteraction', - 'info': 'Unsupported ' + this.errorResponsePull[requestID].type - + ' type. Available data in request was processed.' - } - } + if (FFW.RPCHelper.isSuccessResultCode(resultCode)) { + var params = { + 'choiceID': commandID + }; if (manualTextEntry) { - json.result.manualTextEntry = manualTextEntry - } - - if (commandID) { - json.result.choiceID = commandID; + params.manualTextEntry = manualTextEntry; } - this.client.send(json); - this.errorResponsePull[requestID] = null; - return; - } - if (resultCode === SDL.SDLModel.data.resultCode.SUCCESS) { - // send repsonse - var JSONMessage = { - 'jsonrpc': '2.0', - 'id': requestID, - 'result': { - 'code': resultCode, - 'method': 'UI.PerformInteraction' - } - }; - if (commandID) { - JSONMessage.result.choiceID = commandID; - } - if (manualTextEntry != null) { - JSONMessage.result.manualTextEntry = manualTextEntry; - } + this.sendUIResult( + resultCode, + requestID, + 'UI.PerformInteraction', + info, + params + ); } else { - // send repsonse - var JSONMessage = { - 'jsonrpc': '2.0', - 'id': requestID, - 'error': { - 'code': resultCode, // type (enum) from SDL protocol - 'message': 'Perform Interaction error response.', - 'data': { - 'method': 'UI.PerformInteraction' - } - } - }; + this.sendUIResult( + resultCode, + requestID, + 'UI.PerformInteraction', + info + ); } - this.sendMessage(JSONMessage); }, /** * send notification when DriverDistraction PopUp is visible From 62be9bc1f3ccad2b5a6e1911fca1fae47df71a87 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich Date: Tue, 10 Nov 2020 14:16:49 -0500 Subject: [PATCH 4/5] Update validateImages() function --- app/model/sdl/Abstract/Model.js | 56 +++++++++++++-------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/app/model/sdl/Abstract/Model.js b/app/model/sdl/Abstract/Model.js index b455cc0e9..5f64358f0 100644 --- a/app/model/sdl/Abstract/Model.js +++ b/app/model/sdl/Abstract/Model.js @@ -996,11 +996,7 @@ SDL.SDLModel = Em.Object.extend({ } this.imageCheckList[requestID] = []; - const filteredImageList = imageList.filter(function(item, pos) { - return imageList.indexOf(item) == pos; - }); - - filteredImageList.forEach(image => { + imageList.forEach(image => { this.imageCheckList[requestID].push({ 'path': image.value, 'isTemplate': image.isTemplate, @@ -1016,9 +1012,12 @@ SDL.SDLModel = Em.Object.extend({ return SDL.NavigationController.isPng(image.path); }; - for(var i = 0; i < this.imageCheckList[requestID].length; i++) { - if (!is_valid_template_extension(this.imageCheckList[requestID][i])) { - SDL.SDLModel.imageCheckList[requestID][i].checkResult = { + // Retain reference to requestID checklist as this element might be deleted + // by finalizeImageValidation() if all images are verified be template extension function + let checkList = this.imageCheckList[requestID]; + for(var i = 0; checkList && i < checkList.length; i++) { + if (!is_valid_template_extension(checkList[i])) { + checkList[i].checkResult = { code: false, info : "Template image extension is not valid" }; @@ -1027,38 +1026,27 @@ SDL.SDLModel = Em.Object.extend({ } var image = new Image(); - image.onload = function() { - for(var i = 0; i < SDL.SDLModel.imageCheckList[requestID].length; i++) { - var formattedImgPath = this.src.substring(this.src.indexOf('://') + '://'.length); - var path = SDL.SDLModel.imageCheckList[requestID][i].path; - if (formattedImgPath.endsWith(path)) { - SDL.SDLModel.imageCheckList[requestID][i].checkResult = { - code: true, - info : null - }; - break; - } - } + image.onload = function() { + checkList[this.checkIndex].checkResult = { + code: true, + info : null + }; SDL.SDLModel.finalizeImageValidation(requestID, callback); }; - image.onerror = function() { - for(var i = 0; i < SDL.SDLModel.imageCheckList[requestID].length; i++) { - var formattedImgPath = this.src.substring(this.src.indexOf('://') + '://'.length); - var path = SDL.SDLModel.imageCheckList[requestID][i].path; - if (formattedImgPath.endsWith(path)) { - SDL.SDLModel.imageCheckList[requestID][i].checkResult = { - code: false, - info : "Requested image(s) not found" - }; - break; - } - } + + image.onerror = function() { + checkList[this.checkIndex].checkResult = { + code: false, + info : "Requested image(s) not found" + }; SDL.SDLModel.finalizeImageValidation(requestID, callback); }; - image.src = this.imageCheckList[requestID][i].path; + + image.checkIndex = i; + image.src = checkList[i].path; } }, - + /** * @function finalizeImageValidation * @description Collects result of images validation. From fd93ebfeab939e56fec00794e5e44fef39b8a920 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich Date: Tue, 17 Nov 2020 12:11:31 -0500 Subject: [PATCH 5/5] fixup! Update validateImages() function --- app/model/sdl/Abstract/Model.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/model/sdl/Abstract/Model.js b/app/model/sdl/Abstract/Model.js index 5f64358f0..af560bcab 100644 --- a/app/model/sdl/Abstract/Model.js +++ b/app/model/sdl/Abstract/Model.js @@ -1019,7 +1019,7 @@ SDL.SDLModel = Em.Object.extend({ if (!is_valid_template_extension(checkList[i])) { checkList[i].checkResult = { code: false, - info : "Template image extension is not valid" + info: "Template image extension is not valid" }; SDL.SDLModel.finalizeImageValidation(requestID, callback); continue; @@ -1029,7 +1029,7 @@ SDL.SDLModel = Em.Object.extend({ image.onload = function() { checkList[this.checkIndex].checkResult = { code: true, - info : null + info: null }; SDL.SDLModel.finalizeImageValidation(requestID, callback); }; @@ -1037,7 +1037,7 @@ SDL.SDLModel = Em.Object.extend({ image.onerror = function() { checkList[this.checkIndex].checkResult = { code: false, - info : "Requested image(s) not found" + info: "Requested image(s) not found" }; SDL.SDLModel.finalizeImageValidation(requestID, callback); };