diff --git a/demo-shell-ng2/app/components/files/files.component.html b/demo-shell-ng2/app/components/files/files.component.html
index 8a840af0f1..5cf0ac0361 100644
--- a/demo-shell-ng2/app/components/files/files.component.html
+++ b/demo-shell-ng2/app/components/files/files.component.html
@@ -1,6 +1,7 @@
{
expect(compiled.querySelector('#uploadFolder')).toBeDefined();
});
- it('should call uploadFile with the default folder', () => {
+ it('should call uploadFile with the default root folder', () => {
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
component.onSuccess = null;
component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
@@ -129,7 +129,19 @@ describe('Test ng2-alfresco-upload UploadButton', () => {
fixture.detectChanges();
component.onFilesAdded(fakeEvent);
- expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
+ expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('-root-', '/root-fake-/sites-fake/folder-fake', null);
+ });
+
+ it('should call uploadFile with a custom root folder', () => {
+ component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
+ component.rootFolderId = '-my-';
+ component.onSuccess = null;
+ component._uploaderService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
+
+ fixture.detectChanges();
+
+ component.onFilesAdded(fakeEvent);
+ expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('-my-', '/root-fake-/sites-fake/folder-fake', null);
});
it('should create a folder and emit an File uploaded event', (done) => {
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 8046cb5f29..0ef59ed8eb 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
@@ -53,6 +53,8 @@ const ERROR_FOLDER_ALREADY_EXIST = 409;
})
export class UploadButtonComponent {
+ private static DEFAULT_ROOT_ID: string = '-root-';
+
@ViewChild('undoNotificationBar')
undoNotificationBar: any;
@@ -72,7 +74,10 @@ export class UploadButtonComponent {
acceptedFilesType: string = '*';
@Input()
- currentFolderPath: string = '/Sites/swsdp/documentLibrary';
+ currentFolderPath: string = '/';
+
+ @Input()
+ rootFolderId: string = UploadButtonComponent.DEFAULT_ROOT_ID;
@Output()
onSuccess = new EventEmitter();
@@ -151,7 +156,7 @@ export class UploadButtonComponent {
private uploadFiles(path: string, files: any[]) {
if (files.length) {
let latestFilesAdded = this._uploaderService.addToQueue(files);
- this._uploaderService.uploadFilesInTheQueue(path, this.onSuccess);
+ this._uploaderService.uploadFilesInTheQueue(this.rootFolderId, path, this.onSuccess);
if (this.showUdoNotificationBar) {
this._showUndoNotificationBar(latestFilesAdded);
}
diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts
index 6d724a9b1e..be6bea4f3b 100644
--- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts
+++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts
@@ -99,7 +99,7 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => {
component.onFilesDropped(filesList);
expect(component._uploaderService.addToQueue).toHaveBeenCalledWith(filesList);
- expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
+ expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('-root-', '/root-fake-/sites-fake/folder-fake', null);
});
it('should show the loading messages in the notification bar when the files are dropped', () => {
@@ -114,7 +114,7 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => {
let filesList = [fileFake];
component.onFilesDropped(filesList);
- expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('/root-fake-/sites-fake/folder-fake', null);
+ expect(component._uploaderService.uploadFilesInTheQueue).toHaveBeenCalledWith('-root-', '/root-fake-/sites-fake/folder-fake', null);
expect(component._showUndoNotificationBar).toHaveBeenCalled();
});
@@ -138,7 +138,31 @@ describe('Test ng2-alfresco-upload UploadDragArea', () => {
component.onFilesEntityDropped(itemEntity);
expect(component._uploaderService.uploadFilesInTheQueue)
- .toHaveBeenCalledWith('/root-fake-/sites-fake/document-library-fake/folder-fake/', null);
+ .toHaveBeenCalledWith('-root-', '/root-fake-/sites-fake/document-library-fake/folder-fake/', null);
+ });
+
+ it('should upload a file with a custom root folder ID when dropped', () => {
+ component.currentFolderPath = '/root-fake-/sites-fake/document-library-fake';
+ component.rootFolderId = '-my-';
+ component.onSuccess = null;
+
+ fixture.detectChanges();
+ spyOn(component._uploaderService, 'uploadFilesInTheQueue');
+
+ let itemEntity = {
+ fullPath: '/folder-fake/file-fake.png',
+ isDirectory: false,
+ isFile: true,
+ name: 'file-fake.png',
+ file: (callbackFile) => {
+ let fileFake = new File(['fakefake'], 'file-fake.png', {type: 'image/png'});
+ callbackFile(fileFake);
+ }
+ };
+
+ component.onFilesEntityDropped(itemEntity);
+ expect(component._uploaderService.uploadFilesInTheQueue)
+ .toHaveBeenCalledWith('-my-', '/root-fake-/sites-fake/document-library-fake/folder-fake/', null);
});
it('should throws an exception and show it in the notification bar when the folder already exist', done => {
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 4cdaae74db..62bb485c0c 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
@@ -41,6 +41,8 @@ const ERROR_FOLDER_ALREADY_EXIST = 409;
})
export class UploadDragAreaComponent {
+ private static DEFAULT_ROOT_ID: string = '-root-';
+
@ViewChild('undoNotificationBar')
undoNotificationBar: any;
@@ -51,7 +53,10 @@ export class UploadDragAreaComponent {
versioning: boolean = false;
@Input()
- currentFolderPath: string = '/Sites/swsdp/documentLibrary';
+ currentFolderPath: string = '/';
+
+ @Input()
+ rootFolderId: string = UploadDragAreaComponent.DEFAULT_ROOT_ID;
@Output()
onSuccess = new EventEmitter();
@@ -77,7 +82,7 @@ export class UploadDragAreaComponent {
if (files.length) {
if (this.checkValidity(files)) {
this._uploaderService.addToQueue(files);
- this._uploaderService.uploadFilesInTheQueue(this.currentFolderPath, this.onSuccess);
+ this._uploaderService.uploadFilesInTheQueue(this.rootFolderId, this.currentFolderPath, this.onSuccess);
let latestFilesAdded = this._uploaderService.getQueue();
if (this.showUdoNotificationBar) {
this._showUndoNotificationBar(latestFilesAdded);
@@ -115,7 +120,7 @@ export class UploadDragAreaComponent {
this._uploaderService.addToQueue([file]);
let path = item.fullPath.replace(item.name, '');
let filePath = this.currentFolderPath + path;
- this._uploaderService.uploadFilesInTheQueue(filePath, this.onSuccess);
+ this._uploaderService.uploadFilesInTheQueue(this.rootFolderId, filePath, this.onSuccess);
});
}
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 3f88bdece5..2af2bfc6b2 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
@@ -88,7 +88,7 @@ describe('Test ng2-alfresco-upload', () => {
service.setOptions(options, false);
let filesFake = [{name: 'fake-name', size: 10}];
service.addToQueue(filesFake);
- service.uploadFilesInTheQueue('fake-dir', emitter);
+ service.uploadFilesInTheQueue('-root-', 'fake-dir', emitter);
let request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true');
@@ -111,7 +111,7 @@ describe('Test ng2-alfresco-upload', () => {
service.setOptions(options, false);
let filesFake = [{name: 'fake-name', size: 10}];
service.addToQueue(filesFake);
- service.uploadFilesInTheQueue('', emitter);
+ service.uploadFilesInTheQueue('-root-', '', emitter);
expect(jasmine.Ajax.requests.mostRecent().url)
.toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true');
@@ -132,7 +132,7 @@ describe('Test ng2-alfresco-upload', () => {
service.setOptions(options, false);
let filesFake = [{name: 'fake-name', size: 10}];
service.addToQueue(filesFake);
- service.uploadFilesInTheQueue('', emitter);
+ service.uploadFilesInTheQueue('-root-', '', emitter);
let file = service.getQueue();
file[0].emitAbort();
@@ -148,7 +148,7 @@ describe('Test ng2-alfresco-upload', () => {
service.setOptions(options, false);
let filesFake = [{name: 'fake-name', size: 10}];
service.addToQueue(filesFake);
- service.uploadFilesInTheQueue('', emitter);
+ service.uploadFilesInTheQueue('-root-', '', emitter);
let file = service.getQueue();
file[0].emitError();
@@ -169,7 +169,7 @@ describe('Test ng2-alfresco-upload', () => {
expect(file[0].progress).toEqual(fakeProgress);
done();
});
- service.uploadFilesInTheQueue('', null);
+ service.uploadFilesInTheQueue('-root-', '', null);
let file = service.getQueue();
@@ -231,11 +231,34 @@ describe('Test ng2-alfresco-upload', () => {
service.setOptions(options, enableVersioning);
let filesFake = [{name: 'fake-name', size: 10}];
service.addToQueue(filesFake);
- service.uploadFilesInTheQueue('', emitter);
+ service.uploadFilesInTheQueue('-root-', '', emitter);
console.log(jasmine.Ajax.requests.mostRecent().url);
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('autoRename=true')).toBe(false);
expect(jasmine.Ajax.requests.mostRecent().params.has('majorVersion')).toBe(true);
});
+
+ it('should use custom root folder ID given to the service', (done) => {
+ let emitter = new EventEmitter();
+
+ emitter.subscribe(e => {
+ expect(e.value).toBe('File uploaded');
+ done();
+ });
+ service.setOptions(options, false);
+ let filesFake = [{name: 'fake-name', size: 10}];
+ service.addToQueue(filesFake);
+ service.uploadFilesInTheQueue('123', 'fake-dir', emitter);
+
+ let request = jasmine.Ajax.requests.mostRecent();
+ expect(request.url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/123/children?autoRename=true');
+ expect(request.method).toBe('POST');
+
+ jasmine.Ajax.requests.mostRecent().respondWith({
+ 'status': 200,
+ contentType: 'text/plain',
+ responseText: 'File uploaded'
+ });
+ });
});
});
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 e4c661cae2..9697af64a3 100644
--- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts
+++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts
@@ -87,7 +87,7 @@ export class UploadService {
/**
* Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder.
*/
- public uploadFilesInTheQueue(directory: string, elementEmit: EventEmitter): void {
+ public uploadFilesInTheQueue(rootId: string, directory: string, elementEmit: EventEmitter): void {
let filesToUpload = this.queue.filter((uploadingFileModel) => {
return !uploadingFileModel.uploading && !uploadingFileModel.done && !uploadingFileModel.abort && !uploadingFileModel.error;
});
@@ -105,7 +105,7 @@ export class UploadService {
filesToUpload.forEach((uploadingFileModel: FileModel) => {
uploadingFileModel.setUploading();
- let promiseUpload = this.apiService.getInstance().upload.uploadFile(uploadingFileModel.file, directory, null, null, opts)
+ let promiseUpload = this.apiService.getInstance().upload.uploadFile(uploadingFileModel.file, directory, rootId, null, opts)
.on('progress', (progress: any) => {
uploadingFileModel.setProgres(progress);
this.updateFileListStream(this.queue);