CM-343, add edit annotation dialog. Fix 7069 related bugs.

This commit is contained in:
George 2023-07-28 00:20:29 +03:00
parent ae4af92307
commit 5e0ca8a82a
8 changed files with 164 additions and 33 deletions

View File

@ -0,0 +1,51 @@
<section class="dialog">
<form (submit)="save()" [formGroup]="form">
<div [translate]="'edit-redaction.dialog.title-edit-text'" class="dialog-header heading-l"></div>
<div class="dialog-content redaction">
<div *ngIf="redactedText" class="iqser-input-group w-450">
<label [translate]="'edit-redaction.dialog.content.redacted-text'" class="selected-text"></label>
{{ redactedText }}
</div>
<div class="iqser-input-group required w-450">
<label [translate]="'edit-redaction.dialog.content.type'"></label>
<mat-form-field>
<mat-select formControlName="type">
<mat-select-trigger>{{ displayedDictionaryLabel }}</mat-select-trigger>
<mat-option
*ngFor="let dictionary of dictionaries"
[matTooltip]="dictionary.description"
[value]="dictionary.type"
matTooltipPosition="after"
>
<span> {{ dictionary.label }} </span>
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="iqser-input-group w-450">
<label [translate]="'edit-redaction.dialog.content.comment'"></label>
<textarea
[placeholder]="'edit-redaction.dialog.content.comment-placeholder' | translate"
formControlName="comment"
iqserHasScrollbar
name="comment"
rows="4"
type="text"
></textarea>
</div>
</div>
<div class="dialog-actions">
<iqser-icon-button [label]="'edit-redaction.dialog.actions.save' | translate" [submit]="true" [type]="iconButtonTypes.primary">
</iqser-icon-button>
<div [translate]="'edit-redaction.dialog.actions.cancel'" class="all-caps-label cancel" mat-dialog-close></div>
</div>
</form>
<iqser-circle-button (action)="close()" class="dialog-close" icon="iqser:close"></iqser-circle-button>
</section>

View File

@ -0,0 +1,78 @@
import { Component, OnInit } from '@angular/core';
import { IconButtonTypes, IqserDialogComponent, IqserPermissionsService } from '@iqser/common-ui';
import { Dictionary, Dossier, SuperTypes } from '@red/domain';
import { FormBuilder, UntypedFormGroup } from '@angular/forms';
import { Roles } from '@users/roles';
import { JustificationsService } from '@services/entity-services/justifications.service';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
import { DictionaryService } from '@services/entity-services/dictionary.service';
import { EditRedactionData, EditRedactResult } from '../../../utils/dialog-types';
@Component({
templateUrl: 'edit-annotation-dialog.component.html',
})
export class EditAnnotationDialogComponent
extends IqserDialogComponent<EditAnnotationDialogComponent, EditRedactionData, EditRedactResult>
implements OnInit
{
readonly roles = Roles;
readonly iconButtonTypes = IconButtonTypes;
readonly redactedText: string;
dictionaries: Dictionary[] = [];
form: UntypedFormGroup;
readonly #dossier: Dossier;
constructor(
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);
const annotations = this.data.annotations;
const firstEntry = annotations[0];
this.redactedText = annotations.length === 1 ? firstEntry.value : null;
this.form = this.#getForm();
}
get displayedDictionaryLabel() {
const selectedDictionaryType = this.form.get('type').value;
if (selectedDictionaryType) {
return this.dictionaries.find(d => d.type === selectedDictionaryType)?.label ?? null;
}
return null;
}
async ngOnInit(): Promise<void> {
this.#setTypes();
}
reasonChanged() {
this.form.patchValue({ reason: this.dictionaries.find(d => d.type === SuperTypes.ManualRedaction) });
}
save(): void {
const value = this.form.value;
this.dialogRef.close({
comment: value.comment,
type: value.type,
});
}
#setTypes() {
this.dictionaries = this._dictionaryService.getRedactionTypes(this.#dossier.dossierTemplateId);
}
#getForm(): UntypedFormGroup {
return this._formBuilder.group({
comment: [null],
type: [this.data.annotations[0].type],
});
}
#allRectangles() {
return this.data.annotations.reduce((acc, a) => acc && a.rectangle, true);
}
}

View File

@ -11,7 +11,7 @@
{{ redactedText }}
</div>
<div class="iqser-input-group required w-450">
<div *ngIf="!isManualRedaction" class="iqser-input-group required w-450">
<label [translate]="'edit-redaction.dialog.content.type'"></label>
<mat-form-field>

View File

