updated and called replace file method from files map service instead of reloading all files from backend

This commit is contained in:
Valentin Mihai 2022-02-08 16:30:53 +02:00
parent f464c5e1fe
commit 8d1ad47520
6 changed files with 38 additions and 25 deletions

View File

@ -118,7 +118,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges {
},
{
type: ActionTypes.circleBtn,
action: $event => this._bulkActionsService.toggleAutomaticAnalysis(this.selectedFiles, true),
action: $event => this._bulkActionsService.toggleAutomaticAnalysis(this.selectedFiles),
tooltip: _('dossier-overview.disable-auto-analysis'),
icon: 'red:stop',
show: this.canDisableAutoAnalysis,

View File

@ -85,10 +85,9 @@ export class BulkActionsService {
this._loadingService.stop();
}
async toggleAutomaticAnalysis(files: File[], excluded?: boolean) {
async toggleAutomaticAnalysis(files: File[]) {
this._loadingService.start();
const fileIds = files.map(file => file.fileId);
await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysis(files[0].dossierId, fileIds, excluded));
await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysis(files[0].dossierId, files));
this._loadingService.stop();
}

View File

@ -323,13 +323,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
private async toggleAutomaticAnalysis($event: MouseEvent) {
$event.stopPropagation();
this._loadingService.start();
await firstValueFrom(
this._reanalysisService.toggleAutomaticAnalysis(
this.file.dossierId,
[this.file.fileId],
!this.file.excludedFromAutomaticAnalysis,
),
);
await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysis(this.file.dossierId, [this.file]));
this._loadingService.stop();
}

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { File } from '@red/domain';
import { File, IFile } from '@red/domain';
import { filter, startWith } from 'rxjs/operators';
import { RequiredParam, shareLast, Validate } from '@iqser/common-ui';
@ -66,14 +66,28 @@ export class FilesMapService {
}
}
replace(entity: File) {
const existingFile = this.get(entity.dossierId).find(file => file.fileId === entity.fileId);
if (existingFile.lastUpdated !== entity.lastUpdated) {
const all = this.get(entity.dossierId).filter(file => file.fileId !== entity.fileId);
this.set(entity.dossierId, [...all, entity]);
replace(entities: File[]) {
const dossierId = entities[0].dossierId;
const entityIds = entities.map(entity => entity.id);
let existingFiles = this.get(dossierId).filter(file => entityIds.includes(file.fileId));
entities = entities.filter(entity => {
const existingFile = existingFiles.find(existingFile => existingFile.id === entity.id);
return existingFile.lastUpdated !== entity.lastUpdated;
});
if (entities.length) {
const all = this.get(dossierId).filter(file => !entities.map(entity => entity.id).includes(file.id));
this.set(dossierId, [...all, ...entities]);
}
}
replaceFiles(files: File[], property: keyof IFile, generateValue: Function) {
const newFiles = files.map(
file =>
new File({ ...file, [property]: generateValue(file[property]), lastUpdated: new Date().toISOString() }, file.reviewerName),
);
this.replace(newFiles);
}
@Validate()
watch$(@RequiredParam() key: string, @RequiredParam() entityId: string): Observable<File> {
return this._entityChanged$.pipe(

View File

@ -31,7 +31,7 @@ export class FilesService extends EntitiesService<File, IFile> {
return super._getOne([dossierId, fileId]).pipe(
map(file => new File(file, this._userService.getNameForId(file.assignee))),
switchMap(file => this._dossierStatsService.getFor([dossierId]).pipe(mapTo(file))),
tap(file => this._filesMapService.replace(file)),
tap(file => this._filesMapService.replace([file])),
);
}

View File

@ -1,8 +1,9 @@
import { Injectable, Injector } from '@angular/core';
import { GenericService, List, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
import { IPageExclusionRequest } from '@red/domain';
import { switchMap } from 'rxjs/operators';
import { File, IPageExclusionRequest } from '@red/domain';
import { switchMap, tap } from 'rxjs/operators';
import { FilesService } from './entity-services/files.service';
import { FilesMapService } from './entity-services/files-map.service';
export interface ReanalyzeQueryParams {
force?: boolean;
@ -13,7 +14,11 @@ export interface ReanalyzeQueryParams {
providedIn: 'root',
})
export class ReanalysisService extends GenericService<unknown> {
constructor(protected readonly _injector: Injector, private readonly _filesService: FilesService) {
constructor(
protected readonly _injector: Injector,
private readonly _filesService: FilesService,
private readonly _filesMapService: FilesMapService,
) {
super(_injector, '');
}
@ -53,10 +58,11 @@ export class ReanalysisService extends GenericService<unknown> {
}
@Validate()
toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() fileIds: string[], excluded?: boolean) {
const queryParams: QueryParam[] = [{ key: 'excluded', value: !!excluded }];
return this._post(fileIds, 'toggle-automatic-analysis/bulk', queryParams).pipe(
switchMap(() => this._filesService.loadAll(dossierId)),
toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() files: File[]) {
const fileIds = files.map(file => file.id);
const queryParams: QueryParam[] = [{ key: 'excluded', value: !files[0].excludedFromAutomaticAnalysis }];
return this._post(fileIds, `toggle-automatic-analysis/${dossierId}/bulk`, queryParams).pipe(
tap(() => this._filesMapService.replaceFiles(files, 'excludedFromAutomaticAnalysis', value => !value)),
);
}