mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Migrate from window.console to LogService
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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<FileModel[]>;
|
||||
private totalCompletedObserver: Observer<number>;
|
||||
|
||||
public totalCompleted: number = 0;
|
||||
|
||||
totalCompleted: number = 0;
|
||||
filesUpload$: Observable<FileModel[]>;
|
||||
totalCompleted$: Observable<any>;
|
||||
|
||||
constructor(private apiService: AlfrescoApiService) {
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
this.filesUpload$ = new Observable<FileModel[]>(observer => this.filesUploadObserverProgressBar = observer).share();
|
||||
this.totalCompleted$ = new Observable<number>(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<any>): void {
|
||||
uploadFilesInTheQueue(rootId: string, directory: string, elementEmit: EventEmitter<any>): 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');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user