From 77a8f3687839505beda1a533d94299b06f306eb6 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Tue, 12 Sep 2023 15:47:08 +0300 Subject: [PATCH 1/3] RED-7550: wip --- .../app/models/file/annotation.permissions.ts | 22 ++++++++++- .../edit-redaction-dialog.component.html | 10 +++-- .../edit-redaction-dialog.component.ts | 37 ++++++++++++------- .../services/annotation-actions.service.ts | 13 +++---- .../pdf-annotation-actions.service.ts | 15 +++++++- apps/red-ui/src/assets/config/config.json | 6 +-- apps/red-ui/src/assets/i18n/redact/en.json | 2 +- 7 files changed, 75 insertions(+), 30 deletions(-) diff --git a/apps/red-ui/src/app/models/file/annotation.permissions.ts b/apps/red-ui/src/app/models/file/annotation.permissions.ts index aa287465d..914897ebc 100644 --- a/apps/red-ui/src/app/models/file/annotation.permissions.ts +++ b/apps/red-ui/src/app/models/file/annotation.permissions.ts @@ -16,6 +16,7 @@ import { canUndo, } from './annotation-permissions.utils'; import { AnnotationWrapper } from './annotation.wrapper'; +import { IMAGE_CATEGORIES } from '../../modules/file-preview/utils/constants'; export class AnnotationPermissions { canUndo = true; @@ -30,6 +31,8 @@ export class AnnotationPermissions { canRecategorizeAnnotation = true; canForceHint = true; canEditAnnotations = true; + canEditHints = true; + canEditImages = true; static forUser( isApprover: boolean, @@ -58,7 +61,22 @@ export class AnnotationPermissions { permissions.canChangeLegalBasis = canChangeLegalBasis(annotation, canAddRedaction); permissions.canRecategorizeAnnotation = canRecategorizeAnnotation(annotation, canAddRedaction); permissions.canResizeAnnotation = canResizeAnnotation(annotation, canAddRedaction); - permissions.canEditAnnotations = annotation.isSkipped || annotation.isRedacted; + + // if (isDocumine) { + // annotation.isSkipped || annotation.isRedacted; + // } else { + // annotation.isImage || annotation.isOCR; + // annotation.isSkipped || annotation.isRedacted; + // annotation.isIgnoredHint || annotation.isDictBasedHint || annotation.isHint || annotation.isSuggestionForceHint; + // } + // const skippedRedacted = annotation.isSkipped || annotation.isRedacted; + // const ignoredHints = annotation.isIgnoredHint || annotation.isDictBasedHint || annotation.isHint || annotation.isSuggestionForceHint; + // const image = annotation + + permissions.canEditAnnotations = (annotation.isSkipped || annotation.isRedacted) && !annotation.isImage; + permissions.canEditHints = + annotation.isIgnoredHint || annotation.isDictBasedHint || annotation.isHint || annotation.isSuggestionForceHint; + permissions.canEditImages = [...IMAGE_CATEGORIES, 'ocr'].includes(annotation.type); summedPermissions._merge(permissions); } @@ -79,6 +97,8 @@ export class AnnotationPermissions { result.canRemoveRedaction = permissions.reduce((acc, next) => acc && next.canRemoveRedaction, true); result.canUndo = permissions.reduce((acc, next) => acc && next.canUndo, true); result.canEditAnnotations = permissions.reduce((acc, next) => acc && next.canEditAnnotations, true); + result.canEditHints = permissions.reduce((acc, next) => acc && next.canEditHints, true); + result.canEditImages = permissions.reduce((acc, next) => acc && next.canEditImages, true); return result; } diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html index 0f7faf0f4..31faa525d 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html @@ -7,9 +7,13 @@ >
-
- - {{ redactedText }} +
+ + {{ redactedTexts }}
diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts index 82828a887..71c5f0a75 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.ts @@ -1,5 +1,5 @@ import { Component, inject, OnInit } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; +import { FormBuilder, FormControl } from '@angular/forms'; import { DetailsRadioOption, IconButtonTypes, IqserDialogComponent } from '@iqser/common-ui'; import { Dictionary, SuperTypes } from '@red/domain'; import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service'; @@ -21,7 +21,7 @@ export class EditRedactionDialogComponent readonly #dossier = inject(ActiveDossiersService).find(this.data.dossierId); readonly #applyToAllDossiers = this.data.applyToAllDossiers; readonly iconButtonTypes = IconButtonTypes; - readonly redactedText: string; + readonly redactedTexts?: string[]; readonly isModifyDictionary: boolean; readonly isImage: boolean; readonly isManualRedaction: boolean; @@ -32,27 +32,23 @@ export class EditRedactionDialogComponent options: DetailsRadioOption[] | undefined; legalOptions: LegalBasisOption[] = []; dictionaries: Dictionary[] = []; - readonly form = new FormGroup({ - reason: new FormControl(null), - comment: new FormControl(null), - type: new FormControl(this.data.annotations[0].type), - section: new FormControl(this.data.annotations[0].section), - option: new FormControl(null), - value: new FormControl(this.allRectangles ? this.data.annotations[0].value : null), - }); + readonly form = this.#getForm(); constructor( private readonly _justificationsService: JustificationsService, private readonly _dictionaryService: DictionaryService, + private readonly _formBuilder: FormBuilder, ) { super(); const annotations = this.data.annotations; const firstEntry = annotations[0]; this.isImage = [...IMAGE_CATEGORIES, 'ocr'].includes(firstEntry.type); - this.redactedText = annotations.length === 1 && !this.isImage ? firstEntry.value : null; - this.isModifyDictionary = firstEntry.isModifyDictionary; - this.isManualRedaction = firstEntry.type === SuperTypes.ManualRedaction; - this.isHint = firstEntry.isHint; + const testImage = annotations.reduce((acc, next) => acc && [...IMAGE_CATEGORIES, 'ocr'].includes(next.type), true); + console.log(testImage); + this.redactedTexts = !testImage ? annotations.map(annotation => annotation.value) : null; + this.isModifyDictionary = annotations.every(annotation => annotation.isModifyDictionary); + this.isManualRedaction = annotations.every(annotation => annotation.type === SuperTypes.ManualRedaction); + this.isHint = annotations.every(annotation => annotation.isHint); this.showExtras = !(this.isImage || this.isHint); } @@ -125,4 +121,17 @@ export class EditRedactionDialogComponent { emitEvent: false }, ); } + + #getForm() { + const sameType = new Set(this.data.annotations.map(annotation => annotation.type)).size === 1; + const sameSection = new Set(this.data.annotations.map(annotation => annotation.section)).size === 1; + return this._formBuilder.group({ + reason: new FormControl(null), + comment: new FormControl(null), + type: new FormControl(sameType ? this.data.annotations[0].type : null), + section: new FormControl(sameSection ? this.data.annotations[0].section : null), + option: new FormControl(null), + value: new FormControl(this.allRectangles ? this.data.annotations[0].value : null), + }); + } } 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 b7cb9210f..a222a2f56 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 @@ -97,6 +97,7 @@ export class AnnotationActionsService { }; const result = await this.#getEditRedactionDialog(data).result(); + console.log(result); const requests: Observable[] = []; @@ -113,13 +114,11 @@ export class AnnotationActionsService { })); requests.push(this._manualRedactionService.changeLegalBasis(changeLegalBasisBody, dossierId, fileId)); } - if (this.#isDocumine) { - const recategorizeBody: List = annotations.map(annotation => ({ - annotationId: annotation.id, - type: result.type ?? annotation.type, - })); - requests.push(this._manualRedactionService.recategorizeRedactions(recategorizeBody, dossierId, fileId)); - } + const recategorizeBody: List = annotations.map(annotation => ({ + annotationId: annotation.id, + type: result.type ?? annotation.type, + })); + requests.push(this._manualRedactionService.recategorizeRedactions(recategorizeBody, dossierId, fileId)); if (!requests.length) { return; diff --git a/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts index 329236294..c8e16acd3 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts @@ -48,12 +48,25 @@ export class PdfAnnotationActionsService { availableActions.push(resizeButton); } + + /* + + */ + + console.log(annotations); + console.log(annotations.map(annotation => annotation.type)); + console.log(permissions); const canEditRedactions = permissions.canChangeLegalBasis || permissions.canRecategorizeAnnotation || permissions.canForceHint || permissions.canForceRedaction; - const canEdit = this.#isDocumine && annotations.length > 1 ? permissions.canEditAnnotations : canEditRedactions; + const canEdit = + annotations.length > 1 + ? this.#isDocumine + ? permissions.canEditAnnotations + : permissions.canEditHints || permissions.canEditImages || permissions.canEditAnnotations + : canEditRedactions; if (canEdit) { const editButton = this.#getButton('edit', _('annotation-actions.edit-redaction.label'), () => this.#annotationActionsService.editRedaction(annotations), diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index b022421b1..42bf5941f 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -3,7 +3,7 @@ "ADMIN_CONTACT_URL": null, "API_URL": "https://dan.iqser.cloud", "APP_NAME": "RedactManager", - "IS_DOCUMINE": true, + "IS_DOCUMINE": false, "RULE_EDITOR_DEV_ONLY": false, "AUTO_READ_TIME": 3, "BACKEND_APP_VERSION": "4.4.40", @@ -18,8 +18,8 @@ "SELECTION_MODE": "structural", "MANUAL_BASE_URL": "https://docs.redactmanager.com/preview", "ANNOTATIONS_THRESHOLD": 1000, - "THEME": "scm", - "BASE_TRANSLATIONS_DIRECTORY": "/assets/i18n/scm/", + "THEME": "redact", + "BASE_TRANSLATIONS_DIRECTORY": "/assets/i18n/redact/", "AVAILABLE_NOTIFICATIONS_DAYS": 30, "AVAILABLE_OLD_NOTIFICATIONS_MINUTES": 60, "NOTIFICATIONS_THRESHOLD": 1000, diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index 862b5baa7..6853b04a3 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -2056,7 +2056,7 @@ "label": "Remove here" } }, - "redacted-text": "" + "redacted-text": "Redacted {length, plural, one{text} other {texts}}" }, "title": "Remove {count, plural, one{annotation} other {annotations}}" } From ddaa4cf7f37539501b008ab1c0ff6fdb7869cd10 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Mon, 18 Sep 2023 17:37:02 +0300 Subject: [PATCH 2/3] RED-7550: Bulk edit dialog. --- .../app/models/file/annotation.permissions.ts | 11 ---- .../annotation-actions.component.ts | 46 +++++++++-------- .../edit-redaction-dialog.component.html | 50 +++++++++++++------ .../edit-redaction-dialog.component.scss | 22 ++++++++ .../edit-redaction-dialog.component.ts | 21 ++++---- .../services/annotation-actions.service.ts | 10 ++-- .../pdf-annotation-actions.service.ts | 7 --- apps/red-ui/src/assets/i18n/redact/en.json | 2 +- 8 files changed, 100 insertions(+), 69 deletions(-) create mode 100644 apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.scss diff --git a/apps/red-ui/src/app/models/file/annotation.permissions.ts b/apps/red-ui/src/app/models/file/annotation.permissions.ts index 96acda76d..87ffb175e 100644 --- a/apps/red-ui/src/app/models/file/annotation.permissions.ts +++ b/apps/red-ui/src/app/models/file/annotation.permissions.ts @@ -62,17 +62,6 @@ export class AnnotationPermissions { permissions.canRecategorizeAnnotation = canRecategorizeAnnotation(annotation, canAddRedaction); permissions.canResizeAnnotation = canResizeAnnotation(annotation, canAddRedaction); - // if (isDocumine) { - // annotation.isSkipped || annotation.isRedacted; - // } else { - // annotation.isImage || annotation.isOCR; - // annotation.isSkipped || annotation.isRedacted; - // annotation.isIgnoredHint || annotation.isDictBasedHint || annotation.isHint || annotation.isSuggestionForceHint; - // } - // const skippedRedacted = annotation.isSkipped || annotation.isRedacted; - // const ignoredHints = annotation.isIgnoredHint || annotation.isDictBasedHint || annotation.isHint || annotation.isSuggestionForceHint; - // const image = annotation - permissions.canEditAnnotations = (annotation.isSkipped || annotation.isRedacted) && !annotation.isImage; permissions.canEditHints = annotation.isIgnoredHint || annotation.isDictBasedHint || annotation.isHint || annotation.isSuggestionForceHint; diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts index 60cd1703f..0d7097ec4 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts @@ -39,24 +39,35 @@ export class AnnotationActionsComponent implements OnChanges { }); readonly #isDocumine = getConfig().IS_DOCUMINE; + constructor( + readonly viewModeService: ViewModeService, + readonly helpModeService: HelpModeService, + readonly multiSelectService: MultiSelectService, + private readonly _state: FilePreviewStateService, + private readonly _permissionsService: PermissionsService, + private readonly _iqserPermissionsService: IqserPermissionsService, + private readonly _annotationManager: REDAnnotationManager, + readonly annotationActionsService: AnnotationActionsService, + readonly annotationReferencesService: AnnotationReferencesService, + ) {} + get annotations(): AnnotationWrapper[] { return this.#annotations; } - @Input() - set annotations(annotations: AnnotationWrapper[]) { - this.#annotations = annotations.filter(a => a !== undefined); - this.isImage = this.#annotations?.reduce((accumulator, annotation) => annotation.isImage && accumulator, true); - this._annotationId = this.#annotations[0]?.id; - } - get canEdit(): boolean { - const documineCanEditRedactions = + const canEditRedactions = this.annotationPermissions.canChangeLegalBasis || this.annotationPermissions.canRecategorizeAnnotation || this.annotationPermissions.canForceHint || this.annotationPermissions.canForceRedaction; - return this.#isDocumine && this.annotations.length > 1 ? this.annotationPermissions.canEditAnnotations : documineCanEditRedactions; + return this.annotations.length > 1 + ? this.#isDocumine + ? this.annotationPermissions.canEditAnnotations + : this.annotationPermissions.canEditHints || + this.annotationPermissions.canEditImages || + this.annotationPermissions.canEditAnnotations + : canEditRedactions; } get canRemoveRedaction(): boolean { @@ -76,17 +87,12 @@ export class AnnotationActionsComponent implements OnChanges { return this.annotations.every(a => a.superType === type); } - constructor( - readonly viewModeService: ViewModeService, - readonly helpModeService: HelpModeService, - readonly multiSelectService: MultiSelectService, - private readonly _state: FilePreviewStateService, - private readonly _permissionsService: PermissionsService, - private readonly _iqserPermissionsService: IqserPermissionsService, - private readonly _annotationManager: REDAnnotationManager, - readonly annotationActionsService: AnnotationActionsService, - readonly annotationReferencesService: AnnotationReferencesService, - ) {} + @Input() + set annotations(annotations: AnnotationWrapper[]) { + this.#annotations = annotations.filter(a => a !== undefined); + this.isImage = this.#annotations?.reduce((accumulator, annotation) => annotation.isImage && accumulator, true); + this._annotationId = this.#annotations[0]?.id; + } ngOnChanges(): void { this.#setPermissions(); diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html index aa91b44a1..bb1270077 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/edit-redaction-dialog/edit-redaction-dialog.component.html @@ -7,27 +7,27 @@ >
- - - - - - - -
+
- {{ redactedTexts }} + +
    +
  • {{ text }}
  • +
+
- + {{ displayedDictionaryLabel }} - + - +
- +