mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Merge pull request #257 from Alfresco/dev-mvitale-252
Use new upload API #252
This commit is contained in:
commit
cd20820c18
@ -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);
|
||||
});
|
||||
}));
|
||||
|
||||
|
@ -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,7 +120,7 @@ export class UploadButtonComponent {
|
||||
this._uploaderService.createFolder(absolutePath, directoryName)
|
||||
.subscribe(
|
||||
res => {
|
||||
let relativeDir = this.uploaddirectory + '/' + directoryPath;
|
||||
let relativeDir = this.currentFolderPath + '/' + directoryPath;
|
||||
this.uploadFiles(relativeDir, filesDir);
|
||||
},
|
||||
error => {
|
||||
@ -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
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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';
|
||||
@ -209,7 +209,7 @@ export class UploadService {
|
||||
form.append(key, this._formFields[key]);
|
||||
});
|
||||
|
||||
form.append('uploaddirectory', directory);
|
||||
form.append('relativePath', directory);
|
||||
|
||||
let xmlHttpRequest = this.createXMLHttpRequestInstance(uploadingFileModel, elementEmit);
|
||||
uploadingFileModel._xmlHttpRequest = xmlHttpRequest;
|
||||
|
Loading…
x
Reference in New Issue
Block a user