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

View File

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

View File

@@ -188,8 +188,6 @@ export class UploadService {
const event = new FileUploadEvent(file, FileUploadStatus.Progress); const event = new FileUploadEvent(file, FileUploadStatus.Progress);
this.fileUpload.next(event); this.fileUpload.next(event);
this.fileUploadProgress.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); const event = new FileUploadCompleteEvent(file, this.totalComplete, data, this.totalAborted);
this.fileUpload.next(event); this.fileUpload.next(event);
this.fileUploadComplete.next(event); this.fileUploadComplete.next(event);
this.queueChanged.next(this.queue);
} }
} }