@ -31,7 +31,7 @@ export class EditRedactionDialogComponent
options: DetailsRadioOption<RedactOrHintOption>[] | undefined;
legalOptions: LegalBasisOption[] = [];
dictionaries: Dictionary[] = [];
form!: UntypedFormGroup;
form: UntypedFormGroup;
#applyToAllDossiers: boolean;
readonly #dossier: Dossier;
@ -103,10 +103,6 @@ export class EditRedactionDialogComponent
this.#setOptions(selectedDictionaryType);
}
reasonChanged() {
this.form.patchValue({ reason: this.dictionaries.find(d => d.type === SuperTypes.ManualRedaction) });
}
save(): void {
const value = this.form.value;
this.dialogRef.close({
@ -125,18 +121,17 @@ export class EditRedactionDialogComponent
#setOptions(type: string, reasonChanged = false) {
const selectedDictionary = this.dictionaries.find(d => d.type === type);
const isManualRedaction = type === SuperTypes.ManualRedaction;
this.options = getEditRedactionOptions(
this.#dossier.dossierName,
this.#applyToAllDossiers,
selectedDictionary.dossierDictionaryOnly,
this.isImage,
isManualRedaction,
this.isManualRedaction,
);
this.form.patchValue(
{
option:
this.isImage || selectedDictionary.dossierDictionaryOnly || isManualRedaction || reasonChanged
this.isImage || selectedDictionary.dossierDictionaryOnly || this.isManualRedaction || reasonChanged
? this.options[0]
: this.options[1],
},

View File

@ -70,6 +70,7 @@ import { AddHintDialogComponent } from './dialogs/add-hint-dialog/add-hint-dialo
import { AddAnnotationDialogComponent } from './dialogs/docu-mine/add-annotation-dialog/add-annotation-dialog.component';
import { RemoveAnnotationDialogComponent } from './dialogs/docu-mine/remove-annotation-dialog/remove-annotation-dialog.component';
import { ResizeAnnotationDialogComponent } from './dialogs/docu-mine/resize-annotation-dialog/resize-annotation-dialog.component';
import { EditAnnotationDialogComponent } from './dialogs/docu-mine/edit-annotation-dialog/edit-annotation-dialog.component';
import { EditRedactionDialogComponent } from './dialogs/edit-redaction-dialog/edit-redaction-dialog.component';
const routes: IqserRoutes = [
@ -94,6 +95,7 @@ const dialogs = [
RssDialogComponent,
RedactTextDialogComponent,
EditRedactionDialogComponent,
EditAnnotationDialogComponent,
AddHintDialogComponent,
RemoveRedactionDialogComponent,
AddAnnotationDialogComponent,

View File

@ -35,6 +35,7 @@ import { DossierTemplatesService } from '@services/dossier-templates/dossier-tem
import { isJustOne, List, log } from '@iqser/common-ui/lib/utils';
import { PermissionsService } from '@services/permissions.service';
import {
EditRedactionData,
RemoveRedactionData,
RemoveRedactionPermissions,
RemoveRedactionResult,
@ -46,6 +47,7 @@ import { RemoveAnnotationDialogComponent } from '../dialogs/docu-mine/remove-ann
import { ResizeRedactionDialogComponent } from '../dialogs/resize-redaction-dialog/resize-redaction-dialog.component';
import { ResizeAnnotationDialogComponent } from '../dialogs/docu-mine/resize-annotation-dialog/resize-annotation-dialog.component';
import { EditRedactionDialogComponent } from '../dialogs/edit-redaction-dialog/edit-redaction-dialog.component';
import { EditAnnotationDialogComponent } from '../dialogs/docu-mine/edit-annotation-dialog/edit-annotation-dialog.component';
@Injectable()
export class AnnotationActionsService {
@ -115,28 +117,27 @@ export class AnnotationActionsService {
applyToAllDossiers: dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault,
};
const result = await this._iqserDialog.openDefault(EditRedactionDialogComponent, { data }).result();
const result = await this.#getEditRedactionDialog(data).result();
const requests: Observable<unknown>[] = [];
if (!result) {
return;
}
const changeLegalBasisBody = annotations.map(annotation => ({
annotationId: annotation.id,
legalBasis: result.legalBasis,
section: result.section,
value: result.value,
}));
requests.push(this._manualRedactionService.changeLegalBasis(changeLegalBasisBody, dossierId, fileId));
if (result.typeChanged) {
if (!this.#isDocumine) {
const changeLegalBasisBody = annotations.map(annotation => ({
annotationId: annotation.id,
legalBasis: result.legalBasis,
section: result.section,
value: result.value,
}));
requests.push(this._manualRedactionService.changeLegalBasis(changeLegalBasisBody, dossierId, fileId));
}
if (result.typeChanged || this.#isDocumine) {
const recategorizeBody: List<IRecategorizationRequest> = annotations.map(({ id }) => ({
annotationId: id,
type: result.type,
}));
console.log({ recategorizeBody });
requests.push(this._manualRedactionService.recategorizeRedactions(recategorizeBody, dossierId, fileId));
}
@ -464,4 +465,11 @@ export class AnnotationActionsService {
}
return this._iqserDialog.openDefault(ResizeRedactionDialogComponent, { data });
}
#getEditRedactionDialog(data: EditRedactionData) {
if (this.#isDocumine) {
return this._iqserDialog.openDefault(EditAnnotationDialogComponent, { data });
}
return this._iqserDialog.openDefault(EditRedactionDialogComponent, { data });
}
}

View File

@ -164,13 +164,10 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
}
getEditableRedactionTypes(dossierTemplateId: string, isImage: boolean): Dictionary[] {
console.log(this._dictionariesMapService.get(dossierTemplateId));
return this._dictionariesMapService
.get(dossierTemplateId)
.filter(d =>
isImage
? IMAGE_CATEGORIES.includes(d.type)
: (d.hasDictionary && !d.virtual && !d.systemManaged) || d.type === SuperTypes.ManualRedaction,
)
.filter(d => (isImage ? IMAGE_CATEGORIES.includes(d.type) : d.hasDictionary && !d.virtual && !d.systemManaged))
.sort((a, b) => a.label.localeCompare(b.label));
}

View File

@ -1207,12 +1207,12 @@
"edit-redaction": {
"dialog": {
"actions": {
"cancel": "",
"save": ""
"cancel": "Cancel",
"save": "Save changes"
},
"content": {
"comment": "",
"comment-placeholder": "",
"comment": "Comment",
"comment-placeholder": "Add remarks or mentions ...",
"legal-basis": "",
"options": {
"in-dossier": {
@ -1226,12 +1226,12 @@
}
},
"reason": "",
"redacted-text": "",
"redacted-text": "Annotated text",
"section": "",
"type": ""
"type": "Type"
},
"title-edit-image": "",
"title-edit-text": ""
"title-edit-text": "Edit annotation"
}
},
"entities-listing": {