try fix refreshing files while uploading
This commit is contained in:
parent
8f0e520ba7
commit
903c757da0
@ -115,7 +115,7 @@ export class EditDossierDeletedDocumentsComponent extends ListingComponent<FileL
|
||||
const fileIds = files.map(f => f.fileId);
|
||||
await this._fileManagementService.restore(fileIds, this.dossier.id).toPromise();
|
||||
this._removeFromList(fileIds);
|
||||
await this._appStateService.reloadActiveDossierFiles();
|
||||
await this._appStateService.reloadDossierFiles();
|
||||
this.updateDossier.emit();
|
||||
}
|
||||
|
||||
|
||||
@ -52,11 +52,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</ng-container>
|
||||
|
||||
<ng-template #bulkActions let-dossier="dossier">
|
||||
<redaction-dossier-overview-bulk-actions (reload)="reloadFiles()" [dossier]="dossier"></redaction-dossier-overview-bulk-actions>
|
||||
</ng-template>
|
||||
<ng-template #bulkActions>
|
||||
<redaction-dossier-overview-bulk-actions (reload)="reloadFiles()" [dossier]="dossier"></redaction-dossier-overview-bulk-actions>
|
||||
</ng-template>
|
||||
</ng-container>
|
||||
|
||||
<ng-template #needsWorkFilterTemplate let-filter="filter">
|
||||
<redaction-type-filter [dossierTemplateId]="dossierTemplateId" [filter]="filter"></redaction-type-filter>
|
||||
|
||||
@ -477,11 +477,11 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
case 'reanalyse':
|
||||
await this._loadFileData(true);
|
||||
this._updateCanPerformActions();
|
||||
await this.appStateService.reloadActiveDossierFiles();
|
||||
await this.appStateService.reloadDossierFiles();
|
||||
return;
|
||||
|
||||
case 'exclude-pages':
|
||||
await this.appStateService.reloadActiveDossierFiles();
|
||||
await this.appStateService.reloadDossierFiles();
|
||||
await this._loadFileData(true);
|
||||
this._cleanupAndRedrawManualAnnotations$();
|
||||
await this._stampPDF();
|
||||
|
||||
@ -117,7 +117,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
|
||||
.catch(error => {
|
||||
this._toaster.error(_('error.http.generic'), { params: error });
|
||||
});
|
||||
await this.appStateService.reloadActiveDossierFiles();
|
||||
await this.appStateService.reloadDossierFiles();
|
||||
this.actionPerformed.emit('delete');
|
||||
this._loadingService.stop();
|
||||
},
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { ApplicationRef, Injectable, Injector } from '@angular/core';
|
||||
import { ApplicationRef, Injectable, Injector, OnDestroy } from '@angular/core';
|
||||
import { FileUploadModel } from '../model/file-upload.model';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { HttpErrorResponse, HttpEventType } from '@angular/common/http';
|
||||
import { interval, Subscription } from 'rxjs';
|
||||
import { interval, Subject, Subscription } from 'rxjs';
|
||||
import { ConfigService } from '@services/config.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { UploadDownloadDialogService } from './upload-download-dialog.service';
|
||||
@ -10,6 +10,7 @@ import { IFileUploadResult } from '@red/domain';
|
||||
import { isCsv } from '@utils/file-drop-utils';
|
||||
import { ErrorMessageService, GenericService, HeadersConfiguration, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import { FilesMapService } from '@services/entity-services/files-map.service';
|
||||
import { switchMap, tap, throttleTime } from 'rxjs/operators';
|
||||
|
||||
export interface ActiveUpload {
|
||||
subscription: Subscription;
|
||||
@ -17,15 +18,17 @@ export interface ActiveUpload {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class FileUploadService extends GenericService<IFileUploadResult> {
|
||||
export class FileUploadService extends GenericService<IFileUploadResult> implements OnDestroy {
|
||||
static readonly MAX_PARALLEL_UPLOADS = 5;
|
||||
files: FileUploadModel[] = [];
|
||||
groupedFiles: { [key: string]: FileUploadModel[] } = {};
|
||||
|
||||
activeUploads = 0;
|
||||
private _pendingUploads: FileUploadModel[] = [];
|
||||
private _activeUploads: ActiveUpload[] = [];
|
||||
|
||||
private readonly _fetchFiles$ = new Subject<string>();
|
||||
private readonly _subscriptions = new Subscription();
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _filesMapService: FilesMapService,
|
||||
@ -37,18 +40,23 @@ export class FileUploadService extends GenericService<IFileUploadResult> {
|
||||
protected readonly _injector: Injector,
|
||||
) {
|
||||
super(_injector, 'upload');
|
||||
interval(2500).subscribe(async () => {
|
||||
if (this.activeUploads > 0) {
|
||||
await this._appStateService.reloadActiveDossierFiles();
|
||||
}
|
||||
this._handleUploads();
|
||||
});
|
||||
const fileFetch$ = this._fetchFiles$.pipe(
|
||||
throttleTime(1500),
|
||||
switchMap(dossierId => this._appStateService.reloadDossierFiles(dossierId)),
|
||||
);
|
||||
this._subscriptions.add(fileFetch$.subscribe());
|
||||
const interval$ = interval(2500).pipe(tap(() => this._handleUploads()));
|
||||
this._subscriptions.add(interval$.subscribe());
|
||||
}
|
||||
|
||||
get activeDossierKeys() {
|
||||
return Object.keys(this.groupedFiles).filter(dossierId => this.groupedFiles[dossierId].length > 0);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this._subscriptions.unsubscribe();
|
||||
}
|
||||
|
||||
scheduleUpload(item: FileUploadModel) {
|
||||
if (!item.sizeError) {
|
||||
item.progress = 0;
|
||||
@ -119,6 +127,7 @@ export class FileUploadService extends GenericService<IFileUploadResult> {
|
||||
const index = this.files.indexOf(item);
|
||||
if (index > -1) {
|
||||
this._removeFileFromGroup(item);
|
||||
this._fetchFiles$.next(item.dossierId);
|
||||
this.files.splice(index, 1);
|
||||
}
|
||||
}
|
||||
@ -221,6 +230,7 @@ export class FileUploadService extends GenericService<IFileUploadResult> {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
this._activeUploads.splice(index, 1);
|
||||
this.activeUploads--;
|
||||
}
|
||||
|
||||
@ -161,9 +161,9 @@ export class AppStateService {
|
||||
this._appState.activeDictionaryType = null;
|
||||
}
|
||||
|
||||
async reloadActiveDossierFiles() {
|
||||
if (this._activeDossierId) {
|
||||
return this.getFiles(this._dossiersService.find(this._activeDossierId));
|
||||
async reloadDossierFiles(dossierId = this._activeDossierId) {
|
||||
if (dossierId) {
|
||||
return this.getFiles(this._dossiersService.find(dossierId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user