Merge pull request #668 from Alfresco/dev-denys-dts

AlfrescoApiService, code improvements
This commit is contained in:
Mario Romano
2016-09-05 14:48:45 +01:00
committed by GitHub
27 changed files with 179 additions and 94 deletions

View File

@@ -20,8 +20,9 @@
'ng2-activiti-form': 'node_modules/ng2-activiti-form/dist',
'ng2-alfresco-viewer': 'node_modules/ng2-alfresco-viewer/dist',
'ng2-alfresco-webscript': 'node_modules/ng2-alfresco-webscript/dist',
'ng2-activiti-processlist': 'node_modules/ng2-activiti-processlist/dist',
'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist'
'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist',
'alfresco-js-api': 'node_modules/alfresco-js-api/dist',
'ng2-activiti-processlist': 'node_modules/ng2-activiti-processlist/dist'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
@@ -41,7 +42,8 @@
'ng2-activiti-form': { main: 'index.js', defaultExtension: 'js'},
'ng2-activiti-processlist': { main: 'index.js', defaultExtension: 'js'},
'ng2-activiti-tasklist': { main: 'index.js', defaultExtension: 'js'},
'ng2-alfresco-webscript': { main: 'index.js', defaultExtension: 'js'}
'ng2-alfresco-webscript': { main: 'index.js', defaultExtension: 'js'},
'alfresco-js-api': { main: 'alfresco-js-api.js', defaultExtension: 'js'}
};
var ngPackageNames = [
'common',

View File

@@ -65,7 +65,7 @@
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"ng2-translate": "2.2.2",
"ng2-alfresco-core": "0.3.0"
"ng2-alfresco-core": "^0.3.0"
},
"peerDependencies": {
"material-design-icons": "^2.2.3",
@@ -83,7 +83,6 @@
"karma-jasmine": "1.0.2",
"karma-jasmine-ajax": "0.1.13",
"karma-jasmine-html-reporter": "0.2.0",
"karma-jasmine-ajax": "0.1.13",
"karma-mocha-reporter": "2.0.3",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",

View File

@@ -16,7 +16,7 @@
*/
import { it, inject, describe, expect, beforeEach, beforeEachProviders, afterEach } from '@angular/core/testing';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
import { HTTP_PROVIDERS, Response, ResponseOptions } from '@angular/http';
import { FormService } from './form.service';
import { EcmModelService } from './ecm-model.service';
@@ -32,6 +32,7 @@ describe('FormService', () => {
return [
FormService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
EcmModelService,
HTTP_PROVIDERS,

View File

@@ -70,7 +70,9 @@ export class NodeService {
relativePath: path
};
return Observable.fromPromise(this.authService.getAlfrescoApi().nodes.addNode('-root-', body, {}));
// TODO: requires update to alfresco-js-api typings
let apiService: any = this.authService.getAlfrescoApi();
return Observable.fromPromise(apiService.nodes.addNode('-root-', body, {}));
}
private generateUuid() {

View File

@@ -16,7 +16,7 @@
*/
import { it, describe, expect, beforeEachProviders, beforeEach, inject } from '@angular/core/testing';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
import { ActivitiProcessService } from './activiti-process.service';
// import { ProcessInstance } from '../models/process-instance';
@@ -28,6 +28,7 @@ describe('ActivitiProcessService', () => {
return [
ActivitiProcessService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService
];
});

View File

@@ -17,7 +17,7 @@
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
import { ActivitiTaskListService } from './activiti-tasklist.service';
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core';
import { TaskDetailsModel } from '../models/task-details.model';
import { Comment } from '../models/comment.model';
@@ -96,6 +96,7 @@ describe('ActivitiTaskListService', () => {
return [
ActivitiTaskListService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService
];
});

View File

@@ -16,6 +16,7 @@
*/
import {
AlfrescoApiService,
AlfrescoSettingsService,
AlfrescoTranslationLoader,
AlfrescoTranslationService,
@@ -31,6 +32,7 @@ export * from './src/components/index';
export * from './src/utils/index';
export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoSettingsService,

View File

@@ -0,0 +1,34 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { AlfrescoJsApi } from 'alfresco-js-api';
@Injectable()
export class AlfrescoApiService {
private _instance: AlfrescoJsApi;
public getInstance(): AlfrescoJsApi {
return this._instance;
}
public setInstance(value: AlfrescoJsApi) {
this._instance = value;
}
}

View File

@@ -15,23 +15,30 @@
* limitations under the License.
*/
import {it, describe, beforeEach, afterEach} from '@angular/core/testing';
import {ReflectiveInjector, provide} from '@angular/core';
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
import { it, describe, beforeEach, afterEach } from '@angular/core/testing';
import { ReflectiveInjector } from '@angular/core';
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
declare var AlfrescoApi: any;
declare let jasmine: any;
describe('AlfrescoAuthentication', () => {
let injector, authService;
let injector;
let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService;
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
provide(AlfrescoSettingsService, {useClass: AlfrescoSettingsService}),
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService
]);
authService = injector.get(AlfrescoAuthenticationService);
settingsService = injector.get(AlfrescoSettingsService);
let store = {};
spyOn(localStorage, 'getItem').and.callFake(function (key) {
@@ -61,8 +68,7 @@ describe('AlfrescoAuthentication', () => {
describe('when the setting is ECM', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('ECM');
settingsService.setProviders('ECM');
});
it('should return an ECM ticket after the login done', (done) => {
@@ -144,8 +150,7 @@ describe('AlfrescoAuthentication', () => {
describe('when the setting is BPM', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('BPM');
settingsService.setProviders('BPM');
});
it('should return an BPM ticket after the login done', (done) => {
@@ -212,24 +217,23 @@ describe('AlfrescoAuthentication', () => {
describe('Setting service change should reflect in the api', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('ALL');
settingsService.setProviders('ALL');
});
it('should host ecm url change be reflected in the api configuration', () => {
authService.alfrescoSetting.ecmHost = '127.99.99.99';
settingsService.ecmHost = '127.99.99.99';
expect(authService.getAlfrescoApi().config.hostEcm).toBe('127.99.99.99');
});
it('should host bpm url change be reflected in the api configuration', () => {
authService.alfrescoSetting.bpmHost = '127.99.99.99';
settingsService.bpmHost = '127.99.99.99';
expect(authService.getAlfrescoApi().config.hostBpm).toBe('127.99.99.99');
});
it('should host bpm provider change be reflected in the api configuration', () => {
authService.alfrescoSetting.setProviders('ECM');
settingsService.setProviders('ECM');
expect(authService.getAlfrescoApi().config.provider).toBe('ECM');
});
@@ -239,8 +243,7 @@ describe('AlfrescoAuthentication', () => {
describe('when the setting is both ECM and BPM ', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.providers = 'ALL';
settingsService.setProviders('ALL');
});
it('should return both ECM and BPM tickets after the login done', (done) => {

View File

@@ -15,11 +15,13 @@
* limitations under the License.
*/
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { AlfrescoJsApi } from 'alfresco-js-api';
declare let AlfrescoApi: any;
declare var AlfrescoApi: AlfrescoJsApi;
/**
* The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage
@@ -27,32 +29,37 @@ declare let AlfrescoApi: any;
@Injectable()
export class AlfrescoAuthenticationService {
alfrescoApi: any;
alfrescoApi: AlfrescoJsApi;
/**A
/**
* Constructor
* @param alfrescoSetting
* @param settingsService
* @param apiService
*/
constructor(public alfrescoSetting: AlfrescoSettingsService) {
constructor(private settingsService: AlfrescoSettingsService,
private apiService: AlfrescoApiService) {
this.alfrescoApi = new AlfrescoApi({
provider: this.alfrescoSetting.getProviders(),
provider: this.settingsService.getProviders(),
ticketEcm: this.getTicketEcm(),
ticketBpm: this.getTicketBpm(),
hostEcm: this.alfrescoSetting.ecmHost,
hostBpm: this.alfrescoSetting.bpmHost
hostEcm: this.settingsService.ecmHost,
hostBpm: this.settingsService.bpmHost,
contextRoot: 'alfresco'
});
alfrescoSetting.bpmHostSubject.subscribe((bpmHost) => {
settingsService.bpmHostSubject.subscribe((bpmHost) => {
this.alfrescoApi.changeBpmHost(bpmHost);
});
alfrescoSetting.ecmHostSubject.subscribe((ecmHost) => {
settingsService.ecmHostSubject.subscribe((ecmHost) => {
this.alfrescoApi.changeEcmHost(ecmHost);
});
alfrescoSetting.providerSubject.subscribe((value) => {
settingsService.providerSubject.subscribe((value) => {
this.alfrescoApi.config.provider = value;
});
this.apiService.setInstance(this.alfrescoApi);
}
/**
@@ -69,11 +76,11 @@ export class AlfrescoAuthenticationService {
* @param password
* @returns {Observable<R>|Observable<T>}
*/
login(username: string, password: string) {
login(username: string, password: string): Observable<{ type: string, ticket: any }> {
return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => {
this.saveTickets();
return {type: this.alfrescoSetting.getProviders(), ticket: response};
return {type: this.settingsService.getProviders(), ticket: response};
})
.catch(this.handleError);
}
@@ -189,7 +196,7 @@ export class AlfrescoAuthenticationService {
return Observable.throw(error || 'Server error');
}
getAlfrescoApi(): any {
getAlfrescoApi(): AlfrescoJsApi {
return this.alfrescoApi;
}
}

View File

@@ -20,6 +20,7 @@ import {ReflectiveInjector} from '@angular/core';
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
import {AlfrescoContentService} from './AlfrescoContent.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
describe('AlfrescoContentService', () => {
@@ -29,6 +30,7 @@ describe('AlfrescoContentService', () => {
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
AlfrescoContentService,
AlfrescoAuthenticationService,
AlfrescoSettingsService

View File

@@ -15,6 +15,7 @@
* limitations under the License.
*/
export * from './AlfrescoApi.service';
export * from './AlfrescoSettings.service';
export * from './AlfrescoTranslationLoader.service';
export * from './AlfrescoTranslation.service';

View File

@@ -30,6 +30,7 @@ import {
HostListener
} from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { MinimalNodeEntity } from 'alfresco-js-api';
import {
CONTEXT_MENU_DIRECTIVES,
AlfrescoTranslationService
@@ -43,7 +44,6 @@ import {
} from 'ng2-alfresco-datatable';
import { DocumentListService } from './../services/document-list.service';
import { MinimalNodeEntity } from './../models/document-library.model';
import { ContentActionModel } from './../models/content-action.model';
import {
ShareDataTableAdapter,

View File

@@ -24,7 +24,8 @@ import {
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
AlfrescoContentService,
AlfrescoApiService
} from 'ng2-alfresco-core';
import { FileNode } from '../assets/document-library.model.mock';
import { ReflectiveInjector } from '@angular/core';
@@ -42,6 +43,7 @@ describe('DocumentListService', () => {
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoSettingsService
]);

View File

@@ -18,14 +18,12 @@
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import { AlfrescoJsApi, NodePaging, MinimalNodeEntity } from 'alfresco-js-api';
import {
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core';
declare let AlfrescoApi: any;
@Injectable()
export class DocumentListService {
@@ -66,11 +64,11 @@ export class DocumentListService {
) {
}
private getAlfrescoApi() {
private getAlfrescoApi(): AlfrescoJsApi {
return this.authService.getAlfrescoApi();
}
private getNodesPromise(folder: string, opts?: any) {
private getNodesPromise(folder: string, opts?: any): Promise<NodePaging> {
let nodeId = '-root-';
let params: any = {
relativePath: folder,
@@ -86,11 +84,11 @@ export class DocumentListService {
}
}
return this.getAlfrescoApi().node.getNodeChildren(nodeId, params);
return this.getAlfrescoApi().nodes.getNodeChildren(nodeId, params);
}
deleteNode(nodeId: string) {
return Observable.fromPromise(this.getAlfrescoApi().node.deleteNode(nodeId));
deleteNode(nodeId: string): Observable<any> {
return Observable.fromPromise(this.getAlfrescoApi().nodes.deleteNode(nodeId));
}
/**

View File

@@ -22,6 +22,7 @@ import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.servi
import { TranslationMock } from './../assets/translation.service.mock';
import { AlfrescoSearchService } from '../services/alfresco-search.service';
import {
AlfrescoApiService,
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService,
@@ -68,6 +69,7 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
{provide: AlfrescoTranslationService, useClass: TranslationMock},
AlfrescoThumbnailService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoSearchService

View File

@@ -21,7 +21,12 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
import { AlfrescoSearchControlComponent } from './alfresco-search-control.component';
import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
import { TranslationMock } from './../assets/translation.service.mock';
import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoContentService, AlfrescoTranslationService
import {
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoTranslationService
} from 'ng2-alfresco-core';
import { AlfrescoSearchService } from '../services/alfresco-search.service';
@@ -36,6 +41,7 @@ describe('AlfrescoSearchControlComponent', () => {
provide(AlfrescoTranslationService, {useClass: TranslationMock}),
AlfrescoThumbnailService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService
];

View File

@@ -24,6 +24,7 @@ import { TranslationMock } from './../assets/translation.service.mock';
import { AlfrescoSearchService } from '../services/alfresco-search.service';
import {
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoTranslationService
@@ -70,6 +71,7 @@ describe('AlfrescoSearchComponent', () => {
{provide: AlfrescoTranslationService, useClass: TranslationMock},
AlfrescoThumbnailService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService
];

View File

@@ -17,7 +17,7 @@
import { it, describe, beforeEach, inject, beforeEachProviders } from '@angular/core/testing';
import { AlfrescoSearchService } from './alfresco-search.service';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
declare let jasmine: any;
@@ -58,6 +58,7 @@ describe('AlfrescoSearchService', () => {
return [
AlfrescoSearchService,
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService
];
});

View File

@@ -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 },

View File

@@ -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
];

View File

@@ -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
];

View File

@@ -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?autoRename=true');
expect(request.url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true');
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?autoRename=true');
.toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true');
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 404,

View File

@@ -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';
/**
@@ -44,7 +44,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();
}
@@ -105,7 +105,7 @@ export class UploadService {
filesToUpload.forEach((uploadingFileModel: FileModel) => {
uploadingFileModel.setUploading();
let promiseUpload = this.authService.getAlfrescoApi().upload.uploadFile(uploadingFileModel.file, directory, null, null, opts)
let promiseUpload = this.apiService.getInstance().upload.uploadFile(uploadingFileModel.file, directory, null, null, opts)
.on('progress', (progress: any) => {
uploadingFileModel.setProgres(progress);
this.updateFileListStream(this.queue);
@@ -174,7 +174,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);
}
/**

View File

@@ -19,24 +19,30 @@ import { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEac
import { TestComponentBuilder } from '@angular/compiler/testing';
import { ViewerComponent } from './viewer.component';
import { EventMock } from '../assets/event.mock';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
import { RenderingQueueServices } from '../services/rendering-queue.services';
declare let jasmine: any;
declare let AlfrescoApi: any;
describe('ViewerComponent', () => {
let viewerComponentFixture, element, component;
let apiService: AlfrescoApiService;
beforeEachProviders(() => {
return [
AlfrescoApiService,
AlfrescoSettingsService,
AlfrescoAuthenticationService,
RenderingQueueServices
];
});
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
beforeEach(inject([TestComponentBuilder, AlfrescoApiService], (tcb: TestComponentBuilder, api: AlfrescoApiService) => {
apiService = api;
apiService.setInstance(new AlfrescoApi({}));
return tcb
.createAsync(ViewerComponent)
.then(fixture => {
@@ -160,27 +166,16 @@ describe('ViewerComponent', () => {
}).not.toThrow();
});
it('If FileNodeId is present the node api should be called', (done) => {
it('If FileNodeId is present the node api should be called', (/*done*/) => {
component.showViewer = true;
component.fileNodeId = 'file-node-id';
component.urlFile = undefined;
jasmine.Ajax.stubRequest(
'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/file-node-id'
).andReturn({
status: 200,
responseText: '{"entry":{"isFile":true,"createdByUser":{"id":"admin","displayName":"Administrator"},' +
'"modifiedAt":"2016-08-05T23:08:22.730+0000","nodeType":"cm:content","content":' +
'{"mimeType":"application/pdf","mimeTypeName":"Adobe PDF Document","sizeInBytes":' +
'381778,"encoding":"UTF-8"},"parentId":"8f2105b4-daaf-4874-9e8a-2152569d109b","createdAt":"2016-08-05T23:08:22.730+0000","isFolder":false,' +
'"modifiedByUser":{"id":"admin","displayName":"Administrator"},"name":"content.pdf","id":' +
'"b8bd4c81-6f2e-4ec2-9c4d-30c97cf42bc8"}}'
});
let alfrescoApi = apiService.getInstance();
spyOn(alfrescoApi.nodes, 'getNodeInfo').and.stub();
component.ngOnChanges().then(() => {
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('nodes/file-node-id')).toBe(true);
done();
});
component.ngOnChanges();
expect(alfrescoApi.nodes.getNodeInfo).toHaveBeenCalledWith(component.fileNodeId);
});
it('showViewer default value should be true', () => {

View File

@@ -21,7 +21,8 @@ import { ImgViewerComponent } from './imgViewer.component';
import { MediaPlayerComponent } from './mediaPlayer.component';
import { NotSupportedFormat } from './notSupportedFormat.component';
import { DOCUMENT } from '@angular/platform-browser';
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { AlfrescoApiService } from 'ng2-alfresco-core';
declare let __moduleName: string;
@@ -64,7 +65,9 @@ export class ViewerComponent {
loaded: boolean = false;
constructor(private authService: AlfrescoAuthenticationService, private element: ElementRef, @Inject(DOCUMENT) private document) {
constructor(private apiService: AlfrescoApiService,
private element: ElementRef,
@Inject(DOCUMENT) private document) {
}
ngOnChanges(changes) {
@@ -75,6 +78,7 @@ export class ViewerComponent {
throw new Error('Attribute urlFile or fileNodeId is required');
}
return new Promise((resolve, reject) => {
let alfrescoApi = this.apiService.getInstance();
if (this.urlFile) {
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
this.displayName = filenameFromUrl ? filenameFromUrl : '';
@@ -82,10 +86,10 @@ export class ViewerComponent {
this.urlFileContent = this.urlFile;
resolve();
} else if (this.fileNodeId) {
this.authService.getAlfrescoApi().nodes.getNodeInfo(this.fileNodeId).then((data) => {
alfrescoApi.nodes.getNodeInfo(this.fileNodeId).then((data: MinimalNodeEntryEntity) => {
this.mimeType = data.content.mimeType;
this.displayName = data.name;
this.urlFileContent = this.authService.getAlfrescoApi().content.getContentUrl(data.id);
this.urlFileContent = alfrescoApi.content.getContentUrl(data.id);
this.loaded = true;
resolve();
}, function (error) {

View File

@@ -19,7 +19,7 @@ import { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEac
import { TestComponentBuilder } from '@angular/compiler/testing';
import { WebscriptComponent } from '../src/webscript.component';
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
declare let jasmine: any;
@@ -30,6 +30,7 @@ describe('Test ng2-alfresco-webscript', () => {
beforeEachProviders(() => {
return [
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService
];
});