mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
#160 Added error folder already exists
This commit is contained in:
@@ -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",
|
||||
|
@@ -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",
|
||||
|
@@ -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",
|
||||
|
@@ -25,6 +25,8 @@ import 'rxjs/Rx';
|
||||
declare let componentHandler: any;
|
||||
declare let __moduleName: string;
|
||||
|
||||
const ERROR_FOLDER_ALREADY_EXIST = 409;
|
||||
|
||||
/**
|
||||
* <alfresco-upload-button [showUdoNotificationBar]="boolean"
|
||||
* [uploadFolders]="boolean"
|
||||
@@ -132,8 +134,13 @@ export class UploadButtonComponent {
|
||||
this.uploadFiles(relativeDir, filesDir);
|
||||
},
|
||||
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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user