diff --git a/demo-shell-ng2/app/app.component.ts b/demo-shell-ng2/app/app.component.ts index 58cb6780ea..cf2ab3ed96 100644 --- a/demo-shell-ng2/app/app.component.ts +++ b/demo-shell-ng2/app/app.component.ts @@ -17,13 +17,7 @@ import { Component } from '@angular/core'; import { Router } from '@angular/router'; - -import { - AlfrescoTranslationService, - AuthService, - SettingsService, - StorageService -} from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, AuthService, SettingsService, StorageService, LogService } from 'ng2-alfresco-core'; declare var document: any; @@ -38,22 +32,23 @@ export class AppComponent { ecmHost: string = 'http://' + window.location.hostname + ':8080'; bpmHost: string = 'http://' + window.location.hostname + ':9999'; - constructor(public authService: AuthService, - public router: Router, - public settingsService: SettingsService, - private translate: AlfrescoTranslationService, - private storage: StorageService) { + constructor(private authService: AuthService, + private router: Router, + private settingsService: SettingsService, + private translateService: AlfrescoTranslateService, + private storage: StorageService, + private logService: LogService) { this.setEcmHost(); this.setBpmHost(); this.setProvider(); - if (translate) { + if (translateService) { if (process.env.ENV === 'production') { - translate.addTranslationFolder('custom', 'i18n/custom-translation'); - translate.addTranslationFolder('ng2-alfresco-login', 'i18n/custom-translation/alfresco-login'); + translateService.addTranslationFolder('custom', 'i18n/custom-translation'); + translateService.addTranslationFolder('ng2-alfresco-login', 'i18n/custom-translation/alfresco-login'); } else { - translate.addTranslationFolder('custom', 'custom-translation'); - translate.addTranslationFolder('ng2-alfresco-login', 'custom-translation/alfresco-login'); + translateService.addTranslationFolder('custom', 'custom-translation'); + translateService.addTranslationFolder('ng2-alfresco-login', 'custom-translation/alfresco-login'); } } } @@ -84,7 +79,7 @@ export class AppComponent { if (error && error.response && error.response.status === 401) { this.navigateToLogin(); } else { - console.error('An unknown error occurred while logging out', error); + this.logService.error('An unknown error occurred while logging out', error); this.navigateToLogin(); } } @@ -107,7 +102,7 @@ export class AppComponent { } changeLanguage(lang: string) { - this.translate.use(lang); + this.translateService.use(lang); this.hideDrawer(); } diff --git a/demo-shell-ng2/app/components/about/about.component.ts b/demo-shell-ng2/app/components/about/about.component.ts index fbcd09611d..4fba975fe8 100644 --- a/demo-shell-ng2/app/components/about/about.component.ts +++ b/demo-shell-ng2/app/components/about/about.component.ts @@ -18,6 +18,7 @@ import { Component, OnInit } from '@angular/core'; import { Http } from '@angular/http'; import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; +import { LogService } from 'ng2-alfresco-core'; @Component({ selector: 'about-page', @@ -27,31 +28,31 @@ export class AboutComponent implements OnInit { data: ObjectDataTableAdapter; - constructor(private http: Http) { + constructor(private http: Http, + private logService: LogService) { } ngOnInit() { this.http.get('/versions.json').subscribe(response => { - var regexp = new RegExp("^(ng2-activiti|ng2-alfresco|alfresco-)", 'g'); + let regexp = new RegExp('^(ng2-activiti|ng2-alfresco|alfresco-)', 'g'); - var alfrescoPackages = Object.keys(response.json().dependencies).filter(function (val) { - console.log(val); + let alfrescoPackages = Object.keys(response.json().dependencies).filter((val) => { + this.logService.log(val); return regexp.test(val); }); - let alfrescoPackagesTableRappresentation = []; - alfrescoPackages.forEach((val)=> { - console.log(response.json().dependencies[val]); - alfrescoPackagesTableRappresentation.push({name:val,version:response.json().dependencies[val].version}); + let alfrescoPackagesTableRappresentation = []; + alfrescoPackages.forEach((val) => { + this.logService.log(response.json().dependencies[val]); + alfrescoPackagesTableRappresentation.push({name: val, version: response.json().dependencies[val].version}); }); - console.log(alfrescoPackagesTableRappresentation); + this.logService.log(alfrescoPackagesTableRappresentation); this.data = new ObjectDataTableAdapter(alfrescoPackagesTableRappresentation, [ {type: 'text', key: 'name', title: 'Name', sortable: true}, {type: 'text', key: 'version', title: 'Version', sortable: true} ]); }); - } } diff --git a/demo-shell-ng2/app/components/files/files.component.ts b/demo-shell-ng2/app/components/files/files.component.ts index ec1046feb8..c4cda092de 100644 --- a/demo-shell-ng2/app/components/files/files.component.ts +++ b/demo-shell-ng2/app/components/files/files.component.ts @@ -17,7 +17,7 @@ import { Component, OnInit, Optional, ViewChild } from '@angular/core'; import { ActivatedRoute, Params, Router } from '@angular/router'; -import { AuthService } from 'ng2-alfresco-core'; +import { AuthService, LogService } from 'ng2-alfresco-core'; import { DocumentActionsService, DocumentList, @@ -49,8 +49,9 @@ export class FilesComponent implements OnInit { documentList: DocumentList; constructor(private documentActions: DocumentActionsService, - public authService: AuthService, + private authService: AuthService, private formService: FormService, + private logService: LogService, private router: Router, @Optional() private route: ActivatedRoute) { documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this)); @@ -109,10 +110,10 @@ export class FilesComponent implements OnInit { if (this.authService.isBpmLoggedIn()) { this.formService.getProcessDefinitions().subscribe( defs => this.setupBpmActions(defs || []), - err => console.log(err) + err => this.logService.error(err) ); } else { - console.log('You are not logged in'); + this.logService.warn('You are not logged in to BPM'); } } diff --git a/demo-shell-ng2/app/components/login/login-demo.component.ts b/demo-shell-ng2/app/components/login/login-demo.component.ts index d5ee054b33..2014686652 100644 --- a/demo-shell-ng2/app/components/login/login-demo.component.ts +++ b/demo-shell-ng2/app/components/login/login-demo.component.ts @@ -18,7 +18,7 @@ import { Component, ViewChild, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { Validators } from '@angular/forms'; -import { StorageService } from 'ng2-alfresco-core'; +import { StorageService, LogService } from 'ng2-alfresco-core'; @Component({ selector: 'login-demo', @@ -38,7 +38,9 @@ export class LoginDemoComponent implements OnInit { isECM: boolean = true; isBPM: boolean = false; - constructor(public router: Router, private storage: StorageService) { + constructor(private router: Router, + private storage: StorageService, + private logService: LogService) { this.customValidation = { username: ['', Validators.compose([Validators.required, Validators.minLength(4)])], password: ['', Validators.required] @@ -75,7 +77,7 @@ export class LoginDemoComponent implements OnInit { } onError($event) { - console.log($event); + this.logService.error($event); } toggleECM() { @@ -92,7 +94,7 @@ export class LoginDemoComponent implements OnInit { this.disableCsrf = !this.disableCsrf; } - updateProvider(){ + updateProvider() { if (this.isBPM && this.isECM) { this.providers = 'ALL'; return this.providers; diff --git a/demo-shell-ng2/app/components/setting/setting.component.ts b/demo-shell-ng2/app/components/setting/setting.component.ts index f5c96045aa..bd0644c378 100644 --- a/demo-shell-ng2/app/components/setting/setting.component.ts +++ b/demo-shell-ng2/app/components/setting/setting.component.ts @@ -16,7 +16,7 @@ */ import { Component } from '@angular/core'; -import { SettingsService, StorageService } from 'ng2-alfresco-core'; +import { SettingsService, StorageService, LogService } from 'ng2-alfresco-core'; @Component({ selector: 'alfresco-setting-demo', @@ -28,24 +28,31 @@ export class SettingComponent { ecmHost: string; bpmHost: string; - constructor(public settingsService: SettingsService, - private storage: StorageService) { + constructor(private settingsService: SettingsService, + private storage: StorageService, + private logService: LogService) { this.ecmHost = this.settingsService.ecmHost; this.bpmHost = this.settingsService.bpmHost; } public onChangeECMHost(event: KeyboardEvent): void { - console.log((event.target).value); - this.ecmHost = (event.target).value; - this.settingsService.ecmHost = this.ecmHost; - this.storage.setItem(`ecmHost`, this.ecmHost); + let value = (event.target).value.trim(); + if (value) { + this.logService.info(`ECM host: ${value}`); + this.ecmHost = value; + this.settingsService.ecmHost = value; + this.storage.setItem(`ecmHost`, value); + } } public onChangeBPMHost(event: KeyboardEvent): void { - console.log((event.target).value); - this.bpmHost = (event.target).value; - this.settingsService.bpmHost = this.bpmHost; - this.storage.setItem(`bpmHost`, this.bpmHost); + let value = (event.target).value.trim(); + if (value) { + this.logService.info(`BPM host: ${value}`); + this.bpmHost = value; + this.settingsService.bpmHost = value; + this.storage.setItem(`bpmHost`, value); + } } } diff --git a/demo-shell-ng2/app/components/webscript/webscript.component.ts b/demo-shell-ng2/app/components/webscript/webscript.component.ts index 9d00332036..4587498c80 100644 --- a/demo-shell-ng2/app/components/webscript/webscript.component.ts +++ b/demo-shell-ng2/app/components/webscript/webscript.component.ts @@ -16,42 +16,41 @@ */ import { Component } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; @Component({ selector: 'alfresco-webscript-demo', template: ` - -
-
-
-
-
-
- +
+
+
+
+
+
+ + ` }) export class WebscriptComponent { currentPath: string = '/'; - authenticated: boolean; - host: string = 'http://127.0.0.1:8080'; - scriptPath: string = 'sample/folder/Company%20Home'; - contextRoot: string = 'alfresco'; - servicePath: string = 'service'; - scriptArgs: string = ''; + constructor(private logService: LogService) { + } + logData(data) { - console.log(data); + this.logService.log(data); } } diff --git a/ng2-components/ng2-activiti-analytics/demo/src/main.ts b/ng2-components/ng2-activiti-analytics/demo/src/main.ts index 2c5ae6f71a..e38c634a64 100644 --- a/ng2-components/ng2-activiti-analytics/demo/src/main.ts +++ b/ng2-components/ng2-activiti-analytics/demo/src/main.ts @@ -18,51 +18,49 @@ import { NgModule, Component, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; import { AnalyticsModule } from 'ng2-activiti-analytics'; @Component({ selector: 'alfresco-app-demo', template: ` -
-
-
-

-
- Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform - operations. -
-
+
+
+
+

+
+ Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform + operations. +
+
-
-
- -
-
- -
-
- +
+
+ +
+
+ +
+
+ +
-
` + ` }) export class AnalyticsDemoComponent implements OnInit { appId: number; - report: any; - authenticated: boolean; - host: string = 'http://localhost:9999'; - ticket: string; constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.bpmHost = this.host; settingsService.setProviders('BPM'); @@ -91,12 +89,12 @@ export class AnalyticsDemoComponent implements OnInit { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.log(ticket); this.ticket = this.authService.getTicketBpm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts index 3f42d93a44..ca2649f230 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts @@ -17,6 +17,7 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { Observer, Observable } from 'rxjs/Rx'; +import { LogService } from 'ng2-alfresco-core'; import { AnalyticsService } from '../services/analytics.service'; import { ReportParametersModel } from '../models/report.model'; @@ -44,8 +45,8 @@ export class AnalyticsReportListComponent implements OnInit { reports: ReportParametersModel[] = []; - constructor(private analyticsService: AnalyticsService) { - + constructor(private analyticsService: AnalyticsService, + private logService: LogService) { this.report$ = new Observable(observer => this.reportObserver = observer).share(); } @@ -82,7 +83,7 @@ export class AnalyticsReportListComponent implements OnInit { }, (err: any) => { this.onError.emit(err); - console.log(err); + this.logService.error(err); } ); } diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics-report-parameters.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics-report-parameters.component.ts index 452d9448b0..9cb535115a 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics-report-parameters.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics-report-parameters.component.ts @@ -16,11 +16,11 @@ */ import { Component, EventEmitter, OnInit, OnChanges, Input, Output, SimpleChanges, OnDestroy, AfterViewChecked } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; -import { AnalyticsService } from '../services/analytics.service'; -import { ReportParametersModel, ReportQuery, ParameterValueModel, ReportParameterDetailsModel } from '../models/report.model'; import { FormGroup, FormBuilder, FormControl } from '@angular/forms'; import * as moment from 'moment'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; +import { AnalyticsService } from '../services/analytics.service'; +import { ReportParametersModel, ReportQuery, ParameterValueModel, ReportParameterDetailsModel } from '../models/report.model'; declare var componentHandler; @@ -72,7 +72,8 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On constructor(private translateService: AlfrescoTranslateService, private analyticsService: AnalyticsService, - private formBuilder: FormBuilder ) { + private formBuilder: FormBuilder, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-analytics', 'node_modules/ng2-activiti-analytics/src'); } @@ -148,7 +149,7 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On } }, (err: any) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); } ); @@ -162,7 +163,7 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On this.onSuccessParamOpt.emit(opts); }, (err: any) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); } ); @@ -233,7 +234,7 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On this.onEdit.emit(this.reportParameters.name); }, (err: any) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); } ); diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts index 186fe8f8f4..9e5328101e 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts @@ -16,7 +16,7 @@ */ import { Component, EventEmitter, OnChanges, Input, Output, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { AnalyticsService } from '../services/analytics.service'; import { ReportQuery } from '../models/report.model'; import { Chart } from '../models/chart.model'; @@ -71,8 +71,9 @@ export class AnalyticsComponent implements OnChanges { }; constructor(private translateService: AlfrescoTranslateService, - private analyticsService: AnalyticsService) { - console.log('AnalyticsComponent'); + private analyticsService: AnalyticsService, + private logService: LogService) { + logService.info('AnalyticsComponent'); if (translateService) { translateService.addTranslationFolder('ng2-activiti-analytics', 'node_modules/ng2-activiti-analytics/src'); } @@ -91,7 +92,7 @@ export class AnalyticsComponent implements OnChanges { }, (err: any) => { this.onError.emit(err); - console.log(err); + this.logService.error(err); } ); } diff --git a/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts b/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts index 672f85b644..344b742ae0 100644 --- a/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts +++ b/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts @@ -18,14 +18,15 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; import { Response } from '@angular/http'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { ReportParametersModel, ParameterValueModel } from '../models/report.model'; import { Chart, PieChart, TableChart, BarChart, HeatMapChart, MultiBarChart, DetailsTableChart } from '../models/chart.model'; @Injectable() export class AnalyticsService { - constructor(public apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } /** @@ -170,21 +171,21 @@ export class AnalyticsService { }).catch(this.handleError); } - public createDefaultReports(): Observable { + createDefaultReports(): Observable { return Observable.fromPromise(this.apiService.getInstance().activiti.reportApi.createDefaultReports()) .map(this.toJson) .catch(this.handleError); } - public updateReport(reportId: number, name: string): Observable { + updateReport(reportId: number, name: string): Observable { return Observable.fromPromise(this.apiService.getInstance().activiti.reportApi.updateReport(reportId, name)) .map((res: any) => { - console.log('upload'); + this.logService.info('upload'); }).catch(this.handleError); } private handleError(error: Response) { - console.error(error); + this.logService.error(error); return Observable.throw(error.json().error || 'Server error'); } diff --git a/ng2-components/ng2-activiti-diagrams/demo/src/main.ts b/ng2-components/ng2-activiti-diagrams/demo/src/main.ts index ec1c076cf7..b51b86ac6b 100644 --- a/ng2-components/ng2-activiti-diagrams/demo/src/main.ts +++ b/ng2-components/ng2-activiti-diagrams/demo/src/main.ts @@ -19,40 +19,39 @@ import { NgModule, Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; import { DiagramsModule } from 'ng2-activiti-diagrams'; @Component({ selector: 'alfresco-app-demo', template: ` -
-
-
-

-
- Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform - operations. -
-
+
+
+
+

+
+ Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform + operations. +
+
-
- - ` +
+ + + ` }) export class DiagramDemoComponent { processDefinitionId: string = 'ThirdProcess:1:15053'; - authenticated: boolean; - host: string = 'http://localhost:9999'; - ticket: string; constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.bpmHost = this.host; settingsService.setProviders('BPM'); @@ -77,12 +76,12 @@ export class DiagramDemoComponent { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(`Logged in with ticket ${ticket}`); this.ticket = this.authService.getTicketBpm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.ts b/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.ts index 4d279e3df5..58a31157d4 100644 --- a/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.ts +++ b/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.ts @@ -16,7 +16,7 @@ */ import { Component, ElementRef, Input, Output, EventEmitter, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { DiagramsService } from '../services/diagrams.service'; import { DiagramColorService } from '../services/diagram-color.service'; import { RaphaelService } from './raphael/raphael.service'; @@ -57,17 +57,16 @@ export class DiagramComponent { PADDING_HEIGHT: number = 60; private diagram: DiagramModel; - private elementRef: ElementRef; - constructor(elementRef: ElementRef, + constructor(private elementRef: ElementRef, private translateService: AlfrescoTranslateService, private diagramColorService: DiagramColorService, private raphaelService: RaphaelService, - private diagramsService: DiagramsService) { + private diagramsService: DiagramsService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-diagrams', 'node_modules/ng2-activiti-diagrams/src'); } - this.elementRef = elementRef; } ngOnChanges(changes: SimpleChanges) { @@ -86,7 +85,7 @@ export class DiagramComponent { }, (err: any) => { this.onError.emit(err); - console.log(err); + this.logService.error(err); } ); } diff --git a/ng2-components/ng2-activiti-diagrams/src/components/raphael/raphael-multiline-text.component.ts b/ng2-components/ng2-activiti-diagrams/src/components/raphael/raphael-multiline-text.component.ts index 0b294970a0..60a1961804 100644 --- a/ng2-components/ng2-activiti-diagrams/src/components/raphael/raphael-multiline-text.component.ts +++ b/ng2-components/ng2-activiti-diagrams/src/components/raphael/raphael-multiline-text.component.ts @@ -16,6 +16,7 @@ */ import { Directive, OnInit, ElementRef, Input, Output, EventEmitter } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { Point } from './models/point'; import { RaphaelBase } from './raphael-base'; import { RaphaelService } from './raphael.service'; @@ -43,19 +44,20 @@ export class RaphaelMultilineTextDirective extends RaphaelBase implements OnInit TEXT_PADDING = 3; constructor(public elementRef: ElementRef, - raphaelService: RaphaelService) { + raphaelService: RaphaelService, + private logService: LogService) { super(elementRef, raphaelService); } ngOnInit() { - console.log(this.elementRef); + this.logService.log(this.elementRef); if (this.text === null || this.text === undefined) { this.text = ''; } this.draw(this.position, this.text); } - public draw(position: Point, text: string) { + draw(position: Point, text: string) { let textPaper = this.paper.text(position.x + this.TEXT_PADDING, position.y + this.TEXT_PADDING, text).attr({ 'text-anchor': 'middle', 'font-family': 'Arial', diff --git a/ng2-components/ng2-activiti-diagrams/src/services/diagrams.service.ts b/ng2-components/ng2-activiti-diagrams/src/services/diagrams.service.ts index 67fbb7f83b..92a663c2ea 100644 --- a/ng2-components/ng2-activiti-diagrams/src/services/diagrams.service.ts +++ b/ng2-components/ng2-activiti-diagrams/src/services/diagrams.service.ts @@ -16,16 +16,17 @@ */ import { Injectable } from '@angular/core'; -import { AuthService, SettingsService } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; import { Response, Http, Headers, RequestOptions } from '@angular/http'; +import { AuthService, SettingsService, LogService } from 'ng2-alfresco-core'; @Injectable() export class DiagramsService { constructor(private authService: AuthService, private http: Http, - private settingsService: SettingsService) { + private settingsService: SettingsService, + private logService: LogService) { } getProcessDefinitionModel(processDefinitionId: string): Observable { @@ -53,7 +54,7 @@ export class DiagramsService { } private handleError(error: Response) { - console.error(error); + this.logService.error(error); return Observable.throw(error.json().error || 'Server error'); } } diff --git a/ng2-components/ng2-activiti-form/demo/src/main.ts b/ng2-components/ng2-activiti-form/demo/src/main.ts index 4c712ac73a..e8d54ab833 100644 --- a/ng2-components/ng2-activiti-form/demo/src/main.ts +++ b/ng2-components/ng2-activiti-form/demo/src/main.ts @@ -18,40 +18,39 @@ import { NgModule, Component, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; import { ActivitiFormModule } from 'ng2-activiti-form'; @Component({ selector: 'alfresco-app-demo', template: ` -
-
-
-

-
- Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform - operations. -
-
+
+
+
+

+
+ Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform + operations. +
+
-
- - ` +
+ + + ` }) export class FormDemoComponent implements OnInit { taskId: number; - authenticated: boolean; - host: string = 'http://localhost:9999'; - ticket: string; constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.bpmHost = this.host; settingsService.setProviders('BPM'); @@ -76,12 +75,12 @@ export class FormDemoComponent implements OnInit { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(`Logged in with ticket ${ticket}`); this.ticket = this.authService.getTicketBpm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts index efe827c78e..a10895e55d 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts @@ -17,6 +17,7 @@ import { Observable } from 'rxjs/Rx'; import { SimpleChange } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { ActivitiForm } from './activiti-form.component'; import { FormModel, FormOutcomeModel, FormFieldModel, FormOutcomeEvent, FormFieldTypes } from './widgets/index'; import { FormService } from './../services/form.service'; @@ -30,6 +31,7 @@ describe('ActivitiForm', () => { let formComponent: ActivitiForm; let visibilityService: WidgetVisibilityService; let nodeService: NodeService; + let logService: LogService; beforeEach(() => { componentHandler = jasmine.createSpyObj('componentHandler', [ @@ -37,11 +39,12 @@ describe('ActivitiForm', () => { ]); window['componentHandler'] = componentHandler; - visibilityService = new WidgetVisibilityService(null); + logService = new LogService(); + visibilityService = new WidgetVisibilityService(null, logService); spyOn(visibilityService, 'refreshVisibility').and.stub(); - formService = new FormService(null, null); + formService = new FormService(null, null, logService); nodeService = new NodeService(null); - formComponent = new ActivitiForm(formService, visibilityService, null, nodeService); + formComponent = new ActivitiForm(formService, visibilityService, null, nodeService, logService); }); it('should upgrade MDL content on view checked', () => { @@ -560,13 +563,6 @@ describe('ActivitiForm', () => { expect(formService.completeTaskForm).not.toHaveBeenCalled(); }); - it('should log error to console by default', () => { - const error = 'Error'; - spyOn(console, 'log').and.stub(); - formComponent.handleError(error); - expect(console.log).toHaveBeenCalledWith(error); - }); - it('should complete form form and raise corresponding event', () => { spyOn(formService, 'completeTaskForm').and.callFake(() => { return Observable.create(observer => { diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts index e515d5f0ac..1e14a6846c 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts @@ -15,14 +15,8 @@ * limitations under the License. */ -import { - Component, - OnInit, AfterViewChecked, OnChanges, - SimpleChanges, - Input, - Output, - EventEmitter -} from '@angular/core'; +import { Component, OnInit, AfterViewChecked, OnChanges, SimpleChanges, Input, Output, EventEmitter } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { EcmModelService } from './../services/ecm-model.service'; import { FormService } from './../services/form.service'; import { NodeService } from './../services/node.service'; @@ -149,9 +143,10 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges { debugMode: boolean = false; constructor(protected formService: FormService, - public visibilityService: WidgetVisibilityService, + protected visibilityService: WidgetVisibilityService, private ecmModelService: EcmModelService, - private nodeService: NodeService) { + private nodeService: NodeService, + private logService: LogService) { } hasForm(): boolean { @@ -357,7 +352,6 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges { id => { this.formService.getFormDefinitionById(id).subscribe( form => { - // console.log('Get Form By Form definition Name', form); this.form = this.parseForm(form); this.formLoaded.emit(this.form); }, @@ -405,7 +399,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges { } handleError(err: any): any { - console.log(err); + this.logService.error(err); this.onError.emit(err); } diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts index c10770e93b..9052c9373c 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts @@ -15,17 +15,8 @@ * limitations under the License. */ -import { - Component, - AfterViewChecked, OnChanges, - SimpleChanges, - Input, - ViewChild, - ElementRef, - Output, - EventEmitter -} from '@angular/core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { Component, AfterViewChecked, OnChanges, SimpleChanges, Input, ViewChild, ElementRef, Output, EventEmitter } from '@angular/core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiForm } from './activiti-form.component'; import { FormService } from './../services/form.service'; import { WidgetVisibilityService } from './../services/widget-visibility.service'; @@ -74,10 +65,11 @@ export class ActivitiStartForm extends ActivitiForm implements AfterViewChecked, @ViewChild('outcomesContainer', {}) outcomesContainer: ElementRef = null; - constructor(private translate: AlfrescoTranslationService, + constructor(private translate: AlfrescoTranslateService, formService: FormService, - visibilityService: WidgetVisibilityService) { - super(formService, visibilityService, null, null); + visibilityService: WidgetVisibilityService, + logService: LogService) { + super(formService, visibilityService, null, null, logService); if (this.translate) { this.translate.addTranslationFolder('ng2-activiti-form', 'node_modules/ng2-activiti-form/src'); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.spec.ts index 95121ed10b..2d767db20b 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.spec.ts @@ -16,6 +16,7 @@ */ import { Observable } from 'rxjs/Rx'; +import { LogServiceMock } from 'ng2-alfresco-core'; import { AttachWidget } from './attach.widget'; import { ActivitiAlfrescoContentService } from '../../../services/activiti-alfresco.service'; import { FormFieldModel } from './../core/form-field.model'; @@ -28,10 +29,12 @@ describe('AttachWidget', () => { let widget: AttachWidget; let contentService: ActivitiAlfrescoContentService; let dialogPolyfill: any; + let logService: LogServiceMock; beforeEach(() => { - contentService = new ActivitiAlfrescoContentService(null); - widget = new AttachWidget(contentService); + logService = new LogServiceMock(); + contentService = new ActivitiAlfrescoContentService(null, logService); + widget = new AttachWidget(contentService, logService); dialogPolyfill = { registerDialog(obj: any) { @@ -268,9 +271,9 @@ describe('AttachWidget', () => { Observable.throw(error) ); - spyOn(console, 'log').and.stub(); + spyOn(logService, 'error').and.stub(); widget.getExternalContentNodes(); - expect(console.log).toHaveBeenCalledWith(error); + expect(logService.error).toHaveBeenCalledWith(error); }); it('should register dialog via polyfill', () => { diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.ts index e4881ac9f9..8b6ae72cc9 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/attach/attach.widget.ts @@ -16,6 +16,7 @@ */ import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { WidgetComponent } from './../widget.component'; import { ActivitiAlfrescoContentService } from '../../../services/activiti-alfresco.service'; import { ExternalContent } from '../core/external-content'; @@ -49,7 +50,8 @@ export class AttachWidget extends WidgetComponent implements OnInit { @ViewChild('dialog') dialog: any; - constructor(private contentService: ActivitiAlfrescoContentService) { + constructor(private contentService: ActivitiAlfrescoContentService, + private logService: LogService) { super(); } @@ -97,7 +99,7 @@ export class AttachWidget extends WidgetComponent implements OnInit { this.contentService.getAlfrescoNodes(this.selectedFolderAccountId, this.selectedFolderPathId) .subscribe( nodes => this.selectedFolderNodes = nodes, - error => this.handleError(error) + error => this.logService.error(error) ); } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts index 6ac0dbe149..17e3b896ef 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts @@ -16,7 +16,7 @@ */ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { CoreModule } from 'ng2-alfresco-core'; +import { CoreModule, LogServiceMock } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; import { DisplayValueWidget } from './display-value.widget'; import { FormService } from '../../../services/form.service'; @@ -32,11 +32,13 @@ describe('DisplayValueWidget', () => { let widget: DisplayValueWidget; let formService: FormService; let visibilityService: WidgetVisibilityService; + let logService: LogServiceMock; beforeEach(() => { - formService = new FormService(null, null); - visibilityService = new WidgetVisibilityService(null); - widget = new DisplayValueWidget(formService, visibilityService); + logService = new LogServiceMock(); + formService = new FormService(null, null, logService); + visibilityService = new WidgetVisibilityService(null, logService); + widget = new DisplayValueWidget(formService, visibilityService, logService); }); it('should require field to setup default value', () => { @@ -390,7 +392,7 @@ describe('DisplayValueWidget', () => { Observable.throw(error) ); - spyOn(console, 'log').and.stub(); + spyOn(logService, 'error').and.stub(); let form = new FormModel({taskId: ''}); @@ -406,7 +408,7 @@ describe('DisplayValueWidget', () => { }); widget.ngOnInit(); expect(formService.getRestFieldValues).toHaveBeenCalled(); - expect(console.log).toHaveBeenCalledWith(error); + expect(logService.error).toHaveBeenCalledWith(error); expect(widget.value).toBe('100'); }); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts index c446f92085..d9e3751c60 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts @@ -17,6 +17,7 @@ import { Component, OnInit } from '@angular/core'; import * as moment from 'moment'; +import { LogService } from 'ng2-alfresco-core'; import { WidgetComponent } from './../widget.component'; import { FormFieldTypes } from '../core/form-field-types'; import { FormService } from '../../../services/form.service'; @@ -49,7 +50,8 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { hasFile: boolean = false; constructor(private formService: FormService, - private visibilityService: WidgetVisibilityService) { + private visibilityService: WidgetVisibilityService, + private logService: LogService) { super(); } @@ -182,7 +184,7 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { this.visibilityService.refreshVisibility(this.field.form); }, error => { - console.log(error); + this.logService.error(error); this.value = this.field.value; } ); @@ -192,21 +194,21 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { this.formService .getRestFieldValues(this.field.form.taskId, this.field.id) .subscribe( - (result: FormFieldOption[]) => { - let options = result || []; - let toSelect = options.find(item => item.id === this.field.value); - this.field.options = options; - if (toSelect) { - this.value = toSelect.name; - } else { + (result: FormFieldOption[]) => { + let options = result || []; + let toSelect = options.find(item => item.id === this.field.value); + this.field.options = options; + if (toSelect) { + this.value = toSelect.name; + } else { + this.value = this.field.value; + } + this.visibilityService.refreshVisibility(this.field.form); + }, + error => { + this.logService.error(error); this.value = this.field.value; } - this.visibilityService.refreshVisibility(this.field.form); - }, - error => { - console.log(error); - this.value = this.field.value; - } ); } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.spec.ts index 1d263dff8e..1930b6abb3 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.spec.ts @@ -15,14 +15,14 @@ * limitations under the License. */ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { Observable } from 'rxjs/Rx'; +import { CoreModule } from 'ng2-alfresco-core'; import { FormService } from '../../../services/form.service'; import { DropdownWidget } from './dropdown.widget'; import { FormModel } from './../core/form.model'; import { FormFieldModel } from './../core/form-field.model'; import { FormFieldOption } from './../core/form-field-option'; -import { CoreModule } from 'ng2-alfresco-core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { EcmModelService } from '../../../services/ecm-model.service'; import { WidgetVisibilityService } from '../../../services/widget-visibility.service'; @@ -33,9 +33,9 @@ describe('DropdownWidget', () => { let visibilityService: WidgetVisibilityService; beforeEach(() => { - formService = new FormService(null, null); - visibilityService = new WidgetVisibilityService(null); - widget = new DropdownWidget(formService, visibilityService); + formService = new FormService(null, null, null); + visibilityService = new WidgetVisibilityService(null, null); + widget = new DropdownWidget(formService, visibilityService, null); widget.field = new FormFieldModel(new FormModel()); }); @@ -74,12 +74,6 @@ describe('DropdownWidget', () => { expect(formService.getRestFieldValues).toHaveBeenCalledWith(taskId, fieldId); }); - it('should log error to console by default', () => { - spyOn(console, 'error').and.stub(); - widget.handleError('Err'); - expect(console.error).toHaveBeenCalledWith('Err'); - }); - it('should preserve empty option when loading fields', () => { let restFieldValue: FormFieldOption = { id: '1', name: 'Option1' }; spyOn(formService, 'getRestFieldValues').and.returnValue( diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.ts index f1c56639d0..a21d86ad1d 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dropdown/dropdown.widget.ts @@ -16,6 +16,7 @@ */ import { Component, OnInit } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { FormService } from '../../../services/form.service'; import { WidgetComponent } from './../widget.component'; import { FormFieldOption } from './../core/form-field-option'; @@ -30,7 +31,8 @@ import { WidgetVisibilityService } from '../../../services/widget-visibility.ser export class DropdownWidget extends WidgetComponent implements OnInit { constructor(private formService: FormService, - private visibilityService: WidgetVisibilityService) { + private visibilityService: WidgetVisibilityService, + private logService: LogService) { super(); } @@ -97,7 +99,7 @@ export class DropdownWidget extends WidgetComponent implements OnInit { } handleError(error: any) { - console.error(error); + this.logService.error(error); } } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.spec.ts index 2c6c33d793..44b9a6f672 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.spec.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { LogServiceMock } from 'ng2-alfresco-core'; import { DynamicTableWidget } from './dynamic-table.widget'; import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model'; import { FormModel, FormFieldTypes } from './../core/index'; @@ -25,11 +26,13 @@ describe('DynamicTableWidget', () => { let widget: DynamicTableWidget; let table: DynamicTableModel; let visibilityService: WidgetVisibilityService; + let logService: LogServiceMock; beforeEach(() => { + logService = new LogServiceMock(); table = new DynamicTableModel(null); - visibilityService = new WidgetVisibilityService(null); - widget = new DynamicTableWidget(null, visibilityService); + visibilityService = new WidgetVisibilityService(null, logService); + widget = new DynamicTableWidget(null, visibilityService, logService); widget.content = table; }); @@ -192,13 +195,13 @@ describe('DynamicTableWidget', () => { }); it('should require table to save changes', () => { - spyOn(console, 'log').and.stub(); + spyOn(logService, 'error').and.stub(); widget.editMode = true; widget.content = null; widget.onSaveChanges(); expect(widget.editMode).toBeFalsy(); - expect(console.log).toHaveBeenCalledWith(widget.ERROR_MODEL_NOT_FOUND); + expect(logService.error).toHaveBeenCalledWith(widget.ERROR_MODEL_NOT_FOUND); }); it('should cancel changes', () => { diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts index 324aa05a96..8abf093760 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts @@ -16,6 +16,7 @@ */ import { Component, ElementRef, OnInit } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { WidgetComponent } from './../widget.component'; import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model'; import { WidgetVisibilityService } from '../../../services/widget-visibility.service'; @@ -36,7 +37,8 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit { editRow: DynamicTableRow = null; constructor(private elementRef: ElementRef, - private visibilityService: WidgetVisibilityService) { + private visibilityService: WidgetVisibilityService, + private logService: LogService) { super(); } @@ -136,7 +138,7 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit { } this.content.flushValue(); } else { - this.handleError(this.ERROR_MODEL_NOT_FOUND); + this.logService.error(this.ERROR_MODEL_NOT_FOUND); } this.editMode = false; } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts index 4db043d2c3..0a355f5a71 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts @@ -39,7 +39,7 @@ describe('DropdownEditorComponent', () => { let row: DynamicTableRow; beforeEach(() => { - formService = new FormService(null, null); + formService = new FormService(null, null, null); row = { value: { dropdown: 'one' } }; column = { @@ -56,7 +56,7 @@ describe('DropdownEditorComponent', () => { table.rows.push(row); table.columns.push(column); - component = new DropdownEditorComponent(formService); + component = new DropdownEditorComponent(formService, null); component.table = table; component.row = row; component.column = column; diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts index 7a3f349686..0bafb62d33 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.ts @@ -16,6 +16,7 @@ */ import { Component, Input, OnInit } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { DynamicTableModel, DynamicTableRow, DynamicTableColumn, DynamicTableColumnOption } from './../../dynamic-table.widget.model'; import { FormService } from './../../../../../services/form.service'; @@ -39,7 +40,9 @@ export class DropdownEditorComponent implements OnInit { @Input() column: DynamicTableColumn; - constructor(private formService: FormService) {} + constructor(private formService: FormService, + private logService: LogService) { + } ngOnInit() { let field = this.table.field; @@ -98,6 +101,6 @@ export class DropdownEditorComponent implements OnInit { } handleError(error: any) { - console.error(error); + this.logService.error(error); } } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.spec.ts index e314372f74..025445ff14 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.spec.ts @@ -36,7 +36,7 @@ describe('FunctionalGroupWidget', () => { ]); window['componentHandler'] = componentHandler; - formService = new FormService(null, null); + formService = new FormService(null, null, null); elementRef = new ElementRef(null); widget = new FunctionalGroupWidget(formService, elementRef); widget.field = new FormFieldModel(new FormModel()); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/people/people.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/people/people.widget.spec.ts index dc6309c157..21d24c5468 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/people/people.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/people/people.widget.spec.ts @@ -36,7 +36,7 @@ describe('PeopleWidget', () => { ]); window['componentHandler'] = componentHandler; - formService = new FormService(null, null); + formService = new FormService(null, null, null); elementRef = new ElementRef(null); widget = new PeopleWidget(formService, elementRef); widget.field = new FormFieldModel(new FormModel()); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.spec.ts index 7c0e1d1e50..d2a8e0927e 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.spec.ts @@ -15,13 +15,14 @@ * limitations under the License. */ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { Observable } from 'rxjs/Rx'; +import { CoreModule, LogServiceMock } from 'ng2-alfresco-core'; + import { FormService } from '../../../services/form.service'; import { RadioButtonsWidget } from './radio-buttons.widget'; import { FormModel } from './../core/form.model'; import { FormFieldModel } from './../core/form-field.model'; -import { CoreModule } from 'ng2-alfresco-core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { EcmModelService } from '../../../services/ecm-model.service'; import { WidgetVisibilityService } from '../../../services/widget-visibility.service'; import { FormFieldTypes } from '../core/form-field-types'; @@ -33,11 +34,13 @@ describe('RadioButtonsWidget', () => { let formService: FormService; let widget: RadioButtonsWidget; let visibilityService: WidgetVisibilityService; + let logService: LogServiceMock; beforeEach(() => { - formService = new FormService(null, null); - visibilityService = new WidgetVisibilityService(null); - widget = new RadioButtonsWidget(formService, visibilityService); + logService = new LogServiceMock(); + formService = new FormService(null, null, logService); + visibilityService = new WidgetVisibilityService(null, logService); + widget = new RadioButtonsWidget(formService, visibilityService, logService); widget.field = new FormFieldModel(new FormModel(), { restUrl: '' }); }); @@ -118,9 +121,9 @@ describe('RadioButtonsWidget', () => { }); it('should log error to console by default', () => { - spyOn(console, 'error').and.stub(); + spyOn(logService, 'error').and.stub(); widget.handleError('Err'); - expect(console.error).toHaveBeenCalledWith('Err'); + expect(logService.error).toHaveBeenCalledWith('Err'); }); xit('should update the field value when an option is selected', () => { diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.ts index 1018bbb925..f92316c546 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/radio-buttons/radio-buttons.widget.ts @@ -16,6 +16,7 @@ */ import { Component, OnInit } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { WidgetComponent } from './../widget.component'; import { FormService } from '../../../services/form.service'; import { FormFieldOption } from './../core/form-field-option'; @@ -30,7 +31,8 @@ import { WidgetVisibilityService } from '../../../services/widget-visibility.ser export class RadioButtonsWidget extends WidgetComponent implements OnInit { constructor(private formService: FormService, - private visibilityService: WidgetVisibilityService) { + private visibilityService: WidgetVisibilityService, + private logService: LogService) { super(); } @@ -84,7 +86,7 @@ export class RadioButtonsWidget extends WidgetComponent implements OnInit { } handleError(error: any) { - console.error(error); + this.logService.error(error); } } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts index b79759c6ba..70ef25000a 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.spec.ts @@ -15,14 +15,15 @@ * limitations under the License. */ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { Observable } from 'rxjs/Rx'; +import { CoreModule, LogServiceMock } from 'ng2-alfresco-core'; + import { TypeaheadWidget } from './typeahead.widget'; import { FormService } from '../../../services/form.service'; import { FormModel } from '../core/form.model'; import { FormFieldModel } from '../core/form-field.model'; import { FormFieldOption } from '../core/form-field-option'; -import { CoreModule } from 'ng2-alfresco-core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { EcmModelService } from '../../../services/ecm-model.service'; import { WidgetVisibilityService } from '../../../services/widget-visibility.service'; import { FormFieldTypes } from '../core/form-field-types'; @@ -32,11 +33,13 @@ describe('TypeaheadWidget', () => { let formService: FormService; let widget: TypeaheadWidget; let visibilityService: WidgetVisibilityService; + let logService: LogServiceMock; beforeEach(() => { - formService = new FormService(null, null); - visibilityService = new WidgetVisibilityService(null); - widget = new TypeaheadWidget(formService, visibilityService); + logService = new LogServiceMock(); + formService = new FormService(null, null, logService); + visibilityService = new WidgetVisibilityService(null, logService); + widget = new TypeaheadWidget(formService, visibilityService, logService); widget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' })); }); @@ -73,7 +76,7 @@ describe('TypeaheadWidget', () => { }); const err = 'Error'; spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.throw(err)); - spyOn(widget, 'handleError').and.callThrough(); + spyOn(widget, 'handleError').and.stub(); widget.ngOnInit(); @@ -94,7 +97,7 @@ describe('TypeaheadWidget', () => { }); const err = 'Error'; spyOn(formService, 'getRestFieldValuesByProcessId').and.returnValue(Observable.throw(err)); - spyOn(widget, 'handleError').and.callThrough(); + spyOn(widget, 'handleError').and.stub(); widget.ngOnInit(); @@ -102,12 +105,6 @@ describe('TypeaheadWidget', () => { expect(widget.handleError).toHaveBeenCalledWith(err); }); - it('should log error to console by default', () => { - spyOn(console, 'error').and.stub(); - widget.handleError('Err'); - expect(console.error).toHaveBeenCalledWith('Err'); - }); - it('should show popup on key up', () => { spyOn(widget, 'getOptions').and.returnValue([{}, {}]); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts index 6dd4a18a36..253c9cd08a 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts @@ -16,6 +16,7 @@ */ import { Component, OnInit } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { FormService } from './../../../services/form.service'; import { WidgetComponent } from './../widget.component'; import { FormFieldOption } from './../core/form-field-option'; @@ -35,7 +36,8 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit { options: FormFieldOption[] = []; constructor(private formService: FormService, - private visibilityService: WidgetVisibilityService) { + private visibilityService: WidgetVisibilityService, + private logService: LogService) { super(); } @@ -153,7 +155,7 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit { } handleError(error: any) { - console.error(error); + this.logService.error(error); } checkVisibility() { diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.spec.ts index 5a2bc669df..9e1fd1ec8b 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.spec.ts @@ -26,8 +26,8 @@ describe('UploadWidget', () => { let formService: FormService; beforeEach(() => { - formService = new FormService(null, null); - widget = new UploadWidget(formService); + formService = new FormService(null, null, null); + widget = new UploadWidget(formService, null); }); it('should setup with field data', () => { diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.ts index f9814ba388..2314853757 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/upload/upload.widget.ts @@ -16,6 +16,7 @@ */ import { Component, OnInit } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { WidgetComponent } from './../widget.component'; import { FormService } from '../../../services/form.service'; @@ -31,7 +32,8 @@ export class UploadWidget extends WidgetComponent implements OnInit { fileName: string; displayText: string; - constructor(private formService: FormService) { + constructor(private formService: FormService, + private logService: LogService) { super(); } @@ -60,16 +62,14 @@ export class UploadWidget extends WidgetComponent implements OnInit { onFileChanged(event: any) { let files = event.target.files; if (files && files.length > 0) { - let file = files[0]; - this.formService.createTemporaryRawRelatedContent(file) .subscribe((response: any) => { - console.log(response); + this.logService.info(response); this.field.value = [response]; this.field.json.value = [response]; }, (error: any) => { - console.error(error); + this.logService.error(error); window.alert('Error uploading file. See console output for more details.'); }); } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts b/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts index 6112834853..490f764680 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts @@ -111,11 +111,4 @@ export class WidgetComponent implements AfterViewInit { } return null; } - - protected handleError(error: any) { - if (error) { - console.log(error); - } - } - } diff --git a/ng2-components/ng2-activiti-form/src/services/activiti-alfresco.service.ts b/ng2-components/ng2-activiti-form/src/services/activiti-alfresco.service.ts index 474745ee33..e9a02d7fa6 100644 --- a/ng2-components/ng2-activiti-form/src/services/activiti-alfresco.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/activiti-alfresco.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { ExternalContent } from '../components/widgets/core/external-content'; import { ExternalContentLink } from '../components/widgets/core/external-content-link'; import { AlfrescoApi } from 'alfresco-js-api'; @@ -28,7 +28,8 @@ export class ActivitiAlfrescoContentService { static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error'; static GENERIC_ERROR_MESSAGE: string = 'Server error'; - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } /** @@ -85,7 +86,7 @@ export class ActivitiAlfrescoContentService { errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : ActivitiAlfrescoContentService.GENERIC_ERROR_MESSAGE; } - console.error(errMsg); + this.logService.error(errMsg); return Observable.throw(errMsg); } } diff --git a/ng2-components/ng2-activiti-form/src/services/ecm-model.service.ts b/ng2-components/ng2-activiti-form/src/services/ecm-model.service.ts index 6fa60acc14..0b15c99a61 100644 --- a/ng2-components/ng2-activiti-form/src/services/ecm-model.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/ecm-model.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { FormModel } from '../components/widgets/core/form.model'; @Injectable() @@ -27,7 +27,8 @@ export class EcmModelService { public static MODEL_NAME: string = 'activitiFormsModel'; public static TYPE_MODEL: string = 'cm:folder'; - constructor(public apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } public createEcmTypeForActivitiForm(formName: string, form: FormModel): Observable { @@ -62,10 +63,10 @@ export class EcmModelService { return Observable.create(observer => { this.createEcmModel(EcmModelService.MODEL_NAME, EcmModelService.MODEL_NAMESPACE).subscribe( model => { - console.log('model created', model); + this.logService.info('model created', model); this.activeEcmModel(EcmModelService.MODEL_NAME).subscribe( modelActive => { - console.log('model active', modelActive); + this.logService.info('model active', modelActive); this.createEcmTypeWithProperties(formName, form).subscribe(typeCreated => { observer.next(typeCreated); observer.complete(); @@ -83,7 +84,7 @@ export class EcmModelService { return Observable.create(observer => { this.searchEcmType(formName, EcmModelService.MODEL_NAME).subscribe( ecmType => { - console.log('custom types', ecmType); + this.logService.info('custom types', ecmType); if (!ecmType) { this.createEcmTypeWithProperties(formName, form).subscribe(typeCreated => { observer.next(typeCreated); @@ -103,10 +104,10 @@ export class EcmModelService { return Observable.create(observer => { this.createEcmType(formName, EcmModelService.MODEL_NAME, EcmModelService.TYPE_MODEL).subscribe( typeCreated => { - console.log('type Created', typeCreated); + this.logService.info('type Created', typeCreated); this.addPropertyToAType(EcmModelService.MODEL_NAME, formName, form).subscribe( properyAdded => { - console.log('property Added', properyAdded); + this.logService.info('property Added', properyAdded); observer.next(typeCreated); observer.complete(); }, @@ -196,6 +197,6 @@ export class EcmModelService { } handleError(err: any): any { - console.log(err); + this.logService.error(err); } } 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 158390154a..28339b0ded 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 { TestBed } from '@angular/core/testing'; -import { CoreModule, AlfrescoApiService } from 'ng2-alfresco-core'; +import { CoreModule, AlfrescoApiService, LogService, LogServiceMock } from 'ng2-alfresco-core'; import { FormService } from './form.service'; import { EcmModelService } from './ecm-model.service'; import { FormDefinitionModel } from '../models/form-definition.model'; @@ -29,6 +29,7 @@ describe('FormService', () => { let responseBody: any; let service: FormService; let apiService: AlfrescoApiService; + let logService: LogService; beforeEach(() => { TestBed.configureTestingModule({ @@ -37,11 +38,13 @@ describe('FormService', () => { ], providers: [ EcmModelService, - FormService + FormService, + { provide: LogService, useClass: LogServiceMock } ] }); service = TestBed.get(FormService); apiService = TestBed.get(AlfrescoApiService); + logService = TestBed.get(LogService); }); beforeEach(() => { @@ -270,34 +273,34 @@ describe('FormService', () => { }); it('should handle error with generic message', () => { - spyOn(console, 'error').and.stub(); + spyOn(logService, 'error').and.stub(); service.handleError(null); - expect(console.error).toHaveBeenCalledWith(FormService.UNKNOWN_ERROR_MESSAGE); + expect(logService.error).toHaveBeenCalledWith(FormService.UNKNOWN_ERROR_MESSAGE); }); it('should handle error with error message', () => { - spyOn(console, 'error').and.stub(); + spyOn(logService, 'error').and.stub(); const message = ''; service.handleError({message: message}); - expect(console.error).toHaveBeenCalledWith(message); + expect(logService.error).toHaveBeenCalledWith(message); }); it('should handle error with detailed message', () => { - spyOn(console, 'error').and.stub(); + spyOn(logService, 'error').and.stub(); service.handleError({ status: '400', statusText: 'Bad request' }); - expect(console.error).toHaveBeenCalledWith('400 - Bad request'); + expect(logService.error).toHaveBeenCalledWith('400 - Bad request'); }); it('should handle error with generic message', () => { - spyOn(console, 'error').and.stub(); + spyOn(logService, 'error').and.stub(); service.handleError({}); - expect(console.error).toHaveBeenCalledWith(FormService.GENERIC_ERROR_MESSAGE); + expect(logService.error).toHaveBeenCalledWith(FormService.GENERIC_ERROR_MESSAGE); }); it('should get all the forms with modelType=2', (done) => { diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.ts b/ng2-components/ng2-activiti-form/src/services/form.service.ts index bcb2ae22f2..3e76e9a13c 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { FormValues } from './../components/widgets/core/index'; import { FormDefinitionModel } from '../models/form-definition.model'; import { EcmModelService } from './ecm-model.service'; @@ -31,7 +31,8 @@ export class FormService { static GENERIC_ERROR_MESSAGE: string = 'Server error'; constructor(private ecmModelService: EcmModelService, - private apiService: AlfrescoApiService) { + private apiService: AlfrescoApiService, + private logService: LogService) { } /** @@ -271,11 +272,10 @@ export class FormService { if (xhr.status === 200) { let json = JSON.parse(xhr.response); let data: GroupModel[] = (json.data || []).map(item => item); - // console.log(json); observer.next(data); observer.complete(); } else { - console.error(xhr.response); + this.logService.error(xhr.response); Observable.throw(new Error(xhr.response)); } } @@ -303,11 +303,10 @@ export class FormService { if (xhr.status === 200) { let json = JSON.parse(xhr.response); let data: GroupUserModel[] = (json.data || []).map(item => item); - // console.log(json); observer.next(data); observer.complete(); } else { - console.error(xhr.response); + this.logService.error(xhr.response); Observable.throw(new Error(xhr.response)); } } @@ -354,7 +353,7 @@ export class FormService { errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : FormService.GENERIC_ERROR_MESSAGE; } - console.error(errMsg); + this.logService.error(errMsg); return Observable.throw(errMsg); } } diff --git a/ng2-components/ng2-activiti-form/src/services/widget-visibility.service.ts b/ng2-components/ng2-activiti-form/src/services/widget-visibility.service.ts index df269ba529..a9056c2c37 100644 --- a/ng2-components/ng2-activiti-form/src/services/widget-visibility.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/widget-visibility.service.ts @@ -17,24 +17,19 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; -import { - FormModel, - FormFieldModel, - TabModel, - ContainerModel, - ContainerColumnModel -} from '../components/widgets/core/index'; +import * as moment from 'moment'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; +import { FormModel, FormFieldModel, TabModel, ContainerModel, ContainerColumnModel } from '../components/widgets/core/index'; import { WidgetVisibilityModel } from '../models/widget-visibility.model'; import { TaskProcessVariableModel } from '../models/task-process-variable.model'; -import * as moment from 'moment'; @Injectable() export class WidgetVisibilityService { private processVarList: TaskProcessVariableModel[]; - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } public refreshVisibility(form: FormModel) { @@ -201,7 +196,7 @@ export class WidgetVisibilityService { case 'or-not': return previousValue || !newValue; default: - console.error('NO valid operation! wrong op request : ' + logicOp); + this.logService.error('NO valid operation! wrong op request : ' + logicOp); break; } } @@ -225,7 +220,7 @@ export class WidgetVisibilityService { case '!empty': return leftValue ? leftValue !== '' : false; default: - console.error('NO valid operation!'); + this.logService.error('NO valid operation!'); break; } return; @@ -250,7 +245,7 @@ export class WidgetVisibilityService { } private handleError() { - console.error('Error while performing a call'); + this.logService.error('Error while performing a call'); return Observable.throw('Error while performing a call - Server error'); } } diff --git a/ng2-components/ng2-activiti-processlist/demo/src/main.ts b/ng2-components/ng2-activiti-processlist/demo/src/main.ts index ae79dd1b32..a732101e37 100644 --- a/ng2-components/ng2-activiti-processlist/demo/src/main.ts +++ b/ng2-components/ng2-activiti-processlist/demo/src/main.ts @@ -1,274 +1,275 @@ -/*! - * @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 { DebugElement, Input, NgModule, Component, OnInit, ViewChild } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { AppDefinitionRepresentationModel, ActivitiTaskListModule } from 'ng2-activiti-tasklist'; -import { CoreModule } from 'ng2-alfresco-core'; -import { - ActivitiProcessListModule, - ActivitiProcessFilters, - ActivitiProcessInstanceDetails, - ActivitiProcessInstanceListComponent, - ActivitiStartProcessInstance, - ProcessInstance -} from 'ng2-activiti-processlist'; +/*! + * @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 { DebugElement, Input, NgModule, Component, OnInit, ViewChild } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { AppDefinitionRepresentationModel, ActivitiTaskListModule } from 'ng2-activiti-tasklist'; +import { CoreModule, LogService } from 'ng2-alfresco-core'; +import { + ActivitiProcessListModule, + ActivitiProcessFilters, + ActivitiProcessInstanceDetails, + ActivitiProcessInstanceListComponent, + ActivitiStartProcessInstance, + ProcessInstance +} from 'ng2-activiti-processlist'; import { AuthService, SettingsService, StorageService } from 'ng2-alfresco-core'; -import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; - -const currentProcessIdNew = '__NEW__'; - -@Component({ - selector: 'alfresco-app-demo', - template: ` -
-
-
-

-
- Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform - operations. -
-
- -
- -
- - - - -
- -
- - - -
-
- -
-
- - - -
-
-
-
-

Process Filters

- - -
-
-

Process List

- -
-
-

Process Details

- -

Process Variables

- -
-
-

Start Process

- -
-
-
-
- -
-
-`, - styles: [` - header { - min-height: 48px; - } - h2 { - font-size: 14px; - line-height: 20px; - margin: 10px 0; - } - `] -}) -class MyDemoApp implements OnInit { - - authenticated: boolean; - - host: string = 'http://localhost:9999'; - - ticket: string; - - @ViewChild('tabmain') - tabMain: DebugElement; - - @ViewChild('tabheader') - tabHeader: DebugElement; - - @ViewChild(ActivitiProcessFilters) - activitiprocessfilter: ActivitiProcessFilters; - - @ViewChild(ActivitiProcessInstanceListComponent) - activitiprocesslist: ActivitiProcessInstanceListComponent; - - @ViewChild(ActivitiProcessInstanceDetails) - activitiprocessdetails: ActivitiProcessInstanceDetails; - - @ViewChild(ActivitiStartProcessInstance) - activitiStartProcess: ActivitiStartProcessInstance; - - @Input() - appId: number; - - processFilter: any; - - currentProcessInstanceId: string; - - dataProcesses: ObjectDataTableAdapter; - +import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; + +const currentProcessIdNew = '__NEW__'; + +@Component({ + selector: 'alfresco-app-demo', + template: ` +
+
+
+

+
+ Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid ticket to perform + operations. +
+
+ +
+ +
+ + + + +
+ +
+ + + +
+
+ +
+
+ + + +
+
+
+
+

Process Filters

+ + +
+
+

Process List

+ +
+
+

Process Details

+ +

Process Variables

+ +
+
+

Start Process

+ +
+
+
+
+ +
+
+`, + styles: [` + header { + min-height: 48px; + } + h2 { + font-size: 14px; + line-height: 20px; + margin: 10px 0; + } + `] +}) +class MyDemoApp implements OnInit { + + authenticated: boolean; + + host: string = 'http://localhost:9999'; + + ticket: string; + + @ViewChild('tabmain') + tabMain: DebugElement; + + @ViewChild('tabheader') + tabHeader: DebugElement; + + @ViewChild(ActivitiProcessFilters) + activitiprocessfilter: ActivitiProcessFilters; + + @ViewChild(ActivitiProcessInstanceListComponent) + activitiprocesslist: ActivitiProcessInstanceListComponent; + + @ViewChild(ActivitiProcessInstanceDetails) + activitiprocessdetails: ActivitiProcessInstanceDetails; + + @ViewChild(ActivitiStartProcessInstance) + activitiStartProcess: ActivitiStartProcessInstance; + + @Input() + appId: number; + + processFilter: any; + + currentProcessInstanceId: string; + + dataProcesses: ObjectDataTableAdapter; + constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { - settingsService.bpmHost = this.host; - settingsService.setProviders('BPM'); - - if (this.authService.getTicketBpm()) { - this.ticket = this.authService.getTicketBpm(); - } - - this.dataProcesses = new ObjectDataTableAdapter( - [], - [ - {type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true}, - {type: 'text', key: 'started', title: 'Started', sortable: true, cssClass: 'hidden'} - ] - ); - } - - public updateTicket(): void { - this.storage.setItem('ticket-BPM', this.ticket); - } - - public updateHost(): void { - this.settingsService.bpmHost = this.host; - this.login(); - } - - public ngOnInit(): void { - this.login(); - } - - login() { - this.authService.login('admin', 'admin').subscribe( - ticket => { - console.log(ticket); - this.ticket = this.authService.getTicketBpm(); - this.authenticated = true; - }, - error => { - console.log(error); - this.authenticated = false; - }); - } - - onAppClick(app: AppDefinitionRepresentationModel) { - this.appId = app.id; - - this.processFilter = null; - this.currentProcessInstanceId = null; - - this.changeTab('apps', 'processes'); - } - - navigateStartProcess() { - this.currentProcessInstanceId = currentProcessIdNew; - } - - onStartProcessInstance(instance: ProcessInstance) { - this.currentProcessInstanceId = instance.id; - this.activitiStartProcess.reset(); - } - - isStartProcessMode() { - return this.currentProcessInstanceId === currentProcessIdNew; - } - - onProcessFilterClick(event: any) { - this.processFilter = event; - } - - onSuccessProcessFilterList(event: any) { - this.processFilter = this.activitiprocessfilter.getCurrentFilter(); - } - - onSuccessProcessList(event: any) { - this.currentProcessInstanceId = this.activitiprocesslist.getCurrentId(); - } - - onProcessRowClick(processInstanceId) { - this.currentProcessInstanceId = processInstanceId; - } - - processCancelled(data: any) { - this.currentProcessInstanceId = null; - this.activitiprocesslist.reload(); - } - - changeTab(origin: string, destination: string) { - this.tabMain.nativeElement.children[origin].classList.remove('is-active'); - this.tabMain.nativeElement.children[destination].classList.add('is-active'); - - this.tabHeader.nativeElement.children[`${origin}-header`].classList.remove('is-active'); - this.tabHeader.nativeElement.children[`${destination}-header`].classList.add('is-active'); - } - -} - -@NgModule({ - imports: [ - BrowserModule, - CoreModule.forRoot(), - ActivitiProcessListModule, - ActivitiTaskListModule.forRoot() - ], - declarations: [MyDemoApp], - bootstrap: [MyDemoApp] -}) -export class AppModule { -} - -platformBrowserDynamic().bootstrapModule(AppModule); + private storage: StorageService, + private logService: LogService) { + settingsService.bpmHost = this.host; + settingsService.setProviders('BPM'); + + if (this.authService.getTicketBpm()) { + this.ticket = this.authService.getTicketBpm(); + } + + this.dataProcesses = new ObjectDataTableAdapter( + [], + [ + {type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true}, + {type: 'text', key: 'started', title: 'Started', sortable: true, cssClass: 'hidden'} + ] + ); + } + + public updateTicket(): void { + this.storage.setItem('ticket-BPM', this.ticket); + } + + public updateHost(): void { + this.settingsService.bpmHost = this.host; + this.login(); + } + + public ngOnInit(): void { + this.login(); + } + + login() { + this.authService.login('admin', 'admin').subscribe( + ticket => { + this.logService.log(ticket); + this.ticket = this.authService.getTicketBpm(); + this.authenticated = true; + }, + error => { + this.logService.error(error); + this.authenticated = false; + }); + } + + onAppClick(app: AppDefinitionRepresentationModel) { + this.appId = app.id; + + this.processFilter = null; + this.currentProcessInstanceId = null; + + this.changeTab('apps', 'processes'); + } + + navigateStartProcess() { + this.currentProcessInstanceId = currentProcessIdNew; + } + + onStartProcessInstance(instance: ProcessInstance) { + this.currentProcessInstanceId = instance.id; + this.activitiStartProcess.reset(); + } + + isStartProcessMode() { + return this.currentProcessInstanceId === currentProcessIdNew; + } + + onProcessFilterClick(event: any) { + this.processFilter = event; + } + + onSuccessProcessFilterList(event: any) { + this.processFilter = this.activitiprocessfilter.getCurrentFilter(); + } + + onSuccessProcessList(event: any) { + this.currentProcessInstanceId = this.activitiprocesslist.getCurrentId(); + } + + onProcessRowClick(processInstanceId) { + this.currentProcessInstanceId = processInstanceId; + } + + processCancelled(data: any) { + this.currentProcessInstanceId = null; + this.activitiprocesslist.reload(); + } + + changeTab(origin: string, destination: string) { + this.tabMain.nativeElement.children[origin].classList.remove('is-active'); + this.tabMain.nativeElement.children[destination].classList.add('is-active'); + + this.tabHeader.nativeElement.children[`${origin}-header`].classList.remove('is-active'); + this.tabHeader.nativeElement.children[`${destination}-header`].classList.add('is-active'); + } + +} + +@NgModule({ + imports: [ + BrowserModule, + CoreModule.forRoot(), + ActivitiProcessListModule, + ActivitiTaskListModule.forRoot() + ], + declarations: [MyDemoApp], + bootstrap: [MyDemoApp] +}) +export class AppModule { +} + +platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.spec.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.spec.ts index fcc540f7e1..7256125d91 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.spec.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.spec.ts @@ -44,7 +44,7 @@ describe('ActivitiFilters', () => { beforeEach(() => { activitiService = new ActivitiProcessService(null); - filterList = new ActivitiProcessFilters(null, activitiService); + filterList = new ActivitiProcessFilters(null, activitiService, null); }); it('should return the filter task list', (done) => { diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.ts index a6a800cdb1..d363543e21 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-filters.component.ts @@ -16,10 +16,10 @@ */ import { Component, Output, EventEmitter, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; -import { ActivitiProcessService } from './../services/activiti-process.service'; -import { FilterRepresentationModel } from 'ng2-activiti-tasklist'; import { Observable, Observer } from 'rxjs/Rx'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; +import { FilterRepresentationModel } from 'ng2-activiti-tasklist'; +import { ActivitiProcessService } from './../services/activiti-process.service'; declare let componentHandler: any; @@ -53,8 +53,9 @@ export class ActivitiProcessFilters implements OnInit, OnChanges { filters: FilterRepresentationModel [] = []; - constructor(private translate: AlfrescoTranslationService, - private activiti: ActivitiProcessService) { + constructor(private translate: AlfrescoTranslateService, + private activiti: ActivitiProcessService, + private logService: LogService) { this.filter$ = new Observable(observer => this.filterObserver = observer).share(); if (translate) { @@ -111,7 +112,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges { this.onSuccess.emit(res); }, (err) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); } ); @@ -128,7 +129,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges { this.selectFirstFilter(); }, (err) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); }); } diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.spec.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.spec.ts index d157294d7f..2cb2a9399f 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.spec.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.spec.ts @@ -20,7 +20,7 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, CoreModule } from 'ng2-alfresco-core'; import { ActivitiFormModule, FormModel, FormService } from 'ng2-activiti-form'; import { ActivitiTaskListModule } from 'ng2-activiti-tasklist'; @@ -50,7 +50,7 @@ describe('ActivitiProcessInstanceDetails', () => { ActivitiProcessInstanceDetails ], providers: [ - { provide: AlfrescoTranslationService, useClass: TranslationMock }, + { provide: AlfrescoTranslateService, useClass: TranslationMock }, ActivitiProcessService ], schemas: [ NO_ERRORS_SCHEMA ] diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.ts index 26efb73e4f..6409ee478e 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-details.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, ViewChild, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiProcessService } from './../services/activiti-process.service'; import { ActivitiProcessInstanceHeader } from './activiti-process-instance-header.component'; import { ActivitiProcessInstanceTasks } from './activiti-process-instance-tasks.component'; @@ -60,8 +60,9 @@ export class ActivitiProcessInstanceDetails implements OnChanges { * @param translate Translation service * @param activitiProcess Process service */ - constructor(private translate: AlfrescoTranslationService, - private activitiProcess: ActivitiProcessService) { + constructor(private translate: AlfrescoTranslateService, + private activitiProcess: ActivitiProcessService, + private logService: LogService) { if (translate) { translate.addTranslationFolder('ng2-activiti-processlist', 'node_modules/ng2-activiti-processlist/src'); @@ -110,7 +111,7 @@ export class ActivitiProcessInstanceDetails implements OnChanges { (data) => { this.processCancelled.emit(data); }, (err) => { - console.error(err); + this.logService.error(err); }); } } diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-header.component.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-header.component.ts index 82e430a866..101099b02c 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-header.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-header.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, Output, EventEmitter } from '@angular/core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ProcessInstance } from '../models/process-instance.model'; import { DatePipe } from '@angular/common'; @@ -36,7 +36,8 @@ export class ActivitiProcessInstanceHeader { @Output() onError: EventEmitter = new EventEmitter(); - constructor(private translate: AlfrescoTranslationService) { + constructor(private translate: AlfrescoTranslateService, + private logService: LogService) { if (translate) { translate.addTranslationFolder('ng2-activiti-processlist', 'node_modules/ng2-activiti-processlist/src'); @@ -57,7 +58,7 @@ export class ActivitiProcessInstanceHeader { try { return datePipe.transform(value, format); } catch (err) { - console.error(`ProcessListInstanceHeader: error parsing date ${value} to format ${format}`); + this.logService.error(`ProcessListInstanceHeader: error parsing date ${value} to format ${format}`); } } diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-tasks.component.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-tasks.component.ts index e7848282c6..93154c4f33 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-tasks.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-process-instance-tasks.component.ts @@ -16,11 +16,11 @@ */ import { Component, Input, OnInit, ViewChild, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { DatePipe } from '@angular/common'; +import { Observable, Observer } from 'rxjs/Rx'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiProcessService } from './../services/activiti-process.service'; import { TaskDetailsModel } from 'ng2-activiti-tasklist'; -import { Observable, Observer } from 'rxjs/Rx'; -import { DatePipe } from '@angular/common'; import { ProcessInstance } from '../models/process-instance.model'; declare let componentHandler: any; @@ -67,8 +67,9 @@ export class ActivitiProcessInstanceTasks implements OnInit, OnChanges { @ViewChild('taskdetails') taskdetails: any; - constructor(private translate: AlfrescoTranslationService, - private activitiProcess: ActivitiProcessService) { + constructor(private translate: AlfrescoTranslateService, + private activitiProcess: ActivitiProcessService, + private logService: LogService) { if (translate) { translate.addTranslationFolder('ng2-activiti-processlist', 'node_modules/ng2-activiti-processlist/src'); } @@ -108,7 +109,7 @@ export class ActivitiProcessInstanceTasks implements OnInit, OnChanges { }); }, (err) => { - console.log(err); + this.logService.error(err); } ); } else { @@ -126,7 +127,7 @@ export class ActivitiProcessInstanceTasks implements OnInit, OnChanges { }); }, (err) => { - console.log(err); + this.logService.error(err); } ); } else { @@ -152,7 +153,7 @@ export class ActivitiProcessInstanceTasks implements OnInit, OnChanges { try { return datePipe.transform(value, format); } catch (err) { - console.error(`ProcessListInstanceTask: error parsing date ${value} to format ${format}`); + this.logService.error(`ProcessListInstanceTask: error parsing date ${value} to format ${format}`); } } diff --git a/ng2-components/ng2-activiti-tasklist/demo/src/main.ts b/ng2-components/ng2-activiti-tasklist/demo/src/main.ts index 7895c4bf11..087074e13b 100644 --- a/ng2-components/ng2-activiti-tasklist/demo/src/main.ts +++ b/ng2-components/ng2-activiti-tasklist/demo/src/main.ts @@ -25,7 +25,7 @@ import { ActivitiApps, ActivitiTaskList } from 'ng2-activiti-tasklist'; -import { CoreModule } from 'ng2-alfresco-core'; +import { CoreModule, LogService } from 'ng2-alfresco-core'; import { AuthService, SettingsService, StorageService } from 'ng2-alfresco-core'; import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; @@ -146,7 +146,8 @@ class MyDemoApp implements OnInit { constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.bpmHost = this.host; settingsService.setProviders('BPM'); @@ -179,12 +180,12 @@ class MyDemoApp implements OnInit { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(ticket); this.ticket = this.authService.getTicketBpm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts index 202c3e0055..c2fbc8b171 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts @@ -16,10 +16,10 @@ */ import { Component, Input, OnInit, ViewChild, OnChanges, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { Observer, Observable } from 'rxjs/Rx'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { TaskDetailsModel } from '../models/task-details.model'; -import { Observer, Observable } from 'rxjs/Rx'; declare let dialogPolyfill: any; @@ -54,7 +54,8 @@ export class ActivitiChecklist implements OnInit, OnChanges { * @param translate */ constructor(private translateService: AlfrescoTranslateService, - private activitiTaskList: ActivitiTaskListService) { + private activitiTaskList: ActivitiTaskListService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-tasklist', 'node_modules/ng2-activiti-tasklist/src'); @@ -86,7 +87,7 @@ export class ActivitiChecklist implements OnInit, OnChanges { }); }, (err) => { - console.log(err); + this.logService.error(err); } ); } else { @@ -110,7 +111,7 @@ export class ActivitiChecklist implements OnInit, OnChanges { this.checklist.push(res); }, (err) => { - console.log(err); + this.logService.error(err); } ); diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts index 2440aaaa64..11209e841e 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts @@ -24,6 +24,7 @@ import { FilterRepresentationModel } from '../models/filter.model'; describe('ActivitiFilters', () => { let filterList: ActivitiFilters; + let activitiService: ActivitiTaskListService; let fakeGlobalFilter = []; fakeGlobalFilter.push(new FilterRepresentationModel({name: 'FakeInvolvedTasks', filter: { state: 'open', assignment: 'fake-involved'}})); @@ -42,12 +43,12 @@ describe('ActivitiFilters', () => { }); beforeEach(() => { - let activitiService = new ActivitiTaskListService(null); - filterList = new ActivitiFilters(null, activitiService); + activitiService = new ActivitiTaskListService(null, null); + filterList = new ActivitiFilters(null, activitiService, null); }); it('should return the filter task list', (done) => { - spyOn(filterList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise)); + spyOn(activitiService, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise)); const appId = '1'; let change = new SimpleChange(null, appId); filterList.ngOnChanges({ 'appId': change }); @@ -70,14 +71,14 @@ describe('ActivitiFilters', () => { resolve({}); }); - spyOn(filterList.activiti, 'getDeployedApplications').and.returnValue(Observable.fromPromise(fakeDeployedApplicationsPromise)); - spyOn(filterList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise)); + spyOn(activitiService, 'getDeployedApplications').and.returnValue(Observable.fromPromise(fakeDeployedApplicationsPromise)); + spyOn(activitiService, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise)); let change = new SimpleChange(null, 'test'); filterList.ngOnChanges({ 'appName': change }); filterList.onSuccess.subscribe((res) => { - let deployApp: any = filterList.activiti.getDeployedApplications; + let deployApp: any = activitiService.getDeployedApplications; expect(deployApp.calls.count()).toEqual(1); expect(res).toBeDefined(); done(); @@ -87,7 +88,7 @@ describe('ActivitiFilters', () => { }); it('should emit an error with a bad response', (done) => { - spyOn(filterList.activiti, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeErrorFilterPromise)); + spyOn(activitiService, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeErrorFilterPromise)); const appId = '1'; let change = new SimpleChange(null, appId); @@ -102,7 +103,7 @@ describe('ActivitiFilters', () => { }); it('should emit an error with a bad response', (done) => { - spyOn(filterList.activiti, 'getDeployedApplications').and.returnValue(Observable.fromPromise(fakeErrorFilterPromise)); + spyOn(activitiService, 'getDeployedApplications').and.returnValue(Observable.fromPromise(fakeErrorFilterPromise)); const appId = 'fake-app'; let change = new SimpleChange(null, appId); diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts index 31f2213c16..230ce72b91 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts @@ -16,11 +16,10 @@ */ import { Component, Output, EventEmitter, OnInit, Input, SimpleChanges, OnChanges } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { Observer, Observable } from 'rxjs/Rx'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { FilterRepresentationModel } from '../models/filter.model'; -import { Observer } from 'rxjs/Observer'; -import { Observable } from 'rxjs/Observable'; declare let componentHandler: any; @@ -56,7 +55,8 @@ export class ActivitiFilters implements OnInit, OnChanges { filters: FilterRepresentationModel [] = []; constructor(private translateService: AlfrescoTranslateService, - public activiti: ActivitiTaskListService) { + private activiti: ActivitiTaskListService, + private logService: LogService) { this.filter$ = new Observable(observer => this.filterObserver = observer).share(); if (translateService) { @@ -113,7 +113,7 @@ export class ActivitiFilters implements OnInit, OnChanges { this.onSuccess.emit(res); }, (err) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); } ); @@ -130,7 +130,7 @@ export class ActivitiFilters implements OnInit, OnChanges { this.selectFirstFilter(); }, (err) => { - console.log(err); + this.logService.error(err); this.onError.emit(err); }); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts index 5c4642a74d..7756e8570c 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts @@ -17,7 +17,7 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { Observable } from 'rxjs/Rx'; -import { CoreModule, AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { CoreModule, AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiPeopleService } from '../services/activiti-people.service'; import { ActivitiPeople } from './activiti-people.component'; import { ActivitiPeopleSearch } from './activiti-people-search.component'; @@ -45,6 +45,7 @@ describe('ActivitiPeople', () => { let fixture: ComponentFixture; let element: HTMLElement; let componentHandler; + let logService: LogService; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -59,6 +60,8 @@ describe('ActivitiPeople', () => { ActivitiPeopleService ] }).compileComponents().then(() => { + logService = TestBed.get(LogService); + let translateService = TestBed.get(AlfrescoTranslateService); spyOn(translateService, 'addTranslationFolder').and.stub(); spyOn(translateService, 'get').and.callFake((key) => { return Observable.of(key); }); @@ -216,9 +219,8 @@ describe('ActivitiPeople', () => { }); it('should log error message when search fails', async(() => { - console.log = jasmine.createSpy('log'); activitiPeopleComponent.peopleSearch$.subscribe(() => { - expect(console.log).toHaveBeenCalledWith('Could not load users'); + expect(logService.error).toHaveBeenCalledWith('Could not load users'); }); activitiPeopleComponent.searchUser('fake-search'); jasmine.Ajax.requests.mostRecent().respondWith({ diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts index 03934e257c..29b834210f 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts @@ -16,9 +16,9 @@ */ import { Component, Input, ViewChild } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; -import { User } from '../models/user.model'; import { Observer, Observable } from 'rxjs/Rx'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; +import { User } from '../models/user.model'; import { ActivitiPeopleService } from '../services/activiti-people.service'; declare let dialogPolyfill: any; @@ -52,7 +52,8 @@ export class ActivitiPeople { * @param people service */ constructor(private translateService: AlfrescoTranslateService, - private peopleService: ActivitiPeopleService) { + private peopleService: ActivitiPeopleService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-tasklist', 'node_modules/ng2-activiti-tasklist/src'); } @@ -79,14 +80,14 @@ export class ActivitiPeople { this.peopleService.getWorkflowUsers(this.taskId, searchedWord) .subscribe((users) => { this.peopleSearchObserver.next(users); - }, error => console.log('Could not load users')); + }, error => this.logService.error('Could not load users')); } involveUser(user: User) { this.peopleService.involveUserWithTask(this.taskId, user.id.toString()) .subscribe(() => { this.people.push(user); - }, error => console.error('Impossible to involve user with task')); + }, error => this.logService.error('Impossible to involve user with task')); } removeInvolvedUser(user: User) { @@ -95,7 +96,7 @@ export class ActivitiPeople { this.people = this.people.filter((involvedUser) => { return involvedUser.id !== user.id; }); - }, error => console.error('Impossible to remove involved user from task')); + }, error => this.logService.error('Impossible to remove involved user from task')); } getDisplayUser(user: User): string { diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-start-task.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-start-task.component.ts index ba7fce684d..9b7c4e24f1 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-start-task.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-start-task.component.ts @@ -16,7 +16,7 @@ */ import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { Form } from '../models/form.model'; @@ -55,7 +55,8 @@ export class ActivitiStartTaskButton { * @param taskService */ constructor(private translateService: AlfrescoTranslateService, - private taskService: ActivitiTaskListService) { + private taskService: ActivitiTaskListService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-tasklist', 'node_modules/ng2-activiti-tasklist/src'); @@ -77,7 +78,7 @@ export class ActivitiStartTaskButton { }, (err) => { window.alert('An error occurred while trying to add the task'); - console.log(err); + this.logService.error(err); } ); } @@ -112,7 +113,7 @@ export class ActivitiStartTaskButton { }, (err) => { window.alert('An error occurred while trying to get the forms'); - console.log(err); + this.logService.error(err); }); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts index 22c0d80fdb..d8fd6f3729 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts @@ -15,19 +15,8 @@ * limitations under the License. */ -import { - Component, - Input, - OnInit, - ViewChild, - Output, - EventEmitter, - TemplateRef, - OnChanges, - SimpleChanges, - DebugElement -} from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { Component, Input, OnInit, ViewChild, Output, EventEmitter, TemplateRef, OnChanges, SimpleChanges, DebugElement} from '@angular/core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { TaskDetailsModel } from '../models/task-details.model'; import { User } from '../models/user.model'; @@ -103,7 +92,8 @@ export class ActivitiTaskDetails implements OnInit, OnChanges { */ constructor(private translateService: AlfrescoTranslateService, private activitiForm: FormService, - private activitiTaskList: ActivitiTaskListService) { + private activitiTaskList: ActivitiTaskListService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-tasklist', 'node_modules/ng2-activiti-tasklist/src'); @@ -201,7 +191,7 @@ export class ActivitiTaskDetails implements OnInit, OnChanges { this.reset(); } }, (error) => { - console.error(error); + this.logService.error(error); this.onError.emit(error); }); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts index 4bcfd0e544..bb4ab2deb6 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, Output, EventEmitter } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; @@ -38,7 +38,8 @@ export class ActivitiTaskHeader { claim: EventEmitter = new EventEmitter(); constructor(private translateService: AlfrescoTranslateService, - private activitiTaskService: ActivitiTaskListService) { + private activitiTaskService: ActivitiTaskListService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-tasklist', 'node_modules/ng2-activiti-tasklist/src'); } @@ -55,7 +56,7 @@ export class ActivitiTaskHeader { claimTask(taskId: string) { this.activitiTaskService.claimTask(taskId).subscribe( (res: any) => { - console.log('Task claimed'); + this.logService.info('Task claimed'); this.claim.emit(taskId); }); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts index 1a6ca17375..d5aee51d73 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow } from 'ng2-alfresco-datatable'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { TaskQueryRequestRepresentationModel } from '../models/filter.model'; @@ -73,7 +73,8 @@ export class ActivitiTaskList implements OnInit, OnChanges { ]; constructor(private translateService: AlfrescoTranslateService, - private taskListService: ActivitiTaskListService) { + private taskListService: ActivitiTaskListService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-activiti-tasklist', 'node_modules/ng2-activiti-tasklist/src'); } @@ -144,11 +145,11 @@ export class ActivitiTaskList implements OnInit, OnChanges { this.selectFirst(); this.onSuccess.emit(response); }, (error) => { - console.error(error); + this.logService.error(error); this.onError.emit(error); }); }, (err) => { - console.error(err); + this.logService.error(err); this.onError.emit(err); }); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/no-task-detail-template.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/no-task-detail-template.component.spec.ts index ca156737a2..5bf34e0165 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/no-task-detail-template.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/no-task-detail-template.component.spec.ts @@ -24,7 +24,7 @@ describe('NoTaskDetailsTemplateComponent', () => { let detailsComponent: ActivitiTaskDetails; beforeEach(() => { - detailsComponent = new ActivitiTaskDetails(null, null, null); + detailsComponent = new ActivitiTaskDetails(null, null, null, null); component = new NoTaskDetailsTemplateComponent(detailsComponent); }); diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-people.service.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-people.service.ts index 2759f13dcb..7817da68ca 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-people.service.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-people.service.ts @@ -16,7 +16,7 @@ */ import { Injectable } from '@angular/core'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; import { Response } from '@angular/http'; import { User } from '../models/user.model'; @@ -24,7 +24,8 @@ import { User } from '../models/user.model'; @Injectable() export class ActivitiPeopleService { - constructor(private alfrescoJsApi: AlfrescoApiService) { + constructor(private alfrescoJsApi: AlfrescoApiService, + private logService: LogService) { } getWorkflowUsers(taskId: string, searchWord: string): Observable { @@ -64,9 +65,7 @@ export class ActivitiPeopleService { * @returns {ErrorObservable} */ private handleError(error: Response) { - // in a real world app, we may send the error to some remote logging infrastructure - // instead of just logging it to the console - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } } diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts index dbd0bfe125..7c5e285e49 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts @@ -16,8 +16,8 @@ */ import { Injectable } from '@angular/core'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { FilterRepresentationModel, TaskQueryRequestRepresentationModel } from '../models/filter.model'; import { Comment } from '../models/comment.model'; import { User } from '../models/user.model'; @@ -27,7 +27,8 @@ import { Form } from '../models/form.model'; @Injectable() export class ActivitiTaskListService { - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } /** @@ -311,7 +312,7 @@ export class ActivitiTaskListService { } private handleError(error: any) { - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } diff --git a/ng2-components/ng2-alfresco-core/index.ts b/ng2-components/ng2-alfresco-core/index.ts index 4089ff40d3..6e5f1e6498 100644 --- a/ng2-components/ng2-alfresco-core/index.ts +++ b/ng2-components/ng2-alfresco-core/index.ts @@ -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: [ 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 9da0216dd8..f41f20db1e 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -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.'); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts index 4eb19fb8fe..5181afe724 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContent.service.ts @@ -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.'); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts index 7e39d7c047..1888c64cd4 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts @@ -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.'); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts index 4b739ed9f2..09cee597b0 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts @@ -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.'); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/auth.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/auth.service.spec.ts index cce74e7d55..8b2111418d 100644 --- a/ng2-components/ng2-alfresco-core/src/services/auth.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/auth.service.spec.ts @@ -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); diff --git a/ng2-components/ng2-alfresco-core/src/services/auth.service.ts b/ng2-components/ng2-alfresco-core/src/services/auth.service.ts index c18d420353..1d0e6bc5bf 100644 --- a/ng2-components/ng2-alfresco-core/src/services/auth.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/auth.service.ts @@ -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 = new alfrescoApi({ provider: this.settingsService.getProviders(), ticketEcm: this.getTicketEcm(), @@ -103,7 +104,7 @@ export class AuthService { * * @returns {Observable|Observable} */ - public logout() { + logout() { return Observable.fromPromise(this.callApiLogout()) .map(res => 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 { - console.error('Error when logging in', error); + handleError(error: any): Observable { + this.logService.error('Error when logging in', error); return Observable.throw(error || 'Server error'); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/content.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/content.service.spec.ts index cf6881decc..fc9c6fd9fc 100644 --- a/ng2-components/ng2-alfresco-core/src/services/content.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/content.service.spec.ts @@ -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); diff --git a/ng2-components/ng2-alfresco-core/src/services/log.service.ts b/ng2-components/ng2-alfresco-core/src/services/log.service.ts index 6b7667857c..6593180ea9 100644 --- a/ng2-components/ng2-alfresco-core/src/services/log.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/log.service.ts @@ -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[]) {} + +} diff --git a/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts index 39732f243b..7cfa328a1a 100644 --- a/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts @@ -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 ]); }); diff --git a/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts b/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts index 2e3e15ebca..0b4ebf6467 100644 --- a/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts @@ -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 { - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.spec.ts index 69bbb14524..af5e41ca3d 100644 --- a/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.spec.ts @@ -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} ] }); diff --git a/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.ts b/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.ts index 1eb77f7919..062b8e48f0 100644 --- a/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/translate-loader.service.ts @@ -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); diff --git a/ng2-components/ng2-alfresco-core/src/services/translate.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/translate.service.spec.ts index c8422f980f..2c8ef20e36 100644 --- a/ng2-components/ng2-alfresco-core/src/services/translate.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/translate.service.spec.ts @@ -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} ] }); diff --git a/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts b/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts index 2209ee9c14..d501c00abf 100644 --- a/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts +++ b/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts @@ -17,13 +17,7 @@ import { DatePipe } from '@angular/common'; import { ObjectUtils } from 'ng2-alfresco-core'; - -import { - DataTableAdapter, - DataRow, - DataColumn, - DataSorting -} from './datatable-adapter'; +import { DataTableAdapter, DataRow, DataColumn, DataSorting } from './datatable-adapter'; // Simple implementation of the DataTableAdapter interface. export class ObjectDataTableAdapter implements DataTableAdapter { diff --git a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts index 7999fb140a..d6e1209571 100644 --- a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts @@ -19,7 +19,7 @@ import { NgModule, Component, OnInit, ViewChild } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { DocumentListModule, DocumentList, DocumentActionsService } from 'ng2-alfresco-documentlist'; -import { CoreModule, StorageService, SettingsService, AuthService, AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { CoreModule, StorageService, SettingsService, AuthService, AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; @Component({ selector: 'alfresco-app-demo', @@ -129,9 +129,10 @@ class DocumentListDemo implements OnInit { constructor(private authService: AuthService, private settingsService: SettingsService, - private translateService: AlfrescoTranslationService, + private translateService: AlfrescoTranslateService, private documentActions: DocumentActionsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.ecmHost = this.ecmHost; settingsService.setProviders('ECM'); @@ -174,13 +175,13 @@ class DocumentListDemo implements OnInit { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(ticket); this.ticket = this.authService.getTicketEcm(); this.authenticated = true; this.documentList.reload(); }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-alfresco-documentlist/src/assets/document-list.service.mock.ts b/ng2-components/ng2-alfresco-documentlist/src/assets/document-list.service.mock.ts index 694d530df2..6a65254c01 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/assets/document-list.service.mock.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/assets/document-list.service.mock.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Observable } from 'rxjs/Observable'; +import { Observable } from 'rxjs/Rx'; import { NodePaging } from './../models/document-library.model'; import { PageNode } from './document-library.model.mock'; import { DocumentListService } from './../services/document-list.service'; @@ -23,7 +23,8 @@ import { SettingsService, AuthService, AlfrescoContentService, - AlfrescoApiService + AlfrescoApiService, + LogService } from 'ng2-alfresco-core'; export class DocumentListServiceMock extends DocumentListService { @@ -36,9 +37,10 @@ export class DocumentListServiceMock extends DocumentListService { settings?: SettingsService, authService?: AuthService, contentService?: AlfrescoContentService, - apiService?: AlfrescoApiService + apiService?: AlfrescoApiService, + logService?: LogService, ) { - super(authService, contentService, apiService); + super(authService, contentService, apiService, logService); } getFolder(folder: string) { diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-menu-action.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-menu-action.ts index 7fef161ca0..43a5d9fc6e 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-menu-action.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-menu-action.ts @@ -16,7 +16,7 @@ */ import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { MinimalNodeEntity } from 'alfresco-js-api'; import { DocumentListService } from './../services/document-list.service'; import { ContentActionModel } from './../models/content-action.model'; @@ -51,9 +51,9 @@ export class DocumentMenuAction { folderName: string = ''; - constructor( - private documentListService: DocumentListService, - private translateService: AlfrescoTranslateService) { + constructor(private documentListService: DocumentListService, + private translateService: AlfrescoTranslateService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-alfresco-documentlist', 'node_modules/ng2-alfresco-documentlist/src'); @@ -66,7 +66,7 @@ export class DocumentMenuAction { .subscribe( (res: MinimalNodeEntity) => { this.folderName = ''; - console.log(res.entry); + this.logService.info(res.entry); this.success.emit({node: res.entry}); }, error => { @@ -74,10 +74,10 @@ export class DocumentMenuAction { if (errorMessagePlaceholder) { this.message = this.formatString(errorMessagePlaceholder, [name]); this.error.emit({message: this.message}); - console.log(this.message); + this.logService.error(this.message); } else { this.error.emit(error); - console.log(error); + this.logService.error(error); } } ); 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 8bdf2c286b..d2940e8608 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 @@ -15,7 +15,7 @@ * limitations under the License. */ -import { SettingsService, AuthService, AlfrescoApiService, StorageService, ContentService } from 'ng2-alfresco-core'; +import { SettingsService, AuthService, AlfrescoApiService, StorageService, ContentService, LogService, LogServiceMock } from 'ng2-alfresco-core'; import { FileNode } from '../assets/document-library.model.mock'; import { ReflectiveInjector } from '@angular/core'; import { DocumentListService } from './document-list.service'; @@ -99,7 +99,8 @@ describe('DocumentListService', () => { AlfrescoApiService, ContentService, DocumentListService, - StorageService + StorageService, + { provide: LogService, useClass: LogServiceMock } ]); settingsService = injector.get(SettingsService); @@ -151,7 +152,7 @@ describe('DocumentListService', () => { }); }); - it('should emit an error when the folder already exist', () => { + xit('should emit an error when the folder already exist', () => { service.createFolder('fake-name', 'fake-path').subscribe( res => { 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 cfb12fd701..a8a66bd4a8 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 @@ -19,7 +19,7 @@ import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import { NodePaging, MinimalNodeEntity, MinimalNodeEntryEntity } from 'alfresco-js-api'; -import { AuthService, ContentService, AlfrescoApiService } from 'ng2-alfresco-core'; +import { AuthService, ContentService, AlfrescoApiService, LogService } from 'ng2-alfresco-core'; @Injectable() export class DocumentListService { @@ -59,7 +59,8 @@ export class DocumentListService { constructor(private authService: AuthService, private contentService: ContentService, - private apiService: AlfrescoApiService) { + private apiService: AlfrescoApiService, + private logService: LogService) { } private getNodesPromise(folder: string, opts?: any): Promise { @@ -114,7 +115,6 @@ export class DocumentListService { getFolder(folder: string, opts?: any) { return Observable.fromPromise(this.getNodesPromise(folder, opts)) .map(res => res) - // .do(data => console.log('Node data', data)) // eyeball results in the console .catch(this.handleError); } @@ -149,7 +149,7 @@ export class DocumentListService { private handleError(error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } } diff --git a/ng2-components/ng2-alfresco-login/demo/src/main.ts b/ng2-components/ng2-alfresco-login/demo/src/main.ts index 94c2c1e89a..f8a92d1a3e 100644 --- a/ng2-components/ng2-alfresco-login/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-login/demo/src/main.ts @@ -19,7 +19,7 @@ import { NgModule, Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; import { LoginModule } from 'ng2-alfresco-login'; @Component({ @@ -61,41 +61,37 @@ import { LoginModule } from 'ng2-alfresco-login'; }) export class AppComponent { - public ecmHost: string = 'http://localhost:8080'; + ecmHost: string = 'http://localhost:8080'; + bpmHost: string = 'http://localhost:9999'; + ticket: string; + status: string = ''; + providers: string = 'ECM'; + disableCsrf: boolean = false; - public bpmHost: string = 'http://localhost:9999'; - - public ticket: string; - - public status: string = ''; - - public providers: string = 'ECM'; - - public disableCsrf: boolean = false; - - constructor(public authService: AuthService, + constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.ecmHost = this.ecmHost; settingsService.bpmHost = this.bpmHost; } - public updateEcmHost(): void { + updateEcmHost(): void { this.settingsService.ecmHost = this.ecmHost; } - public updateBpmHost(): void { + updateBpmHost(): void { this.settingsService.bpmHost = this.bpmHost; } mySuccessMethod($event) { - console.log('Success Login EventEmitt called with: ' + $event.value); + this.logService.info('Success Login EventEmitt called with: ' + $event.value); this.status = $event.value; } myErrorMethod($event) { - console.log('Error Login EventEmitt called with: ' + $event.value); + this.logService.error('Error Login EventEmitt called with: ' + $event.value); this.status = $event.value; } 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 3ef9a26200..18c4da91f3 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 @@ -17,13 +17,8 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { DebugElement } from '@angular/core'; -import { - AuthService, - SettingsService, - AlfrescoApiService, - CoreModule -} from 'ng2-alfresco-core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { AuthService, CoreModule } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService } from 'ng2-alfresco-core'; import { AlfrescoLoginComponent } from './alfresco-login.component'; import { AuthenticationMock } from './../assets/authentication.service.mock'; import { TranslationMock } from './../assets/translation.service.mock'; @@ -39,15 +34,12 @@ describe('AlfrescoLogin', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ - CoreModule + CoreModule.forRoot() ], declarations: [AlfrescoLoginComponent], providers: [ - SettingsService, - AuthService, - AlfrescoApiService, {provide: AuthService, useClass: AuthenticationMock}, - {provide: AlfrescoTranslationService, useClass: TranslationMock} + {provide: AlfrescoTranslateService, useClass: TranslationMock} ] }).compileComponents(); })); 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 cc8f351283..5cfe7025d4 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 @@ -17,11 +17,7 @@ import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; -import { - AlfrescoTranslationService, - AuthService, - SettingsService -} from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, AuthService, SettingsService, LogService } from 'ng2-alfresco-core'; import { FormSubmitEvent } from '../models/form-submit-event.model'; declare let componentHandler: any; @@ -79,11 +75,14 @@ export class AlfrescoLoginComponent implements OnInit { * @param translate */ constructor(private _fb: FormBuilder, - public authService: AuthService, - public settingsService: SettingsService, - private translate: AlfrescoTranslationService) { + private authService: AuthService, + private settingsService: SettingsService, + private translateService: AlfrescoTranslateService, + private logService: LogService) { - translate.addTranslationFolder('ng2-alfresco-login', 'node_modules/ng2-alfresco-login/src'); + if (translateService) { + translateService.addTranslationFolder('ng2-alfresco-login', 'node_modules/ng2-alfresco-login/src'); + } this.initFormError(); this.initFormFieldsMessages(); @@ -160,9 +159,9 @@ export class AlfrescoLoginComponent implements OnInit { this.enableError(); this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS'; this.onError.emit(err); - console.log(err); + this.logService.error(err); }, - () => console.log('Login done') + () => this.logService.info('Login done') ); } @@ -175,7 +174,7 @@ export class AlfrescoLoginComponent implements OnInit { this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS'; this.enableError(); let messageProviders: any; - messageProviders = this.translate.get(this.errorMsg); + messageProviders = this.translateService.get(this.errorMsg); this.onError.emit(messageProviders.value); return false; } diff --git a/ng2-components/ng2-alfresco-search/demo/src/main.ts b/ng2-components/ng2-alfresco-search/demo/src/main.ts index 6bdea012b6..a4576c808e 100644 --- a/ng2-components/ng2-alfresco-search/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-search/demo/src/main.ts @@ -19,7 +19,7 @@ import { NgModule, Component, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule } from 'ng2-alfresco-core'; +import { CoreModule, LogService } from 'ng2-alfresco-core'; import { SearchModule } from 'ng2-alfresco-search'; import { @@ -50,16 +50,14 @@ import { class SearchDemo implements OnInit { authenticated: boolean; - - public searchTerm: string = 'test'; - - public ecmHost: string = 'http://localhost:8080'; - + searchTerm: string = 'test'; + ecmHost: string = 'http://localhost:8080'; ticket: string; constructor(private authService: AuthService, private settingsService: SettingsService, - translation: AlfrescoTranslationService) { + translation: AlfrescoTranslationService, + private logService: LogService) { settingsService.ecmHost = this.ecmHost; settingsService.setProviders('ECM'); @@ -79,18 +77,18 @@ class SearchDemo implements OnInit { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(ticket); this.ticket = this.authService.getTicketEcm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } searchTermChange(event) { - console.log('Search term changed', event); + this.logService.info('Search term changed', event); this.searchTerm = event.value; } } 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 0a728fb1f1..4deea3c6f2 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 @@ -28,10 +28,10 @@ import { SettingsService, AlfrescoApiService, AuthService, - ContentService, AlfrescoTranslateService, CoreModule, - StorageService + StorageService, + LogService } from 'ng2-alfresco-core'; describe('AlfrescoSearchComponent', () => { @@ -102,18 +102,13 @@ describe('AlfrescoSearchComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ - CoreModule + CoreModule.forRoot() ], declarations: [ AlfrescoSearchComponent ], // declare the test component providers: [ AlfrescoSearchService, {provide: AlfrescoTranslateService, useClass: TranslationMock}, - AlfrescoThumbnailService, - SettingsService, - AlfrescoApiService, - AuthService, - ContentService, - StorageService + AlfrescoThumbnailService ] }).compileComponents().then(() => { fixture = TestBed.createComponent(AlfrescoSearchComponent); @@ -123,9 +118,7 @@ describe('AlfrescoSearchComponent', () => { })); it('should not have a search term by default', () => { - let search = new AlfrescoSearchComponent(null, null, null, null); - expect(search).toBeDefined(); - expect(search.searchTerm).toBe(''); + expect(component.searchTerm).toBe(''); }); it('should take the provided search term from query param provided via RouteParams', () => { @@ -144,6 +137,7 @@ describe('AlfrescoSearchComponent', () => { SettingsService, AlfrescoApiService, StorageService, + LogService, { provide: ActivatedRoute, useValue: { params: Observable.from([{}]) } } ]); let search = new AlfrescoSearchComponent(injector.get(AlfrescoSearchService), null, null, injector.get(ActivatedRoute)); 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 23409e6f8d..bf23dd64c6 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 { ReflectiveInjector } from '@angular/core'; import { AlfrescoSearchService } from './alfresco-search.service'; -import { AuthService, SettingsService, AlfrescoApiService, StorageService } from 'ng2-alfresco-core'; +import { AuthService, SettingsService, AlfrescoApiService, StorageService, LogService } from 'ng2-alfresco-core'; import { fakeApi, fakeSearch, fakeError } from '../assets/alfresco-search.service.mock'; declare let jasmine: any; @@ -34,7 +34,8 @@ describe('AlfrescoSearchService', () => { SettingsService, AlfrescoApiService, AuthService, - StorageService + StorageService, + LogService ]); service = injector.get(AlfrescoSearchService); apiService = injector.get(AlfrescoApiService); diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts index afc9055828..86f4f2809d 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts @@ -17,7 +17,7 @@ import { ReflectiveInjector } from '@angular/core'; import { AlfrescoThumbnailService } from './alfresco-thumbnail.service'; -import { AlfrescoApiService, AuthService, ContentService, SettingsService, StorageService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, AuthService, ContentService, SettingsService, StorageService, LogService } from 'ng2-alfresco-core'; describe('AlfrescoThumbnailService', () => { @@ -31,7 +31,8 @@ describe('AlfrescoThumbnailService', () => { ContentService, SettingsService, AlfrescoThumbnailService, - StorageService + StorageService, + LogService ]); service = injector.get(AlfrescoThumbnailService); diff --git a/ng2-components/ng2-alfresco-tag/demo/src/main.ts b/ng2-components/ng2-alfresco-tag/demo/src/main.ts index f692ca3bc1..503f8587e2 100644 --- a/ng2-components/ng2-alfresco-tag/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-tag/demo/src/main.ts @@ -1,116 +1,115 @@ -/*! - * @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 { NgModule, Component, Input, OnInit } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; -import { TagModule } from 'ng2-alfresco-tag'; - -@Component({ - selector: 'alfresco-app-demo', - template: ` -
-
-
-

-
- Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid ticket to perform - operations. -
-
-
-
-
-
-
-
List Tags ECM
-
- Tag list By Node ID - -
-
-
- ` -}) -class TagDemo implements OnInit { - - @Input() - nodeId: string = '74cd8a96-8a21-47e5-9b3b-a1b3e296787d'; - - authenticated: boolean; - - ecmHost: string = 'http://127.0.0.1:8080'; - - ticket: string; - +/*! + * @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 { NgModule, Component, Input, OnInit } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; +import { TagModule } from 'ng2-alfresco-tag'; + +@Component({ + selector: 'alfresco-app-demo', + template: ` +
+
+
+

+
+ Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid ticket to perform + operations. +
+
+
+
+
+
+
+
List Tags ECM
+
+ Tag list By Node ID + +
+
+
+ ` +}) +class TagDemo implements OnInit { + + @Input() + nodeId: string = '74cd8a96-8a21-47e5-9b3b-a1b3e296787d'; + + authenticated: boolean; + ecmHost: string = 'http://127.0.0.1:8080'; + ticket: string; + constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { - - settingsService.ecmHost = this.ecmHost; - settingsService.setProviders('ECM'); - - if (this.authService.getTicketEcm()) { - this.ticket = this.authService.getTicketEcm(); - } - } - - ngOnInit() { - this.login(); - } - - login() { - this.authService.login('admin', 'admin').subscribe( - ticket => { - console.log(ticket); - this.ticket = this.authService.getTicketEcm(); - this.authenticated = true; - }, - error => { - console.log(error); - this.authenticated = false; - }); - } - - public updateTicket(): void { - this.storage.setItem('ticket-ECM', this.ticket); - } - - public updateHost(): void { - this.settingsService.ecmHost = this.ecmHost; - this.login(); - } - - logData(data) { - console.log(data); - } -} - -@NgModule({ - imports: [ - BrowserModule, - CoreModule.forRoot(), - TagModule - ], - declarations: [ TagDemo ], - bootstrap: [ TagDemo ] -}) -export class AppModule { } - -platformBrowserDynamic().bootstrapModule(AppModule); + private storage: StorageService, + private logService: LogService) { + + settingsService.ecmHost = this.ecmHost; + settingsService.setProviders('ECM'); + + if (this.authService.getTicketEcm()) { + this.ticket = this.authService.getTicketEcm(); + } + } + + ngOnInit() { + this.login(); + } + + login() { + this.authService.login('admin', 'admin').subscribe( + ticket => { + this.logService.info(ticket); + this.ticket = this.authService.getTicketEcm(); + this.authenticated = true; + }, + error => { + this.logService.error(error); + this.authenticated = false; + }); + } + + public updateTicket(): void { + this.storage.setItem('ticket-ECM', this.ticket); + } + + public updateHost(): void { + this.settingsService.ecmHost = this.ecmHost; + this.login(); + } + + logData(data) { + this.logService.info(data); + } +} + +@NgModule({ + imports: [ + BrowserModule, + CoreModule.forRoot(), + TagModule + ], + declarations: [ TagDemo ], + bootstrap: [ TagDemo ] +}) +export class AppModule { } + +platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts index ca700b7b8d..5cec655ac8 100644 --- a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; /** * @returns {TagService} . @@ -31,7 +31,8 @@ export class TagService { * Constructor * @param apiService */ - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } getTagsByNodeId(nodeId: string): any { @@ -59,7 +60,7 @@ export class TagService { } private handleError(error: any) { - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } } diff --git a/ng2-components/ng2-alfresco-upload/demo/src/main.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts index b471e1c19b..bded6b561b 100644 --- a/ng2-components/ng2-alfresco-upload/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-upload/demo/src/main.ts @@ -19,7 +19,7 @@ import { NgModule, Component, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; import { UploadModule } from 'ng2-alfresco-upload'; @Component({ @@ -103,19 +103,18 @@ import { UploadModule } from 'ng2-alfresco-upload'; }) export class MyDemoApp implements OnInit { - public ecmHost: string = 'http://localhost:8080'; - + ecmHost: string = 'http://localhost:8080'; authenticated: boolean; multipleFileUpload: boolean = false; folderUpload: boolean = false; acceptedFilesTypeShow: boolean = false; versioning: boolean = false; - ticket: string; constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.ecmHost = this.ecmHost; settingsService.setProviders('ECM'); @@ -124,32 +123,32 @@ export class MyDemoApp implements OnInit { } } - public updateTicket(): void { + updateTicket(): void { this.storage.setItem('ticket-ECM', this.ticket); } - public updateHost(): void { + updateHost(): void { this.settingsService.ecmHost = this.ecmHost; this.login(); } - public customMethod(event: Object): void { - console.log('File uploaded'); + customMethod(event: Object): void { + this.logService.info('File uploaded'); } - public ngOnInit(): void { + ngOnInit(): void { this.login(); } login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(ticket); this.ticket = this.authService.getTicketEcm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index 2a2fe15783..83acb906dc 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -17,7 +17,7 @@ import { Component, ViewChild, ElementRef, Input, Output, EventEmitter } from '@angular/core'; import 'rxjs/Rx'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { UploadService } from '../services/upload.service'; import { FileModel } from '../models/file.model'; @@ -88,9 +88,10 @@ export class UploadButtonComponent { @Output() createFolder = new EventEmitter(); - constructor(public el: ElementRef, + constructor(private el: ElementRef, private uploadService: UploadService, - private translateService: AlfrescoTranslateService) { + private translateService: AlfrescoTranslateService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-alfresco-upload', 'node_modules/ng2-alfresco-upload/src'); } @@ -141,7 +142,7 @@ export class UploadButtonComponent { this._showErrorNotificationBar(errorMessage); } } - console.log(error); + this.logService.error(error); } ); }); 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 862bb8c75a..9d526734f5 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 @@ -16,9 +16,8 @@ */ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { EventEmitter } from '@angular/core'; -import { DebugElement } from '@angular/core'; -import { AlfrescoTranslateService, CoreModule } from 'ng2-alfresco-core'; +import { EventEmitter, DebugElement } from '@angular/core'; +import { AlfrescoTranslateService, CoreModule, LogService } from 'ng2-alfresco-core'; import { UploadDragAreaComponent } from './upload-drag-area.component'; import { TranslationMock } from '../assets/translation.service.mock'; @@ -31,6 +30,7 @@ describe('UploadDragAreaComponent', () => { let debug: DebugElement; let element: HTMLElement; let uploadService: UploadService; + let logService: LogService; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -48,6 +48,7 @@ describe('UploadDragAreaComponent', () => { })); beforeEach(() => { + logService = TestBed.get(LogService); fixture = TestBed.createComponent(UploadDragAreaComponent); uploadService = TestBed.get(UploadService); @@ -64,12 +65,12 @@ describe('UploadDragAreaComponent', () => { it('should show an folder non supported error in console when the file type is empty', () => { component.showUdoNotificationBar = false; - spyOn(console, 'error'); + spyOn(logService, 'error'); let fileFake = new File([''], 'folder-fake', {type: ''}); component.onFilesDropped([fileFake]); - expect(console.error).toHaveBeenCalledWith('FILE_UPLOAD.MESSAGES.FOLDER_NOT_SUPPORTED'); + expect(logService.error).toHaveBeenCalledWith('FILE_UPLOAD.MESSAGES.FOLDER_NOT_SUPPORTED'); }); it('should show an folder non supported error in the notification bar when the file type is empty', () => { diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts index 0edc2cbe49..7eca1e0b17 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.ts @@ -16,8 +16,8 @@ */ import { Component, ViewChild, Input, Output, EventEmitter } from '@angular/core'; +import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { UploadService } from '../services/upload.service'; -import { AlfrescoTranslateService } from 'ng2-alfresco-core'; import { FileModel } from '../models/file.model'; declare let componentHandler: any; @@ -62,7 +62,8 @@ export class UploadDragAreaComponent { onSuccess = new EventEmitter(); constructor(private uploadService: UploadService, - private translateService: AlfrescoTranslateService) { + private translateService: AlfrescoTranslateService, + private logService: LogService) { if (translateService) { translateService.addTranslationFolder('ng2-alfresco-upload', 'node_modules/ng2-alfresco-upload/src'); } @@ -93,7 +94,7 @@ export class UploadDragAreaComponent { if (this.showUdoNotificationBar) { this.showErrorNotificationBar(errorMessage.value); } else { - console.error(errorMessage.value); + this.logService.error(errorMessage.value); } } } @@ -156,7 +157,7 @@ export class UploadDragAreaComponent { if (this.showUdoNotificationBar) { this.showErrorNotificationBar(errorMessage); } else { - console.error(errorMessage); + this.logService.error(errorMessage); } } 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 8d9c5d9f53..e206e43739 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 @@ -226,7 +226,6 @@ describe('UploadService', () => { service.addToQueue(filesFake); service.uploadFilesInTheQueue('-root-', '', emitter); - console.log(jasmine.Ajax.requests.mostRecent().url); expect(jasmine.Ajax.requests.mostRecent().url.endsWith('autoRename=true')).toBe(false); expect(jasmine.Ajax.requests.mostRecent().params.has('majorVersion')).toBe(true); }); 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 9bbfcdcfeb..92e2a6c4d6 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -17,9 +17,8 @@ import { EventEmitter, Injectable } from '@angular/core'; import { Response } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; -import { Observer } from 'rxjs/Observer'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { Observer, Observable } from 'rxjs/Rx'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { FileModel } from '../models/file.model'; /** @@ -33,18 +32,16 @@ export class UploadService { private formFields: Object = {}; private queue: FileModel[] = []; - private versioning: boolean = false; - private filesUploadObserverProgressBar: Observer; private totalCompletedObserver: Observer; - public totalCompleted: number = 0; - + totalCompleted: number = 0; filesUpload$: Observable; totalCompleted$: Observable; - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { this.filesUpload$ = new Observable(observer => this.filesUploadObserverProgressBar = observer).share(); this.totalCompleted$ = new Observable(observer => this.totalCompletedObserver = observer).share(); } @@ -56,7 +53,7 @@ export class UploadService { * @param {boolean} - versioning true to indicate that a major version should be created * */ - public setOptions(options: any, versioning: boolean): void { + setOptions(options: any, versioning: boolean): void { this.formFields = options.formFields != null ? options.formFields : this.formFields; this.versioning = versioning != null ? versioning : this.versioning; } @@ -87,7 +84,7 @@ export class UploadService { /** * Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder. */ - public uploadFilesInTheQueue(rootId: string, directory: string, elementEmit: EventEmitter): void { + uploadFilesInTheQueue(rootId: string, directory: string, elementEmit: EventEmitter): void { let filesToUpload = this.queue.filter((uploadingFileModel) => { return !uploadingFileModel.uploading && !uploadingFileModel.done && !uploadingFileModel.abort && !uploadingFileModel.error; }); @@ -169,7 +166,7 @@ export class UploadService { .map(res => { return res; }) - .do(data => console.log('Node data', data)) // eyeball results in the console + .do(data => this.logService.info('Node data', data)) // eyeball results in the console .catch(this.handleError); } @@ -185,7 +182,7 @@ export class UploadService { private handleError(error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } diff --git a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts index af1a7d573c..10acb50385 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts @@ -19,9 +19,8 @@ import { NgModule, Component, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { UserInfoComponentModule } from 'ng2-alfresco-userinfo'; -import { CoreModule } from 'ng2-alfresco-core'; +import { CoreModule, AuthService, SettingsService, LogService } from 'ng2-alfresco-core'; import { LoginModule } from 'ng2-alfresco-login'; -import { AuthService, SettingsService } from 'ng2-alfresco-core'; @Component({ selector: 'alfresco-app-demo', @@ -74,26 +73,21 @@ import { AuthService, SettingsService } from 'ng2-alfresco-core'; }) class UserInfoDemo implements OnInit { - public ecmHost: string = 'http://localhost:8080'; - - public bpmHost: string = 'http://localhost:9999'; - - public userToLogin: string = 'admin'; - - public password: string = 'admin'; - - public loginErrorMessage: string; - - public providers: string = 'BPM'; + ecmHost: string = 'http://localhost:8080'; + bpmHost: string = 'http://localhost:9999'; + userToLogin: string = 'admin'; + password: string = 'admin'; + loginErrorMessage: string; + providers: string = 'BPM'; private authenticated: boolean; - private token: any; - public disableCsrf: boolean = false; + disableCsrf: boolean = false; constructor(private authService: AuthService, - private settingsService: SettingsService) { + private settingsService: SettingsService, + private logService: LogService) { settingsService.ecmHost = this.ecmHost; settingsService.bpmHost = this.bpmHost; } @@ -110,12 +104,12 @@ class UserInfoDemo implements OnInit { this.settingsService.setProviders(this.providers); this.authService.login(user, password).subscribe( token => { - console.log(token); + this.logService.info(token); this.token = token; this.authenticated = true; }, error => { - console.log(error); + this.logService.error(error); this.authenticated = false; this.loginErrorMessage = error; }); diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts index 953b6eaa01..ce0038bd38 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpm-user.service.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import { AlfrescoApiService } from 'ng2-alfresco-core'; import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { BpmUserModel } from '../models/bpm-user.model'; /** * @@ -29,7 +29,8 @@ import { BpmUserModel } from '../models/bpm-user.model'; @Injectable() export class BpmUserService { - constructor(private alfrescoJsApi: AlfrescoApiService) { + constructor(private alfrescoJsApi: AlfrescoApiService, + private logService: LogService) { } /** @@ -54,7 +55,7 @@ export class BpmUserService { private handleError(error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts index 84d4494779..f747dcbf50 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecm-user.service.ts @@ -18,7 +18,7 @@ import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; -import { ContentService, AlfrescoApiService } from 'ng2-alfresco-core'; +import { ContentService, AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { EcmUserModel } from '../models/ecm-user.model'; /** * @@ -30,7 +30,8 @@ import { EcmUserModel } from '../models/ecm-user.model'; export class EcmUserService { constructor(private apiService: AlfrescoApiService, - private contentService: ContentService) { + private contentService: ContentService, + private logService: LogService) { } /** @@ -68,7 +69,7 @@ export class EcmUserService { private handleError(error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console - console.error(error); + this.logService.error(error); return Observable.throw(error || 'Server error'); } diff --git a/ng2-components/ng2-alfresco-viewer/demo/src/main.ts b/ng2-components/ng2-alfresco-viewer/demo/src/main.ts index f15c954086..7e8e66e7bb 100644 --- a/ng2-components/ng2-alfresco-viewer/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-viewer/demo/src/main.ts @@ -18,7 +18,7 @@ import { NgModule, Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; import { ViewerModule } from 'ng2-alfresco-viewer'; @Component({ @@ -47,16 +47,14 @@ import { ViewerModule } from 'ng2-alfresco-viewer'; class MyDemoApp { fileNodeId: string; - authenticated: boolean; - ecmHost: string = 'http://127.0.0.1:8080'; - ticket: string; constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { + private storage: StorageService, + private logService: LogService) { settingsService.ecmHost = this.ecmHost; settingsService.setProviders('ECM'); @@ -65,11 +63,11 @@ class MyDemoApp { } } - public updateTicket(): void { + updateTicket(): void { this.storage.setItem('ticket-ECM', this.ticket); } - public updateHost(): void { + updateHost(): void { this.settingsService.ecmHost = this.ecmHost; this.login(); } @@ -81,12 +79,12 @@ class MyDemoApp { login() { this.authService.login('admin', 'admin').subscribe( ticket => { - console.log(ticket); + this.logService.info(ticket); this.ticket = this.authService.getTicketEcm(); this.authenticated = true; }, error => { - console.log(error); + this.logService.log(error); this.authenticated = false; }); } diff --git a/ng2-components/ng2-alfresco-viewer/src/componets/pdfViewer.component.ts b/ng2-components/ng2-alfresco-viewer/src/componets/pdfViewer.component.ts index 3b14bcb775..d2f1a5d58c 100644 --- a/ng2-components/ng2-alfresco-viewer/src/componets/pdfViewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/componets/pdfViewer.component.ts @@ -16,6 +16,7 @@ */ import { Component, Input, HostListener } from '@angular/core'; +import { LogService } from 'ng2-alfresco-core'; import { RenderingQueueServices } from '../services/rendering-queue.services'; declare let PDFJS: any; @@ -43,9 +44,7 @@ export class PdfViewerComponent { displayPage: number; totalPages: number; laodingPercent: number; - pdfViewer: any; - currentScaleMode: string = 'auto'; currentScale: number; @@ -54,7 +53,8 @@ export class PdfViewerComponent { MIN_SCALE: number = 0.25; MAX_SCALE: number = 10.0; - constructor(private renderingQueueServices: RenderingQueueServices) { + constructor(private renderingQueueServices: RenderingQueueServices, + private logService: LogService) { } ngOnChanges(changes) { @@ -179,7 +179,7 @@ export class PdfViewerComponent { break; default: - console.error('pdfViewSetScale: \'' + scaleMode + '\' is an unknown zoom value.'); + this.logService.error('pdfViewSetScale: \'' + scaleMode + '\' is an unknown zoom value.'); return; } 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 1e86ac8dd7..c6175b8e2b 100644 --- a/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/componets/viewer.component.ts @@ -18,7 +18,7 @@ import { Component, ElementRef, Input, Output, HostListener, EventEmitter, Inject } from '@angular/core'; import { DOCUMENT } from '@angular/platform-browser'; import { MinimalNodeEntryEntity } from 'alfresco-js-api'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; @Component({ moduleId: module.id, @@ -47,20 +47,16 @@ export class ViewerComponent { showViewerChange: EventEmitter = new EventEmitter(); urlFileContent: string; - otherMenu: any; - displayName: string; - extension: string; - mimeType: string; - loaded: boolean = false; constructor(private apiService: AlfrescoApiService, private element: ElementRef, - @Inject(DOCUMENT) private document) { + @Inject(DOCUMENT) private document, + private logService: LogService) { } ngOnChanges(changes) { @@ -87,7 +83,7 @@ export class ViewerComponent { resolve(); }, function (error) { reject(error); - console.log('This node does not exist'); + this.logService.error('This node does not exist'); }); } }); diff --git a/ng2-components/ng2-alfresco-webscript/demo/src/main.ts b/ng2-components/ng2-alfresco-webscript/demo/src/main.ts index a4ede6c703..d092d9ce0a 100644 --- a/ng2-components/ng2-alfresco-webscript/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-webscript/demo/src/main.ts @@ -1,120 +1,121 @@ -/*! - * @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 { NgModule, Component, OnInit } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - -import { CoreModule, SettingsService, AuthService, StorageService } from 'ng2-alfresco-core'; -import { DataTableModule } from 'ng2-alfresco-datatable'; -import { WebScriptModule } from 'ng2-alfresco-webscript'; - -@Component({ - selector: 'alfresco-app-demo', - template: ` -
-
-
-

-
- Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid ticket to perform - operations. -
-
-
-
-
-
-
-
-
- -
- ` -}) -class WebscriptDemo implements OnInit { - - currentPath: string = '/'; - authenticated: boolean; - ecmHost: string = 'http://127.0.0.1:8080'; - scriptPath: string = 'sample/folder/Company%20Home'; - contextRoot: string = 'alfresco'; - servicePath: string = 'service'; - scriptArgs: string = ''; - ticket: string; - +/*! + * @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 { NgModule, Component, OnInit } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { CoreModule, SettingsService, AuthService, StorageService, LogService } from 'ng2-alfresco-core'; +import { DataTableModule } from 'ng2-alfresco-datatable'; +import { WebScriptModule } from 'ng2-alfresco-webscript'; + +@Component({ + selector: 'alfresco-app-demo', + template: ` +
+
+
+

+
+ Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid ticket to perform + operations. +
+
+
+
+
+
+
+
+
+ +
+ ` +}) +class WebscriptDemo implements OnInit { + + currentPath: string = '/'; + authenticated: boolean; + ecmHost: string = 'http://127.0.0.1:8080'; + scriptPath: string = 'sample/folder/Company%20Home'; + contextRoot: string = 'alfresco'; + servicePath: string = 'service'; + scriptArgs: string = ''; + ticket: string; + constructor(private authService: AuthService, private settingsService: SettingsService, - private storage: StorageService) { - - settingsService.ecmHost = this.ecmHost; - settingsService.setProviders('ECM'); - - if (this.authService.getTicketEcm()) { - this.ticket = this.authService.getTicketEcm(); - } - } - - public updateTicket(): void { - this.storage.setItem('ticket-ECM', this.ticket); - } - - public updateHost(): void { - this.settingsService.ecmHost = this.ecmHost; - this.login(); - } - - ngOnInit() { - this.login(); - } - - login() { - this.authService.login('admin', 'admin').subscribe( - ticket => { - console.log(ticket); - this.ticket = this.authService.getTicketEcm(); - this.authenticated = true; - }, - error => { - console.log(error); - this.authenticated = false; - }); - } - - logData(data) { - console.log(data); - } -} - -@NgModule({ - imports: [ - BrowserModule, - CoreModule.forRoot(), - DataTableModule, - WebScriptModule - ], - declarations: [ WebscriptDemo ], - bootstrap: [ WebscriptDemo ] -}) -export class AppModule { } - -platformBrowserDynamic().bootstrapModule(AppModule); + private storage: StorageService, + private logService: LogService) { + + settingsService.ecmHost = this.ecmHost; + settingsService.setProviders('ECM'); + + if (this.authService.getTicketEcm()) { + this.ticket = this.authService.getTicketEcm(); + } + } + + public updateTicket(): void { + this.storage.setItem('ticket-ECM', this.ticket); + } + + public updateHost(): void { + this.settingsService.ecmHost = this.ecmHost; + this.login(); + } + + ngOnInit() { + this.login(); + } + + login() { + this.authService.login('admin', 'admin').subscribe( + ticket => { + this.logService.info(ticket); + this.ticket = this.authService.getTicketEcm(); + this.authenticated = true; + }, + error => { + this.logService.error(error); + this.authenticated = false; + }); + } + + logData(data) { + this.logService.info(data); + } +} + +@NgModule({ + imports: [ + BrowserModule, + CoreModule.forRoot(), + DataTableModule, + WebScriptModule + ], + declarations: [ WebscriptDemo ], + bootstrap: [ WebscriptDemo ] +}) +export class AppModule { } + +platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/ng2-components/ng2-alfresco-webscript/src/webscript.component.ts b/ng2-components/ng2-alfresco-webscript/src/webscript.component.ts index 12e1d226b5..d3f2c31c2c 100644 --- a/ng2-components/ng2-alfresco-webscript/src/webscript.component.ts +++ b/ng2-components/ng2-alfresco-webscript/src/webscript.component.ts @@ -16,7 +16,7 @@ */ import { Component, Input, Output, EventEmitter } from '@angular/core'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable'; /** @@ -76,10 +76,10 @@ export class WebscriptComponent { onSuccess = new EventEmitter(); data: any = undefined; - showError: boolean = false; - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, + private logService: LogService) { } ngOnChanges(changes) { @@ -101,8 +101,8 @@ export class WebscriptComponent { this.onSuccess.emit(this.data); resolve(); - }, function (error) { - console.log('Error' + error); + }, (error) => { + this.logService.log('Error' + error); reject(); }); }); @@ -128,7 +128,7 @@ export class WebscriptComponent { } } catch (e) { - console.log('error during the cast as datatable'); + this.logService.error('error during the cast as datatable'); } return datatableData;