From 698e0c1a3bab0db0ff6cc7ecfdb438830614e7e3 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 2 Feb 2022 22:07:29 +0200 Subject: [PATCH 1/7] WIP on enabling/disabling automatic analysis process for a document --- ...dossier-overview-bulk-actions.component.ts | 20 +++++++++++ .../services/bulk-actions.service.ts | 7 ++++ .../file-workload.component.html | 8 ++++- .../file-workload.component.scss | 15 ++++++-- .../file-actions/file-actions.component.ts | 35 +++++++++++++++++-- .../src/app/modules/icons/icons.module.ts | 3 ++ .../src/app/services/permissions.service.ts | 18 ++++++++++ .../src/app/services/reanalysis.service.ts | 10 ++++++ apps/red-ui/src/assets/i18n/de.json | 3 ++ apps/red-ui/src/assets/i18n/en.json | 3 ++ .../src/assets/icons/general/denied.svg | 7 ++++ apps/red-ui/src/assets/icons/general/play.svg | 7 ++++ apps/red-ui/src/assets/icons/general/stop.svg | 5 +++ libs/red-domain/src/lib/files/file.model.ts | 2 ++ libs/red-domain/src/lib/files/file.ts | 4 +++ 15 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 apps/red-ui/src/assets/icons/general/denied.svg create mode 100644 apps/red-ui/src/assets/icons/general/play.svg create mode 100644 apps/red-ui/src/assets/icons/general/stop.svg 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 c9730e14b..e46967dab 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 @@ -25,6 +25,8 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { canAssign: boolean; canDelete: boolean; canReanalyse: boolean; + canDisableAutoAnalysis: boolean; + canEnableAutoAnalysis: boolean; canOcr: boolean; canSetToUnderReview: boolean; canSetToUnderApproval: boolean; @@ -114,6 +116,20 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { icon: 'iqser:refresh', show: this.canReanalyse && this.analysisForced, }, + { + type: ActionTypes.circleBtn, + action: $event => this._bulkActionsService.toggleAutomaticAnalysis(this.selectedFiles, true), + tooltip: _('dossier-overview.disable-auto-analysis'), + icon: 'red:stop', + show: this.canDisableAutoAnalysis, + }, + { + type: ActionTypes.circleBtn, + action: $event => this._bulkActionsService.toggleAutomaticAnalysis(this.selectedFiles), + tooltip: _('dossier-overview.enable-auto-analysis'), + icon: 'red:play', + show: this.canEnableAutoAnalysis, + }, ].filter(btn => btn.show); } @@ -149,6 +165,10 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles); + this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles); + + this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles); + this.canOcr = this.selectedFiles.reduce((acc, file) => acc && file.canBeOCRed, true); this.canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles) && !isWorkflow; 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 a0b27b673..8ca255a02 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 @@ -83,6 +83,13 @@ export class BulkActionsService { this._loadingService.stop(); } + 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)); + this._loadingService.stop(); + } + async backToUnderReview(files: File[]): Promise { this._loadingService.start(); await firstValueFrom( diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html index 71c41366d..050024486 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html @@ -31,12 +31,18 @@
-
+ +
diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.scss b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.scss index 78609b428..8407e6b6c 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.scss +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.scss @@ -1,13 +1,13 @@ @use 'apps/red-ui/src/assets/styles/variables'; @use 'libs/common-ui/src/assets/styles/common-mixins'; -.read-only { +.banner { padding: 13px 16px; - background-color: variables.$primary; color: variables.$white; justify-content: space-between; - .read-only-text { + .read-only-text, + .disabled-auto-analysis-text { font-size: 11px; font-weight: 600; line-height: 14px; @@ -33,8 +33,17 @@ } } +.read-only { + background-color: variables.$primary; +} + +.disabled-auto-analysis { + background-color: variables.$yellow-2; +} + .right-content { flex-direction: column; + overflow: hidden; .no-annotations-buttons-container { display: flex; 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 ae697a33e..03a3494b1 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 @@ -62,6 +62,8 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, showDelete = false; showOCR = false; canReanalyse = false; + canDisableAutoAnalysis = false; + canEnableAutoAnalysis = false; showUnderReview = false; showUnderApproval = false; showApprove = false; @@ -182,6 +184,20 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, disabled: !this.file.canBeApproved, show: this.showApprove, }, + { + type: ActionTypes.circleBtn, + action: $event => this.toggleAutomaticAnalysis($event), + tooltip: _('dossier-overview.disable-auto-analysis'), + icon: 'red:stop', + show: this.canDisableAutoAnalysis, + }, + { + type: ActionTypes.circleBtn, + action: $event => this.toggleAutomaticAnalysis($event), + tooltip: _('dossier-overview.enable-auto-analysis'), + icon: 'red:play', + show: this.canEnableAutoAnalysis, + }, { type: ActionTypes.circleBtn, action: $event => this._setFileUnderApproval($event), @@ -296,12 +312,23 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, } private async _reanalyseFile($event?: MouseEvent) { - if ($event) { - $event.stopPropagation(); - } + $event?.stopPropagation(); await firstValueFrom(this._reanalysisService.reanalyzeFilesForDossier([this.file.fileId], this.file.dossierId, true)); } + private async toggleAutomaticAnalysis($event: MouseEvent) { + $event.stopPropagation(); + this._loadingService.start(); + await firstValueFrom( + this._reanalysisService.toggleAutomaticAnalysis( + this.file.dossierId, + [this.file.fileId], + !this.file.excludedFromAutomaticAnalysis, + ), + ); + this._loadingService.stop(); + } + private async _setFileUnderApproval($event: MouseEvent) { $event.stopPropagation(); await this._fileAssignService.assignApprover($event, this.file, true); @@ -345,6 +372,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.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/modules/icons/icons.module.ts b/apps/red-ui/src/app/modules/icons/icons.module.ts index cf4598843..7d808ccd7 100644 --- a/apps/red-ui/src/app/modules/icons/icons.module.ts +++ b/apps/red-ui/src/app/modules/icons/icons.module.ts @@ -24,6 +24,7 @@ export class IconsModule { 'comment-fill', 'csv', 'dictionary', + 'denied', 'double-chevron-right', 'enter', 'entries', @@ -44,6 +45,7 @@ export class IconsModule { 'new-tab', 'notification', 'page', + 'play', 'preview', 'put-back', 'read-only', @@ -59,6 +61,7 @@ export class IconsModule { 'secret', 'status', 'status-info', + 'stop', 'template', 'thumb-down', 'thumb-up', diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index a69c5e6a7..0d82eb7c0 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -32,6 +32,16 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canReanalyseFile(_file) && acc, true); } + canDisableAutoAnalysis(file: File | File[]): boolean { + const files = file instanceof File ? [file] : file; + return files.reduce((acc, _file) => this._canDisableAutoAnalysis(_file) && acc, true); + } + + canEnableAutoAnalysis(file: File | File[]): boolean { + const files = file instanceof File ? [file] : file; + return files.reduce((acc, _file) => this._canEnableAutoAnalysis(_file) && acc, true); + } + isFileAssignee(file: File): boolean { return file.assignee === this._userService.currentUser.id; } @@ -158,6 +168,14 @@ export class PermissionsService { return this.isReviewerOrApprover(file) || file.isNew || (file.isError && file.isNew); } + private _canDisableAutoAnalysis(file: File): boolean { + return !file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id; + } + + private _canEnableAutoAnalysis(file: File): boolean { + return file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id; + } + private _canAssignToSelf(file: File, dossier: Dossier): boolean { const precondition = this.isDossierMember(dossier) && !this.isFileAssignee(file) && !file.isError && !file.isProcessing; return precondition && (file.isNew || file.isUnderReview || (file.isUnderApproval && this.isApprover(dossier))); diff --git a/apps/red-ui/src/app/services/reanalysis.service.ts b/apps/red-ui/src/app/services/reanalysis.service.ts index 1707aca5a..3a3bded63 100644 --- a/apps/red-ui/src/app/services/reanalysis.service.ts +++ b/apps/red-ui/src/app/services/reanalysis.service.ts @@ -44,6 +44,16 @@ 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.length > 1 ? fileIds : {}, + `toggle-automatic-analysis/${dossierId}/${fileIds.length > 1 ? 'bulk' : fileIds[0]}`, + queryParams, + ).pipe(switchMap(() => this._filesService.loadAll(dossierId))); + } + @Validate() ocrFiles(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string) { return this._post(fileIds, `ocr/reanalyze/${dossierId}/bulk`).pipe(switchMap(() => this._filesService.loadAll(dossierId))); diff --git a/apps/red-ui/src/assets/i18n/de.json b/apps/red-ui/src/assets/i18n/de.json index 33bd2c739..e1926fb1b 100644 --- a/apps/red-ui/src/assets/i18n/de.json +++ b/apps/red-ui/src/assets/i18n/de.json @@ -608,6 +608,7 @@ "placeholder": "Begründung" } }, + "disabled-auto-analysis": "", "document-info": { "save": "Dokumenteninformation speichern", "title": "Datei-Attribute anlegen" @@ -719,6 +720,7 @@ "delete": { "action": "Datei löschen" }, + "disable-auto-analysis": "", "dossier-details": { "attributes": { "expand": "{count} {count, plural, one{benutzerdefiniertes Attribut} other{benutzerdefinierte Attribute}}", @@ -742,6 +744,7 @@ }, "download-file": "Herunterladen", "download-file-disabled": "Nur genehmigte Dateien können heruntergeladen werden", + "enable-auto-analysis": "", "file-listing": { "file-entry": { "file-error": "Reanalyse erforderlich", diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index 5f60b49ec..7f6941b71 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -608,6 +608,7 @@ "placeholder": "Reason" } }, + "disabled-auto-analysis": "Automatic analysys is disabled", "document-info": { "save": "Save Document Info", "title": "Introduce File Attributes" @@ -719,6 +720,7 @@ "delete": { "action": "Delete File" }, + "disable-auto-analysis": "Disable auto-analysis", "dossier-details": { "attributes": { "expand": "{count} custom {count, plural, one{attribute} other{attributes}}", @@ -742,6 +744,7 @@ }, "download-file": "Download", "download-file-disabled": "You need to be approver in the dossier and the {count, plural, one{file needs} other{files need}} to be approved in order to download.", + "enable-auto-analysis": "Enable auto-analysis", "file-listing": { "file-entry": { "file-error": "Re-processing required", diff --git a/apps/red-ui/src/assets/icons/general/denied.svg b/apps/red-ui/src/assets/icons/general/denied.svg new file mode 100644 index 000000000..6530d96ff --- /dev/null +++ b/apps/red-ui/src/assets/icons/general/denied.svg @@ -0,0 +1,7 @@ + + + + + Svg Vector Icons : http://www.onlinewebfonts.com/icon + + \ No newline at end of file diff --git a/apps/red-ui/src/assets/icons/general/play.svg b/apps/red-ui/src/assets/icons/general/play.svg new file mode 100644 index 000000000..1b37e3874 --- /dev/null +++ b/apps/red-ui/src/assets/icons/general/play.svg @@ -0,0 +1,7 @@ + + + + + Svg Vector Icons : http://www.onlinewebfonts.com/icon + + \ No newline at end of file diff --git a/apps/red-ui/src/assets/icons/general/stop.svg b/apps/red-ui/src/assets/icons/general/stop.svg new file mode 100644 index 000000000..db10a7bb9 --- /dev/null +++ b/apps/red-ui/src/assets/icons/general/stop.svg @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/libs/red-domain/src/lib/files/file.model.ts b/libs/red-domain/src/lib/files/file.model.ts index ad1c1e501..735b5cdc1 100644 --- a/libs/red-domain/src/lib/files/file.model.ts +++ b/libs/red-domain/src/lib/files/file.model.ts @@ -16,6 +16,7 @@ export class File extends Entity implements IFile { readonly dossierDictionaryVersion?: number; readonly dossierId: string; readonly excluded: boolean; + readonly excludedFromAutomaticAnalysis: boolean; readonly fileAttributes?: FileAttributes; readonly fileId: string; readonly filename: string; @@ -68,6 +69,7 @@ export class File extends Entity implements IFile { this.dossierDictionaryVersion = file.dossierDictionaryVersion; this.dossierId = file.dossierId; this.excluded = !!file.excluded; + this.excludedFromAutomaticAnalysis = Math.random() < 0.5; //!!file.excludedFromAutomaticAnalysis; this.fileAttributes = file.fileAttributes; this.fileId = file.fileId; this.filename = file.filename; diff --git a/libs/red-domain/src/lib/files/file.ts b/libs/red-domain/src/lib/files/file.ts index a93082aa8..6208d4fab 100644 --- a/libs/red-domain/src/lib/files/file.ts +++ b/libs/red-domain/src/lib/files/file.ts @@ -46,6 +46,10 @@ export interface IFile { * Shows if the file was excluded from analysis. */ readonly excluded?: boolean; + /** + * Shows if the file was excluded from automatic analysis. + */ + readonly excludedFromAutomaticAnalysis?: boolean; /** * Set of excluded pages for this file. */ From dc5d898ec96b2eb983bde42e2ada455ded0db292 Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 3 Feb 2022 12:06:05 +0200 Subject: [PATCH 2/7] added back "reanalyse" button when automatic analysis is disabled --- .../dossier-overview-bulk-actions.component.ts | 6 +++--- .../file-actions/file-actions.component.ts | 9 +++++---- .../src/app/services/permissions.service.ts | 18 +++++------------- libs/common-ui | 2 +- libs/red-domain/src/lib/files/file.model.ts | 2 +- 5 files changed, 15 insertions(+), 22 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 e46967dab..94197c8f0 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 @@ -114,7 +114,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { action: () => this._bulkActionsService.reanalyse(this.selectedFiles), tooltip: _('dossier-overview.bulk.reanalyse'), icon: 'iqser:refresh', - show: this.canReanalyse && this.analysisForced, + show: this.canReanalyse && (this.analysisForced || this.canEnableAutoAnalysis), }, { type: ActionTypes.circleBtn, @@ -165,9 +165,9 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles); - this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles); + this.canDisableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.selectedFiles, 'disable'); - this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles); + this.canEnableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.selectedFiles, 'enable'); this.canOcr = this.selectedFiles.reduce((acc, file) => acc && file.canBeOCRed, true); 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 03a3494b1..7f4dc6cc7 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 @@ -372,8 +372,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.canDisableAutoAnalysis(this.file); - this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.file); + this.canDisableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.file, 'disable'); + this.canEnableAutoAnalysis = this._permissionsService.canEnableDisableAutoAnalysis(this.file, 'enable'); this.showStatusBar = !this.file.isError && !this.file.isPending && this.isDossierOverviewList; @@ -382,8 +382,9 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, (this._permissionsService.canAssignUser(this.file) || this._permissionsService.canUnassignUser(this.file)) && this.isDossierOverview; - this.showReanalyseFilePreview = this.canReanalyse && this.isFilePreview && this.analysisForced; - this.showReanalyseDossierOverview = this.canReanalyse && this.isDossierOverview && this.analysisForced; + this.showReanalyseFilePreview = this.canReanalyse && this.isFilePreview && (this.analysisForced || this.canEnableAutoAnalysis); + this.showReanalyseDossierOverview = + this.canReanalyse && this.isDossierOverview && (this.analysisForced || this.canEnableAutoAnalysis); this.buttons = this._buttons; diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index 0d82eb7c0..6d8baf3ee 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -32,14 +32,9 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canReanalyseFile(_file) && acc, true); } - canDisableAutoAnalysis(file: File | File[]): boolean { + canEnableDisableAutoAnalysis(file: File | File[], value: 'enable' | 'disable'): boolean { const files = file instanceof File ? [file] : file; - return files.reduce((acc, _file) => this._canDisableAutoAnalysis(_file) && acc, true); - } - - canEnableAutoAnalysis(file: File | File[]): boolean { - const files = file instanceof File ? [file] : file; - return files.reduce((acc, _file) => this._canEnableAutoAnalysis(_file) && acc, true); + return files.reduce((acc, _file) => this._canEnableDisableAutoAnalysis(_file, value) && acc, true); } isFileAssignee(file: File): boolean { @@ -168,12 +163,9 @@ export class PermissionsService { return this.isReviewerOrApprover(file) || file.isNew || (file.isError && file.isNew); } - private _canDisableAutoAnalysis(file: File): boolean { - return !file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id; - } - - private _canEnableAutoAnalysis(file: File): boolean { - return file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id; + 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 _canAssignToSelf(file: File, dossier: Dossier): boolean { diff --git a/libs/common-ui b/libs/common-ui index 31b60ff11..b808e4661 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 31b60ff117a8d8ecb9617be3b0c9e1822d437034 +Subproject commit b808e4661e56aa93baca96c57f910443437112d4 diff --git a/libs/red-domain/src/lib/files/file.model.ts b/libs/red-domain/src/lib/files/file.model.ts index d0518b8f6..d1168ffa2 100644 --- a/libs/red-domain/src/lib/files/file.model.ts +++ b/libs/red-domain/src/lib/files/file.model.ts @@ -69,7 +69,7 @@ export class File extends Entity implements IFile { this.dossierDictionaryVersion = file.dossierDictionaryVersion; this.dossierId = file.dossierId; this.excluded = !!file.excluded; - this.excludedFromAutomaticAnalysis = Math.random() < 0.5; //!!file.excludedFromAutomaticAnalysis; + this.excludedFromAutomaticAnalysis = !!file.excludedFromAutomaticAnalysis; this.fileAttributes = file.fileAttributes; this.fileId = file.fileId; this.filename = file.filename; From 825b92cf8e0c1a9584015b6d7999ea6cf3234a92 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 4 Feb 2022 17:02:34 +0200 Subject: [PATCH 3/7] fix for reanalyze request when is triggered by user --- .../services/bulk-actions.service.ts | 6 ++++-- .../file-preview-screen.component.ts | 2 +- .../file-actions/file-actions.component.ts | 8 ++++++-- apps/red-ui/src/app/services/reanalysis.service.ts | 14 +++++++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) 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 8ca255a02..59b7c76cb 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 @@ -78,8 +78,10 @@ export class BulkActionsService { async reanalyse(files: File[]) { this._loadingService.start(); - const fileIds = files.filter(file => file.analysisRequired).map(file => file.fileId); - await firstValueFrom(this._reanalysisService.reanalyzeFilesForDossier(fileIds, files[0].dossierId)); + const fileIds = files.map(file => file.fileId); + await firstValueFrom( + this._reanalysisService.reanalyzeFilesForDossier(fileIds, files[0].dossierId, { force: true, triggeredByUser: true }), + ); this._loadingService.stop(); } diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 145405297..1a450979f 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -209,7 +209,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni const file = await this.stateService.file; if (file?.analysisRequired) { - const reanalyzeFiles = this._reanalysisService.reanalyzeFilesForDossier([this.fileId], this.dossierId, true); + const reanalyzeFiles = this._reanalysisService.reanalyzeFilesForDossier([this.fileId], this.dossierId, { force: true }); await firstValueFrom(reanalyzeFiles); } 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 7f4dc6cc7..11b25cf28 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 @@ -30,7 +30,7 @@ import { FileAssignService } from '../../services/file-assign.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { FileManagementService } from '@services/entity-services/file-management.service'; import { FilesService } from '@services/entity-services/files.service'; -import { ReanalysisService } from '@services/reanalysis.service'; +import { ReanalysisService, ReanalyzeQueryParams } from '@services/reanalysis.service'; import { Router } from '@angular/router'; import { ExcludedPagesService } from '../../../screens/file-preview-screen/services/excluded-pages.service'; import { tap } from 'rxjs/operators'; @@ -313,7 +313,11 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, private async _reanalyseFile($event?: MouseEvent) { $event?.stopPropagation(); - await firstValueFrom(this._reanalysisService.reanalyzeFilesForDossier([this.file.fileId], this.file.dossierId, true)); + const params: ReanalyzeQueryParams = { + force: true, + triggeredByUser: true, + }; + await firstValueFrom(this._reanalysisService.reanalyzeFilesForDossier([this.file.fileId], this.file.dossierId, params)); } private async toggleAutomaticAnalysis($event: MouseEvent) { diff --git a/apps/red-ui/src/app/services/reanalysis.service.ts b/apps/red-ui/src/app/services/reanalysis.service.ts index 3a3bded63..5e193e27a 100644 --- a/apps/red-ui/src/app/services/reanalysis.service.ts +++ b/apps/red-ui/src/app/services/reanalysis.service.ts @@ -4,6 +4,11 @@ import { IPageExclusionRequest } from '@red/domain'; import { switchMap } from 'rxjs/operators'; import { FilesService } from './entity-services/files.service'; +export interface ReanalyzeQueryParams { + force?: boolean; + triggeredByUser?: boolean; +} + @Injectable({ providedIn: 'root', }) @@ -23,10 +28,13 @@ export class ReanalysisService extends GenericService { } @Validate() - reanalyzeFilesForDossier(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string, force?: boolean) { + reanalyzeFilesForDossier(@RequiredParam() fileIds: List, @RequiredParam() dossierId: string, params?: ReanalyzeQueryParams) { const queryParams: QueryParam[] = []; - if (force) { - queryParams.push({ key: 'force', value: force }); + if (params?.force) { + queryParams.push({ key: 'force', value: true }); + } + if (params?.triggeredByUser) { + queryParams.push({ key: 'triggeredByUser', value: true }); } return this._post(fileIds, `reanalyze/${dossierId}/bulk`, queryParams).pipe(switchMap(() => this._filesService.loadAll(dossierId))); From fb3cc7fc5b8b1dec895cfeffff6b5edcaf67e051 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Mon, 7 Feb 2022 13:31:01 +0200 Subject: [PATCH 4/7] - 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() From f464c5e1fe5c4ad1d89a9645e52f088f8a21d50a Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Mon, 7 Feb 2022 13:43:34 +0200 Subject: [PATCH 5/7] used bulk api for both requests(toggle one file or bulk files) --- .../dossier-overview/services/bulk-actions.service.ts | 2 +- .../components/file-actions/file-actions.component.ts | 2 +- apps/red-ui/src/app/services/reanalysis.service.ts | 10 +--------- 3 files changed, 3 insertions(+), 11 deletions(-) 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 9ca37fb01..59b7c76cb 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.toggleAutomaticAnalysisBulk(files[0].dossierId, fileIds, excluded)); + await firstValueFrom(this._reanalysisService.toggleAutomaticAnalysis(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 215427cc3..242360812 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, ), ); diff --git a/apps/red-ui/src/app/services/reanalysis.service.ts b/apps/red-ui/src/app/services/reanalysis.service.ts index 68607bb79..479cd0ee2 100644 --- a/apps/red-ui/src/app/services/reanalysis.service.ts +++ b/apps/red-ui/src/app/services/reanalysis.service.ts @@ -53,15 +53,7 @@ export class ReanalysisService extends GenericService { } @Validate() - toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() fileId: string, excluded?: boolean) { - const queryParams: QueryParam[] = [{ key: 'excluded', value: !!excluded }]; - 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) { + 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)), From 8d1ad47520f99a403a5d3ca73b254f006e74589f Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 8 Feb 2022 16:30:53 +0200 Subject: [PATCH 6/7] updated and called replace file method from files map service instead of reloading all files from backend --- ...dossier-overview-bulk-actions.component.ts | 2 +- .../services/bulk-actions.service.ts | 5 ++-- .../file-actions/file-actions.component.ts | 8 +----- .../entity-services/files-map.service.ts | 26 ++++++++++++++----- .../services/entity-services/files.service.ts | 2 +- .../src/app/services/reanalysis.service.ts | 20 +++++++++----- 6 files changed, 38 insertions(+), 25 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 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)), ); } From 32408542afcbc60ab05e1f6262ba4598a6e62325 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 8 Feb 2022 17:35:16 +0200 Subject: [PATCH 7/7] shown confirmation message for enable/disable auto-analysis --- .../src/app/services/reanalysis.service.ts | 19 ++++++++++++++++--- apps/red-ui/src/assets/i18n/de.json | 4 ++++ apps/red-ui/src/assets/i18n/en.json | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/red-ui/src/app/services/reanalysis.service.ts b/apps/red-ui/src/app/services/reanalysis.service.ts index 6479eaa3d..a636a7b60 100644 --- a/apps/red-ui/src/app/services/reanalysis.service.ts +++ b/apps/red-ui/src/app/services/reanalysis.service.ts @@ -1,9 +1,11 @@ import { Injectable, Injector } from '@angular/core'; -import { GenericService, List, QueryParam, RequiredParam, Validate } from '@iqser/common-ui'; +import { GenericService, List, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui'; import { File, IPageExclusionRequest } from '@red/domain'; -import { switchMap, tap } from 'rxjs/operators'; +import { catchError, switchMap, tap } from 'rxjs/operators'; import { FilesService } from './entity-services/files.service'; import { FilesMapService } from './entity-services/files-map.service'; +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; +import { of } from 'rxjs'; export interface ReanalyzeQueryParams { force?: boolean; @@ -16,6 +18,7 @@ export interface ReanalyzeQueryParams { export class ReanalysisService extends GenericService { constructor( protected readonly _injector: Injector, + private readonly _toaster: Toaster, private readonly _filesService: FilesService, private readonly _filesMapService: FilesMapService, ) { @@ -60,9 +63,19 @@ export class ReanalysisService extends GenericService { @Validate() toggleAutomaticAnalysis(@RequiredParam() dossierId: string, @RequiredParam() files: File[]) { const fileIds = files.map(file => file.id); - const queryParams: QueryParam[] = [{ key: 'excluded', value: !files[0].excludedFromAutomaticAnalysis }]; + const excluded = !files[0].excludedFromAutomaticAnalysis; + const queryParams: QueryParam[] = [{ key: 'excluded', value: excluded }]; return this._post(fileIds, `toggle-automatic-analysis/${dossierId}/bulk`, queryParams).pipe( tap(() => this._filesMapService.replaceFiles(files, 'excludedFromAutomaticAnalysis', value => !value)), + tap(() => + this._toaster.success(_('toggle-auto-analysis-message.success'), { + params: { toggleOperation: excluded ? 'Deactivated' : 'Activated' }, + }), + ), + catchError(() => { + this._toaster.error(_('toggle-auto-analysis-message.error')); + return of({}); + }), ); } diff --git a/apps/red-ui/src/assets/i18n/de.json b/apps/red-ui/src/assets/i18n/de.json index 6bfc8c910..21819e941 100644 --- a/apps/red-ui/src/assets/i18n/de.json +++ b/apps/red-ui/src/assets/i18n/de.json @@ -1597,6 +1597,10 @@ "less-than-an-hour": "< 1 Stunde", "no-time-left": "Frist für Wiederherstellung verstrichen" }, + "toggle-auto-analysis-message": { + "success": "", + "error": "" + }, "top-bar": { "navigation-items": { "back": "Zurück", diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index eb16fd1b4..642abf35c 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -1636,6 +1636,10 @@ "less-than-an-hour": "< 1 hour", "no-time-left": "Time to restore already passed" }, + "toggle-auto-analysis-message": { + "success": "{toggleOperation} automatic processing.", + "error": "Something went wrong." + }, "top-bar": { "navigation-items": { "back": "Back",