RED-7069, use dictop type in displaying options.

This commit is contained in:
George 2023-07-28 15:05:40 +03:00
parent 48e5bf5716
commit 9baa562300
2 changed files with 16 additions and 21 deletions

View File

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { DetailsRadioOption, IconButtonTypes, IqserDialogComponent, IqserPermissionsService } from '@iqser/common-ui';
import { DetailsRadioOption, IconButtonTypes, IqserDialogComponent } from '@iqser/common-ui';
import { Dictionary, Dossier, SuperTypes } from '@red/domain';
import { FormBuilder, UntypedFormGroup } from '@angular/forms';
import { Roles } from '@users/roles';
@ -24,15 +24,15 @@ export class EditRedactionDialogComponent
readonly roles = Roles;
readonly iconButtonTypes = IconButtonTypes;
readonly redactedText: string;
readonly isModifyDictionary: boolean;
readonly isImage: boolean;
readonly initialReason: string;
readonly initialType: string;
readonly isManualRedaction: boolean;
options: DetailsRadioOption<RedactOrHintOption>[] | undefined;
legalOptions: LegalBasisOption[] = [];
dictionaries: Dictionary[] = [];
form: UntypedFormGroup;
readonly #initialType: string;
readonly #initialReason: string;
#applyToAllDossiers: boolean;
readonly #dossier: Dossier;
@ -40,26 +40,26 @@ export class EditRedactionDialogComponent
private readonly _justificationsService: JustificationsService,
private readonly _activeDossiersService: ActiveDossiersService,
private readonly _dictionaryService: DictionaryService,
private readonly _iqserPermissionsService: IqserPermissionsService,
private readonly _formBuilder: FormBuilder,
) {
super();
this.#dossier = _activeDossiersService.find(this.data.dossierId);
this.#dossier = this._activeDossiersService.find(this.data.dossierId);
this.#applyToAllDossiers = this.data.applyToAllDossiers;
const annotations = this.data.annotations;
const firstEntry = annotations[0];
this.isImage = IMAGE_CATEGORIES.includes(firstEntry.type);
this.redactedText = annotations.length === 1 && !this.isImage ? firstEntry.value : null;
this.initialReason = firstEntry.legalBasis;
this.initialType = firstEntry.type;
this.#initialReason = firstEntry.legalBasis;
this.#initialType = firstEntry.type;
this.isModifyDictionary = firstEntry.isModifyDictionary;
this.isManualRedaction = firstEntry.type === SuperTypes.ManualRedaction;
this.form = this.#getForm();
this.form.valueChanges
.pipe(
tap(value => {
const reasonChanged = this.initialReason !== value?.reason?.legalBasis;
const typeChanged = this.initialType !== value?.type;
const reasonChanged = this.#initialReason !== value?.reason?.legalBasis;
const typeChanged = this.#initialType !== value?.type;
if (typeChanged || reasonChanged) {
this.#setOptions(value.type, reasonChanged);
}
@ -106,7 +106,7 @@ export class EditRedactionDialogComponent
save(): void {
const value = this.form.value;
this.dialogRef.close({
typeChanged: this.initialType !== value.type,
typeChanged: this.#initialType !== value.type,
legalBasis: value.reason.legalBasis,
section: value.section,
comment: value.comment,
@ -124,16 +124,12 @@ export class EditRedactionDialogComponent
this.options = getEditRedactionOptions(
this.#dossier.dossierName,
this.#applyToAllDossiers,
selectedDictionary.dossierDictionaryOnly,
this.isImage,
this.isManualRedaction,
!!selectedDictionary?.dossierDictionaryOnly,
this.isModifyDictionary,
);
this.form.patchValue(
{
option:
this.isImage || selectedDictionary.dossierDictionaryOnly || this.isManualRedaction || reasonChanged
? this.options[0]
: this.options[1],
option: !this.isModifyDictionary || reasonChanged ? this.options[0] : this.options[1],
},
{ emitEvent: false },
);

View File

@ -36,8 +36,7 @@ export const getEditRedactionOptions = (
dossierName: string,
applyToAllDossiers: boolean,
dossierDictionaryOnly: boolean,
isImage: boolean,
isManualRedaction: boolean,
isModifyDictionary: boolean,
): DetailsRadioOption<RedactOrHintOption>[] => {
const options: DetailsRadioOption<RedactOrHintOption>[] = [
{
@ -47,7 +46,7 @@ export const getEditRedactionOptions = (
value: ResizeOptions.ONLY_HERE,
},
];
if (!isImage && !isManualRedaction) {
if (isModifyDictionary) {
options.push({
label: editRedactionTranslations.inDossier.label,
description: editRedactionTranslations.inDossier.description,