diff --git a/ng2-components/ng2-alfresco-upload/i18n/en.json b/ng2-components/ng2-alfresco-upload/i18n/en.json index 7c6b12cc2f..e1ef9f26ec 100644 --- a/ng2-components/ng2-alfresco-upload/i18n/en.json +++ b/ng2-components/ng2-alfresco-upload/i18n/en.json @@ -7,7 +7,8 @@ }, "MESSAGES": { "COMPLETED": "uploads complete", - "PROGRESS": "Upload in progress..." + "PROGRESS": "Upload in progress...", + "FOLDER_ALREADY_EXIST": "The folder {0} already exist" }, "FILE_INFO": { "NAME": "File name", diff --git a/ng2-components/ng2-alfresco-upload/i18n/it.json b/ng2-components/ng2-alfresco-upload/i18n/it.json index e5b64499e8..1fbb24a290 100644 --- a/ng2-components/ng2-alfresco-upload/i18n/it.json +++ b/ng2-components/ng2-alfresco-upload/i18n/it.json @@ -7,7 +7,8 @@ }, "MESSAGES": { "COMPLETED": "caricamenti completati", - "PROGRESS": "caricamento in corso..." + "PROGRESS": "caricamento in corso...", + "FOLDER_ALREADY_EXIST": "Cartella {0} giĆ  presente" }, "FILE_INFO": { "NAME": "Nome file", diff --git a/ng2-components/ng2-alfresco-upload/package.json b/ng2-components/ng2-alfresco-upload/package.json index 31762ce558..23771995ce 100644 --- a/ng2-components/ng2-alfresco-upload/package.json +++ b/ng2-components/ng2-alfresco-upload/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-upload", "description": "Alfresco Angular2 Upload Component", - "version": "0.1.34", + "version": "0.1.35", "author": "Alfresco Software, Ltd.", "scripts": { "typings": "typings install", diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index 7cf2ab4c22..2ae11f33a0 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -25,6 +25,8 @@ import 'rxjs/Rx'; declare let componentHandler: any; declare let __moduleName: string; +const ERROR_FOLDER_ALREADY_EXIST = 409; + /** * { - console.log(error); - } + let errorMessagePlaceholder = this.getErrorMessage(error.response); + let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]); + if (errorMessage) { + this._showErrorNotificationBar(errorMessage); + } + console.log(error); + } ); }); // reset the value of the input file @@ -217,7 +224,7 @@ export class UploadButtonComponent { this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ message: messageTranslate.value, - timeout: 5000, + timeout: 3000, actionHandler: function () { latestFilesAdded.forEach((uploadingFileModel: FileModel) => { uploadingFileModel.setAbort(); @@ -227,6 +234,35 @@ export class UploadButtonComponent { }); } + /** + * Retrive the error message using the error status code + * @param response - object that contain the HTTP response + * @returns {string} + */ + private getErrorMessage(response: any): string { + if(response.body.error.statusCode === ERROR_FOLDER_ALREADY_EXIST ) { + let errorMessage: any; + errorMessage = this.translate.get('FILE_UPLOAD.MESSAGES.FOLDER_ALREADY_EXIST'); + return errorMessage.value; + } + } + + /** + * Show the error inside Notification bar + * @param Error message + * @private + */ + private _showErrorNotificationBar(errorMessage: string) { + if (componentHandler) { + componentHandler.upgradeAllRegistered(); + } + + this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ + message: errorMessage, + timeout: 3000 + }); + } + /** * Return the site from the path * @returns {any} @@ -254,4 +290,18 @@ export class UploadButtonComponent { console.log('Path: ' + file.webkitRelativePath); } } + + /** + * Replace a placeholder {0} in a message with the input keys + * @param message - the message that conains the placeholder + * @param keys - array of value + * @returns {string} - The message without placeholder + */ + private formatString(message: string, keys: any []) { + let i = keys.length; + while (i--) { + message = message.replace(new RegExp('\\{' + i + '\\}', 'gm'), keys[i]); + } + return message; + } }