Skip to content
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
21 changes: 20 additions & 1 deletion lib/js/src/manager/file/_FileManagerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,27 @@ class _FileManagerBase extends _SubManagerBase {
return isInRemoteFiles && isInEphemeralFiles;
}
}


/**
* Check if an SdlFile needs to be uploaded to Core or not.
* It is different from hasUploadedFile() because it takes isStaticIcon and overwrite properties into consideration.
* ie, if the file is static icon, the method always returns false.
* If the file is dynamic, it returns true in one of these situations:
* 1) the file has the overwrite property set to true
* 2) the file hasn't been uploaded to Core before.
*
* @param {SdlFile} file - SdlFile with file name and one of A) fileData, B) Uri, or C) resourceID set
* @returns {Boolean} - Whether file has been uploaded to core (true) or not (false)
*/
fileNeedsUpload (file = null) {
if (file !== null && !file.isStaticIcon()) {
return file.getOverwrite() || !this.hasUploadedFile(file);
}
return false;
}
}

const SPACE_AVAILABLE_MAX_VALUE = _FileManagerBase.SPACE_AVAILABLE_MAX_VALUE = 2000000000;

export { _FileManagerBase };
export { _FileManagerBase };
19 changes: 19 additions & 0 deletions lib/js/src/manager/file/filetypes/SdlFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SdlFile {
this._persistentFile = persistentFile;
this._filePath = null;
this._isStaticIcon = null;
this._overwrite = true; // default to true
}

/**
Expand Down Expand Up @@ -158,6 +159,24 @@ class SdlFile {
isStaticIcon () {
return this._isStaticIcon;
}

/**
* Sets the overwrite property for an SdlFile
* @param {Boolean} overwrite - A boolean value that indicates if the file can be overwritten
* @returns {SdlFile} - A reference to this instance to support method chaining
*/
setOverwrite (overwrite) {
this._overwrite = overwrite;
return this;
}

/**
* Gets the overwrite property for an SdlFile
* @returns {Boolean} - A boolean value that indicates if the file can be overwritten
*/
getOverwrite () {
return this._overwrite;
}
}


