Migrate from window.console to LogService

This commit is contained in:
Denys Vuika
2017-01-05 21:06:30 +00:00
parent 2d98a04f87
commit d42f41ec00
106 changed files with 1177 additions and 1171 deletions

View File

@@ -33,7 +33,7 @@ import {
AuthGuard,
AuthGuardEcm,
AuthGuardBpm,
LogService,
LogService, LogServiceMock,
/** @deprecated */ AlfrescoSettingsService,
/** @deprecated */ AlfrescoTranslationService,
@@ -49,7 +49,7 @@ export * from './src/components/index';
export * from './src/utils/index';
export const ALFRESCO_CORE_PROVIDERS: any[] = [
LogService,
LogService, LogServiceMock,
AuthService,
ContentService,
SettingsService,
@@ -69,8 +69,8 @@ export const ALFRESCO_CORE_PROVIDERS: any[] = [
/** @deprecated */ AlfrescoTranslationService
];
export function createTranslateLoader(http: Http) {
return new AlfrescoTranslateLoader(http);
export function createTranslateLoader(http: Http, logService: LogService) {
return new AlfrescoTranslateLoader(http, logService);
}
@NgModule({
@@ -82,7 +82,7 @@ export function createTranslateLoader(http: Http) {
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
deps: [Http, LogService]
})
],
declarations: [

View File

@@ -16,6 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { LogService } from './log.service';
import { SettingsService } from './settings.service';
import { StorageService } from './storage.service';
import { AlfrescoApiService } from './alfresco-api.service';
@@ -26,8 +27,9 @@ import { AuthService } from './auth.service';
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.');
storage: StorageService,
logService: LogService) {
super(settingsService, apiService, storage, logService);
logService.warn('Warning: AlfrescoAuthenticationService is deprecated. Use AuthService instead.');
}
}

View File

@@ -16,7 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { LogService } from './log.service';
import { AuthService } from './auth.service';
import { ContentService } from './content.service';
import { AlfrescoApiService } from './alfresco-api.service';
@@ -25,8 +25,10 @@ import { AlfrescoApiService } from './alfresco-api.service';
@Injectable()
export class AlfrescoContentService extends ContentService {
constructor(authService: AuthService, apiService: AlfrescoApiService) {
constructor(authService: AuthService,
apiService: AlfrescoApiService,
logService: LogService) {
super(authService, apiService);
console.log('Warning: AlfrescoContentService is deprecated. Use ContentService instead.');
logService.warn('Warning: AlfrescoContentService is deprecated. Use ContentService instead.');
}
}

View File

@@ -17,13 +17,14 @@
import { Injectable } from '@angular/core';
import { SettingsService } from './settings.service';
import { LogService } from './log.service';
/** @deprecated AlfrescoSettingsService is deprecated. Use SettingsService instead */
@Injectable()
export class AlfrescoSettingsService extends SettingsService {
constructor() {
constructor(logService: LogService) {
super();
console.log('Warning: AlfrescoSettingsService is deprecated. Use SettingsService instead.');
logService.warn('Warning: AlfrescoSettingsService is deprecated. Use SettingsService instead.');
}
}

View File

@@ -18,14 +18,16 @@
import { Injectable } from '@angular/core';
import { TranslateService } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslateService } from './translate.service';
import { LogService } from './log.service';
/** @deprecated AlfrescoTranslationService is deprecated. Use AlfrescoTranslateService instead */
@Injectable()
export class AlfrescoTranslationService extends AlfrescoTranslateService {
constructor(translate: TranslateService) {
constructor(translate: TranslateService,
logService: LogService) {
super(translate);
console.log('Warning: AlfrescoTranslationService is deprecated. Use AlfrescoTranslateService instead.');
logService.warn('Warning: AlfrescoTranslationService is deprecated. Use AlfrescoTranslateService instead.');
}
}

View File

@@ -20,6 +20,7 @@ import { SettingsService } from './settings.service';
import { AuthService } from './auth.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { StorageService } from './storage.service';
import { LogService } from './log.service';
declare let jasmine: any;
@@ -34,7 +35,8 @@ describe('AuthService', () => {
SettingsService,
AlfrescoApiService,
AuthService,
StorageService
StorageService,
LogService
]);
authService = injector.get(AuthService);

View File

@@ -16,13 +16,13 @@
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { Observable, Subject } 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';
import { LogService } from './log.service';
@Injectable()
export class AuthService {
@@ -33,7 +33,8 @@ export class AuthService {
constructor(private settingsService: SettingsService,
private apiService: AlfrescoApiService,
private storage: StorageService) {
private storage: StorageService,
private logService: LogService) {
this.alfrescoApi = <AlfrescoApi>new alfrescoApi({
provider: this.settingsService.getProviders(),
ticketEcm: this.getTicketEcm(),
@@ -103,7 +104,7 @@ export class AuthService {
*
* @returns {Observable<R>|Observable<T>}
*/
public logout() {
logout() {
return Observable.fromPromise(this.callApiLogout())
.map(res => <any> res)
.do(response => {
@@ -127,7 +128,7 @@ export class AuthService {
/**
* Remove the login ticket from Storage
*/
public removeTicket(): void {
removeTicket(): void {
this.storage.removeItem('ticket-ECM');
this.storage.removeItem('ticket-BPM');
this.alfrescoApi.setTicket(undefined, undefined);
@@ -137,7 +138,7 @@ export class AuthService {
* The method return the ECM ticket stored in the Storage
* @returns ticket
*/
public getTicketEcm(): string | null {
getTicketEcm(): string | null {
return this.storage.getItem('ticket-ECM');
}
@@ -145,11 +146,11 @@ export class AuthService {
* The method return the BPM ticket stored in the Storage
* @returns ticket
*/
public getTicketBpm(): string | null {
getTicketBpm(): string | null {
return this.storage.getItem('ticket-BPM');
}
public getTicketEcmBase64(): string | null {
getTicketEcmBase64(): string | null {
let ticket = this.storage.getItem('ticket-ECM');
if (ticket) {
return 'Basic ' + btoa(ticket);
@@ -160,7 +161,7 @@ export class AuthService {
/**
* The method save the ECM and BPM ticket in the Storage
*/
public saveTickets() {
saveTickets() {
this.saveTicketEcm();
this.saveTicketBpm();
}
@@ -168,7 +169,7 @@ export class AuthService {
/**
* The method save the ECM ticket in the Storage
*/
public saveTicketEcm(): void {
saveTicketEcm(): void {
if (this.alfrescoApi && this.alfrescoApi.getTicketEcm()) {
this.storage.setItem('ticket-ECM', this.alfrescoApi.getTicketEcm());
}
@@ -177,7 +178,7 @@ export class AuthService {
/**
* The method save the BPM ticket in the Storage
*/
public saveTicketBpm(): void {
saveTicketBpm(): void {
if (this.alfrescoApi && this.alfrescoApi.getTicketBpm()) {
this.storage.setItem('ticket-BPM', this.alfrescoApi.getTicketBpm());
}
@@ -186,14 +187,14 @@ export class AuthService {
/**
* The method return true if user is logged in on ecm provider
*/
public isEcmLoggedIn() {
isEcmLoggedIn() {
return this.alfrescoApi.ecmAuth && !!this.alfrescoApi.ecmAuth.isLoggedIn();
}
/**
* The method return true if user is logged in on bpm provider
*/
public isBpmLoggedIn() {
isBpmLoggedIn() {
return this.alfrescoApi.bpmAuth && !!this.alfrescoApi.bpmAuth.isLoggedIn();
}
@@ -202,8 +203,8 @@ export class AuthService {
* @param error
* @returns {ErrorObservable}
*/
public handleError(error: any): Observable<any> {
console.error('Error when logging in', error);
handleError(error: any): Observable<any> {
this.logService.error('Error when logging in', error);
return Observable.throw(error || 'Server error');
}
}

View File

@@ -21,6 +21,7 @@ import { AuthService } from './auth.service';
import { ContentService } from './content.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { StorageService } from './storage.service';
import { LogService } from './log.service';
declare let jasmine: any;
@@ -40,7 +41,8 @@ describe('ContentService', () => {
ContentService,
AuthService,
SettingsService,
StorageService
StorageService,
LogService
]);
authService = injector.get(AuthService);

View File

@@ -21,7 +21,7 @@ import { Injectable } from '@angular/core';
export class LogService {
get assert(): (message?: any, ...optionalParams: any[]) => void {
return console.error.bind(console);
return console.assert.bind(console);
}
get error(): (message?: any, ...optionalParams: any[]) => void {
@@ -29,11 +29,11 @@ export class LogService {
}
get group(): (message?: any, ...optionalParams: any[]) => void {
return console.error.bind(console);
return console.group.bind(console);
}
get groupEnd(): (message?: any, ...optionalParams: any[]) => void {
return console.error.bind(console);
return console.groupEnd.bind(console);
}
get info(): (message?: any, ...optionalParams: any[]) => void {
@@ -49,3 +49,15 @@ export class LogService {
}
}
export class LogServiceMock {
assert(message?: any, ...optionalParams: any[]) {}
error(message?: any, ...optionalParams: any[]) {}
group(message?: any, ...optionalParams: any[]) {}
groupEnd(message?: any, ...optionalParams: any[]) {}
info(message?: any, ...optionalParams: any[]) {}
log(message?: any, ...optionalParams: any[]) {}
warn(message?: any, ...optionalParams: any[]) {}
}

View File

@@ -18,11 +18,8 @@
import { ReflectiveInjector } from '@angular/core';
import { AlfrescoApiService } from './alfresco-api.service';
import { RenditionsService } from './renditions.service';
import {
fakeRedition,
fakeReditionCreated,
fakeReditionsList
} from '../assets/renditionsService.mock';
import { LogService } from './log.service';
import { fakeRedition, fakeReditionCreated, fakeReditionsList } from '../assets/renditionsService.mock';
declare let jasmine: any;
declare let AlfrescoApi: any;
@@ -33,7 +30,8 @@ describe('RenditionsService', () => {
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoApiService,
RenditionsService
RenditionsService,
LogService
]);
});

View File

@@ -18,6 +18,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { AlfrescoApiService } from './alfresco-api.service';
import { LogService } from './log.service';
/**
* RenditionsService
@@ -27,7 +28,8 @@ import { AlfrescoApiService } from './alfresco-api.service';
@Injectable()
export class RenditionsService {
constructor(private apiService: AlfrescoApiService) {
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
}
@@ -75,7 +77,7 @@ export class RenditionsService {
}
private handleError(error: any): Observable<any> {
console.error(error);
this.logService.error(error);
return Observable.throw(error || 'Server error');
}
}

View File

@@ -23,6 +23,7 @@ import {getTestBed, TestBed} from '@angular/core/testing';
import { AlfrescoTranslateLoader } from './translate-loader.service';
import { AlfrescoTranslateService } from './translate.service';
import { LogService } from './log.service';
let componentJson1 = ' {"TEST": "This is a test", "TEST2": "This is another test"} ' ;
@@ -39,12 +40,16 @@ describe('TranslateLoader', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule, TranslateModule.forRoot({
provide: TranslateLoader,
useClass: AlfrescoTranslateLoader
})],
imports: [
HttpModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useClass: AlfrescoTranslateLoader
})
],
providers: [
AlfrescoTranslateService,
LogService,
{provide: XHRBackend, useClass: MockBackend}
]
});

View File

@@ -17,9 +17,10 @@
import { Injectable } from '@angular/core';
import { Response, Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs/Rx';
import { TranslateLoader } from 'ng2-translate/ng2-translate';
import { ComponentTranslationModel } from '../models/component.model';
import { LogService } from './log.service';
@Injectable()
export class AlfrescoTranslateLoader implements TranslateLoader {
@@ -29,7 +30,8 @@ export class AlfrescoTranslateLoader implements TranslateLoader {
private _componentList: ComponentTranslationModel[] = [];
private queue: string [][] = [];
constructor(private http: Http) {
constructor(private http: Http,
private logService: LogService) {
}
addComponentList(nameInput: string, pathInput: string) {
@@ -95,7 +97,7 @@ export class AlfrescoTranslateLoader implements TranslateLoader {
observer.complete();
},
(err: any) => {
console.error(err);
this.logService.error(err);
});
} else {
let fullTranslation = this.getFullTranslationJSON(lang);

View File

@@ -23,6 +23,7 @@ import { getTestBed, TestBed } from '@angular/core/testing';
import { AlfrescoTranslateService } from './translate.service';
import { AlfrescoTranslateLoader } from './translate-loader.service';
import { LogService } from './log.service';
const mockBackendResponse = (connection: MockConnection, response: string) => {
connection.mockRespond(new Response(new ResponseOptions({body: response})));
@@ -36,12 +37,16 @@ describe('AlfrescoTranslateService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule, TranslateModule.forRoot({
provide: TranslateLoader,
useClass: AlfrescoTranslateLoader
})],
imports: [
HttpModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useClass: AlfrescoTranslateLoader
})
],
providers: [
AlfrescoTranslateService,
LogService,
{provide: XHRBackend, useClass: MockBackend}
]
});