From 14139ab40577521ecc2212833bc691184392acb2 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Wed, 21 Jun 2023 00:11:00 +0300 Subject: [PATCH] RED-6774 - added "Apply to all dossiers" extra option for detailed options component --- .../redact-text-dialog.component.html | 6 ++++- .../redact-text-dialog.component.ts | 22 ++++++++++++++----- .../remove-redaction-dialog.component.ts | 22 +++++++++++++++++++ .../file-preview-screen.component.ts | 10 ++++++++- .../services/annotation-actions.service.ts | 13 +++++++++-- .../remove-redaction-translations.ts | 3 +++ apps/red-ui/src/assets/i18n/redact/de.json | 22 +++++++++++-------- apps/red-ui/src/assets/i18n/redact/en.json | 22 +++++++++++-------- apps/red-ui/src/assets/i18n/scm/de.json | 16 ++++++++++---- apps/red-ui/src/assets/i18n/scm/en.json | 16 ++++++++++---- 10 files changed, 116 insertions(+), 36 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.html b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.html index a63abac23..f0652bbb7 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.html +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.html @@ -8,7 +8,11 @@ {{ form.get('selectedText').value }} - +
diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts index f535dd0e3..d9ab15bdc 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { DetailsRadioOption, IconButtonTypes, IqserPermissionsService } from '@iqser/common-ui'; -import { Dictionary, Dossier, File, IAddRedactionRequest, IManualRedactionEntry, SuperTypes } from '@red/domain'; +import { Dictionary, Dossier, DossierTemplate, File, IAddRedactionRequest, IManualRedactionEntry, SuperTypes } from '@red/domain'; import { FormBuilder, UntypedFormGroup } from '@angular/forms'; import { Roles } from '@users/roles'; import { firstValueFrom } from 'rxjs'; @@ -19,6 +19,7 @@ import { RedactTextOption, RedactTextOptions } from './redact-text-options'; import { tap } from 'rxjs/operators'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { IqserDialogComponent } from '../../../../../../../../libs/common-ui/src/lib/dialog/iqser-dialog-component.directive'; +import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; const PIN_ICON = 'red:push-pin'; const FOLDER_ICON = 'red:folder'; @@ -32,6 +33,7 @@ interface RedactTextData { interface DialogResult { redaction: IManualRedactionEntry; dictionary: Dictionary; + applyToAllDossiers: boolean | null; } @Component({ @@ -52,6 +54,7 @@ export class RedactTextDialogComponent form!: UntypedFormGroup; #manualRedactionTypeExists = true; + #applyToAllDossiers = true; readonly #translations = redactTextTranslations; readonly #dossier: Dossier; @@ -62,6 +65,7 @@ export class RedactTextDialogComponent private readonly _activeDossiersService: ActiveDossiersService, private readonly _dictionaryService: DictionaryService, private readonly _iqserPermissionsService: IqserPermissionsService, + private readonly _dossierTemplatesService: DossierTemplatesService, private readonly _formBuilder: FormBuilder, ) { super(); @@ -78,7 +82,6 @@ export class RedactTextDialogComponent .valueChanges.pipe( tap((option: DetailsRadioOption) => { this.dictionaryRequest = option.value === RedactTextOptions.IN_DOSSIER; - console.log('this.dictionaryRequest: ', this.dictionaryRequest); this.#resetValues(); }), takeUntilDestroyed(), @@ -116,12 +119,17 @@ export class RedactTextDialogComponent this.#formatSelectedTextValue(); } + extraOptionChanged(option: DetailsRadioOption): void { + this.#applyToAllDossiers = option.extraOption.checked; + } + save(): void { this.#enhanceManualRedaction(this.data.manualRedactionEntryWrapper.manualRedactionEntry); const redaction = this.data.manualRedactionEntryWrapper.manualRedactionEntry; this.dialogRef.close({ redaction, dictionary: this.dictionaries.find(d => d.type === this.form.get('dictionary').value), + applyToAllDossiers: this.dictionaryRequest ? this.#applyToAllDossiers : null, }); } @@ -195,16 +203,18 @@ export class RedactTextDialogComponent descriptionParams: { dossierName: this.#dossier.dossierName }, icon: FOLDER_ICON, value: RedactTextOptions.IN_DOSSIER, - // extraOption: { - // label: this.#translations[this.type].inDossier.extraOptionLabel, - // checked: true, - // }, + extraOption: { + label: this.#translations[this.type].inDossier.extraOptionLabel, + checked: true, + }, }); } return options; } #resetValues() { + this.#applyToAllDossiers = true; + this.options[1].extraOption.checked = true; if (this.dictionaryRequest) { this.form.get('reason').setValue(null); this.form.get('dictionary').setValue(null); diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts index a9832aef3..1ffd08512 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts @@ -7,6 +7,8 @@ import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { Dossier } from '@red/domain'; import { IqserDialogComponent } from '../../../../../../../../libs/common-ui/src/lib/dialog/iqser-dialog-component.directive'; import { PermissionsService } from '@services/permissions.service'; +import { tap } from 'rxjs/operators'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; const PIN_ICON = 'red:push-pin'; const FOLDER_ICON = 'red:folder'; @@ -28,6 +30,7 @@ export interface RemoveRedactionData { export interface RemoveRedactionResult { comment: string; option: DetailsRadioOption; + applyToAllDossiers: boolean | null; } @Component({ @@ -54,6 +57,17 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< this.#permissions = this.data.permissions; this.options = this.#options(); this.form = this.#getForm(); + + this.form + .get('option') + .valueChanges.pipe( + tap(() => { + this.options[1].extraOption.checked = true; + this.options[2].extraOption.checked = true; + }), + takeUntilDestroyed(), + ) + .subscribe(); } save(): void { @@ -85,6 +99,10 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< descriptionParams: { value: this.#redaction.value }, icon: FOLDER_ICON, value: RemoveRedactionOptions.IN_DOSSIER, + extraOption: { + label: this.#translations.IN_DOSSIER.extraOptionLabel, + checked: true, + }, }); } if (this.#permissions.canMarkAsFalsePositive) { @@ -94,6 +112,10 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< descriptionParams: { value: this.#redaction.value, type: this.#redaction.type, context: this.data.falsePositiveContext }, icon: REMOVE_FROM_DICT_ICON, value: RemoveRedactionOptions.FALSE_POSITIVE, + extraOption: { + label: this.#translations.FALSE_POSITIVE.extraOptionLabel, + checked: true, + }, }); } return options; diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index f09e02638..f61b83323 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -76,7 +76,7 @@ import { Roles } from '@users/roles'; import { SuggestionsService } from './services/suggestions.service'; import { IqserDialog } from '../../../../../../libs/common-ui/src/lib/dialog/iqser-dialog.service'; import { RedactTextDialogComponent } from './dialogs/redact-text-dialog/redact-text-dialog.component'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; const textActions = [TextPopups.ADD_DICTIONARY, TextPopups.ADD_FALSE_POSITIVE]; @@ -141,6 +141,7 @@ export class FilePreviewScreenComponent private readonly _readableRedactionsService: ReadableRedactionsService, private readonly _helpModeService: HelpModeService, private readonly _suggestionsService: SuggestionsService, + private readonly _dossierTemplatesService: DossierTemplatesService, private readonly _dialog: MatDialog, ) { super(); @@ -386,6 +387,13 @@ export class FilePreviewScreenComponent result.dictionary?.label, ); + if (result.applyToAllDossiers !== null) { + const dossierTemplate = this._dossierTemplatesService.find(this.state.dossierTemplateId); + const { ...body } = dossierTemplate; + body.applyDictionaryUpdatesToAllDossiersByDefault = result.applyToAllDossiers; + await this._dossierTemplatesService.createOrUpdate(body); + } + const addAndReload$ = add$.pipe(switchMap(() => this._filesService.reload(this.dossierId, file))); return firstValueFrom(addAndReload$.pipe(catchError(() => of(undefined)))); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts index 0625c2ca0..17d76a25d 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts @@ -33,10 +33,11 @@ import { REDDocumentViewer } from '../../pdf-viewer/services/document-viewer.ser import { RemoveRedactionDialogComponent, RemoveRedactionPermissions, + RemoveRedactionResult, } from '../dialogs/remove-redaction-dialog/remove-redaction-dialog.component'; import { RemoveRedactionOptions } from '../dialogs/remove-redaction-dialog/remove-redaction-options'; import { IqserDialog } from '../../../../../../../libs/common-ui/src/lib/dialog/iqser-dialog.service'; -import { AnnotationPermissions } from '@models/file/annotation.permissions'; +import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; @Injectable() export class AnnotationActionsService { @@ -52,6 +53,7 @@ export class AnnotationActionsService { private readonly _state: FilePreviewStateService, private readonly _fileDataService: FileDataService, private readonly _skippedService: SkippedService, + private readonly _dossierTemplatesService: DossierTemplatesService, ) {} acceptSuggestion(annotations: AnnotationWrapper[]) { @@ -144,7 +146,7 @@ export class AnnotationActionsService { canMarkAsFalsePositive: permissions.canMarkAsFalsePositive, }; - const result = await this._iqserDialog + const result: RemoveRedactionResult = await this._iqserDialog .openDefault(RemoveRedactionDialogComponent, { data: { redaction, @@ -163,6 +165,13 @@ export class AnnotationActionsService { this.#removeRedaction(redaction, result.comment, removeFromDictionary); } } + + if (result.option.extraOption) { + const dossierTemplate = this._dossierTemplatesService.find(this._state.dossierTemplateId); + const { ...body } = dossierTemplate; + body.applyDictionaryUpdatesToAllDossiersByDefault = result.applyToAllDossiers; + await this._dossierTemplatesService.createOrUpdate(body); + } } recategorizeImages(annotations: AnnotationWrapper[]) { diff --git a/apps/red-ui/src/app/translations/remove-redaction-translations.ts b/apps/red-ui/src/app/translations/remove-redaction-translations.ts index d90195846..93d939562 100644 --- a/apps/red-ui/src/app/translations/remove-redaction-translations.ts +++ b/apps/red-ui/src/app/translations/remove-redaction-translations.ts @@ -4,6 +4,7 @@ import { RemoveRedactionOption } from '../modules/file-preview/dialogs/remove-re interface Option { label: string; description: string; + extraOptionLabel?: string; } export const removeRedactionTranslations: { [key in RemoveRedactionOption]: Option } = { @@ -14,9 +15,11 @@ export const removeRedactionTranslations: { [key in RemoveRedactionOption]: Opti IN_DOSSIER: { label: _('remove-redaction.dialog.content.options.in-dossier.label'), description: _('remove-redaction.dialog.content.options.in-dossier.description'), + extraOptionLabel: _('remove-redaction.dialog.content.options.redact.in-dossier.extraOptionLabel'), }, FALSE_POSITIVE: { label: _('remove-redaction.dialog.content.options.false-positive.label'), description: _('remove-redaction.dialog.content.options.false-positive.description'), + extraOptionLabel: _('remove-redaction.dialog.content.options.redact.false-positive.extraOptionLabel'), }, }; diff --git a/apps/red-ui/src/assets/i18n/redact/de.json b/apps/red-ui/src/assets/i18n/redact/de.json index a6bddeaee..88d1fc086 100644 --- a/apps/red-ui/src/assets/i18n/redact/de.json +++ b/apps/red-ui/src/assets/i18n/redact/de.json @@ -43,6 +43,10 @@ "generic": "Fehler beim Erstellen der Dossiervorlage." }, "form": { + "apply-updates-default": { + "description": "", + "heading": "" + }, "description": "Beschreibung", "description-placeholder": "Beschreibung eingeben", "hidden-text": { @@ -61,11 +65,7 @@ "title": "" }, "valid-from": "Gültig ab", - "valid-to": "Gültig bis", - "apply-updates-default": { - "heading": "", - "description": "" - } + "valid-to": "Gültig bis" }, "save": "Dossier-Vorlage speichern", "title": "{type, select, edit{Dossier-Vorlage {name} bearbeiten} create{Dossier-Vorlage erstellen} clone{} other{}}" @@ -330,9 +330,6 @@ "recategorize-image": "neu kategorisieren", "reject-suggestion": "Vorschlag ablehnen", "remove-annotation": { - "false-positive": "Falsch positiv", - "only-here": "nur hier entfernen", - "remove-from-dict": "Aus dem Wörterbuch entfernen", "remove-redaction": "" }, "remove-highlights": { @@ -1945,7 +1942,6 @@ "type": "", "type-placeholder": "" }, - "error": "", "title": "" } }, @@ -1987,6 +1983,14 @@ "only-here": { "description": "", "label": "" + }, + "redact": { + "false-positive": { + "extraOptionLabel": "" + }, + "in-dossier": { + "extraOptionLabel": "" + } } } }, diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index 43c8c7528..567695e9d 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -43,6 +43,10 @@ "generic": "Failed to create dossier template." }, "form": { + "apply-updates-default": { + "description": "Apply dictionary updates to all dossiers by default", + "heading": "Entity configuration" + }, "description": "Description", "description-placeholder": "Enter Description", "hidden-text": { @@ -61,11 +65,7 @@ "title": "Keep overlapping elements" }, "valid-from": "Valid from", - "valid-to": "Valid to", - "apply-updates-default": { - "heading": "Entity configuration", - "description": "Apply dictionary updates to all dossiers by default" - } + "valid-to": "Valid to" }, "save": "Save Dossier Template", "title": "{type, select, edit{Edit {name}} create{Create} clone{Clone} other{}} Dossier Template" @@ -330,9 +330,6 @@ "recategorize-image": "Recategorize", "reject-suggestion": "Reject Suggestion", "remove-annotation": { - "false-positive": "False Positive", - "only-here": "Remove only here", - "remove-from-dict": "Remove from dictionary", "remove-redaction": "Remove" }, "remove-highlights": { @@ -1945,7 +1942,6 @@ "type": "Type", "type-placeholder": "Select type ..." }, - "error": "Error! Invalid page selection", "title": "Redact text" } }, @@ -1987,6 +1983,14 @@ "only-here": { "description": "Do not redact \"{value}\" at this position in the current document.", "label": "Remove here" + }, + "redact": { + "false-positive": { + "extraOptionLabel": "Apply to all dossiers" + }, + "in-dossier": { + "extraOptionLabel": "Apply to all dossiers" + } } } }, diff --git a/apps/red-ui/src/assets/i18n/scm/de.json b/apps/red-ui/src/assets/i18n/scm/de.json index 353c3901e..0fd3be53c 100644 --- a/apps/red-ui/src/assets/i18n/scm/de.json +++ b/apps/red-ui/src/assets/i18n/scm/de.json @@ -43,6 +43,10 @@ "generic": "Fehler beim Erstellen der Dossiervorlage." }, "form": { + "apply-updates-default": { + "description": "", + "heading": "" + }, "description": "Beschreibung", "description-placeholder": "Beschreibung eingeben", "hidden-text": { @@ -326,9 +330,6 @@ "recategorize-image": "neu kategorisieren", "reject-suggestion": "Vorschlag ablehnen", "remove-annotation": { - "false-positive": "Falsch positiv", - "only-here": "nur hier entfernen", - "remove-from-dict": "Aus dem Wörterbuch entfernen", "remove-redaction": "" }, "remove-highlights": { @@ -1941,7 +1942,6 @@ "type": "", "type-placeholder": "" }, - "error": "", "title": "" } }, @@ -1983,6 +1983,14 @@ "only-here": { "description": "", "label": "" + }, + "redact": { + "false-positive": { + "extraOptionLabel": "" + }, + "in-dossier": { + "extraOptionLabel": "" + } } } }, diff --git a/apps/red-ui/src/assets/i18n/scm/en.json b/apps/red-ui/src/assets/i18n/scm/en.json index 83c2c8246..6ed676a41 100644 --- a/apps/red-ui/src/assets/i18n/scm/en.json +++ b/apps/red-ui/src/assets/i18n/scm/en.json @@ -43,6 +43,10 @@ "generic": "Failed to create dossier template." }, "form": { + "apply-updates-default": { + "description": "", + "heading": "" + }, "description": "Description", "description-placeholder": "Enter Description", "hidden-text": { @@ -326,9 +330,6 @@ "recategorize-image": "Recategorize", "reject-suggestion": "Reject Suggestion", "remove-annotation": { - "false-positive": "False Positive", - "only-here": "Remove only here", - "remove-from-dict": "Remove from dictionary", "remove-redaction": "Remove" }, "remove-highlights": { @@ -1941,7 +1942,6 @@ "type": "Type", "type-placeholder": "Select type ..." }, - "error": "Error! Invalid page selection", "title": "Redact text" } }, @@ -1983,6 +1983,14 @@ "only-here": { "description": "Do not redact \"{value}\" at this position in the current document.", "label": "Remove here" + }, + "redact": { + "false-positive": { + "extraOptionLabel": "Apply to all dossiers" + }, + "in-dossier": { + "extraOptionLabel": "Apply to all dossiers" + } } } },