Expand Down
4 changes: 3 additions & 1 deletion lib/js/src/manager/screen/_SoftButtonManagerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ class _SoftButtonManagerBase extends _SubManagerBase {
}
if (initialState !== null && Array.isArray(softButtonObject.getStates())) {
for (const softButtonState of softButtonObject.getStates()) {
if (softButtonState !== null && softButtonState.getName() !== null && this._sdlArtworkNeedsUpload(softButtonState.getArtwork())) {
if (softButtonState !== null && softButtonState.getName() !== null &&
this._fileManager !== null && this._fileManager !== undefined &&
this._fileManager.fileNeedsUpload(softButtonState.getArtwork()) && this._softButtonImagesSupported()) {
if (softButtonState.getName() === initialState.getName()) {
initialStatesToBeUploaded.push(softButtonObject.getCurrentState().getArtwork());
} else {
Expand Down
47 changes: 25 additions & 22 deletions lib/js/src/manager/screen/_TextAndGraphicUpdateOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ class _TextAndGraphicUpdateOperation extends _Task {
console.info('No images to send, sending text');
const success = await this._sendShow(this._extractTextAndLayoutFromShow(show));
this._finishOperation(success);
} else if (!this._sdlArtworkNeedsUpload(this._updatedState.getPrimaryGraphic()) &&
!this._sdlArtworkNeedsUpload(this._updatedState.getSecondaryGraphic())) {
} else if (this._fileManager !== null && this._fileManager !== undefined &&
!this._fileManager.fileNeedsUpload(this._updatedState.getPrimaryGraphic()) &&
!this._fileManager.fileNeedsUpload(this._updatedState.getSecondaryGraphic())) {
console.info('Images already uploaded, sending full update');
const success = await this._sendShow(show);
this._finishOperation(success);
Expand Down Expand Up @@ -258,15 +259,28 @@ class _TextAndGraphicUpdateOperation extends _Task {
*/
_createImageOnlyShowWithPrimaryArtwork (primaryArtwork, secondaryArtwork) {
const newShow = new Show();
newShow.setGraphic((primaryArtwork !== null && primaryArtwork !== undefined && !(this._sdlArtworkNeedsUpload(primaryArtwork))) ? primaryArtwork.getImageRPC() : null);
newShow.setSecondaryGraphic((secondaryArtwork !== null && secondaryArtwork !== undefined && !(this._sdlArtworkNeedsUpload(secondaryArtwork))) ? secondaryArtwork.getImageRPC() : null);
newShow.setGraphic(this._shouldRpcIncludeImage(primaryArtwork) ? primaryArtwork.getImageRPC() : null);
newShow.setSecondaryGraphic(this._shouldRpcIncludeImage(secondaryArtwork) ? secondaryArtwork.getImageRPC() : null);
if ((newShow.getGraphic() === null || newShow.getGraphic() === undefined) && (newShow.getSecondaryGraphic() === null || newShow.getSecondaryGraphic() === undefined)) {
console.info('No graphics to upload');
return null;
}
return newShow;
}

/**
* Checks if an artwork has been uploaded
* @private
* @param {SdlArtwork} artwork - The graphic
* @returns {Boolean} - Whether the artwork
*/
_shouldRpcIncludeImage (artwork = null) {
if (artwork !== null) {
return artwork.isStaticIcon() || (this._fileManager !== null && this._fileManager !== undefined && this._fileManager.hasUploadedFile(artwork));
}
return false;
}

/**
* Sets the Show's text information
* @private
Expand Down Expand Up @@ -708,19 +722,6 @@ class _TextAndGraphicUpdateOperation extends _Task {
return metadataArray;
}

/**
* Checks whether the passed in artwork needs to be sent out
* @private
* @param {SdlArtwork} artwork - An instance of SdlArtwork.
* @returns {Boolean} - Whether or not the artwork needs to be uploaded.
*/
_sdlArtworkNeedsUpload (artwork) {
if (this._fileManager !== null && this._fileManager !== undefined) {
return artwork !== null && artwork !== undefined && !this._fileManager.hasUploadedFile(artwork) && !artwork.isStaticIcon();
}
return false;
}

/**
* Checks whether the primary image should be sent out
* @private
Expand All @@ -731,9 +732,10 @@ class _TextAndGraphicUpdateOperation extends _Task {
const currentScreenDataPrimaryGraphicName = (this._currentScreenData !== null && this._currentScreenData !== undefined && this._currentScreenData.getPrimaryGraphic() !== null && this._currentScreenData.getPrimaryGraphic() !== undefined) ? this._currentScreenData.getPrimaryGraphic().getName() : null;
const primaryGraphicName = (this._updatedState.getPrimaryGraphic() !== null && this._updatedState.getPrimaryGraphic() !== undefined) ? this._updatedState.getPrimaryGraphic().getName() : null;

const graphicMatchesExisting = currentScreenDataPrimaryGraphicName === primaryGraphicName;
const graphicNameMatchesExisting = currentScreenDataPrimaryGraphicName === primaryGraphicName;
const shouldOverwriteGraphic = this._updatedState.getPrimaryGraphic() !== null && this._updatedState.getPrimaryGraphic().getOverwrite();

return templateSupportsPrimaryArtwork && !graphicMatchesExisting;
return templateSupportsPrimaryArtwork && (shouldOverwriteGraphic || !graphicNameMatchesExisting);
}

/**
Expand All @@ -747,13 +749,14 @@ class _TextAndGraphicUpdateOperation extends _Task {
const currentScreenDataSecondaryGraphicName = (this._currentScreenData !== null && this._currentScreenData !== undefined && this._currentScreenData.getSecondaryGraphic() !== null && this._currentScreenData.getSecondaryGraphic() !== undefined) ? this._currentScreenData.getSecondaryGraphic().getName() : null;
const secondaryGraphicName = (this._updatedState.getSecondaryGraphic() !== null && this._updatedState.getSecondaryGraphic() !== undefined) ? this._updatedState.getSecondaryGraphic().getName() : null;

const graphicMatchesExisting = currentScreenDataSecondaryGraphicName === secondaryGraphicName;
const graphicNameMatchesExisting = currentScreenDataSecondaryGraphicName === secondaryGraphicName;
const shouldOverwriteGraphic = this._updatedState.getSecondaryGraphic() !== null && this._updatedState.getSecondaryGraphic().getOverwrite();

// Cannot detect if there is a secondary image below v5.0, so we'll just try to detect if the primary image is allowed and allow the secondary image if it is.
if (this._lifecycleManager !== null && this._lifecycleManager.getSdlMsgVersion().getMajorVersion() >= 5) {
return templateSupportsSecondaryArtwork && !graphicMatchesExisting;
return templateSupportsSecondaryArtwork && (shouldOverwriteGraphic || !graphicNameMatchesExisting);
} else {
return this._templateSupportsImageField(ImageFieldName.graphic) && !graphicMatchesExisting;
return this._templateSupportsImageField(ImageFieldName.graphic) && (shouldOverwriteGraphic || !graphicNameMatchesExisting);
}
}

Expand Down