diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts index 5625c1cae..90d3354dd 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts @@ -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, diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/services/bulk-actions.service.ts b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/services/bulk-actions.service.ts index 59b7c76cb..b72dbe887 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/services/bulk-actions.service.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/services/bulk-actions.service.ts @@ -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(); } diff --git a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts index 242360812..e084f178c 100644 --- a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts @@ -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(); } diff --git a/apps/red-ui/src/app/services/entity-services/files-map.service.ts b/apps/red-ui/src/app/services/entity-services/files-map.service.ts index 07936d006..372fadc42 100644 --- a/apps/red-ui/src/app/services/entity-services/files-map.service.ts +++ b/apps/red-ui/src/app/services/entity-services/files-map.service.ts @@ -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 { return this._entityChanged$.pipe( diff --git a/apps/red-ui/src/app/services/entity-services/files.service.ts b/apps/red-ui/src/app/services/entity-services/files.service.ts index 258c93870..f28eeb296 100644 --- a/apps/red-ui/src/app/services/entity-services/files.service.ts +++ b/apps/red-ui/src/app/services/entity-services/files.service.ts @@ -31,7 +31,7 @@ export class FilesService extends EntitiesService { 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])), ); } diff --git a/apps/red-ui/src/app/services/reanalysis.service.ts b/apps/red-ui/src/app/services/reanalysis.service.ts index 479cd0ee2..6479eaa3d 100644 --- a/apps/red-ui/src/app/services/reanalysis.service.ts +++ b/apps/red-ui/src/app/services/reanalysis.service.ts @@ -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 { - 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 { } @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)), ); }