RED-7762: updated conditions based on specific annotation combinations.

This commit is contained in:
Nicoleta Panaghiu 2023-11-09 13:49:16 +02:00
parent 372e6b887a
commit 9041ed9a0c

View File

@ -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<LegalBasisOption>(null),
return new FormGroup({
reason: new FormControl<LegalBasisOption>({ value: null, disabled: this.allSkipped }),
comment: new FormControl<string>(null),
type: new FormControl<string>(sameType ? this.data.annotations[0].type : null),
section: new FormControl<string>(sameSection ? this.data.annotations[0].section : null),