Upload csv order
This commit is contained in:
parent
6b7c77c363
commit
54d33bebce
@ -8,6 +8,7 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { UploadDownloadDialogService } from './upload-download-dialog.service';
|
||||
import { toNumber } from '@utils/functions';
|
||||
import { UploadControllerService } from '@redaction/red-ui-http';
|
||||
import { isCsv } from '@utils/file-drop-utils';
|
||||
|
||||
export interface ActiveUpload {
|
||||
subscription: Subscription;
|
||||
@ -135,18 +136,23 @@ export class FileUploadService {
|
||||
this._pendingUploads.length > 0
|
||||
) {
|
||||
let cnt = FileUploadService.MAX_PARALLEL_UPLOADS - this._activeUploads.length;
|
||||
while (cnt > 0) {
|
||||
cnt--;
|
||||
const poppedFileUploadModel = this._pendingUploads.shift();
|
||||
if (poppedFileUploadModel) {
|
||||
const subscription = this._createSubscription(poppedFileUploadModel);
|
||||
this._activeUploads.push({
|
||||
subscription: subscription,
|
||||
fileUploadModel: poppedFileUploadModel
|
||||
});
|
||||
} else {
|
||||
while (cnt > 0 && this._pendingUploads.length > 0) {
|
||||
// Only schedule CSVs when no other file types in queue.
|
||||
// CSVs are sorted at the end of `_pendingUploads`.
|
||||
if (
|
||||
isCsv(this._pendingUploads[0]) &&
|
||||
this._activeUploads.filter(upload => !isCsv(upload.fileUploadModel)).length > 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
cnt--;
|
||||
const poppedFileUploadModel = this._pendingUploads.shift();
|
||||
const subscription = this._createSubscription(poppedFileUploadModel);
|
||||
this._activeUploads.push({
|
||||
subscription: subscription,
|
||||
fileUploadModel: poppedFileUploadModel
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,7 +165,7 @@ export class FileUploadService {
|
||||
'events',
|
||||
true
|
||||
);
|
||||
const subscription = obs.subscribe(
|
||||
return obs.subscribe(
|
||||
async event => {
|
||||
if (event.type === HttpEventType.UploadProgress) {
|
||||
uploadFile.progress = Math.round(
|
||||
@ -198,7 +204,6 @@ export class FileUploadService {
|
||||
}
|
||||
}
|
||||
);
|
||||
return subscription;
|
||||
}
|
||||
|
||||
private _removeUpload(fileUploadModel: FileUploadModel) {
|
||||
|
||||
@ -30,6 +30,13 @@ export function handleFileDrop(
|
||||
}
|
||||
}
|
||||
|
||||
export function isCsv(file: FileUploadModel): boolean {
|
||||
return (
|
||||
file.file.type?.toLowerCase() === 'text/csv' ||
|
||||
file.file.name.toLowerCase().endsWith('.csv')
|
||||
);
|
||||
}
|
||||
|
||||
export function convertFiles(files: FileList | File[], dossier: DossierWrapper): FileUploadModel[] {
|
||||
let uploadFiles: FileUploadModel[] = [];
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
@ -53,9 +60,9 @@ export function convertFiles(files: FileList | File[], dossier: DossierWrapper):
|
||||
file.file.name.toLowerCase().endsWith('.pdf') ||
|
||||
file.file.type?.toLowerCase() === 'application/zip' ||
|
||||
file.file.name.toLowerCase().endsWith('.zip') ||
|
||||
file.file.type?.toLowerCase() === 'text/csv' ||
|
||||
file.file.name.toLowerCase().endsWith('.csv')
|
||||
isCsv(file)
|
||||
);
|
||||
uploadFiles.sort((a, b) => a.size - b.size);
|
||||
uploadFiles.sort(a => (isCsv(a) ? 1 : -1));
|
||||
return uploadFiles;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user