From 75629ca95e3163b8eb6d057689867f6324b84bc7 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 11 Jul 2016 18:07:02 +0100 Subject: [PATCH] uploader create Folder porting new Api --- .../demo/src/main.ts | 4 ++- .../ng2-alfresco-upload/demo/src/main.ts | 6 ++-- .../src/services/upload.service.spec.ts | 4 +-- .../src/services/upload.service.ts | 34 ++----------------- 4 files changed, 11 insertions(+), 37 deletions(-) diff --git a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts index e1a772d508..1e19129db4 100644 --- a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts @@ -155,7 +155,9 @@ class DocumentListDemo implements OnInit { private documentActions: DocumentActionsService) { alfrescoSettingsService.host = this.host; - + if (this.authService.getTicket()) { + this.token = this.authService.getTicket(); + } translation.addTranslationFolder(); documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this)); } diff --git a/ng2-components/ng2-alfresco-upload/demo/src/main.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts index 9fa655656b..369b908600 100644 --- a/ng2-components/ng2-alfresco-upload/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-upload/demo/src/main.ts @@ -83,8 +83,8 @@ export class MyDemoApp implements OnInit { constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) { alfrescoSettingsService.host = this.host; - if (this.authService.getToken()) { - this.token = this.authService.getToken(); + if (this.authService.getTicket()) { + this.token = this.authService.getTicket(); } } @@ -106,7 +106,7 @@ export class MyDemoApp implements OnInit { } login() { - this.authService.login('admin', 'admin').subscribe( + this.authService.login('admin', 'admin', ['ECM']).subscribe( token => { console.log(token); this.token = token; 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 41e041c8ab..f4ce2843c4 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 @@ -87,13 +87,13 @@ describe('AlfrescoUploadService', () => { service.setOptions(empty); expect(service.getUrl()).toEqual('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); let formFields: Object = {}; - expect(service.getFormFileds()).toEqual(formFields); + expect(service.getFormFields()).toEqual(formFields); }); it('should show the option passed as input', () => { service.setOptions(options); expect(service.getUrl()).toEqual('/some/cool/url'); - expect(service.getFormFileds()).toEqual({ + expect(service.getFormFields()).toEqual({ siteid: 'fakeSite', containerid: 'fakeFolder' }); 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 f9cbc734a9..b69cdbc513 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -14,8 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - import { EventEmitter, Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; @@ -33,8 +31,6 @@ declare let AlfrescoApi: any; */ @Injectable() export class UploadService { - private _url: string = '/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'; - private _formFields: Object = {}; private _queue: FileModel[] = []; @@ -61,31 +57,15 @@ export class UploadService { * */ public setOptions(options: any): void { - this._url = options.url || this._url; this._formFields = options.formFields != null ? options.formFields : this._formFields; } - /** - * Get the host - * @returns {string} - */ - public getHost(): string { - return this.settings.host; - } - - /** - * Get the url - * @returns {string} - */ - public getUrl(): string { - return this._url; - } /** * Get the form fields * @returns {Object} */ - public getFormFileds(): Object { + public getFormFields(): Object { return this._formFields; } @@ -121,7 +101,7 @@ export class UploadService { }); filesToUpload.forEach((uploadingFileModel) => { uploadingFileModel.setUploading(); - this.authService.alfrescoApi. + this.authService.getAlfrescoApi(). upload.uploadFile(uploadingFileModel.file, directory) .on('progress', (progress: any) => { uploadingFileModel.setProgres(progress); @@ -175,15 +155,7 @@ export class UploadService { * @param name - the folder name */ createFolder(relativePath: string, name: string) { - console.log('Directory created' + name); - let apiInstance = new AlfrescoApi.NodesApi(this._alfrescoClient); - let nodeId = '-root-'; - let nodeBody = { - 'name': name, - 'nodeType': 'cm:folder', - 'relativePath': relativePath - }; - return Observable.fromPromise(apiInstance.addNode(nodeId, nodeBody)) + return Observable.fromPromise(this.authService.getAlfrescoApi().node.createFolder(name, relativePath)) .map(res => { return res; })