RED-9757: Check for changes in dossier dictionary
This commit is contained in:
parent
8d9df1f397
commit
2b6001402a
@ -8,7 +8,7 @@ import {
|
||||
IconButtonTypes,
|
||||
IqserDialogComponent,
|
||||
} from '@iqser/common-ui';
|
||||
import { Dictionary, Dossier, SuperTypes } from '@red/domain';
|
||||
import { Dictionary, Dossier } from '@red/domain';
|
||||
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
|
||||
import { DictionaryService } from '@services/entity-services/dictionary.service';
|
||||
import { Roles } from '@users/roles';
|
||||
@ -47,12 +47,12 @@ export class EditAnnotationDialogComponent
|
||||
extends IqserDialogComponent<EditAnnotationDialogComponent, EditRedactionData, EditRedactResult>
|
||||
implements OnInit
|
||||
{
|
||||
readonly #dossier: Dossier;
|
||||
readonly roles = Roles;
|
||||
readonly iconButtonTypes = IconButtonTypes;
|
||||
readonly redactedTexts: string[];
|
||||
dictionaries: Dictionary[] = [];
|
||||
form: UntypedFormGroup;
|
||||
readonly #dossier: Dossier;
|
||||
|
||||
constructor(
|
||||
private readonly _activeDossiersService: ActiveDossiersService,
|
||||
@ -60,7 +60,7 @@ export class EditAnnotationDialogComponent
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
) {
|
||||
super();
|
||||
this.#dossier = _activeDossiersService.find(this.data.dossierId);
|
||||
this.#dossier = this._activeDossiersService.find(this.data.dossierId);
|
||||
const annotations = this.data.annotations;
|
||||
this.redactedTexts = annotations.map(annotation => annotation.value);
|
||||
this.form = this.#getForm();
|
||||
@ -83,10 +83,6 @@ export class EditAnnotationDialogComponent
|
||||
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({
|
||||
@ -106,8 +102,4 @@ export class EditAnnotationDialogComponent
|
||||
type: [sameType ? this.data.annotations[0].type : null],
|
||||
});
|
||||
}
|
||||
|
||||
#allRectangles() {
|
||||
return this.data.annotations.reduce((acc, a) => acc && a.AREA, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<div *ngIf="dictionaries && selectedDictionary" class="dictionary-content">
|
||||
<div class="dictionaries">
|
||||
<div
|
||||
(click)="selectDictionary(dictionary)"
|
||||
(click)="selectDictionary(dictionary, undefined, true)"
|
||||
*ngFor="let dictionary of dictionaries"
|
||||
[class.active]="dictionary.label === selectedDictionary.label"
|
||||
class="dictionary"
|
||||
@ -59,12 +59,12 @@
|
||||
<ng-container slot="typeSwitch">
|
||||
<div class="flex">
|
||||
<iqser-icon-button
|
||||
(click)="selectEntryType(entryTypes.ENTRY)"
|
||||
(click)="selectEntryType(entryTypes.ENTRY, true)"
|
||||
[active]="activeEntryType === entryTypes.ENTRY"
|
||||
[label]="'edit-dossier-dialog.dictionary.to-redact' | translate: { count: selectedDictionary.entries.length }"
|
||||
></iqser-icon-button>
|
||||
<iqser-icon-button
|
||||
(click)="selectEntryType(entryTypes.FALSE_POSITIVE)"
|
||||
(click)="selectEntryType(entryTypes.FALSE_POSITIVE, true)"
|
||||
[active]="activeEntryType === entryTypes.FALSE_POSITIVE"
|
||||
[label]="
|
||||
'edit-dossier-dialog.dictionary.false-positives'
|
||||
@ -72,7 +72,7 @@
|
||||
"
|
||||
></iqser-icon-button>
|
||||
<iqser-icon-button
|
||||
(click)="selectEntryType(entryTypes.FALSE_RECOMMENDATION)"
|
||||
(click)="selectEntryType(entryTypes.FALSE_RECOMMENDATION, true)"
|
||||
[active]="activeEntryType === entryTypes.FALSE_RECOMMENDATION"
|
||||
[label]="
|
||||
'edit-dossier-dialog.dictionary.false-recommendations'
|
||||
|
||||
@ -1,5 +1,12 @@
|
||||
import { Component, Input, OnInit, ViewChild } from '@angular/core';
|
||||
import { CircleButtonComponent, IconButtonComponent, IqserDialog, LoadingService } from '@iqser/common-ui';
|
||||
import {
|
||||
CircleButtonComponent,
|
||||
ConfirmationDialogService,
|
||||
ConfirmOptions,
|
||||
IconButtonComponent,
|
||||
IqserDialog,
|
||||
LoadingService,
|
||||
} from '@iqser/common-ui';
|
||||
import { List } from '@iqser/common-ui/lib/utils';
|
||||
import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, Dossier } from '@red/domain';
|
||||
import { DictionaryService } from '@services/entity-services/dictionary.service';
|
||||
@ -42,6 +49,14 @@ export class EditDossierDictionaryComponent implements OnInit {
|
||||
readonly entryTypes = DictionaryEntryTypes;
|
||||
@ViewChild(DictionaryManagerComponent, { static: false }) private readonly _dictionaryManager: DictionaryManagerComponent;
|
||||
|
||||
constructor(
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _permissionsService: PermissionsService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _iqserDialog: IqserDialog,
|
||||
private readonly _confirmationDialogService: ConfirmationDialogService,
|
||||
) {}
|
||||
|
||||
get changed(): boolean {
|
||||
return this._dictionaryManager?.editor.hasChanges;
|
||||
}
|
||||
@ -54,13 +69,6 @@ export class EditDossierDictionaryComponent implements OnInit {
|
||||
return this._dictionaryManager?.editor.hasChanges;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _permissionsService: PermissionsService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _iqserDialog: IqserDialog,
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
this._loadingService.start();
|
||||
this.canEdit = this._permissionsService.canEditDossierDictionary(this.dossier);
|
||||
@ -95,16 +103,23 @@ export class EditDossierDictionaryComponent implements OnInit {
|
||||
this._dictionaryManager.revert();
|
||||
}
|
||||
|
||||
selectDictionary(dictionary: Dictionary, entryType?: DictionaryEntryType) {
|
||||
async selectDictionary(dictionary: Dictionary, entryType?: DictionaryEntryType, checkForChanges = false) {
|
||||
if (checkForChanges && !(await this._checkForChanges()).continue) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedDictionary = dictionary;
|
||||
this.selectEntryType(entryType);
|
||||
await this.selectEntryType(entryType);
|
||||
}
|
||||
|
||||
selectEntryType(selectedEntryType: DictionaryEntryType) {
|
||||
this.activeEntryType = selectedEntryType ?? this.activeEntryType;
|
||||
const entryType = this.selectedDictionary.hint ? DictionaryEntryTypes.ENTRY : this.activeEntryType;
|
||||
async selectEntryType(selectedEntryType: DictionaryEntryType, checkForChanges = false) {
|
||||
if (checkForChanges && !(await this._checkForChanges()).continue) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (entryType) {
|
||||
this.activeEntryType = selectedEntryType ?? this.activeEntryType;
|
||||
|
||||
switch (this.activeEntryType) {
|
||||
case DictionaryEntryTypes.ENTRY: {
|
||||
this.entriesToDisplay = this.selectedDictionary.entries;
|
||||
break;
|
||||
@ -141,13 +156,32 @@ export class EditDossierDictionaryComponent implements OnInit {
|
||||
await this.#retrieveDictionaries();
|
||||
}
|
||||
|
||||
private async _checkForChanges(): Promise<{ continue: boolean }> {
|
||||
if (this.changed) {
|
||||
const dialogRef = this._confirmationDialogService.open({ disableConfirm: !this.valid });
|
||||
const result = await firstValueFrom(dialogRef.afterClosed());
|
||||
if (result === ConfirmOptions.CONFIRM) {
|
||||
this._loadingService.start();
|
||||
const { success } = await this.save();
|
||||
this._loadingService.stop();
|
||||
if (!success) {
|
||||
return { continue: false };
|
||||
}
|
||||
} else if (!result) {
|
||||
return { continue: false };
|
||||
}
|
||||
}
|
||||
|
||||
return { continue: true };
|
||||
}
|
||||
|
||||
async #updateDossierDictionary() {
|
||||
await this.#retrieveDictionaries();
|
||||
let dictionaryToSelect = this.dictionaries[0];
|
||||
if (this.selectedDictionary) {
|
||||
dictionaryToSelect = this.dictionaries.find(d => d.type === this.selectedDictionary.type);
|
||||
}
|
||||
this.selectDictionary(dictionaryToSelect, this.activeEntryType);
|
||||
await this.selectDictionary(dictionaryToSelect, this.activeEntryType);
|
||||
}
|
||||
|
||||
async #retrieveDictionaries() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user