[ADF - 778] Fixed error on wrong change detection strategy (#2021)

This commit is contained in:
Vito
2017-07-03 07:20:56 -07:00
committed by Eugenio Romano
parent 5eeb16b6b6
commit 033939615d
3 changed files with 7 additions and 19 deletions

View File

@@ -114,8 +114,8 @@ describe('FileUploadingDialogComponent', () => {
it('should show the close button when the file upload is completed', async(() => {
component.isDialogActive = true;
uploadService.addToQueue(new FileModel(<File> { name: 'file' }));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let closeButton = element.querySelector('#button-close-upload-list');
expect(closeButton).not.toBeNull();
});
@@ -125,8 +125,8 @@ describe('FileUploadingDialogComponent', () => {
it('should show the close button when the file upload is in error', async(() => {
component.isDialogActive = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let closeButton = element.querySelector('#button-close-upload-list');
expect(closeButton).not.toBeNull();
});
@@ -136,8 +136,8 @@ describe('FileUploadingDialogComponent', () => {
it('should show the close button when the file upload is cancelled', async(() => {
component.isDialogActive = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let closeButton = element.querySelector('#button-close-upload-list');
expect(closeButton).not.toBeNull();
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, ChangeDetectorRef, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { FileModel, FileUploadStatus } from '../models/file.model';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { UploadService } from '../services/upload.service';
@@ -23,14 +23,13 @@ import { FileUploadCompleteEvent } from '../events/file.event';
@Component({
selector: 'file-uploading-dialog',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './file-uploading-dialog.component.html',
styleUrls: ['./file-uploading-dialog.component.css']
})
export class FileUploadingDialogComponent implements OnInit, OnDestroy {
@Input()
filesUploadingList: FileModel [];
filesUploadingList: FileModel[];
isDialogActive: boolean = false;
totalCompleted: number = 0;
@@ -41,13 +40,10 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
private counterSubscription: any;
private showCloseButton: boolean = false;
constructor(private cd: ChangeDetectorRef,
translateService: AlfrescoTranslationService,
private uploadService: UploadService) {
constructor(translateService: AlfrescoTranslationService, private uploadService: UploadService) {
if (translateService) {
translateService.addTranslationFolder('ng2-alfresco-upload', 'assets/ng2-alfresco-upload');
}
cd.detach();
}
ngOnInit() {
@@ -55,7 +51,6 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
this.filesUploadingList = fileList;
if (this.filesUploadingList.length > 0) {
this.isDialogActive = true;
this.cd.detectChanges();
}
this.showCloseButton = false;
});
@@ -65,14 +60,12 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
if (this.totalCompleted > 1) {
this.totalCompletedMsg = 'FILE_UPLOAD.MESSAGES.COMPLETED';
}
this.cd.detectChanges();
});
this.uploadService.fileUpload.subscribe((event: FileUploadCompleteEvent) => {
if (event.status !== FileUploadStatus.Progress) {
this.isUploadProcessCompleted(event);
}
this.cd.detectChanges();
});
}
@@ -82,7 +75,6 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
toggleVisible(): void {
this.isDialogActive = !this.isDialogActive;
this.uploadService.clearQueue();
this.cd.detectChanges();
}
/**
@@ -90,10 +82,10 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
*/
toggleMinimized(): void {
this.isDialogMinimized = !this.isDialogMinimized;
this.cd.detectChanges();
}
ngOnDestroy() {
this.uploadService.clearQueue();
this.listSubscription.unsubscribe();
this.counterSubscription.unsubscribe();
}

View File

@@ -188,8 +188,6 @@ export class UploadService {
const event = new FileUploadEvent(file, FileUploadStatus.Progress);
this.fileUpload.next(event);
this.fileUploadProgress.next(event);
this.queueChanged.next(this.queue);
}
}
@@ -221,8 +219,6 @@ export class UploadService {
const event = new FileUploadCompleteEvent(file, this.totalComplete, data, this.totalAborted);
this.fileUpload.next(event);
this.fileUploadComplete.next(event);
this.queueChanged.next(this.queue);
}
}