diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index 296f73d0ee..ea9f5e47cf 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -87,8 +87,9 @@ describe('AlfrescoUploadButton', () => { .createAsync(UploadButtonComponent) .then((fixture) => { let component = fixture.componentInstance; - component.uploaddirectory = 'folder-default'; - component.uploadFiles = jasmine.createSpy('uploadFiles'); + component.currentFolderPath = '/root-fake-/sites-fake/folder-fake'; + component.onSuccess = null; + component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue'); fixture.detectChanges(); let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'}; @@ -101,7 +102,7 @@ describe('AlfrescoUploadButton', () => { }; component.onFilesAdded(fakeEvent); - expect(component.uploadFiles).toHaveBeenCalledWith('folder-default', [file]); + expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null); }); })); 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 e18ab7bea9..a2d8173e2b 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 @@ -73,9 +73,6 @@ export class UploadButtonComponent { @Input() currentFolderPath: string = '/Sites/swsdp/documentLibrary'; - @Input() - uploaddirectory: string = ''; - @Output() onSuccess = new EventEmitter(); @@ -87,15 +84,8 @@ export class UploadButtonComponent { translate: AlfrescoTranslationService) { console.log('UploadComponent constructor', el); - let site = this.getSiteId(); - let container = this.getContainerId(); - - this._uploaderService.setOptions({ - formFields: { - siteid: site, - containerid: container - } - }); + let formFields = this.createFormFields(); + this._uploaderService.setOptions(formFields); this.translate = translate; this.translate.addTranslationFolder('node_modules/ng2-alfresco-upload'); } @@ -108,7 +98,7 @@ export class UploadButtonComponent { onFilesAdded($event: any): void { let files = $event.currentTarget.files; this.printFileInfo(files); - this.uploadFiles(this.uploaddirectory, files); + this.uploadFiles(this.currentFolderPath, files); // reset the value of the input file $event.target.value = ''; } @@ -130,19 +120,19 @@ export class UploadButtonComponent { this._uploaderService.createFolder(absolutePath, directoryName) .subscribe( res => { - let relativeDir = this.uploaddirectory + '/' + directoryPath; - this.uploadFiles(relativeDir, filesDir); - }, + let relativeDir = this.currentFolderPath + '/' + directoryPath; + this.uploadFiles(relativeDir, filesDir); + }, error => { - let errorMessagePlaceholder = this.getErrorMessage(error.response); - if (errorMessagePlaceholder) { - let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]); - if (errorMessage) { - this._showErrorNotificationBar(errorMessage); - } + let errorMessagePlaceholder = this.getErrorMessage(error.response); + if (errorMessagePlaceholder) { + let errorMessage = this.formatString(errorMessagePlaceholder, [directoryName]); + if (errorMessage) { + this._showErrorNotificationBar(errorMessage); } - console.log(error); } + console.log(error); + } ); }); // reset the value of the input file @@ -244,7 +234,7 @@ export class UploadButtonComponent { * @returns {string} */ private getErrorMessage(response: any): string { - if (response.body && response.body.error.statusCode === ERROR_FOLDER_ALREADY_EXIST ) { + if (response.body && response.body.error.statusCode === ERROR_FOLDER_ALREADY_EXIST) { let errorMessage: any; errorMessage = this.translate.get('FILE_UPLOAD.MESSAGES.FOLDER_ALREADY_EXIST'); return errorMessage.value; @@ -269,22 +259,6 @@ export class UploadButtonComponent { } } - /** - * Return the site from the path - * @returns {any} - */ - private getSiteId(): string { - return this.currentFolderPath.replace('/Sites/', '').split('/')[0]; - } - - /** - * Return the container from the path - * @returns {any} - */ - private getContainerId(): string { - return this.currentFolderPath.replace('/Sites/', '').split('/')[1]; - } - /** * Prints the basic information of a file * @param files @@ -310,4 +284,12 @@ export class UploadButtonComponent { } return message; } + + private createFormFields(): any { + return { + formFields: { + overwrite: true + } + }; + } } diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts index 8993e00f7c..bdcaa3a1d6 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts @@ -51,9 +51,6 @@ export class UploadDragAreaComponent { @Input() showUdoNotificationBar: boolean = true; - @Input() - uploaddirectory: string = ''; - @Input() currentFolderPath: string = '/Sites/swsdp/documentLibrary'; @@ -65,15 +62,8 @@ export class UploadDragAreaComponent { constructor(private _uploaderService: UploadService, translate: AlfrescoTranslationService) { - let site = this.getSiteId(); - let container = this.getContainerId(); - - this._uploaderService.setOptions({ - formFields: { - siteid: site, - containerid: container - } - }); + let formFields = this.createFormFields(); + this._uploaderService.setOptions(formFields); this.translate = translate; this.translate.addTranslationFolder('node_modules/ng2-alfresco-upload'); @@ -87,7 +77,7 @@ export class UploadDragAreaComponent { onFilesDropped(files: File[]): void { if (files.length) { this._uploaderService.addToQueue(files); - this._uploaderService.uploadFilesInTheQueue(this.uploaddirectory, this.onSuccess); + this._uploaderService.uploadFilesInTheQueue(this.currentFolderPath, this.onSuccess); let latestFilesAdded = this._uploaderService.getQueue(); if (this.showUdoNotificationBar) { this._showUndoNotificationBar(latestFilesAdded); @@ -104,7 +94,7 @@ export class UploadDragAreaComponent { item.file(function (file: any) { self._uploaderService.addToQueue([file]); let path = item.fullPath.replace(item.name, ''); - let filePath = self.uploaddirectory + path; + let filePath = self.currentFolderPath + path; self._uploaderService.uploadFilesInTheQueue(filePath, self.onSuccess); let latestFilesAdded = self._uploaderService.getQueue(); if (self.showUdoNotificationBar) { @@ -162,22 +152,6 @@ export class UploadDragAreaComponent { } } - /** - * Return the site from the path - * @returns {string} - */ - private getSiteId(): string { - return this.currentFolderPath.replace('/Sites/', '').split('/')[0]; - } - - /** - * Return the container from the path - * @returns {string} - */ - private getContainerId(): string { - return this.currentFolderPath.replace('/Sites/', '').split('/')[1]; - } - /** * Show undo notification bar. * @@ -246,4 +220,12 @@ export class UploadDragAreaComponent { } return message; } + + private createFormFields(): any { + return { + formFields: { + overwrite: true + } + }; + } } diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index 86e5feaf8a..e05ee26737 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -83,7 +83,7 @@ describe('AlfrescoUploadService', () => { it('should show the default option if no method setOption is called', () => { let empty = {}; service.setOptions(empty); - expect(service.getUrl()).toEqual('/alfresco/service/api/upload'); + expect(service.getUrl()).toEqual('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); let formFields: Object = {}; expect(service.getFormFileds()).toEqual(formFields); }); diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index 50347c1eb2..8a657d2ded 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -33,7 +33,7 @@ declare let AlfrescoApi: any; */ @Injectable() export class UploadService { - private _url: string = '/alfresco/service/api/upload'; + private _url: string = '/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'; private _method: string = 'POST'; private _fieldName: string = 'filedata'; @@ -206,10 +206,10 @@ export class UploadService { let form = new FormData(); form.append(this._fieldName, uploadingFileModel.file, uploadingFileModel.name); Object.keys(this._formFields).forEach((key: any) => { - form.append(key, this._formFields[key]); + form.append(key, this._formFields[key]); }); - form.append('uploaddirectory', directory); + form.append('relativePath', directory); let xmlHttpRequest = this.createXMLHttpRequestInstance(uploadingFileModel, elementEmit); uploadingFileModel._xmlHttpRequest = xmlHttpRequest;