mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1348] Upload Dialog - 'Cancel All' button does not render (#2192)
* refactored isUploadCancelled and isUploadCompleted * improved checks
This commit is contained in:
committed by
Mario Romano
parent
e6ae21a0bc
commit
734c1260ca
@@ -54,7 +54,7 @@ export class FileModel {
|
||||
this.id = this.generateId();
|
||||
this.name = file.name;
|
||||
this.size = file.size;
|
||||
this.data = {};
|
||||
this.data = null;
|
||||
|
||||
this.progress = {
|
||||
loaded: 0,
|
||||
|
@@ -11,26 +11,26 @@
|
||||
{{ isDialogMinimized ? 'keyboard_arrow_up' : 'keyboard_arrow_down' }}
|
||||
</md-icon>
|
||||
|
||||
<span
|
||||
<span
|
||||
class="upload-dialog__title"
|
||||
*ngIf="!uploadList.isUploadCompleted()">
|
||||
*ngIf="!uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()">
|
||||
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_PROGRESS' | translate: { completed: totalCompleted, total: filesUploadingList.length } }}
|
||||
</span>
|
||||
|
||||
<span
|
||||
<span
|
||||
class="upload-dialog__title"
|
||||
*ngIf="uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()">
|
||||
*ngIf="uploadList.isUploadCompleted()">
|
||||
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_COMPLETED' | translate: { completed: totalCompleted, total: filesUploadingList.length } }}
|
||||
</span>
|
||||
|
||||
<span
|
||||
<span
|
||||
class="upload-dialog__title"
|
||||
*ngIf="uploadList.isUploadCancelled()">
|
||||
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_CANCELED' | translate }}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<section
|
||||
<section
|
||||
class="upload-dialog__info"
|
||||
*ngIf="uploadList.totalErrorFiles()">
|
||||
{{
|
||||
@@ -56,15 +56,15 @@
|
||||
</section>
|
||||
|
||||
<footer class="upload-dialog__actions">
|
||||
<button
|
||||
*ngIf="!uploadList.isUploadCompleted()"
|
||||
<button
|
||||
*ngIf="!uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()"
|
||||
md-button
|
||||
(click)="uploadList.cancelAllFiles($event)">
|
||||
{{ 'ADF_FILE_UPLOAD.BUTTON.CANCEL_ALL' | translate }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
*ngIf="uploadList.isUploadCompleted()"
|
||||
*ngIf="uploadList.isUploadCompleted() || uploadList.isUploadCancelled()"
|
||||
md-button
|
||||
(click)="close($event)">
|
||||
{{ 'ADF_FILE_UPLOAD.BUTTON.CLOSE' | translate }}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoTranslationService, FileModel, NodesApiService, NotificationService, UploadService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, FileModel, FileUploadStatus, NodesApiService, NotificationService, UploadService } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { UploadModule } from '../../index';
|
||||
import { FileUploadService } from '../services/file-uploading.service';
|
||||
@@ -92,14 +92,14 @@ describe('FileUploadingListComponent', () => {
|
||||
});
|
||||
|
||||
it('calls remove method if file was uploaded', () => {
|
||||
file.status = 1;
|
||||
file.status = FileUploadStatus.Complete;
|
||||
component.cancelAllFiles(null);
|
||||
|
||||
expect(component.removeFile).toHaveBeenCalledWith(file);
|
||||
});
|
||||
|
||||
it('calls cancel method if file is in progress', () => {
|
||||
file.status = 3;
|
||||
file.status = FileUploadStatus.Progress;
|
||||
component.cancelAllFiles(null);
|
||||
|
||||
expect(component.cancelFileUpload).toHaveBeenCalledWith(file);
|
||||
@@ -107,30 +107,105 @@ describe('FileUploadingListComponent', () => {
|
||||
});
|
||||
|
||||
describe('isUploadCompleted()', () => {
|
||||
it('returns true', () => {
|
||||
file.status = 1;
|
||||
|
||||
expect(component.isUploadCompleted()).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false', () => {
|
||||
file.status = 3;
|
||||
it('returns false when at least one file is in progress', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Progress },
|
||||
{ status: FileUploadStatus.Cancelled },
|
||||
{ status: FileUploadStatus.Complete }
|
||||
];
|
||||
|
||||
expect(component.isUploadCompleted()).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false when at least one file is in pending', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Pending },
|
||||
{ status: FileUploadStatus.Cancelled },
|
||||
{ status: FileUploadStatus.Complete }
|
||||
];
|
||||
|
||||
expect(component.isUploadCompleted()).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false when none of the files is completed', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Error },
|
||||
{ status: FileUploadStatus.Error },
|
||||
{ status: FileUploadStatus.Cancelled }
|
||||
];
|
||||
|
||||
expect(component.isUploadCompleted()).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true when none of the files is in progress', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Error },
|
||||
{ status: FileUploadStatus.Cancelled },
|
||||
{ status: FileUploadStatus.Complete }
|
||||
];
|
||||
|
||||
expect(component.isUploadCompleted()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isUploadCancelled()', () => {
|
||||
it('return true', () => {
|
||||
file.status = 4;
|
||||
it('return false when not all files are cancelled', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Complete },
|
||||
{ status: FileUploadStatus.Cancelled },
|
||||
{ status: FileUploadStatus.Error }
|
||||
];
|
||||
|
||||
expect(component.isUploadCancelled()).toBe(false);
|
||||
});
|
||||
|
||||
it('return false when there are no cancelled files', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Complete },
|
||||
{ status: FileUploadStatus.Error },
|
||||
{ status: FileUploadStatus.Error }
|
||||
];
|
||||
|
||||
expect(component.isUploadCancelled()).toBe(false);
|
||||
});
|
||||
|
||||
it('return false when there is at leat one file in progress', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Progress },
|
||||
{ status: FileUploadStatus.Error },
|
||||
{ status: FileUploadStatus.Error }
|
||||
];
|
||||
|
||||
expect(component.isUploadCancelled()).toBe(false);
|
||||
});
|
||||
|
||||
it('return false when there is at leat one file in pendding', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Pending },
|
||||
{ status: FileUploadStatus.Error },
|
||||
{ status: FileUploadStatus.Error }
|
||||
];
|
||||
|
||||
expect(component.isUploadCancelled()).toBe(false);
|
||||
});
|
||||
|
||||
it('return true when all files are aborted', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Aborted },
|
||||
{ status: FileUploadStatus.Aborted }
|
||||
];
|
||||
|
||||
expect(component.isUploadCancelled()).toBe(true);
|
||||
});
|
||||
|
||||
it('return false', () => {
|
||||
file.status = 1;
|
||||
it('return true when all files are cancelled', () => {
|
||||
component.files = <any> [
|
||||
{ status: FileUploadStatus.Cancelled },
|
||||
{ status: FileUploadStatus.Cancelled },
|
||||
{ status: FileUploadStatus.Error }
|
||||
];
|
||||
|
||||
expect(component.isUploadCancelled()).toBe(false);
|
||||
expect(component.isUploadCancelled()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -91,17 +91,14 @@ export class FileUploadingListComponent {
|
||||
* @returns {boolean} - false if there is at least one file in Progress
|
||||
*/
|
||||
isUploadCompleted(): boolean {
|
||||
let isPending = false;
|
||||
let isAllCompleted = true;
|
||||
|
||||
for (let i = 0; i < this.files.length && !isPending; i++) {
|
||||
let file = this.files[i];
|
||||
if (file.status === FileUploadStatus.Progress) {
|
||||
isPending = true;
|
||||
isAllCompleted = false;
|
||||
}
|
||||
}
|
||||
return isAllCompleted;
|
||||
return !this.isUploadCancelled() &&
|
||||
!!this.files.length &&
|
||||
!this.files
|
||||
.some(({status}) =>
|
||||
status === FileUploadStatus.Starting ||
|
||||
status === FileUploadStatus.Progress ||
|
||||
status === FileUploadStatus.Pending
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,10 +106,13 @@ export class FileUploadingListComponent {
|
||||
* @returns {boolean} - false if there is at least one file in Progress
|
||||
*/
|
||||
isUploadCancelled(): boolean {
|
||||
return this.files
|
||||
.filter((file) => file.status !== FileUploadStatus.Error)
|
||||
.every((file) => file.status === FileUploadStatus.Cancelled
|
||||
|| file.status === FileUploadStatus.Aborted);
|
||||
return !!this.files.length &&
|
||||
this.files
|
||||
.every(({status}) =>
|
||||
status === FileUploadStatus.Aborted ||
|
||||
status === FileUploadStatus.Cancelled ||
|
||||
status === FileUploadStatus.Error
|
||||
);
|
||||
}
|
||||
|
||||
uploadErrorFiles(): FileModel[] {
|
||||
|
Reference in New Issue
Block a user