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