diff --git a/src/app/service-code-way/service-code-way.component.html b/src/app/service-code-way/service-code-way.component.html index 50c18f3c..71936fb7 100644 --- a/src/app/service-code-way/service-code-way.component.html +++ b/src/app/service-code-way/service-code-way.component.html @@ -32,8 +32,8 @@ -
+ {{numberOfCopies}}/{{options.concurrency}}
{{state | async | json}}
diff --git a/src/app/service-code-way/service-code-way.component.ts b/src/app/service-code-way/service-code-way.component.ts index 5b0dc795..2baa89a5 100644 --- a/src/app/service-code-way/service-code-way.component.ts +++ b/src/app/service-code-way/service-code-way.component.ts @@ -6,6 +6,8 @@ import { takeUntil } from 'rxjs/operators'; import { UploadxOptions, UploadState, UploadxService, UploadItem } from '../../uploadx'; import { environment } from '../../environments/environment'; import { Ufile } from '../ufile'; +import {Uploader} from '../../uploadx/src/uploader'; +import {UploadStatus} from '../../uploadx/src/interfaces'; @Component({ selector: 'app-service-way', @@ -23,6 +25,7 @@ export class ServiceCodeWayComponent implements OnDestroy, OnInit { chunkSize: 1024 * 256 * 8 }; private ngUnsubscribe: Subject = new Subject(); + numberOfCopies = 0; @ViewChild('file', { read: ElementRef }) fileInput: ElementRef; @@ -72,6 +75,8 @@ export class ServiceCodeWayComponent implements OnDestroy, OnInit { onUpload(uploadsOutStream: Observable) { this.state = uploadsOutStream; uploadsOutStream.pipe(takeUntil(this.ngUnsubscribe)).subscribe((item: UploadState) => { + this.numberOfCopies = this.uploadService.queue + .filter((uploader: Uploader) => uploader.status === 'uploading' as UploadStatus).length; const index = this.uploads.findIndex(f => f.uploadId === item.uploadId); if (item.status === 'added') { const cfg: UploadItem = { diff --git a/src/uploadx/src/uploadx.service.ts b/src/uploadx/src/uploadx.service.ts index c243cd94..5b06acb6 100644 --- a/src/uploadx/src/uploadx.service.ts +++ b/src/uploadx/src/uploadx.service.ts @@ -63,9 +63,6 @@ export class UploadxService { */ private async autoUploadFiles() { if (this.autoUpload) { - for (const upload of this.queue) { - await upload.upload(); - } this.processQueue(); } } @@ -92,7 +89,8 @@ export class UploadxService { break; case 'upload': const uploadId = event.uploadId || event.itemOptions.uploadId; - this.queue.find(f => f.uploadId === uploadId).upload(event.itemOptions); + // noinspection TsLint + (this.concurrency - this.runningProcess() > 0) && this.queue.find(f => f.uploadId === uploadId).upload(event.itemOptions); this.processQueue(); break; case 'cancel': @@ -109,13 +107,17 @@ export class UploadxService { * Queue management */ private processQueue() { - const running = this.queue.filter((uploader: Uploader) => uploader.status === 'uploading'); + const running = this.runningProcess(); this.queue .filter((uploader: Uploader) => uploader.status === 'queue') - .slice(0, Math.max(this.concurrency - running.length, 0)) + .slice(0, Math.max(this.concurrency - running, 0)) .forEach((uploader: Uploader) => { uploader.upload(); }); } + + runningProcess(): number { + return this.queue.filter((uploader: Uploader) => uploader.status === 'uploading').length; + } }