Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix success response code on jpeg images #462

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions app/controller/NavigationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ 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;

FFW.Navigation.sendNavigationResult(
failed ? WARNINGS : SUCCESS,
request.id,
request.method,
failed ? "Requested image(s) not found" : null
info
);
}
SDL.SDLModel.validateImages(request.id, callback, imageList);
Expand Down Expand Up @@ -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);
},

/**
Expand All @@ -464,27 +464,27 @@ 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);
}
}
}
if(params.softButtons) {
var countButtons=params.softButtons.length;
for(var i=0;i<countButtons;i++) {
if(params.softButtons[i].image) {
var iconPath = params.softButtons[i].image.value;
if(!this.isPng(iconPath)) {
var icon = params.softButtons[i].image;
if(!this.isPng(icon.value)) {
delete params.softButtons[i].image;
nonPngCounter++;
continue;
}
imageList.push(iconPath);
imageList.push(icon);
}
}
}
Expand All @@ -493,15 +493,15 @@ SDL.NavigationController = Em.Object.create(
delete params.turnIcon;
nonPngCounter++;
} else {
imageList.push(params.turnIcon.value);
imageList.push(params.turnIcon);
}
}
if(params.nextTurnIcon) {
if(!this.isPng(params.nextTurnIcon.value)) {
delete params.nextTurnIcon;
nonPngCounter++;
} else {
imageList.push(params.nextTurnIcon.value);
imageList.push(params.nextTurnIcon);
}
}

Expand All @@ -514,14 +514,14 @@ SDL.NavigationController = Em.Object.create(
return;
}

var callback = function(failed) {
var callback = function(failed, info) {
var WARNINGS = SDL.SDLModel.data.resultCode.WARNINGS;
var SUCCESS = SDL.SDLModel.data.resultCode.SUCCESS;
FFW.Navigation.sendNavigationResult(
failed ? WARNINGS : SUCCESS,
request.id,
request.method,
failed ? "Requested image(s) not found" : null);
failed ? WARNINGS : SUCCESS,
request.id,
request.method,
info);
}
SDL.SDLModel.validateImages(request.id, callback, imageList);
},
Expand Down
4 changes: 2 additions & 2 deletions app/controller/sdl/Abstract/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ SDL.SDLController = Em.Object.extend(
* @param {Number}
* messageRequestId
*/
scrollableMessageResponse: function(result, messageRequestId) {
scrollableMessageResponse: function(result, info, messageRequestId) {
if (result == SDL.SDLModel.data.resultCode.SUCCESS) {
FFW.UI.sendUIResult(
result,
Expand All @@ -892,7 +892,7 @@ SDL.SDLController = Em.Object.extend(
result,
messageRequestId,
'UI.ScrollableMessage',
'Requested image(s) not found'
info
);
} else {
FFW.UI.sendUIResult(
Expand Down
19 changes: 7 additions & 12 deletions app/model/sdl/Abstract/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,24 +555,19 @@ SDL.ABSAppModel = Em.Object.extend(

if(request.params.cmdIcon) {

var image = request.params.cmdIcon.value;
if(!SDL.NavigationController.isPng(image)) {
FFW.UI.sendUIResult(
SDL.SDLModel.data.resultCode.WARNINGS, request.id,
request.method);
return;
}
var image = request.params.cmdIcon;

var callback = function(failed) {
var callback = function(failed, info) {
var WARNINGS = SDL.SDLModel.data.resultCode.WARNINGS;
var SUCCESS = SDL.SDLModel.data.resultCode.SUCCESS;

FFW.UI.sendUIResult(
failed ? WARNINGS : SUCCESS,
request.id,
request.method,
failed ? "Requested image(s) not found" : null);
info);
}

SDL.SDLModel.validateImages(request.id, callback, [image]);
return;
}
Expand Down Expand Up @@ -674,19 +669,19 @@ SDL.ABSAppModel = Em.Object.extend(
SDL.SDLController.buttonsSort(parentID, this.appID);
SDL.OptionsView.commands.refreshItems();
}
var callback = function(failed) {
var callback = function(failed, info) {
var WARNINGS = SDL.SDLModel.data.resultCode.WARNINGS;
var SUCCESS = SDL.SDLModel.data.resultCode.SUCCESS;

FFW.UI.sendUIResult(
failed ? WARNINGS : SUCCESS,
request.id,
request.method,
failed ? "Requested image(s) not found" : null);
info);
}
var imageList = [];
if(request.params.menuIcon) {
imageList.push(request.params.menuIcon.value);
imageList.push(request.params.menuIcon);
}
SDL.SDLModel.validateImages(request.id, callback, imageList);
} else {
Expand Down
80 changes: 47 additions & 33 deletions app/model/sdl/Abstract/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,57 +984,69 @@ SDL.SDLModel = Em.Object.extend({

/**
* @function validateImages
* @description Checks if image exists by path provided in request data
* @description Checks if image exists by path provided in request data
* @param requestID - request id, to which images belong
* @param callback - user callback after check
* @param imageList - list of paths to check
* @param imageList - list of Image structures to check
*/
validateImages: function(requestID, callback, imageList) {
if(imageList == null || imageList.length == 0) {
callback(false);
callback(false, null);
return;
}

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,
'path': image.value,
'isTemplate': image.isTemplate,
'checkResult': null
});
});

for(var i = 0; i < this.imageCheckList[requestID].length; i++) {
let is_valid_template_extension = function(image) {
if (image.isTemplate !== true) {
return true;
}

return SDL.NavigationController.isPng(image.path);
};

// 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"
};
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;
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(path === formattedImgPath) {
SDL.SDLModel.imageCheckList[requestID][i].checkResult = false;
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.
Expand All @@ -1043,14 +1055,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) {
Expand All @@ -1059,8 +1073,8 @@ SDL.SDLModel = Em.Object.extend({
}
}

delete SDL.SDLModel.imageCheckList.requestID;
callback(failed);
delete SDL.SDLModel.imageCheckList[requestID];
callback(failed, info);
},

/**
Expand Down
18 changes: 11 additions & 7 deletions app/view/sdl/AlertManeuverPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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( () => {
Expand Down
Loading