From 9041ed9a0cd53b58d732fc7ba1b4505ff86b65fb Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Thu, 9 Nov 2023 13:49:16 +0200 Subject: [PATCH] RED-7762: updated conditions based on specific annotation combinations. --- .../edit-redaction-dialog.component.ts | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) 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 306e149fe..123006f92 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 { FormBuilder, FormControl } from '@angular/forms'; +import { FormControl, FormGroup } 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'; @@ -36,7 +36,6 @@ export class EditRedactionDialogComponent constructor( private readonly _justificationsService: JustificationsService, private readonly _dictionaryService: DictionaryService, - private readonly _formBuilder: FormBuilder, ) { super(); const annotations = this.data.annotations; @@ -58,7 +57,28 @@ export class EditRedactionDialogComponent } get disabled() { - return this.form.invalid || (this.showExtras ? !this.form.controls.reason.value : false); + return ( + this.form.invalid || + (this.showExtras && (!this.allSkipped || this.isRedactBasedType) ? !this.form.controls.reason.value : false) + ); + } + + get allRedacted() { + return this.data.annotations.every(annotation => annotation.isRedacted); + } + + get allSkipped() { + return this.data.annotations.every(annotation => annotation.isSkipped); + } + + get redactBasedTypes() { + return this._dictionaryService + .getRedactTextDictionaries(this.#dossier.dossierTemplateId, !this.#applyToAllDossiers) + .map(dictionary => dictionary.type); + } + + get isRedactBasedType() { + return this.redactBasedTypes.includes(this.form.controls.type.value); } async ngOnInit() { @@ -83,6 +103,13 @@ export class EditRedactionDialogComponent typeChanged() { const selectedDictionaryType = this.form.controls.type.value; this.#setOptions(selectedDictionaryType); + + if (this.redactBasedTypes.includes(selectedDictionaryType)) { + this.form.controls.reason.enable(); + } else { + this.form.patchValue({ reason: null, option: null }); + this.form.controls.reason.disable(); + } } save() { @@ -122,10 +149,12 @@ export class EditRedactionDialogComponent } #getForm() { - const sameType = this.data.annotations.every(annotation => annotation.type === this.data.annotations[0].type); + const sameType = + this.data.annotations.every(annotation => annotation.type === this.data.annotations[0].type) && + (this.allRedacted || this.allSkipped); const sameSection = this.data.annotations.every(annotation => annotation.section === this.data.annotations[0].section); - return this._formBuilder.group({ - reason: new FormControl(null), + return new FormGroup({ + reason: new FormControl({ value: null, disabled: this.allSkipped }), comment: new FormControl(null), type: new FormControl(sameType ? this.data.annotations[0].type : null), section: new FormControl(sameSection ? this.data.annotations[0].section : null),