Single naming convention for core services (#1363)

* remove temporary file from repo

* fix: alfresco-api.service

* new: auth.service.ts

- new auth.service.ts implementation
- deprecation warning for AlfrescoAuthenticationService
- fix ‘clean-build’ typo
- extra vscode settings for ‘.d.ts’ files

* use AuthService internally

* new: content.service.ts

- deprecation warning for AlfrescoContentService
- use new ContentService internally

* new: settings.service.ts

- new SettingsService
- deprecation warning for AlfrescoSettingsService
- using new SettingsService internally

* new: translate.service and translate-loader.service

- custom TranslateLoader becomes AlfrescoTranslateLoader
- custom TranslateService becomes AlfrescoTranslateService
- deprecation notices for old service and loader implementations

* fix: document list

* fix: search

* fix: tag

also fixes #1364

* fix: activiti form

* fix: activiti tasklist, improve unit tests

* fix: activiti processlist, unit tests improvements

* fix: diagram component

* fix: analytics component

* fix: upload component

- fix numerous issues with unit tests (hidden by ‘any’ type)
- test improvements

* fix: webscript

* fix: userinfo unit tests

* code fixes

* fix 'beforeAll' issue

* tasklist unit testing improvements

* fix: form unit tests

* fix: unit tests
This commit is contained in:
Denys Vuika
2017-01-03 10:46:27 +00:00
committed by Maurizio Vitale
parent 92fc7d1df3
commit facafbd55c
122 changed files with 1376 additions and 1392 deletions

View File

@@ -22,17 +22,22 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule, TranslateLoader } from 'ng2-translate/ng2-translate';
import {
AuthService,
ContentService,
SettingsService,
StorageService,
AlfrescoApiService,
AlfrescoSettingsService,
AlfrescoTranslationLoader,
AlfrescoTranslationService,
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoTranslateLoader,
AlfrescoTranslateService,
RenditionsService,
AuthGuard,
AuthGuardEcm,
AuthGuardBpm
AuthGuardBpm,
/** @deprecated */ AlfrescoSettingsService,
/** @deprecated */ AlfrescoTranslationService,
/** @deprecated */ AlfrescoAuthenticationService,
/** @deprecated */ AlfrescoContentService
} from './src/services/index';
import { MATERIAL_DESIGN_DIRECTIVES } from './src/components/material/index';
@@ -43,22 +48,27 @@ export * from './src/components/index';
export * from './src/utils/index';
export const ALFRESCO_CORE_PROVIDERS: any[] = [
AuthService,
ContentService,
SettingsService,
StorageService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoSettingsService,
AlfrescoTranslationLoader,
AlfrescoTranslationService,
AlfrescoTranslateLoader,
AlfrescoTranslateService,
RenditionsService,
AuthGuard,
AuthGuardEcm,
AuthGuardBpm,
...CONTEXT_MENU_PROVIDERS
...CONTEXT_MENU_PROVIDERS,
/** @deprecated */ AlfrescoAuthenticationService,
/** @deprecated */ AlfrescoContentService,
/** @deprecated */ AlfrescoSettingsService,
/** @deprecated */ AlfrescoTranslationService
];
export function createTranslateLoader(http: Http) {
return new AlfrescoTranslationLoader(http);
return new AlfrescoTranslateLoader(http);
}
@NgModule({
@@ -71,7 +81,8 @@ export function createTranslateLoader(http: Http) {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
}) ],
})
],
declarations: [
...MATERIAL_DESIGN_DIRECTIVES,
...CONTEXT_MENU_DIRECTIVES

View File

@@ -5,7 +5,7 @@
"author": "Alfresco Software, Ltd.",
"scripts": {
"clean": "npm install rimraf && npm run clean-build && rimraf dist node_modules typings",
"clean-build": "rimraf index.js index.js.map index.d.ts'src/{,**/}**.js' 'src/{,**/}**.js.map' 'src/{,**/}**.d.ts' bundles",
"clean-build": "rimraf index.js index.js.map index.d.ts 'src/{,**/}**.js' 'src/{,**/}**.js.map' 'src/{,**/}**.d.ts' bundles",
"build": "npm run clean-build && npm run tslint && rimraf dist && tsc && license-check && npm run build.umd",
"build:w": "npm run clean-build && npm run tslint && rimraf dist && tsc:w && license-check npm run build.umd",
"tslint": "tslint -c tslint.json 'src/{,**/}**.ts' 'index.ts' -e '{,**/}**.d.ts' -e './gulpfile.ts'",

View File

@@ -16,204 +16,18 @@
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { SettingsService } from './settings.service';
import { StorageService } from './storage.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
import * as alfrescoApi from 'alfresco-js-api';
import { AlfrescoApi } from 'alfresco-js-api';
import { Subject } from 'rxjs/Subject';
import { AlfrescoApiService } from './alfresco-api.service';
import { AuthService } from './auth.service';
/**
* The AlfrescoAuthenticationService provide the login service and store the ticket in the Storage
*/
/** @deprecated AlfrescoAuthenticationService is deprecated. Use AuthService instead */
@Injectable()
export class AlfrescoAuthenticationService {
alfrescoApi: AlfrescoApi;
public loginSubject: Subject<any> = new Subject<any>();
public logoutSubject: Subject<any> = new Subject<any>();
/**
* Constructor
* @param settingsService
* @param apiService
*/
constructor(private settingsService: AlfrescoSettingsService,
private apiService: AlfrescoApiService,
private storage: StorageService) {
this.alfrescoApi = <AlfrescoApi>new alfrescoApi({
provider: this.settingsService.getProviders(),
ticketEcm: this.getTicketEcm(),
ticketBpm: this.getTicketBpm(),
hostEcm: this.settingsService.ecmHost,
hostBpm: this.settingsService.bpmHost,
contextRoot: 'alfresco',
disableCsrf: true
});
settingsService.bpmHostSubject.subscribe((bpmHost) => {
this.alfrescoApi.changeBpmHost(bpmHost);
});
settingsService.ecmHostSubject.subscribe((ecmHost) => {
this.alfrescoApi.changeEcmHost(ecmHost);
});
settingsService.csrfSubject.subscribe((csrf) => {
this.alfrescoApi.changeCsrfConfig(csrf);
});
settingsService.providerSubject.subscribe((value) => {
this.alfrescoApi.config.provider = value;
});
this.apiService.setInstance(this.alfrescoApi);
}
/**
* The method return tru if the user is logged in
* @returns {boolean}
*/
isLoggedIn(): boolean {
return !!this.alfrescoApi.isLoggedIn();
}
/**
* Method to delegate to POST login
* @param username
* @param password
* @returns {Observable<R>|Observable<T>}
*/
login(username: string, password: string): Observable<{ type: string, ticket: any }> {
this.removeTicket();
return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => {
this.saveTickets();
this.loginSubject.next(response);
return {type: this.settingsService.getProviders(), ticket: response};
})
.catch(this.handleError);
}
/**
* Initialize the alfresco Api with user and password end call the login method
* @param username
* @param password
* @returns {*|Observable<any>}
*/
private callApiLogin(username: string, password: string) {
return this.alfrescoApi.login(username, password);
}
/**
* The method remove the ticket from the Storage
*
* @returns {Observable<R>|Observable<T>}
*/
public logout() {
return Observable.fromPromise(this.callApiLogout())
.map(res => <any> res)
.do(response => {
this.removeTicket();
this.logoutSubject.next(response);
return response;
})
.catch(this.handleError);
}
/**
*
* @returns {*|Observable<string>|Observable<any>|Promise<T>}
*/
private callApiLogout(): Promise<any> {
if (this.alfrescoApi) {
return this.alfrescoApi.logout();
}
}
/**
* Remove the login ticket from Storage
*/
public removeTicket(): void {
this.storage.removeItem('ticket-ECM');
this.storage.removeItem('ticket-BPM');
this.alfrescoApi.setTicket(undefined, undefined);
}
/**
* The method return the ECM ticket stored in the Storage
* @returns ticket
*/
public getTicketEcm(): string | null {
return this.storage.getItem('ticket-ECM');
}
/**
* The method return the BPM ticket stored in the Storage
* @returns ticket
*/
public getTicketBpm(): string | null {
return this.storage.getItem('ticket-BPM');
}
public getTicketEcmBase64(): string | null {
let ticket = this.storage.getItem('ticket-ECM');
if (ticket) {
return 'Basic ' + btoa(ticket);
}
return null;
}
/**
* The method save the ECM and BPM ticket in the Storage
*/
public saveTickets() {
this.saveTicketEcm();
this.saveTicketBpm();
}
/**
* The method save the ECM ticket in the Storage
*/
public saveTicketEcm(): void {
if (this.alfrescoApi && this.alfrescoApi.getTicketEcm()) {
this.storage.setItem('ticket-ECM', this.alfrescoApi.getTicketEcm());
}
}
/**
* The method save the BPM ticket in the Storage
*/
public saveTicketBpm(): void {
if (this.alfrescoApi && this.alfrescoApi.getTicketBpm()) {
this.storage.setItem('ticket-BPM', this.alfrescoApi.getTicketBpm());
}
}
/**
* The method return true if user is logged in on ecm provider
*/
public isEcmLoggedIn() {
return this.alfrescoApi.ecmAuth && !!this.alfrescoApi.ecmAuth.isLoggedIn();
}
/**
* The method return true if user is logged in on bpm provider
*/
public isBpmLoggedIn() {
return this.alfrescoApi.bpmAuth && !!this.alfrescoApi.bpmAuth.isLoggedIn();
}
/**
* The method write the error in the console browser
* @param error
* @returns {ErrorObservable}
*/
public handleError(error: any): Observable<any> {
console.error('Error when logging in', error);
return Observable.throw(error || 'Server error');
export class AlfrescoAuthenticationService extends AuthService {
constructor(settingsService: SettingsService,
apiService: AlfrescoApiService,
storage: StorageService) {
super(settingsService, apiService, storage);
console.log('Warning: AlfrescoAuthenticationService is deprecated. Use AuthService instead.');
}
}

View File

@@ -17,30 +17,16 @@
import { Injectable } from '@angular/core';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { AuthService } from './auth.service';
import { ContentService } from './content.service';
import { AlfrescoApiService } from './alfresco-api.service';
/** @deprecated AlfrescoContentService is deprecated. Use ContentService instead */
@Injectable()
export class AlfrescoContentService {
export class AlfrescoContentService extends ContentService {
constructor(public authService: AlfrescoAuthenticationService, public apiService: AlfrescoApiService) {
}
/**
* Get thumbnail URL for the given document node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any): string {
return this.apiService.getInstance().content.getDocumentThumbnailUrl(document.entry.id);
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any): string {
return this.apiService.getInstance().content.getContentUrl(document.entry.id);
constructor(authService: AuthService, apiService: AlfrescoApiService) {
super(authService, apiService);
console.log('Warning: AlfrescoContentService is deprecated. Use ContentService instead.');
}
}

View File

@@ -16,63 +16,14 @@
*/
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { SettingsService } from './settings.service';
/** @deprecated AlfrescoSettingsService is deprecated. Use SettingsService instead */
@Injectable()
export class AlfrescoSettingsService {
export class AlfrescoSettingsService extends SettingsService {
static DEFAULT_ECM_ADDRESS: string = 'http://' + window.location.hostname + ':8080';
static DEFAULT_BPM_ADDRESS: string = 'http://' + window.location.hostname + ':9999';
static DEFAULT_CSRF_CONFIG: boolean = false;
static DEFAULT_BPM_CONTEXT_PATH: string = '/activiti-app';
private _ecmHost: string = AlfrescoSettingsService.DEFAULT_ECM_ADDRESS;
private _bpmHost: string = AlfrescoSettingsService.DEFAULT_BPM_ADDRESS;
private _csrfDisabled: boolean = AlfrescoSettingsService.DEFAULT_CSRF_CONFIG;
private _bpmContextPath = AlfrescoSettingsService.DEFAULT_BPM_CONTEXT_PATH;
private providers: string = 'ALL'; // ECM, BPM , ALL
public bpmHostSubject: Subject<string> = new Subject<string>();
public ecmHostSubject: Subject<string> = new Subject<string>();
public csrfSubject: Subject<boolean> = new Subject<boolean>();
public providerSubject: Subject<string> = new Subject<string>();
public get ecmHost(): string {
return this._ecmHost;
}
public set csrfDisabled(csrfDisabled: boolean) {
this.csrfSubject.next(csrfDisabled);
this._csrfDisabled = csrfDisabled;
}
public set ecmHost(ecmHostUrl: string) {
this.ecmHostSubject.next(ecmHostUrl);
this._ecmHost = ecmHostUrl;
}
public get bpmHost(): string {
return this._bpmHost;
}
public set bpmHost(bpmHostUrl: string) {
this.bpmHostSubject.next(bpmHostUrl);
this._bpmHost = bpmHostUrl;
}
public getBPMApiBaseUrl(): string {
return this._bpmHost + this._bpmContextPath;
}
public getProviders(): string {
return this.providers;
}
public setProviders(providers: string) {
this.providerSubject.next(providers);
this.providers = providers;
constructor() {
super();
console.log('Warning: AlfrescoSettingsService is deprecated. Use SettingsService instead.');
}
}

View File

@@ -16,39 +16,16 @@
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { TranslateService } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service';
import { AlfrescoTranslateService } from './translate.service';
/** @deprecated AlfrescoTranslationService is deprecated. Use AlfrescoTranslateService instead */
@Injectable()
export class AlfrescoTranslationService {
userLang: string = 'en';
customLoader: AlfrescoTranslationLoader;
export class AlfrescoTranslationService extends AlfrescoTranslateService {
constructor(public translate: TranslateService) {
this.userLang = translate.getBrowserLang() || 'en';
translate.setDefaultLang(this.userLang);
this.customLoader = <AlfrescoTranslationLoader> this.translate.currentLoader;
this.customLoader.init(this.userLang);
constructor(translate: TranslateService) {
super(translate);
console.log('Warning: AlfrescoTranslationService is deprecated. Use AlfrescoTranslateService instead.');
}
addTranslationFolder(name: string = '', path: string = '') {
if (!this.customLoader.existComponent(name)) {
this.customLoader.addComponentList(name, path);
this.translate.getTranslation(this.userLang).subscribe(
() => {
this.translate.use(this.userLang);
}
);
}
}
use(lang: string): Observable<any> {
this.customLoader.init(lang);
return this.translate.use(lang);
}
get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
return this.translate.get(key, interpolateParams);
}
}

View File

@@ -16,6 +16,7 @@
*/
import { Injectable } from '@angular/core';
import * as alfrescoApi from 'alfresco-js-api';
import { AlfrescoApi } from 'alfresco-js-api';
@Injectable()
@@ -31,4 +32,16 @@ export class AlfrescoApiService {
this._instance = value;
}
constructor() {
this._instance = <AlfrescoApi>new alfrescoApi({
provider: 'ALL',
ticketEcm: null,
ticketBpm: null,
hostEcm: 'http://localhost:8080',
hostBpm: 'http://localhost:9999',
contextRoot: 'alfresco',
disableCsrf: true
});
}
}

View File

@@ -22,11 +22,11 @@ import {
RouterStateSnapshot
} from '@angular/router';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuardBpm implements CanActivate, CanActivateChild {
constructor(private authService: AlfrescoAuthenticationService, private router: Router) {}
constructor(private authService: AuthService, private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let url: string = state.url;

View File

@@ -22,11 +22,11 @@ import {
RouterStateSnapshot
} from '@angular/router';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuardEcm implements CanActivate, CanActivateChild {
constructor(private authService: AlfrescoAuthenticationService, private router: Router) {}
constructor(private authService: AuthService, private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let url: string = state.url;

View File

@@ -22,11 +22,11 @@ import {
RouterStateSnapshot
} from '@angular/router';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate, CanActivateChild {
constructor(private authService: AlfrescoAuthenticationService, private router: Router) {}
constructor(private authService: AuthService, private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let url: string = state.url;

View File

@@ -16,29 +16,29 @@
*/
import { ReflectiveInjector } from '@angular/core';
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { SettingsService } from './settings.service';
import { AuthService } from './auth.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { StorageService } from './storage.service';
declare let jasmine: any;
describe('AlfrescoAuthentication', () => {
describe('AuthService', () => {
let injector;
let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService;
let authService: AuthService;
let settingsService: SettingsService;
let storage: StorageService;
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoSettingsService,
SettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AuthService,
StorageService
]);
authService = injector.get(AlfrescoAuthenticationService);
settingsService = injector.get(AlfrescoSettingsService);
authService = injector.get(AuthService);
settingsService = injector.get(SettingsService);
storage = injector.get(StorageService);
storage.clear();

View File

@@ -0,0 +1,209 @@
/*!
* @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 { Observable } from 'rxjs/Rx';
import { SettingsService } from './settings.service';
import { StorageService } from './storage.service';
import { AlfrescoApiService } from './alfresco-api.service';
import * as alfrescoApi from 'alfresco-js-api';
import { AlfrescoApi } from 'alfresco-js-api';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class AuthService {
alfrescoApi: AlfrescoApi;
loginSubject: Subject<any> = new Subject<any>();
logoutSubject: Subject<any> = new Subject<any>();
constructor(private settingsService: SettingsService,
private apiService: AlfrescoApiService,
private storage: StorageService) {
this.alfrescoApi = <AlfrescoApi>new alfrescoApi({
provider: this.settingsService.getProviders(),
ticketEcm: this.getTicketEcm(),
ticketBpm: this.getTicketBpm(),
hostEcm: this.settingsService.ecmHost,
hostBpm: this.settingsService.bpmHost,
contextRoot: 'alfresco',
disableCsrf: true
});
settingsService.bpmHostSubject.subscribe((bpmHost) => {
this.alfrescoApi.changeBpmHost(bpmHost);
});
settingsService.ecmHostSubject.subscribe((ecmHost) => {
this.alfrescoApi.changeEcmHost(ecmHost);
});
settingsService.csrfSubject.subscribe((csrf) => {
this.alfrescoApi.changeCsrfConfig(csrf);
});
settingsService.providerSubject.subscribe((value) => {
this.alfrescoApi.config.provider = value;
});
this.apiService.setInstance(this.alfrescoApi);
}
/**
* The method return tru if the user is logged in
* @returns {boolean}
*/
isLoggedIn(): boolean {
return !!this.alfrescoApi.isLoggedIn();
}
/**
* Method to delegate to POST login
* @param username
* @param password
* @returns {Observable<R>|Observable<T>}
*/
login(username: string, password: string): Observable<{ type: string, ticket: any }> {
this.removeTicket();
return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => {
this.saveTickets();
this.loginSubject.next(response);
return {type: this.settingsService.getProviders(), ticket: response};
})
.catch(this.handleError);
}
/**
* Initialize the alfresco Api with user and password end call the login method
* @param username
* @param password
* @returns {*|Observable<any>}
*/
private callApiLogin(username: string, password: string) {
return this.alfrescoApi.login(username, password);
}
/**
* The method remove the ticket from the Storage
*
* @returns {Observable<R>|Observable<T>}
*/
public logout() {
return Observable.fromPromise(this.callApiLogout())
.map(res => <any> res)
.do(response => {
this.removeTicket();
this.logoutSubject.next(response);
return response;
})
.catch(this.handleError);
}
/**
*
* @returns {*|Observable<string>|Observable<any>|Promise<T>}
*/
private callApiLogout(): Promise<any> {
if (this.alfrescoApi) {
return this.alfrescoApi.logout();
}
}
/**
* Remove the login ticket from Storage
*/
public removeTicket(): void {
this.storage.removeItem('ticket-ECM');
this.storage.removeItem('ticket-BPM');
this.alfrescoApi.setTicket(undefined, undefined);
}
/**
* The method return the ECM ticket stored in the Storage
* @returns ticket
*/
public getTicketEcm(): string | null {
return this.storage.getItem('ticket-ECM');
}
/**
* The method return the BPM ticket stored in the Storage
* @returns ticket
*/
public getTicketBpm(): string | null {
return this.storage.getItem('ticket-BPM');
}
public getTicketEcmBase64(): string | null {
let ticket = this.storage.getItem('ticket-ECM');
if (ticket) {
return 'Basic ' + btoa(ticket);
}
return null;
}
/**
* The method save the ECM and BPM ticket in the Storage
*/
public saveTickets() {
this.saveTicketEcm();
this.saveTicketBpm();
}
/**
* The method save the ECM ticket in the Storage
*/
public saveTicketEcm(): void {
if (this.alfrescoApi && this.alfrescoApi.getTicketEcm()) {
this.storage.setItem('ticket-ECM', this.alfrescoApi.getTicketEcm());
}
}
/**
* The method save the BPM ticket in the Storage
*/
public saveTicketBpm(): void {
if (this.alfrescoApi && this.alfrescoApi.getTicketBpm()) {
this.storage.setItem('ticket-BPM', this.alfrescoApi.getTicketBpm());
}
}
/**
* The method return true if user is logged in on ecm provider
*/
public isEcmLoggedIn() {
return this.alfrescoApi.ecmAuth && !!this.alfrescoApi.ecmAuth.isLoggedIn();
}
/**
* The method return true if user is logged in on bpm provider
*/
public isBpmLoggedIn() {
return this.alfrescoApi.bpmAuth && !!this.alfrescoApi.bpmAuth.isLoggedIn();
}
/**
* The method write the error in the console browser
* @param error
* @returns {ErrorObservable}
*/
public handleError(error: any): Observable<any> {
console.error('Error when logging in', error);
return Observable.throw(error || 'Server error');
}
}

View File

@@ -16,19 +16,19 @@
*/
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';
import { SettingsService } from './settings.service';
import { AuthService } from './auth.service';
import { ContentService } from './content.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { StorageService } from './storage.service';
declare let jasmine: any;
describe('AlfrescoContentService', () => {
describe('ContentService', () => {
let injector, contentService: AlfrescoContentService;
let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService;
let injector, contentService: ContentService;
let authService: AuthService;
let settingsService: SettingsService;
let storage: StorageService;
let node: any;
@@ -37,15 +37,15 @@ describe('AlfrescoContentService', () => {
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
AlfrescoContentService,
AlfrescoAuthenticationService,
AlfrescoSettingsService,
ContentService,
AuthService,
SettingsService,
StorageService
]);
authService = injector.get(AlfrescoAuthenticationService);
settingsService = injector.get(AlfrescoSettingsService);
contentService = injector.get(AlfrescoContentService);
authService = injector.get(AuthService);
settingsService = injector.get(SettingsService);
contentService = injector.get(ContentService);
storage = injector.get(StorageService);
storage.clear();

View File

@@ -0,0 +1,47 @@
/*!
* @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 { AuthService } from './auth.service';
import { AlfrescoApiService } from './alfresco-api.service';
@Injectable()
export class ContentService {
constructor(public authService: AuthService,
public apiService: AlfrescoApiService) {
}
/**
* Get thumbnail URL for the given document node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any): string {
return this.apiService.getInstance().content.getDocumentThumbnailUrl(document.entry.id);
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any): string {
return this.apiService.getInstance().content.getContentUrl(document.entry.id);
}
}

View File

@@ -16,9 +16,8 @@
*/
export * from './storage.service';
export * from './AlfrescoApi.service';
export * from './alfresco-api.service';
export * from './AlfrescoSettings.service';
export * from './AlfrescoTranslationLoader.service';
export * from './AlfrescoTranslation.service';
export * from './AlfrescoAuthentication.service';
export * from './AlfrescoContent.service';
@@ -26,3 +25,9 @@ export * from './renditions.service';
export * from './auth-guard.service';
export * from './auth-guard-ecm.service';
export * from './auth-guard-bpm.service';
export * from './auth.service';
export * from './content.service';
export * from './settings.service';
export * from './translate.service';
export * from './translate-loader.service';

View File

@@ -16,7 +16,7 @@
*/
import { ReflectiveInjector } from '@angular/core';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { RenditionsService } from './renditions.service';
import {
fakeRedition,

View File

@@ -17,7 +17,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { AlfrescoApiService } from './alfresco-api.service';
/**
* RenditionsService

View File

@@ -15,18 +15,18 @@
* limitations under the License.
*/
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { SettingsService } from './settings.service';
describe('AlfrescoSettingsService', () => {
let service: AlfrescoSettingsService;
let service: SettingsService;
beforeEach(() => {
service = new AlfrescoSettingsService();
service = new SettingsService();
});
it('should have default ECM host', () => {
expect(service.ecmHost).toBe(AlfrescoSettingsService.DEFAULT_ECM_ADDRESS);
expect(service.ecmHost).toBe(SettingsService.DEFAULT_ECM_ADDRESS);
});
it('should change host ECM', () => {
@@ -37,7 +37,7 @@ describe('AlfrescoSettingsService', () => {
});
it('should have default BPM host', () => {
expect(service.bpmHost).toBe(AlfrescoSettingsService.DEFAULT_BPM_ADDRESS);
expect(service.bpmHost).toBe(SettingsService.DEFAULT_BPM_ADDRESS);
});
it('should change host BPM', () => {

View File

@@ -0,0 +1,78 @@
/*!
* @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 { Subject } from 'rxjs/Subject';
@Injectable()
export class SettingsService {
static DEFAULT_ECM_ADDRESS: string = 'http://' + window.location.hostname + ':8080';
static DEFAULT_BPM_ADDRESS: string = 'http://' + window.location.hostname + ':9999';
static DEFAULT_CSRF_CONFIG: boolean = false;
static DEFAULT_BPM_CONTEXT_PATH: string = '/activiti-app';
private _ecmHost: string = SettingsService.DEFAULT_ECM_ADDRESS;
private _bpmHost: string = SettingsService.DEFAULT_BPM_ADDRESS;
private _csrfDisabled: boolean = SettingsService.DEFAULT_CSRF_CONFIG;
private _bpmContextPath = SettingsService.DEFAULT_BPM_CONTEXT_PATH;
private providers: string = 'ALL'; // ECM, BPM , ALL
public bpmHostSubject: Subject<string> = new Subject<string>();
public ecmHostSubject: Subject<string> = new Subject<string>();
public csrfSubject: Subject<boolean> = new Subject<boolean>();
public providerSubject: Subject<string> = new Subject<string>();
public get ecmHost(): string {
return this._ecmHost;
}
public set csrfDisabled(csrfDisabled: boolean) {
this.csrfSubject.next(csrfDisabled);
this._csrfDisabled = csrfDisabled;
}
public set ecmHost(ecmHostUrl: string) {
this.ecmHostSubject.next(ecmHostUrl);
this._ecmHost = ecmHostUrl;
}
public get bpmHost(): string {
return this._bpmHost;
}
public set bpmHost(bpmHostUrl: string) {
this.bpmHostSubject.next(bpmHostUrl);
this._bpmHost = bpmHostUrl;
}
public getBPMApiBaseUrl(): string {
return this._bpmHost + this._bpmContextPath;
}
public getProviders(): string {
return this.providers;
}
public setProviders(providers: string) {
this.providerSubject.next(providers);
this.providers = providers;
}
}

View File

@@ -15,17 +15,15 @@
* limitations under the License.
*/
import { TranslateLoader } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationLoader } from '../services/AlfrescoTranslationLoader.service';
import { AlfrescoTranslationService } from '../services/AlfrescoTranslation.service';
import { TranslateModule, TranslateLoader } from 'ng2-translate/ng2-translate';
import { Injector } from '@angular/core';
import { ResponseOptions, Response, XHRBackend, HttpModule } from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
import {
TranslateModule
} from 'ng2-translate/ng2-translate';
import {getTestBed, TestBed} from '@angular/core/testing';
import { AlfrescoTranslateLoader } from './translate-loader.service';
import { AlfrescoTranslateService } from './translate.service';
let componentJson1 = ' {"TEST": "This is a test", "TEST2": "This is another test"} ' ;
const mockBackendResponse = (connection: MockConnection, response: string) => {
@@ -35,7 +33,7 @@ const mockBackendResponse = (connection: MockConnection, response: string) => {
describe('TranslateLoader', () => {
let injector: Injector;
let backend: MockBackend;
let alfrescoTranslationService: AlfrescoTranslationService;
let alfrescoTranslationService: AlfrescoTranslateService;
let connection: MockConnection; // this will be set when a new connection is emitted from the backend.
let customLoader;
@@ -43,16 +41,16 @@ describe('TranslateLoader', () => {
TestBed.configureTestingModule({
imports: [HttpModule, TranslateModule.forRoot({
provide: TranslateLoader,
useClass: AlfrescoTranslationLoader
useClass: AlfrescoTranslateLoader
})],
providers: [
AlfrescoTranslationService,
AlfrescoTranslateService,
{provide: XHRBackend, useClass: MockBackend}
]
});
injector = getTestBed();
backend = injector.get(XHRBackend);
alfrescoTranslationService = injector.get(AlfrescoTranslationService);
alfrescoTranslationService = injector.get(AlfrescoTranslateService);
backend.connections.subscribe((c: MockConnection) => connection = c);
customLoader = alfrescoTranslationService.translate.currentLoader;
});
@@ -60,7 +58,7 @@ describe('TranslateLoader', () => {
it('should be able to provide any TranslateLoader', () => {
expect(alfrescoTranslationService).toBeDefined();
expect(alfrescoTranslationService.translate.currentLoader).toBeDefined();
expect(alfrescoTranslationService.translate.currentLoader instanceof AlfrescoTranslationLoader).toBeTruthy();
expect(alfrescoTranslationService.translate.currentLoader instanceof AlfrescoTranslateLoader).toBeTruthy();
});
it('should add the component to the list', () => {

View File

@@ -22,7 +22,7 @@ import { TranslateLoader } from 'ng2-translate/ng2-translate';
import { ComponentTranslationModel } from '../models/component.model';
@Injectable()
export class AlfrescoTranslationLoader implements TranslateLoader {
export class AlfrescoTranslateLoader implements TranslateLoader {
private prefix: string = 'i18n';
private suffix: string = '.json';

View File

@@ -15,48 +15,46 @@
* limitations under the License.
*/
import { AlfrescoTranslationService } from '../services/AlfrescoTranslation.service';
import { TranslateLoader } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationLoader } from '../services/AlfrescoTranslationLoader.service';
import { TranslateModule, TranslateLoader } from 'ng2-translate/ng2-translate';
import { Injector } from '@angular/core';
import { ResponseOptions, Response, XHRBackend, HttpModule } from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
import {
TranslateModule
} from 'ng2-translate/ng2-translate';
import {getTestBed, TestBed} from '@angular/core/testing';
import { getTestBed, TestBed } from '@angular/core/testing';
import { AlfrescoTranslateService } from './translate.service';
import { AlfrescoTranslateLoader } from './translate-loader.service';
const mockBackendResponse = (connection: MockConnection, response: string) => {
connection.mockRespond(new Response(new ResponseOptions({body: response})));
};
describe('AlfrescoTranslationService', () => {
describe('AlfrescoTranslateService', () => {
let injector: Injector;
let backend: MockBackend;
let alfrescoTranslationService: AlfrescoTranslationService;
let alfrescoTranslationService: AlfrescoTranslateService;
let connection: MockConnection; // this will be set when a new connection is emitted from the backend.
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule, TranslateModule.forRoot({
provide: TranslateLoader,
useClass: AlfrescoTranslationLoader
useClass: AlfrescoTranslateLoader
})],
providers: [
AlfrescoTranslationService,
AlfrescoTranslateService,
{provide: XHRBackend, useClass: MockBackend}
]
});
injector = getTestBed();
backend = injector.get(XHRBackend);
alfrescoTranslationService = injector.get(AlfrescoTranslationService);
alfrescoTranslationService = injector.get(AlfrescoTranslateService);
backend.connections.subscribe((c: MockConnection) => connection = c);
alfrescoTranslationService.addTranslationFolder('fake-name', 'fake-path');
});
it('is defined', () => {
expect(AlfrescoTranslationService).toBeDefined();
expect(alfrescoTranslationService instanceof AlfrescoTranslationService).toBeTruthy();
expect(AlfrescoTranslateService).toBeDefined();
expect(alfrescoTranslationService instanceof AlfrescoTranslateService).toBeTruthy();
});
it('should be able to get translations of the KEY: TEST', () => {

View File

@@ -0,0 +1,54 @@
/*!
* @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 { Observable } from 'rxjs/Rx';
import { TranslateService } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslateLoader } from './translate-loader.service';
@Injectable()
export class AlfrescoTranslateService {
userLang: string = 'en';
customLoader: AlfrescoTranslateLoader;
constructor(public translate: TranslateService) {
this.userLang = translate.getBrowserLang() || 'en';
translate.setDefaultLang(this.userLang);
this.customLoader = <AlfrescoTranslateLoader> this.translate.currentLoader;
this.customLoader.init(this.userLang);
}
addTranslationFolder(name: string = '', path: string = '') {
if (!this.customLoader.existComponent(name)) {
this.customLoader.addComponentList(name, path);
this.translate.getTranslation(this.userLang).subscribe(
() => {
this.translate.use(this.userLang);
}
);
}
}
use(lang: string): Observable<any> {
this.customLoader.init(lang);
return this.translate.use(lang);
}
get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
return this.translate.get(key, interpolateParams);
}
}