#160 Added error folder already exists

This commit is contained in:
mauriziovitale84
2016-06-09 12:00:48 +01:00
parent 66d45f5461
commit 7b69e57d0b
4 changed files with 58 additions and 6 deletions

View File

@@ -7,7 +7,8 @@
}, },
"MESSAGES": { "MESSAGES": {
"COMPLETED": "uploads complete", "COMPLETED": "uploads complete",
"PROGRESS": "Upload in progress..." "PROGRESS": "Upload in progress...",
"FOLDER_ALREADY_EXIST": "The folder {0} already exist"
}, },
"FILE_INFO": { "FILE_INFO": {
"NAME": "File name", "NAME": "File name",

View File

@@ -7,7 +7,8 @@
}, },
"MESSAGES": { "MESSAGES": {
"COMPLETED": "caricamenti completati", "COMPLETED": "caricamenti completati",
"PROGRESS": "caricamento in corso..." "PROGRESS": "caricamento in corso...",
"FOLDER_ALREADY_EXIST": "Cartella {0} già presente"
}, },
"FILE_INFO": { "FILE_INFO": {
"NAME": "Nome file", "NAME": "Nome file",

View File

@@ -1,7 +1,7 @@
{ {
"name": "ng2-alfresco-upload", "name": "ng2-alfresco-upload",
"description": "Alfresco Angular2 Upload Component", "description": "Alfresco Angular2 Upload Component",
"version": "0.1.34", "version": "0.1.35",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",

View File

@@ -25,6 +25,8 @@ import 'rxjs/Rx';
declare let componentHandler: any; declare let componentHandler: any;
declare let __moduleName: string; declare let __moduleName: string;
const ERROR_FOLDER_ALREADY_EXIST = 409;
/** /**
* <alfresco-upload-button [showUdoNotificationBar]="boolean" * <alfresco-upload-button [showUdoNotificationBar]="boolean"
* [uploadFolders]="boolean" * [uploadFolders]="boolean"
@@ -132,8 +134,13 @@ export class UploadButtonComponent {
this.uploadFiles(relativeDir, filesDir); this.uploadFiles(relativeDir, filesDir);
}, },
error => { error => {
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 // reset the value of the input file
@@ -217,7 +224,7 @@ export class UploadButtonComponent {
this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({
message: messageTranslate.value, message: messageTranslate.value,
timeout: 5000, timeout: 3000,
actionHandler: function () { actionHandler: function () {
latestFilesAdded.forEach((uploadingFileModel: FileModel) => { latestFilesAdded.forEach((uploadingFileModel: FileModel) => {
uploadingFileModel.setAbort(); 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 * Return the site from the path
* @returns {any} * @returns {any}
@@ -254,4 +290,18 @@ export class UploadButtonComponent {
console.log('Path: ' + file.webkitRelativePath); 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;
}
} }