diff --git a/demo-shell-ng2/systemjs.config.js b/demo-shell-ng2/systemjs.config.js index 782acb4d85..f8375ae5cc 100644 --- a/demo-shell-ng2/systemjs.config.js +++ b/demo-shell-ng2/systemjs.config.js @@ -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', diff --git a/ng2-components/ng2-activiti-form/package.json b/ng2-components/ng2-activiti-form/package.json index d0594e8c52..151a5d824c 100644 --- a/ng2-components/ng2-activiti-form/package.json +++ b/ng2-components/ng2-activiti-form/package.json @@ -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", diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts b/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts index a93a0abe25..577963736e 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts @@ -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, diff --git a/ng2-components/ng2-activiti-form/src/services/node.service.ts b/ng2-components/ng2-activiti-form/src/services/node.service.ts index 10a9c39815..7c52f703a0 100644 --- a/ng2-components/ng2-activiti-form/src/services/node.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/node.service.ts @@ -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() { diff --git a/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts b/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts index ddfe2d0ab9..a5695d4a21 100644 --- a/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts +++ b/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.spec.ts @@ -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 ]; }); diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts index d0368efa84..5a562b2894 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts @@ -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 ]; }); diff --git a/ng2-components/ng2-alfresco-core/index.ts b/ng2-components/ng2-alfresco-core/index.ts index 231df2fe5b..be1f41d742 100644 --- a/ng2-components/ng2-alfresco-core/index.ts +++ b/ng2-components/ng2-alfresco-core/index.ts @@ -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, diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts new file mode 100644 index 0000000000..f71d5f5df5 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoApi.service.ts @@ -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; + } + +} diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index 34e9ccf2f6..97a14e3c9a 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -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) => { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index ba92bff800..174c626ae2 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -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|Observable} */ - 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; } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts index 922f976d63..064fb7f0b2 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts @@ -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 diff --git a/ng2-components/ng2-alfresco-core/src/services/index.ts b/ng2-components/ng2-alfresco-core/src/services/index.ts index 7c013a4b4c..b4d963d6e1 100644 --- a/ng2-components/ng2-alfresco-core/src/services/index.ts +++ b/ng2-components/ng2-alfresco-core/src/services/index.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +export * from './AlfrescoApi.service'; export * from './AlfrescoSettings.service'; export * from './AlfrescoTranslationLoader.service'; export * from './AlfrescoTranslation.service'; diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts index 295e84879d..fa79a3d14d 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -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, diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts index 21bb90e4c5..036d9eacde 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.spec.ts @@ -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 ]); diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts index dced40e264..c73b96182c 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/document-list.service.ts @@ -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 { 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 { + return Observable.fromPromise(this.getAlfrescoApi().nodes.deleteNode(nodeId)); } /** diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts index dd1474c155..a2a6f261d2 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.spec.ts @@ -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 diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts index daaa56deee..f06af22be2 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-control.component.spec.ts @@ -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 ]; diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts index d1ac7b7fa7..055a6f043a 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts @@ -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 ]; diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts index e72f0c8509..64e4062759 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts @@ -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 ]; }); diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts index e72f85c22c..5323da124d 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts @@ -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 }, diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index 25081c240b..ad311a00ba 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -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 ]; diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts index d90e49f0f9..c4c79ae0ec 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts @@ -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 ]; 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 8f992a0033..395aa9ae04 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 @@ -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, 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 20ca5c35bf..e4c661cae2 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -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; totalCompleted$: Observable; - constructor(private authService: AlfrescoAuthenticationService) { + constructor(private apiService: AlfrescoApiService) { this.filesUpload$ = new Observable(observer => this.filesUploadObserverProgressBar = observer).share(); this.totalCompleted$ = new Observable(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); } /** diff --git a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts index 2b1b16daed..9e44fbb0a7 100644 --- a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts +++ b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.spec.ts @@ -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', () => { diff --git a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts index 02a6df1d4d..4df9c01460 100644 --- a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts @@ -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) { diff --git a/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts b/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts index bdade46782..fd11aa8534 100644 --- a/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts +++ b/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts @@ -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 ]; });