uploader create Folder porting new Api

This commit is contained in:
Eugenio Romano
2016-07-11 18:07:02 +01:00
parent 9075fce60a
commit 75629ca95e
4 changed files with 11 additions and 37 deletions

View File

@@ -155,7 +155,9 @@ class DocumentListDemo implements OnInit {
private documentActions: DocumentActionsService) { private documentActions: DocumentActionsService) {
alfrescoSettingsService.host = this.host; alfrescoSettingsService.host = this.host;
if (this.authService.getTicket()) {
this.token = this.authService.getTicket();
}
translation.addTranslationFolder(); translation.addTranslationFolder();
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this)); documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
} }

View File

@@ -83,8 +83,8 @@ export class MyDemoApp implements OnInit {
constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) { constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) {
alfrescoSettingsService.host = this.host; alfrescoSettingsService.host = this.host;
if (this.authService.getToken()) { if (this.authService.getTicket()) {
this.token = this.authService.getToken(); this.token = this.authService.getTicket();
} }
} }
@@ -106,7 +106,7 @@ export class MyDemoApp implements OnInit {
} }
login() { login() {
this.authService.login('admin', 'admin').subscribe( this.authService.login('admin', 'admin', ['ECM']).subscribe(
token => { token => {
console.log(token); console.log(token);
this.token = token; this.token = token;

View File

@@ -87,13 +87,13 @@ describe('AlfrescoUploadService', () => {
service.setOptions(empty); service.setOptions(empty);
expect(service.getUrl()).toEqual('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children'); expect(service.getUrl()).toEqual('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children');
let formFields: Object = {}; let formFields: Object = {};
expect(service.getFormFileds()).toEqual(formFields); expect(service.getFormFields()).toEqual(formFields);
}); });
it('should show the option passed as input', () => { it('should show the option passed as input', () => {
service.setOptions(options); service.setOptions(options);
expect(service.getUrl()).toEqual('/some/cool/url'); expect(service.getUrl()).toEqual('/some/cool/url');
expect(service.getFormFileds()).toEqual({ expect(service.getFormFields()).toEqual({
siteid: 'fakeSite', siteid: 'fakeSite',
containerid: 'fakeFolder' containerid: 'fakeFolder'
}); });

View File

@@ -14,8 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { EventEmitter, Injectable } from '@angular/core'; import { EventEmitter, Injectable } from '@angular/core';
import { Response } from '@angular/http'; import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
@@ -33,8 +31,6 @@ declare let AlfrescoApi: any;
*/ */
@Injectable() @Injectable()
export class UploadService { export class UploadService {
private _url: string = '/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children';
private _formFields: Object = {}; private _formFields: Object = {};
private _queue: FileModel[] = []; private _queue: FileModel[] = [];
@@ -61,31 +57,15 @@ export class UploadService {
* *
*/ */
public setOptions(options: any): void { public setOptions(options: any): void {
this._url = options.url || this._url;
this._formFields = options.formFields != null ? options.formFields : this._formFields; 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 * Get the form fields
* @returns {Object} * @returns {Object}
*/ */
public getFormFileds(): Object { public getFormFields(): Object {
return this._formFields; return this._formFields;
} }
@@ -121,7 +101,7 @@ export class UploadService {
}); });
filesToUpload.forEach((uploadingFileModel) => { filesToUpload.forEach((uploadingFileModel) => {
uploadingFileModel.setUploading(); uploadingFileModel.setUploading();
this.authService.alfrescoApi. this.authService.getAlfrescoApi().
upload.uploadFile(uploadingFileModel.file, directory) upload.uploadFile(uploadingFileModel.file, directory)
.on('progress', (progress: any) => { .on('progress', (progress: any) => {
uploadingFileModel.setProgres(progress); uploadingFileModel.setProgres(progress);
@@ -175,15 +155,7 @@ export class UploadService {
* @param name - the folder name * @param name - the folder name
*/ */
createFolder(relativePath: string, name: string) { createFolder(relativePath: string, name: string) {
console.log('Directory created' + name); return Observable.fromPromise(this.authService.getAlfrescoApi().node.createFolder(name, relativePath))
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))
.map(res => { .map(res => {
return res; return res;
}) })