From fb3cc7fc5b8b1dec895cfeffff6b5edcaf67e051 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Mon, 7 Feb 2022 13:31:01 +0200 Subject: [PATCH] - split check for can disable or enable auto analysis in two different methods - split request method for toggle auto analysis in two methods, one for a single file and another for bulk --- .../dossier-overview-bulk-actions.component.ts | 4 ++-- .../services/bulk-actions.service.ts | 2 +- .../file-actions/file-actions.component.ts | 6 +++--- .../src/app/services/permissions.service.ts | 18 ++++++++++++------ .../src/app/services/reanalysis.service.ts | 18 ++++++++++++------ 5 files changed, 30 insertions(+), 18 deletions(-) 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 94197c8f0..5625c1cae 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 @@ -165,9 +165,9 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles); - this.canDisableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.selectedFiles, 'disable'); + this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles); - this.canEnableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.selectedFiles, 'enable'); + this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles); this.canOcr = this.selectedFiles.reduce((acc, file) => acc && file.canBeOCRed, true); 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..9ca37fb01 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 @@ -88,7 +88,7 @@ export class BulkActionsService { async toggleAutomaticAnalysis(files: File[], excluded?: boolean) { this._loadingService.start(); const fileIds = files.map(file => file.fileId); - await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysis(files[0].dossierId, fileIds, excluded)); + await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysisBulk(files[0].dossierId, fileIds, excluded)); 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 11b25cf28..215427cc3 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 @@ -326,7 +326,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, await firstValueFrom( this._reanalysisService.toggleAutomaticAnalysis( this.file.dossierId, - [this.file.fileId], + this.file.fileId, !this.file.excludedFromAutomaticAnalysis, ), ); @@ -376,8 +376,8 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, this.showDelete = this._permissionsService.canDeleteFile(this.file); this.showOCR = this.file.canBeOCRed; this.canReanalyse = this._permissionsService.canReanalyseFile(this.file); - this.canDisableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.file, 'disable'); - this.canEnableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.file, 'enable'); + this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis([this.file]); + this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis([this.file]); this.showStatusBar = !this.file.isError && !this.file.isPending && this.isDossierOverviewList; diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index 5dd6f6c51..b476bd189 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -32,9 +32,12 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canReanalyseFile(_file) && acc, true); } - canEnableDisableAutoAnalysis(file: File | File[], value: 'enable' | 'disable'): boolean { - const files = file instanceof File ? [file] : file; - return files.reduce((acc, _file) => this._canEnableDisableAutoAnalysis(_file, value) && acc, true); + canEnableAutoAnalysis(files: File[]): boolean { + return files.reduce((acc, _file) => this._canEnableAutoAnalysis(_file) && acc, true); + } + + canDisableAutoAnalysis(files: File[]): boolean { + return files.reduce((acc, _file) => this._canDisableAutoAnalysis(_file) && acc, true); } isFileAssignee(file: File): boolean { @@ -163,9 +166,12 @@ export class PermissionsService { return this.isReviewerOrApprover(file) || file.isNew || (file.isError && file.isNew); } - private _canEnableDisableAutoAnalysis(file: File, value: 'enable' | 'disable'): boolean { - const enableOrDisable = value === 'enable' ? file.excludedFromAutomaticAnalysis : !file.excludedFromAutomaticAnalysis; - return enableOrDisable && file.assignee === this._userService.currentUser.id; + private _canEnableAutoAnalysis(file: File): boolean { + return file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id; + } + + private _canDisableAutoAnalysis(file: File): boolean { + return !file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id; } private _canAssignToSelf(file: File, dossier: Dossier): boolean { diff --git a/apps/red-ui/src/app/services/reanalysis.service.ts b/apps/red-ui/src/app/services/reanalysis.service.ts index 5e193e27a..68607bb79 100644 --- a/apps/red-ui/src/app/services/reanalysis.service.ts +++ b/apps/red-ui/src/app/services/reanalysis.service.ts @@ -53,13 +53,19 @@ export class ReanalysisService extends GenericService { } @Validate() - toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() fileIds: string[], excluded?: boolean) { + toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() fileId: string, excluded?: boolean) { const queryParams: QueryParam[] = [{ key: 'excluded', value: !!excluded }]; - return this._post( - fileIds.length > 1 ? fileIds : {}, - `toggle-automatic-analysis/${dossierId}/${fileIds.length > 1 ? 'bulk' : fileIds[0]}`, - queryParams, - ).pipe(switchMap(() => this._filesService.loadAll(dossierId))); + return this._post({}, `toggle-automatic-analysis/${dossierId}/${fileId}`, queryParams).pipe( + switchMap(() => this._filesService.loadAll(dossierId)), + ); + } + + @Validate() + toggleAutomaticAnalysisBulk(@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)), + ); } @Validate()