mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +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
Denys Vuika
parent
f372f4925d
commit
a277a00a96
@@ -54,7 +54,7 @@ export class FileModel {
|
|||||||
this.id = this.generateId();
|
this.id = this.generateId();
|
||||||
this.name = file.name;
|
this.name = file.name;
|
||||||
this.size = file.size;
|
this.size = file.size;
|
||||||
this.data = {};
|
this.data = null;
|
||||||
|
|
||||||
this.progress = {
|
this.progress = {
|
||||||
loaded: 0,
|
loaded: 0,
|
||||||
|
@@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
<span
|
<span
|
||||||
class="upload-dialog__title"
|
class="upload-dialog__title"
|
||||||
*ngIf="!uploadList.isUploadCompleted()">
|
*ngIf="!uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()">
|
||||||
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_PROGRESS' | translate: { completed: totalCompleted, total: filesUploadingList.length } }}
|
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_PROGRESS' | translate: { completed: totalCompleted, total: filesUploadingList.length } }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="upload-dialog__title"
|
class="upload-dialog__title"
|
||||||
*ngIf="uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()">
|
*ngIf="uploadList.isUploadCompleted()">
|
||||||
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_COMPLETED' | translate: { completed: totalCompleted, total: filesUploadingList.length } }}
|
{{ 'FILE_UPLOAD.MESSAGES.UPLOAD_COMPLETED' | translate: { completed: totalCompleted, total: filesUploadingList.length } }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -57,14 +57,14 @@
|
|||||||
|
|
||||||
<footer class="upload-dialog__actions">
|
<footer class="upload-dialog__actions">
|
||||||
<button
|
<button
|
||||||
*ngIf="!uploadList.isUploadCompleted()"
|
*ngIf="!uploadList.isUploadCompleted() && !uploadList.isUploadCancelled()"
|
||||||
md-button
|
md-button
|
||||||
(click)="uploadList.cancelAllFiles($event)">
|
(click)="uploadList.cancelAllFiles($event)">
|
||||||
{{ 'ADF_FILE_UPLOAD.BUTTON.CANCEL_ALL' | translate }}
|
{{ 'ADF_FILE_UPLOAD.BUTTON.CANCEL_ALL' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
*ngIf="uploadList.isUploadCompleted()"
|
*ngIf="uploadList.isUploadCompleted() || uploadList.isUploadCancelled()"
|
||||||
md-button
|
md-button
|
||||||
(click)="close($event)">
|
(click)="close($event)">
|
||||||
{{ 'ADF_FILE_UPLOAD.BUTTON.CLOSE' | translate }}
|
{{ 'ADF_FILE_UPLOAD.BUTTON.CLOSE' | translate }}
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
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 { Observable } from 'rxjs/Rx';
|
||||||
import { UploadModule } from '../../index';
|
import { UploadModule } from '../../index';
|
||||||
import { FileUploadService } from '../services/file-uploading.service';
|
import { FileUploadService } from '../services/file-uploading.service';
|
||||||
@@ -92,14 +92,14 @@ describe('FileUploadingListComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls remove method if file was uploaded', () => {
|
it('calls remove method if file was uploaded', () => {
|
||||||
file.status = 1;
|
file.status = FileUploadStatus.Complete;
|
||||||
component.cancelAllFiles(null);
|
component.cancelAllFiles(null);
|
||||||
|
|
||||||
expect(component.removeFile).toHaveBeenCalledWith(file);
|
expect(component.removeFile).toHaveBeenCalledWith(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls cancel method if file is in progress', () => {
|
it('calls cancel method if file is in progress', () => {
|
||||||
file.status = 3;
|
file.status = FileUploadStatus.Progress;
|
||||||
component.cancelAllFiles(null);
|
component.cancelAllFiles(null);
|
||||||
|
|
||||||
expect(component.cancelFileUpload).toHaveBeenCalledWith(file);
|
expect(component.cancelFileUpload).toHaveBeenCalledWith(file);
|
||||||
@@ -107,30 +107,105 @@ describe('FileUploadingListComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('isUploadCompleted()', () => {
|
describe('isUploadCompleted()', () => {
|
||||||
it('returns true', () => {
|
it('returns false when at least one file is in progress', () => {
|
||||||
file.status = 1;
|
component.files = <any> [
|
||||||
|
{ status: FileUploadStatus.Progress },
|
||||||
expect(component.isUploadCompleted()).toBe(true);
|
{ status: FileUploadStatus.Cancelled },
|
||||||
});
|
{ status: FileUploadStatus.Complete }
|
||||||
|
];
|
||||||
it('returns false', () => {
|
|
||||||
file.status = 3;
|
|
||||||
|
|
||||||
expect(component.isUploadCompleted()).toBe(false);
|
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()', () => {
|
describe('isUploadCancelled()', () => {
|
||||||
it('return true', () => {
|
it('return false when not all files are cancelled', () => {
|
||||||
file.status = 4;
|
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);
|
expect(component.isUploadCancelled()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return false', () => {
|
it('return true when all files are cancelled', () => {
|
||||||
file.status = 1;
|
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
|
* @returns {boolean} - false if there is at least one file in Progress
|
||||||
*/
|
*/
|
||||||
isUploadCompleted(): boolean {
|
isUploadCompleted(): boolean {
|
||||||
let isPending = false;
|
return !this.isUploadCancelled() &&
|
||||||
let isAllCompleted = true;
|
!!this.files.length &&
|
||||||
|
!this.files
|
||||||
for (let i = 0; i < this.files.length && !isPending; i++) {
|
.some(({status}) =>
|
||||||
let file = this.files[i];
|
status === FileUploadStatus.Starting ||
|
||||||
if (file.status === FileUploadStatus.Progress) {
|
status === FileUploadStatus.Progress ||
|
||||||
isPending = true;
|
status === FileUploadStatus.Pending
|
||||||
isAllCompleted = false;
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
return isAllCompleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,10 +106,13 @@ export class FileUploadingListComponent {
|
|||||||
* @returns {boolean} - false if there is at least one file in Progress
|
* @returns {boolean} - false if there is at least one file in Progress
|
||||||
*/
|
*/
|
||||||
isUploadCancelled(): boolean {
|
isUploadCancelled(): boolean {
|
||||||
return this.files
|
return !!this.files.length &&
|
||||||
.filter((file) => file.status !== FileUploadStatus.Error)
|
this.files
|
||||||
.every((file) => file.status === FileUploadStatus.Cancelled
|
.every(({status}) =>
|
||||||
|| file.status === FileUploadStatus.Aborted);
|
status === FileUploadStatus.Aborted ||
|
||||||
|
status === FileUploadStatus.Cancelled ||
|
||||||
|
status === FileUploadStatus.Error
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadErrorFiles(): FileModel[] {
|
uploadErrorFiles(): FileModel[] {
|
||||||
|
Reference in New Issue
Block a user