All files / src/app/workspace-admin/files/iqb-files-upload-queue iqb-files-upload-queue.component.ts

43.47% Statements 10/23
10% Branches 1/10
42.85% Functions 3/7
43.47% Lines 10/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                      1x     1x 1x   1x 1x 1x 1x             1x       1x 1x                                                    
import {
  Component, EventEmitter, OnDestroy, QueryList, ViewChildren, Input, Output
} from '@angular/core';
import { IqbFilesUploadComponent } from '../iqb-files-upload/iqb-files-upload.component';
import { UploadStatus } from '../files.interfaces';
 
@Component({
  selector: 'tc-files-upload-queue',
  templateUrl: 'iqb-files-upload-queue.component.html',
  styleUrls: ['../iqb-files.scss']
})
export class IqbFilesUploadQueueComponent implements OnDestroy {
  @ViewChildren(IqbFilesUploadComponent) fileUploads!: QueryList<IqbFilesUploadComponent>;
 
  files: Array<File> = [];
  disableClearButton = true;
 
  @Input() fileAlias: string = '';
  @Input() folderName: string = '';
  @Input() folder: string = '';
  @Output() uploadCompleteEvent = new EventEmitter<IqbFilesUploadQueueComponent>();
 
  add(file: File): void {
    this.files.push(file);
  }
 
  removeAll(): void {
    this.files.splice(0, this.files.length);
  }
 
  ngOnDestroy(): void {
    if (this.files) {
      this.removeAll();
    }
  }
 
  removeFile(fileToRemove: IqbFilesUploadComponent): void {
    this.files.splice(fileToRemove.id, 1);
  }
 
  analyseStatus(): void {
    this.disableClearButton = true;
    let someoneisbusy = false;
    let countcomplete = 0;
    this.fileUploads.forEach(fileUpload => {
      if ((fileUpload.status === UploadStatus.ok) || (fileUpload.status === UploadStatus.error)) {
        countcomplete += 1;
      } else Iif (fileUpload.status === UploadStatus.busy) {
        someoneisbusy = true;
      }
    });
 
    Iif (countcomplete === this.fileUploads.length && !someoneisbusy && this.fileUploads.length > 0) {
      this.uploadCompleteEvent.emit();
      this.disableClearButton = false;
    }
  }
}