mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Update upload service with Api service
This commit is contained in:
@@ -17,14 +17,21 @@
|
||||
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||
import { FileModel } from '../models/file.model';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
import {
|
||||
AlfrescoTranslationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService
|
||||
} from 'ng2-alfresco-core';
|
||||
|
||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||
import { FileModel } from '../models/file.model';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
|
||||
describe('FileUploadDialog', () => {
|
||||
|
||||
let componentFixture;
|
||||
@@ -33,6 +40,7 @@ describe('FileUploadDialog', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
HTTP_PROVIDERS,
|
||||
AlfrescoApiService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
|
@@ -17,11 +17,18 @@
|
||||
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
import {
|
||||
AlfrescoTranslationService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService
|
||||
} from 'ng2-alfresco-core';
|
||||
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
declare var AlfrescoApi: any;
|
||||
|
||||
@@ -71,6 +78,7 @@ describe('AlfrescoUploadButton', () => {
|
||||
HTTP_PROVIDERS,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
UploadService
|
||||
];
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
@@ -39,6 +39,7 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
HTTP_PROVIDERS,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoApiService,
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
UploadService
|
||||
];
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { UploadService } from './upload.service';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsService, AlfrescoApiService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
declare let jasmine: any;
|
||||
@@ -39,14 +39,16 @@ describe('AlfrescoUploadService', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoAuthenticationService,
|
||||
UploadService
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach( inject([UploadService], (uploadService: UploadService) => {
|
||||
beforeEach( inject([UploadService, AlfrescoApiService], (uploadService: UploadService, apiService: AlfrescoApiService) => {
|
||||
jasmine.Ajax.install();
|
||||
service = uploadService;
|
||||
apiService.setInstance(new AlfrescoApi({}));
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
@@ -85,7 +87,7 @@ describe('AlfrescoUploadService', () => {
|
||||
service.uploadFilesInTheQueue('fake-dir', emitter);
|
||||
|
||||
let request = jasmine.Ajax.requests.mostRecent();
|
||||
expect(request.url).toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children');
|
||||
expect(request.url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children');
|
||||
expect(request.method).toBe('POST');
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
@@ -107,7 +109,7 @@ describe('AlfrescoUploadService', () => {
|
||||
service.addToQueue(filesFake);
|
||||
service.uploadFilesInTheQueue('', emitter);
|
||||
expect(jasmine.Ajax.requests.mostRecent().url)
|
||||
.toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children');
|
||||
.toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children');
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 404,
|
||||
contentType: 'text/plain',
|
||||
|
@@ -19,7 +19,7 @@ import { EventEmitter, Injectable } from '@angular/core';
|
||||
import { Response } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { AlfrescoAuthenticationService} from 'ng2-alfresco-core';
|
||||
import { AlfrescoApiService } from 'ng2-alfresco-core';
|
||||
import { FileModel } from '../models/file.model';
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ export class UploadService {
|
||||
filesUpload$: Observable<FileModel[]>;
|
||||
totalCompleted$: Observable<any>;
|
||||
|
||||
constructor(private authService: AlfrescoAuthenticationService) {
|
||||
constructor(private apiService: AlfrescoApiService) {
|
||||
this.filesUpload$ = new Observable<FileModel[]>(observer => this.filesUploadObserverProgressBar = observer).share();
|
||||
this.totalCompleted$ = new Observable<number>(observer => this.totalCompletedObserver = observer).share();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ export class UploadService {
|
||||
filesToUpload.forEach((uploadingFileModel: FileModel) => {
|
||||
uploadingFileModel.setUploading();
|
||||
|
||||
let promiseUpload = this.authService.getAlfrescoApi().
|
||||
let promiseUpload = this.apiService.getInstance().
|
||||
upload.uploadFile(uploadingFileModel.file, directory, null, null, {renditions: 'doclib'})
|
||||
.on('progress', (progress: any) => {
|
||||
uploadingFileModel.setProgres(progress);
|
||||
@@ -161,7 +161,7 @@ export class UploadService {
|
||||
}
|
||||
|
||||
private callApiCreateFolder(relativePath: string, name: string) {
|
||||
return this.authService.getAlfrescoApi().node.createFolder(name, relativePath);
|
||||
return this.apiService.getInstance().nodes.createFolder(name, relativePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user