diff --git a/ng2-components/ng2-alfresco-core/README.md b/ng2-components/ng2-alfresco-core/README.md index d77abaa509..078df01b91 100644 --- a/ng2-components/ng2-alfresco-core/README.md +++ b/ng2-components/ng2-alfresco-core/README.md @@ -126,6 +126,9 @@ class MyDemoApp { constructor(public alfrescoAuthenticationService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) { + + alfrescoSettingsService.ecmHost = this.ecmHost; + alfrescoSettingsService.setProviders('ECM'); } ngOnInit() { @@ -133,7 +136,7 @@ class MyDemoApp { } login() { - this.alfrescoAuthenticationService.login('admin', 'admin', 'ECM').subscribe( + this.alfrescoAuthenticationService.login('admin', 'admin').subscribe( token => { this.token = token.ticket; this.authenticated = true; diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts similarity index 68% rename from ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts rename to ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index a01a4038e7..571620356c 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -17,15 +17,15 @@ import {it, describe} from '@angular/core/testing'; import {ReflectiveInjector, provide} from '@angular/core'; -import {AlfrescoSettingsService} from './AlfrescoSettingsService.service'; -import {AlfrescoAuthenticationService} from './AlfrescoAuthenticationService.service'; +import {AlfrescoSettingsService} from './AlfrescoSettings.service'; +import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service'; import {XHRBackend, HTTP_PROVIDERS} from '@angular/http'; import {MockBackend} from '@angular/http/testing'; declare var AlfrescoApi: any; describe('AlfrescoAuthentication', () => { - let injector, fakePromiseECM, fakePromiseBPM, service, fakePromiseBPMECM; + let injector, fakePromiseECM, fakePromiseBPM, authService, fakePromiseBPMECM; fakePromiseECM = new Promise(function (resolve, reject) { resolve( @@ -90,16 +90,15 @@ describe('AlfrescoAuthentication', () => { describe('when the setting is ECM', () => { beforeEach(() => { - this.providers = 'ECM'; - service = injector.get(AlfrescoAuthenticationService); + authService = injector.get(AlfrescoAuthenticationService); }); it('should return an ECM ticket after the login done', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseECM); - service.login('fake-username', 'fake-password', this.providers).subscribe(() => { - expect(service.isLoggedIn()).toBe(true); - expect(service.getTicket()).toEqual('fake-post-ticket-ECM'); + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicket()).toEqual('fake-post-ticket-ECM'); done(); }); }); @@ -108,12 +107,12 @@ describe('AlfrescoAuthentication', () => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin') .and.returnValue(Promise.reject('fake invalid credentials')); - service.login('fake-wrong-username', 'fake-wrong-password', this.providers).subscribe( + authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( (res) => { }, (err: any) => { - expect(service.isLoggedIn()).toBe(false); - expect(service.getTicket()).toBeUndefined(); + expect(authService.isLoggedIn()).toBe(false); + expect(authService.getTicket()).toBeUndefined(); done(); }); }); @@ -121,8 +120,7 @@ describe('AlfrescoAuthentication', () => { it('should login in the ECM if no provider are defined calling the login', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseECM); - service.login('fake-username', 'fake-password').subscribe(() => { - service.TYPE = 'ECM'; + authService.login('fake-username', 'fake-password').subscribe(() => { done(); }); }); @@ -131,9 +129,9 @@ describe('AlfrescoAuthentication', () => { localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM'); spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseECM); - service.logout().subscribe(() => { - expect(service.isLoggedIn()).toBe(false); - expect(service.getTicket()).toBeUndefined(); + authService.logout().subscribe(() => { + expect(authService.isLoggedIn()).toBe(false); + expect(authService.getTicket()).toBeUndefined(); expect(localStorage.getItem('ticket-ECM')).toBeUndefined(); done(); }); @@ -141,35 +139,38 @@ describe('AlfrescoAuthentication', () => { it('should logout only if the provider is already logged in', (done) => { localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM'); + spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseECM); - service.saveTicket('fake-ticket-ECM'); - service.logout().subscribe(() => { - expect(service.isLoggedIn()).toBe(false); - expect(service.getTicket()).toBeUndefined(); + + authService.saveTicket('fake-ticket-ECM'); + + authService.logout().subscribe(() => { + expect(authService.isLoggedIn()).toBe(false); + expect(authService.getTicket()).toBeUndefined(); expect(localStorage.getItem('ticket-ECM')).toBeUndefined(); done(); }); }); it('should return false if the user is not logged in', () => { - expect(service.isLoggedIn()).toBe(false); + expect(authService.isLoggedIn()).toBe(false); }); }); describe('when the setting is BPM', () => { beforeEach(() => { - this.providers = 'BPM'; - service = injector.get(AlfrescoAuthenticationService); + authService = injector.get(AlfrescoAuthenticationService); + authService.providers = 'BPM'; }); it('should return an BPM ticket after the login done', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPM); - service.login('fake-username', 'fake-password', this.providers).subscribe(() => { - expect(service.isLoggedIn()).toBe(true); - expect(service.getTicket()).toEqual('fake-post-ticket-BPM'); + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicket()).toEqual('fake-post-ticket-BPM'); done(); }); }); @@ -177,12 +178,12 @@ describe('AlfrescoAuthentication', () => { it('should return ticket undefined when the credentials are wrong', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(Promise.reject('fake invalid credentials')); - service.login('fake-wrong-username', 'fake-wrong-password', this.providers).subscribe( + authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( (res) => { }, (err: any) => { - expect(service.isLoggedIn()).toBe(false); - expect(service.getTicket()).toBeUndefined(); + expect(authService.isLoggedIn()).toBe(false); + expect(authService.getTicket()).toBeUndefined(); done(); }); }); @@ -190,12 +191,12 @@ describe('AlfrescoAuthentication', () => { it('should return a ticket undefined after logout', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPM); - service.login('fake-username', 'fake-password', this.providers).subscribe(() => { + authService.login('fake-username', 'fake-password').subscribe(() => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseBPM); - service.logout().subscribe(() => { - expect(service.isLoggedIn()).toBe(false); - expect(service.getTicket()).toBeUndefined(); + authService.logout().subscribe(() => { + expect(authService.isLoggedIn()).toBe(false); + expect(authService.getTicket()).toBeUndefined(); expect(localStorage.getItem('ticket-BPM')).toBeUndefined(); done(); }); @@ -206,7 +207,7 @@ describe('AlfrescoAuthentication', () => { localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM'); spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(Promise.reject('fake logout error')); - service.logout().subscribe( + authService.logout().subscribe( (res) => { }, (err: any) => { @@ -220,26 +221,16 @@ describe('AlfrescoAuthentication', () => { describe('when the setting is both ECM and BPM ', () => { beforeEach(() => { - this.providers = 'ALL'; - service = injector.get(AlfrescoAuthenticationService); - }); - - it('should create both instances', (done) => { - spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPMECM); - - service.login('fake-username', 'fake-password', this.providers).subscribe(() => { - expect(service.isLoggedIn()).toBe(true); - expect(service.TYPE).toEqual(this.providers); - done(); - }); + authService = injector.get(AlfrescoAuthenticationService); + authService.providers = 'ALL'; }); it('should return both ECM and BPM tickets after the login done', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPMECM); - service.login('fake-username', 'fake-password', this.providers).subscribe(() => { - expect(service.isLoggedIn()).toBe(true); - expect(service.getTicket()).toEqual('fake-post-ticket-ECM,fake-post-ticket-BPM'); + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicket()).toEqual('fake-post-ticket-ECM,fake-post-ticket-BPM'); done(); }); }); @@ -247,12 +238,12 @@ describe('AlfrescoAuthentication', () => { it('should return ticket undefined when the credentials are wrong', (done) => { spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(Promise.reject('fake invalid credentials')); - service.login('fake-username', 'fake-password', this.providers).subscribe( + authService.login('fake-username', 'fake-password').subscribe( (res) => { }, (err: any) => { - expect(service.isLoggedIn()).toBe(false); - expect(service.getTicket()).toBeUndefined(); + expect(authService.isLoggedIn()).toBe(false); + expect(authService.getTicket()).toBeUndefined(); done(); }); }); diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts similarity index 70% rename from ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.ts rename to ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index 01841c311f..b51c83f2cd 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -17,7 +17,7 @@ import {Injectable} from '@angular/core'; import {Observable} from 'rxjs/Rx'; -import {AlfrescoSettingsService} from './AlfrescoSettingsService.service'; +import {AlfrescoSettingsService} from './AlfrescoSettings.service'; declare let AlfrescoApi: any; @@ -29,26 +29,11 @@ export class AlfrescoAuthenticationService { alfrescoApi: any; - TYPE: string = 'ECM'; - /**A * Constructor * @param alfrescoSetting */ constructor(public alfrescoSetting: AlfrescoSettingsService) { - - if (!this.isLoggedIn()) { - this.alfrescoApi = new AlfrescoApi({ - host: alfrescoSetting.ecmHost, - hostActiviti: alfrescoSetting.bpmHost - }); - } else { - this.alfrescoApi = new AlfrescoApi({ - ticket: this.getTicket(), - host: alfrescoSetting.ecmHost, - hostActiviti: alfrescoSetting.bpmHost - }); - } } /** @@ -63,29 +48,43 @@ export class AlfrescoAuthenticationService { * Method to delegate to POST login * @param username * @param password - * @param provider * @returns {Observable|Observable} */ - login(username: string, password: string, provider: string) { + login(username: string, password: string) { - this.TYPE = provider || this.TYPE; - return Observable.fromPromise(this.callApiLogin(username, password, provider)) - .map((response: any) => { - this.saveTicket(response); - return {type: provider, ticket: response}; - }) - .catch(this.handleError); + if (this.isLoggedIn()) { + this.alfrescoApi = new AlfrescoApi({ + provider: this.alfrescoSetting.getProviders(), + ticket: this.getTicket(), + host: this.alfrescoSetting.ecmHost, + hostActiviti: this.alfrescoSetting.bpmHost + }); + + return Observable.create((observer) => { + observer.next({type: this.alfrescoSetting.getProviders(), ticket: this.getTicket()}); + observer.complete(); + }).catch(this.handleError); + + } else { + return Observable.fromPromise(this.callApiLogin(username, password)) + .map((response: any) => { + this.saveTicket(response); + return {type: this.alfrescoSetting.getProviders(), ticket: response}; + }) + .catch(this.handleError); + } } /** * Initialize the alfresco Api with user and password end call the login method * @param username * @param password - * @param provider * @returns {*|Observable} */ - private callApiLogin(username: string, password: string, provider: string) { + private callApiLogin(username: string, password: string) { + this.alfrescoApi = new AlfrescoApi({ + provider: this.alfrescoSetting.getProviders(), username: username, password: password, host: this.alfrescoSetting.ecmHost, @@ -114,7 +113,7 @@ export class AlfrescoAuthenticationService { * Remove the login ticket from localStorage */ public removeTicket(): void { - localStorage.removeItem(`ticket-${this.TYPE}`); + localStorage.removeItem(`ticket-${this.alfrescoSetting.getProviders()}`); } /** @@ -122,16 +121,17 @@ export class AlfrescoAuthenticationService { * @returns {*|Observable|Observable|Promise} */ private callApiLogout(): Promise { - return this.alfrescoApi.logout(); + if (this.alfrescoApi) { + return this.alfrescoApi.logout(); + } } - /** * The method return the ticket stored in the localStorage * @returns ticket */ public getTicket(): string { - return localStorage.getItem(`ticket-${this.TYPE}`); + return localStorage.getItem(`ticket-${this.alfrescoSetting.getProviders()}`); } /** @@ -140,7 +140,7 @@ export class AlfrescoAuthenticationService { */ public saveTicket(ticket): void { if (ticket) { - localStorage.setItem(`ticket-${this.TYPE}`, ticket); + localStorage.setItem(`ticket-${this.alfrescoSetting.getProviders()}`, ticket); } } @@ -155,6 +155,6 @@ export class AlfrescoAuthenticationService { } getAlfrescoApi(): any { - return this.alfrescoApi; + return this.alfrescoApi; } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts similarity index 98% rename from ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.service.ts rename to ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts index 98327e6d66..4e91c639ff 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; -import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service'; +import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service'; @Injectable() export class AlfrescoContentService { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts new file mode 100644 index 0000000000..e65f105d99 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.spec.ts @@ -0,0 +1,63 @@ +/*! + * @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 {describe, it, beforeEach} from '@angular/core/testing'; +import {ReflectiveInjector} from '@angular/core'; +import {AlfrescoSettingsService} from './AlfrescoSettings.service'; +import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service'; +import {AlfrescoContentService} from './AlfrescoContent.service'; +import {HTTP_PROVIDERS} from '@angular/http'; + +describe('AlfrescoContentService', () => { + + let injector, contentService: AlfrescoContentService, authService: AlfrescoAuthenticationService, node; + + const nodeId = 'fake-node-id'; + + beforeEach(() => { + injector = ReflectiveInjector.resolveAndCreate([ + HTTP_PROVIDERS, + AlfrescoContentService, + AlfrescoAuthenticationService, + AlfrescoSettingsService + ]); + spyOn(localStorage, 'getItem').and.callFake(function (key) { + return 'myTicket'; + }); + + contentService = injector.get(AlfrescoContentService); + authService = injector.get(AlfrescoAuthenticationService); + authService.login('fake-username', 'fake-password'); + + node = { + entry: { + id: nodeId + } + }; + }); + + it('should return a valid content URL', () => { + expect(contentService.getContentUrl(node)).toBe('http://127.0.0.1:8080/alfresco/api/' + + '-default-/public/alfresco/versions/1/nodes/fake-node-id/content?attachment=false&alf_ticket=myTicket'); + }); + + it('should return a valid thumbnail URL', () => { + expect(contentService.getDocumentThumbnailUrl(node)) + .toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco' + + '/versions/1/nodes/fake-node-id/renditions/doclib/content?attachment=false&alf_ticket=myTicket'); + }); +}); diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.spec.ts deleted file mode 100644 index ddb31efa85..0000000000 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.spec.ts +++ /dev/null @@ -1,69 +0,0 @@ -/*! - * @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 { describe, it, beforeEach } from '@angular/core/testing'; -import { ReflectiveInjector } from '@angular/core'; -import { AlfrescoSettingsService } from './AlfrescoSettingsService.service'; -import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service'; -import { AlfrescoContentService } from './AlfrescoContentService.service'; -import { HTTP_PROVIDERS } from '@angular/http'; - -describe('AlfrescoContentService', () => { - - let injector, service: AlfrescoContentService, authService: AlfrescoAuthenticationService; - const nodeId = 'blah'; - let DEFAULT_CONTEXT_PATH: string = '/alfresco'; - let DEFAULT_BASE_API_PATH: string = '/api/-default-/public/alfresco/versions/1'; - - beforeEach(() => { - injector = ReflectiveInjector.resolveAndCreate([ - HTTP_PROVIDERS, - AlfrescoContentService, - AlfrescoAuthenticationService, - AlfrescoSettingsService - ]); - spyOn(localStorage, 'getItem').and.callFake(function (key) { - return 'myTicket'; - }); - service = injector.get(AlfrescoContentService); - authService = injector.get(AlfrescoAuthenticationService); - }); - - it('should return a valid content URL', () => { - expect(service.getContentUrl({ - entry: { - id: nodeId - } - })).toBe( - AlfrescoSettingsService.DEFAULT_ECM_ADDRESS + DEFAULT_CONTEXT_PATH + - DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' + - '?attachment=false&alf_ticket=' + authService.getTicket() - ); - }); - - it('should return a valid thumbnail URL', () => { - expect(service.getDocumentThumbnailUrl({ - entry: { - id: nodeId - } - })).toBe( - AlfrescoSettingsService.DEFAULT_ECM_ADDRESS + DEFAULT_CONTEXT_PATH + - DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' + - '?attachment=false&alf_ticket=' + authService.getTicket() - ); - }); -}); diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts index 0901f3182e..12ba8b9b7f 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts @@ -17,7 +17,7 @@ import { Injectable, ChangeDetectorRef, Pipe } from '@angular/core'; import { TranslatePipe } from 'ng2-translate/ng2-translate'; -import { AlfrescoTranslationService } from './AlfrescoTranslationService.service'; +import { AlfrescoTranslationService } from './AlfrescoTranslation.service'; @Injectable() @Pipe({ diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts similarity index 87% rename from ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts rename to ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts index 53ac00f971..54df384d1d 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts @@ -30,8 +30,8 @@ export class AlfrescoSettingsService { private _bpmContextPath = AlfrescoSettingsService.DEFAULT_BPM_CONTEXT_PATH; - private providers: string[] = 'ALL'; - + private providers: string = 'ECM'; // ECM, BPM , ALL + public get ecmHost(): string { return this._ecmHost; } @@ -52,4 +52,12 @@ export class AlfrescoSettingsService { return this._bpmHost + this._bpmContextPath; } + public getProviders(): string { + return this.providers; + } + + public setProviders(providers: string) { + this.providers = providers; + } + } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts similarity index 95% rename from ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts rename to ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts index 96fc5a1745..6b83975c23 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts @@ -16,7 +16,7 @@ */ import { describe, it, beforeEach } from '@angular/core/testing'; -import { AlfrescoSettingsService } from './AlfrescoSettingsService.service'; +import { AlfrescoSettingsService } from './AlfrescoSettings.service'; describe('AlfrescoSettingsService', () => { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts similarity index 100% rename from ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationService.service.ts rename to ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts diff --git a/ng2-components/ng2-alfresco-core/src/services/index.ts b/ng2-components/ng2-alfresco-core/src/services/index.ts index bdde5bffd4..7c013a4b4c 100644 --- a/ng2-components/ng2-alfresco-core/src/services/index.ts +++ b/ng2-components/ng2-alfresco-core/src/services/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -export * from './AlfrescoSettingsService.service'; +export * from './AlfrescoSettings.service'; export * from './AlfrescoTranslationLoader.service'; -export * from './AlfrescoTranslationService.service'; +export * from './AlfrescoTranslation.service'; export * from './AlfrescoPipeTranslate.service'; -export * from './AlfrescoAuthenticationService.service'; -export * from './AlfrescoContentService.service'; +export * from './AlfrescoAuthentication.service'; +export * from './AlfrescoContent.service'; diff --git a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts index 889b008da8..cceb9379d4 100644 --- a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts @@ -189,7 +189,7 @@ class DocumentListDemo implements OnInit { } login() { - this.authService.login('admin', 'admin', 'ECM').subscribe( + this.authService.login('admin', 'admin').subscribe( token => { console.log(token); this.token = token; diff --git a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.spec.ts b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.spec.ts index 8c8432c156..4f6a1897ba 100644 --- a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.spec.ts +++ b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.spec.ts @@ -23,7 +23,7 @@ import { beforeEach, beforeEachProviders } from '@angular/core/testing'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; import { TestComponentBuilder } from '@angular/compiler/testing'; import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { AlfrescoLoginComponent } from './alfresco-login.component'; @@ -38,6 +38,7 @@ describe('AlfrescoLogin', () => { beforeEachProviders(() => { return [ { provide: AlfrescoAuthenticationService, useClass: AuthenticationMock }, + { provide: AlfrescoSettingsService, useClass: AlfrescoSettingsService }, { provide: AlfrescoTranslationService, useClass: TranslationMock } ]; }); diff --git a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts index faec805e3b..1e4388f163 100644 --- a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts +++ b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts @@ -15,12 +15,13 @@ * limitations under the License. */ -import { Component, Input, Output, EventEmitter } from '@angular/core'; -import { FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from '@angular/common'; +import {Component, Input, Output, EventEmitter} from '@angular/core'; +import {FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators} from '@angular/common'; import { AlfrescoTranslationService, AlfrescoPipeTranslate, - AlfrescoAuthenticationService + AlfrescoAuthenticationService, + AlfrescoSettingsService } from 'ng2-alfresco-core'; declare let componentHandler: any; @@ -67,11 +68,13 @@ export class AlfrescoLoginComponent { /** * Constructor * @param _fb - * @param auth + * @param authService + * @param settingService * @param translate */ constructor(private _fb: FormBuilder, - public auth: AlfrescoAuthenticationService, + public authService: AlfrescoAuthenticationService, + public settingService: AlfrescoSettingsService, private translate: AlfrescoTranslationService) { this.formError = { @@ -79,7 +82,7 @@ export class AlfrescoLoginComponent { 'password': '' }; - this.form = this._fb.group({ + this.form = this._fb.group({ username: ['', Validators.compose([Validators.required, Validators.minLength(4)])], password: ['', Validators.required] }); @@ -104,12 +107,15 @@ export class AlfrescoLoginComponent { * @param value * @param event */ - onSubmit(value: any, event) { + onSubmit(value: any, event: any) { this.error = false; if (event) { event.preventDefault(); } - this.auth.login(value.username, value.password, this.providers) + + this.settingService.setProviders(this.providers); + + this.authService.login(value.username, value.password) .subscribe( (token: any) => { this.success = true; diff --git a/ng2-components/ng2-alfresco-search/demo/src/main.ts b/ng2-components/ng2-alfresco-search/demo/src/main.ts index 1e3f9fddc6..c9e6f7a702 100644 --- a/ng2-components/ng2-alfresco-search/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-search/demo/src/main.ts @@ -81,7 +81,7 @@ class SearchDemo implements OnInit { } login() { - this.authService.login('admin', 'admin', 'ECM').subscribe( + this.authService.login('admin', 'admin').subscribe( token => { console.log(token); this.token = token; diff --git a/ng2-components/ng2-alfresco-upload/demo/src/main.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts index 6471746c14..b239fd9131 100644 --- a/ng2-components/ng2-alfresco-upload/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-upload/demo/src/main.ts @@ -106,7 +106,7 @@ export class MyDemoApp implements OnInit { } login() { - this.authService.login('admin', 'admin', 'ECM').subscribe( + this.authService.login('admin', 'admin').subscribe( token => { console.log(token); this.token = token; diff --git a/ng2-components/ng2-alfresco-viewer/demo/src/main.ts b/ng2-components/ng2-alfresco-viewer/demo/src/main.ts index fbbfdb7862..1b28fad5ac 100644 --- a/ng2-components/ng2-alfresco-viewer/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-viewer/demo/src/main.ts @@ -79,7 +79,7 @@ class MyDemoApp { } login() { - this.authService.login('admin', 'admin', 'ECM').subscribe( + this.authService.login('admin', 'admin').subscribe( token => { console.log(token); this.token = token; diff --git a/ng2-components/ng2-alfresco-webscript/demo/src/main.ts b/ng2-components/ng2-alfresco-webscript/demo/src/main.ts index d7dbd363d9..2b9edfe97c 100644 --- a/ng2-components/ng2-alfresco-webscript/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-webscript/demo/src/main.ts @@ -79,6 +79,8 @@ class WebscriptDemo implements OnInit { private alfrescoSettingsService: AlfrescoSettingsService) { alfrescoSettingsService.ecmHost = this.ecmHost; + alfrescoSettingsService.setProviders('ECM'); + if (this.authService.getTicket()) { this.token = this.authService.getTicket(); } @@ -98,7 +100,7 @@ class WebscriptDemo implements OnInit { } login() { - this.authService.login('admin', 'admin', ['ECM']).subscribe( + this.authService.login('admin', 'admin').subscribe( token => { console.log(token); this.token = token;